Fandom Developers Wiki
m (correcting mistake in script name)
m (Make the ListGroupMembers demo work)
Line 411: Line 411:
 
page: 'UserAvatarLink',
 
page: 'UserAvatarLink',
 
scripts: ['MediaWiki:UserAvatarLink.js', 'MediaWiki:User_Avatar_Finder/code.js']
 
scripts: ['MediaWiki:UserAvatarLink.js', 'MediaWiki:User_Avatar_Finder/code.js']
}
+
},
   
  +
ListGroupMembers: {
  +
page: 'Special:BlankPage/LGM',
  +
scripts: 'MediaWiki:ListGroupMembers.js'
  +
},
 
};
 
};
   

Revision as of 23:03, 23 January 2020

/*jshint curly:false, jquery:true, browser:true */
/*global mediaWiki:true, importArticles:true, importArticle:true, dev:true*/

;(function ($, mw, cfg) {
    'use strict';

    // killswitch&dblrun protection
    if ($.getUrlVar('nodemo') || cfg.loaded) return;
    cfg.loaded = true;

    var includes = {

        /**
         * possible fields:
         *
         * - selector: element(s) to look for in the page
         * - page: name of the page
         * - subpages: exclude subpages     when set to false
         * - exec: callback to execute      when selector or page are detected
         * - styles: stylesheet(s) to load  when selector or page are detected
         * - scripts: script(s) to load     when selector or page are detected
         *
         */

        JsDoc: {
            selector: '#js-doc',
            styles: 'MediaWiki:Documentation.css'
        },

        InfoWidgets: {
            selector: '#infowidgets-demo',
            styles: 'MediaWiki:InfoWidgets/demo.css',
            scripts: 'MediaWiki:InfoWidgets/demo.js'
        },

        BotoneraPopups: {
            page: 'BotoneraPopups',
            scripts: 'MediaWiki:BotoneraPopups/Code/en.js',
            styles: 'MediaWiki:BotoneraPopups.css'
        },

        /*
        // disabled in favour of ProfileTags
        UserTags: {
            exec: function () {
                window.UserTagsJS = {
                    modules: {
                        mwGroups: ['bureaucrat', 'rollback', 'sysop', 'bot', 'bot-global'],
                        metafilter: {
                            sysop: ['bureaucrat']
                        }
                    }
                };
            },
            scripts: 'MediaWiki:UserTags/code.js'
        },
        */

        ReferencePopups: {
            page: 'ReferencePopups/demo',
            scripts: 'MediaWiki:ReferencePopups/custom.js',
            styles: 'MediaWiki:ReferencePopups/demo.css'
        },

        StarRatingsUi: {
            selector: '.rating-widget',
            scripts: 'MediaWiki:StarRatings/ui.js'
        },

        DropdownMenu: {
            selector: '.custom-dropdown',
            styles: 'MediaWiki:DropdownMenu.css'
        },

        TimedSlider: {
            page: 'TimedSlider',
            scripts: 'MediaWiki:TimedSlider/code.js',
            styles: 'MediaWiki:TimedSlider/code.css'
        },

        MiniComplete: {
            page: 'MiniComplete',
            exec: function () {
                mw.loader.implement( 'minicomplete',
                    [ '/load.php?mode=articles&articles=u%3Acamtest%3AMediaWiki%3ATextareaHelper.js%7Cu%3Adev%3AColors%2Fcode.js%7Cu%3Adev%3AMiniComplete%2Fcode.js&only=scripts' ],
                        {}, {} );

                $( '#minicomplete-demo' )
                .empty()
                .append(
                    $( '<textarea>' )
                    .attr( {
                        id: 'minicomplete-textarea',
                        placeholder: 'Try the MiniComplete demo here!'
                    } )
                    .css( {
                        // 100% forces the far right edge to be cut off by
                        // .WikiaArticle {overflow:hidden;} (set in oasis.scss)
                        width: '98.3%',
                        height: '80px',
                        resize: 'none',
                        padding: '2px 5px'
                    } )
                );

                mw.loader.using( [ 'mediawiki.api', 'minicomplete' ], function () {
                    dev.minicomplete.load( '#minicomplete-textarea' );
                } );
            }
        },

        Tooltips: {
            page: 'Tooltips',
            scripts: 'MediaWiki:Tooltips.js',
            styles: 'MediaWiki:Tooltips.css',
            exec: function () {
                window.tooltips_list = [
                    {
                        classname: 'custom-tooltip-text',
                        text: "Parameter: <#parameter#><br/>This is just text and HTML - wikitext '''won't''' be parsed"
                    }, {
                        classname: 'custom-tooltip-parse',
                        parse: '{|style="white-space:nowrap;"\n!Parameter:\n|<#parameter#>\n|-\n!Lc:\n|{'+'{lc:<#parameter#>}}\n|-\n!Uc:\n|{'+'{uc:<#parameter#>}}\n|-\n!PAGENAME:\n|{'+'{PAGENAME}}\n|}'
                    }
                ];
                window.tooltips_config = { offsetX: 15, offsetY: 15 };
            }
        },

        NavboxBuilder: {
            selector: '.navbox .navbox-table-wrapper',
            styles: 'MediaWiki:Global_Lua_Modules/NavboxBuilder.css'
        },
        
        DiscordBanner: {
            page: 'DiscordBanner',
            scripts: 'MediaWiki:DiscordBanner.js',
            exec: function () {
                console.log('[DemoScrts] We\'re on the DiscordBanner page, so I hid the Discord rail module.');
                mw.util.addCSS('#WikiaRail .discord-module { display: none; }');
            }
        },

        Flags: {
            selector: '.flag-icon',
            scripts: 'MediaWiki:Flags/code.js'
        },

        GlobalEditcount: {
            page: 'User:Wikia',
            scripts: 'MediaWiki:GlobalEditcount/code.js'
        },

        QuickLogs: {
            page: 'Special:Contributions/Wikia',
            scripts: 'MediaWiki:QuickLogs/code.js'
        },

        SnowStorm: {
            page: 'SnowStorm/Demo',
            scripts: 'MediaWiki:SnowStorm.js',
            styles: 'MediaWiki:SnowStorm/demo.css'
        },

        SnowStorm1: {
            page: 'SnowStorm/Demo1',
            scripts: ['MediaWiki:SnowStorm.js/DemoSettings1.js' , 'MediaWiki:SnowStorm.js'],
            styles: 'MediaWiki:SnowStorm/demo.css'
        },

        UserActivityTab: {
            page: 'User:' + mw.config.get('wgUserName'),
            scripts: 'MediaWiki:UserActivityTab/code.js'
        },
        
        ProtectionIcons: {
            page: 'Module:Sandbox',
            scripts: 'MediaWiki:ProtectionIcons.js'
        },

        EditcountTag: {
            page: 'User:Wikia',
            scripts: 'MediaWiki:EditcountTag/code.js'
        },

        UnhideUserMasthead: {
            page: 'Special:Contributions/UnhideUserMastheadTest',
            scripts: 'MediaWiki:UnhideUserMasthead/code.js'
        },

        SnowStormCSS: {
            page: 'SnowStormCSS',
            styles: 'MediaWiki:SnowStormCSS/code.css'
        },

        MastheadGender: {
            page: 'User:Kirkburn',
            scripts: 'MediaWiki:MastheadGender/code.js'
        },

        FastFileDelete: {
            page: 'FastFileDelete',
            scripts: 'MediaWiki:FastFileDelete.js',
            exec: function () {
                (window.dev = window.dev || {}).fastFileDelete = window.dev.fastFileDelete || {};
                window.dev.fastFileDelete.groups = '\\*';
            }
        },

        WantedPagesFilter: {
            page: 'WantedPagesFilter',
            scripts: 'MediaWiki:WantedPagesFilter/code.js',
            exec: function () {
                window.wgCanonicalSpecialPageName = 'Wantedpages';
            }
        },

        WikiaNotification: {
            page: 'WikiaNotification',
            scripts: 'MediaWiki:WikiaNotification/code.js',
            exec: function () {
                window.localStorage.removeItem('ls-wikianotifications');
            }
        },

        Wikificator: {
            page: 'Wikificator',
            scripts: ['MediaWiki:Wikificator.js', 'MediaWiki:TrymeButton.js'],
            exec: function () {
                if ($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1) return;
                mw.loader.load('jquery.textSelection');
                window.wikificator = window.wikificator || {};
                window.wikificator.forced = true;
                var t = $('#wpTextbox1').text();
                $('#wpTextbox1').replaceWith($('<textarea>', {id: 'wpTextbox1', value: t, style: 'width:inherit;min-width:50%;height:inherit;min-height:100px;'}));
            }
        },
        
        ModernRail: {
            page: 'ModernRail',
            styles: 'MediaWiki:ModernRail.css'
        },

        CSSForTheColorBlind: {
            page: 'CSSForTheColorBlind',
            styles: 'MediaWiki:CSSForTheColorBlind.css'
        },

        FandomIcons: {
            page: 'FandomIcons',
            styles: 'MediaWiki:FandomIcons.css'
        },

        Contextlink: {
            selector: '.context-link',
            styles: 'MediaWiki:Global_Lua_Modules/Context-link.css'
        },

        Mbox: {
            selector: '.mbox',
            styles: 'MediaWiki:Global_Lua_Modules/Mbox.css'
        },

        Quote: {
            selector: '.pull-quote',
            styles: 'MediaWiki:Global_Lua_Modules/Quote.css'
        },

        Less: {
            selector: 'body.page-MediaWiki_Custom-Less_test_less, body.page-MediaWiki_Custom-Less_test_css',
            scripts: 'MediaWiki:Less/code.2.js',
            exec: function () {
                // example config used for testing
                window.lessOpts = [{
                    target: 'MediaWiki:Custom-Less/test.css',
                    source: 'MediaWiki:Custom-Less/test.less',
                    load: [
                        'MediaWiki:Custom-Less/test.css',
                        'MediaWiki:Custom-Less/test.less'
                    ],
                    header: 'MediaWiki:Custom-less-header'
                }];
                window.lessConfig = {
                    allowed: ['user']
                };
            }
        },

        LightGlobalNav: {
            page: 'LightGlobalNav',
            styles: 'MediaWiki:LightGlobalNav.css'
        },

        Katsuragi: {
            page: 'Katsuragi',
            styles: 'MediaWiki:Katsuragi.css'
        },

        BackToTopButton: {
            page: 'BackToTopButton',
            scripts: 'MediaWiki:BackToTopButton/code.js',
            exec: function () {
                window.BackToTopModern = true;
            }
        },
        BlendGlobalNav: {
            page: 'BlendGlobalNav',
            styles: 'MediaWiki:BlendGlobalNav.css'
        },
        UpgradedToolbar: {
            page: 'UpgradedToolbar',
            styles: 'MediaWiki:UpgradedToolbar.css'
        },

        GlobalNavigationIcons: {
            page: 'GlobalNavigationIcons',
            styles: 'MediaWiki:GlobalNavigationIcons.css'
        },

        SearchSuggest: {
            page: 'Special:Search',
            scripts: 'MediaWiki:SearchSuggest/code.js'
        },

        UserCheck: {
            page: 'Special:Contributions/Klopsik600',
            scripts: 'MediaWiki:UserCheck/code.js'
        },

        DisambiguationManagement: {
            page: 'Special:Disambiguations',
            scripts: 'MediaWiki:DisambiguationManagement/code.js'
        },

        FileLogs: {
            page: 'File:QQX_Oasis.png',
            scripts: 'MediaWiki:FileLogs.js'
        },
        
        MastheadRightsBadge: {
            page: 'User:Americhino',
            scripts: 'MediaWiki:MastheadRightsBadge.js'
        },

        TZclock: {
            page: 'TZclock',
            scripts: 'MediaWiki:TZclock.js',
            styles: 'MediaWiki:TZclock.css'
        },

        UserStatus: {
            page: 'User:SapphireSonata',
            scripts: 'MediaWiki:UserStatus/demo.js'
        },

        ProfileTags: {
            page: 'User:Rappy_4187',
            scripts: 'MediaWiki:ProfileTags.js'
        },

        ShowHide: {
            page: 'ShowHide',
            scripts: 'MediaWiki:ShowHide/code.js',
            styles: 'MediaWiki:ShowHide.css',
            exec: function() {
                // allow to show the banner on the doc page
                window.ShowHideDisplayWarning = true;
                // show the banner every time
                $.storage.del('ShowHide-warning');
            },
        },

        CollapsibleInfobox: {
            page: 'CollapsibleInfobox',
            scripts: 'MediaWiki:CollapsibleInfobox/code.js',
            styles: 'MediaWiki:CollapsibleInfobox.css'
        },

        MoreSocialLinks: {
            page: 'User:KockaAdmiralac',
            scripts: 'MediaWiki:MoreSocialLinks.js'
        },

        PortableNavbox: {
            selector: '.portable-infobox.pi-theme-navbox',
            styles: 'MediaWiki:PortableNavbox.css'
        },
 
        FontAwesome5: {
            page: 'FontAwesome5',
            styles: 'MediaWiki:FontAwesome5.css'
        },

        TableHash: {
            page: 'TableHash',
            scripts: 'MediaWiki:TableHash.js',
            styles: 'MediaWiki:TableHash.css'
        },
        
        ProgressBar: {
            page: 'ProgressBar',
            styles: 'MediaWiki:ProgressBar.css'
        },

        EditcountTab: {
            page: 'User:Puxlit',
            scripts: 'MediaWiki:EditcountTab.js'
        },

        UserAvatarLink: {
            page: 'UserAvatarLink',
            scripts: ['MediaWiki:UserAvatarLink.js', 'MediaWiki:User_Avatar_Finder/code.js']
        },

        ListGroupMembers: {
            page: 'Special:BlankPage/LGM',
            scripts: 'MediaWiki:ListGroupMembers.js'
        },
    };

    function merge (other) {
        /*jshint validthis:true*/
        var self = this;

        if (Array.isArray(other)) {
            other.forEach(function (elem) {
                if (self.indexOf(elem) === -1) {
                    self.push(elem);
                }
            });
        } else {
            self.push(other);
        }
    }

    $.get(mw.util.wikiScript('load'), {
        mode: 'articles',
        articles: 'MediaWiki:Custom-DemoScripts.json',
        only: 'styles',
        cb: Date.now()
    }).always(function(data) {
        if (data && !data.error) {
            data = JSON.parse(data.replace(/\/\*.*\*\//g, ''));
            $.each(data, function() {
                this.restricted = 1;
            });
            // keep includes on top and preserve it from overwriting by data
            includes = $.extend(true, {}, includes, data, includes);
        }
        $(function () {
            var scripts = [],
                styles = [],
                page = mw.config.get('wgPageName'),
                basepage = page.replace(/\/.*/, '');

            scripts.merge = merge;
            styles.merge = merge;

            $.each(includes, function (name, actions) {
                var pageRestriction = new RegExp('^MediaWiki:' + basepage + '(/.*)*\\.js$');
                if (actions.restricted) {
                    actions.selector = '#mw-content-text ' + (actions.selector || '').split(',')[0];
                    if (actions.scripts) {
                        if (actions.scripts instanceof Array) {
                            actions.disabled = actions.disabled || !actions.scripts.every(function(v) {
                                return (!/\|/.test(v) && pageRestriction.test(v));
                            });
                        } else {
                            actions.disabled = actions.disabled ||
                                (!(!/\|/.test(actions.scripts) && pageRestriction.test(actions.scripts)));
                        }
                    }
                }

                if (actions.disabled) {
                    return;
                }

                if (actions.selector && !$(actions.selector).length) {
                    return;
                }

                if (actions.page && (actions.subpages === false ? page : basepage) !== actions.page) {
                    return;
                }

                if (actions.exec && !actions.restricted) {
                    actions.exec();
                }

                if (actions.styles && !actions.restricted) {
                    styles.merge(actions.styles);
                }

                if (actions.scripts) {
                    scripts.merge(actions.scripts);
                }
            });

            if (scripts.length) {
                importArticles({ type: 'script', articles: scripts });
            }
            if (styles.length) {
                importArticles({ type: 'style', articles: styles });
            }
        });
    });
}(jQuery, mediaWiki, (window.dev = window.dev || {}).demoscripts = window.dev.demoscripts || {}));