From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.

//<nowiki>

( function ( $, mw ) {

    mw.loader.load( "jquery.chosen" );

    mw.loader.load( "mediawiki.ui.input", "text/css" );



    if ( mw.config.get( "wgNamespaceNumber" ) !== 2 ) return;



    const WIKIPROJECT_LIST_AFCH = "User:Theo's Little Bot/afchwikiproject.js";

    const WIKIPROJECT_LIST_IBX = "User:Enterprisey/ibx-wproj-map.js";

    const STUBLIST = "User:Kb.au/StubSort-templates.js";



    var portletLink = mw.util.addPortletLink('p-cactions', '#', 'StubSort', 'pt-draftsort', 'Add stub tags');

    $( portletLink ).click( function ( e ) {

        e.preventDefault();



        // If it's already there, don't duplicate

        if ( $( "#draft-sorter-wrapper" ).length ) return;



        // Construct the form

        var form = $( "<div>" )

            .attr( "id", "draft-sorter-wrapper" )

            .css( { "background-image": "url(https://upload.wikimedia.org/wikipedia/commons/b/b8/OOjs_UI_icon_tag-progressive.svg)",

                    "background-repeat": "no-repeat",

                    "background-position-y": "center",

                    "background-size": "50px",

                    "margin": "1em auto",

                    "border": "thin solid #BBB",

                    "padding": "0.5em 0",

                    "padding-left": "50px",

                    "display": "inline-block",

                    "border-radius": "0.25em"

            } )

            .append( $( "<span>" )

                .text( "Loading form..." )

                .css( "color", "gray" ) );



        // Now, make two JSON calls to the WikiProject lists

        var select = $( "<select>" )

            .attr( "id", "draft-sorter-form" )

            .attr( "multiple", "multiple" );

        var wikiprojects = {}; // maps names to template names

        $.when(

            $.getJSON( mw.config.get( 'wgServer' ) + "/?title=" +

                STUBLIST + "&action=raw&ctype=text/javascript" ).done( function ( data ) {

                console.log( "got afch" );

                $.each( data, function ( name, template ) {

                    wikiprojectsname = template;

                } );

            } )

        ).then( function ( a, b ) {

            console.log( wikiprojects );

            console.log( arguments );

            $.each( wikiprojects, function ( name, template ) {

            	select.append( $( "<option>" )

            	    .attr( "value", template )

            	    .text( name ) );

            } );

            form.hide();

            form.empty();

            form.append( $( "<span>" )

                .text( "Tag WikiProjects: " )

                .css( {

                	"font-size": "115%",

                	"font-weight": "bold"

                } ) );

            form.append( select );

            form.append( $( "<button>" )

                .text( "Submit" )

                .addClass( "mw-ui-button" )

                .addClass( "mw-ui-progressive" )

                .addClass( "mw-ui-big" )

                .css( "margin-left", "0.25em" )

                .click( submit ) );

            form.append( $( "<button>" )

                        .addClass( "mw-ui-button mw-ui-destructive mw-ui-quiet" )

                        .text( "Cancel" )

                        .click( function ( e ) {

                                $( "#draft-sorter-wrapper" ).remove();

                        } ) );

            form.show();

            $( select ).chosen( {

            	"placeholder_text_multiple": "Select a stub template"

            } );

        } ).catch(function(e){console.log(e);});

        

        // Add the form to the page

        form.insertAfter( "#jump-to-nav" );

                        

        // The submission function

        var submit = function () {

        	var newTags = $( "#draft-sorter-form").val();

        	console.log( newTags );

        	var statusList = $( "<ul>" )

        	    .appendTo( "#draft-sorter-wrapper" )

        	    .append( $( "<li>" ).text( "Saving " + newTags.length + " new tags." ) );

        	var showStatus = function ( status ) {

        		return $( "<li>" )

        		    .text( status )

        		    .appendTo( statusList );

        	};

        	var newText = "";

        	newTags.forEach( function ( element ) {

        		newText += "{{" + element + "}}";

        	} );

        	$.ajax( {

                url: mw.util.wikiScript( 'api' ),

                type: 'POST',

                dataType: 'json',

                data: {

                    format: 'json',

                    action: 'edit',

                    title: mw.config.get( 'wgPageName' ),

                    summary: "Adding stub template ([[User:Kb.au/StubSort|StubSort]])",

                    token: mw.user.tokens.get( 'editToken' ),

                    appendtext: newText

                }

        	} ).done( function ( data ) {

        		if ( data && data. && data..result && data..result === "Success" ) {

        			showStatus( "Edit saved successfully! (" )

                        .append( $( "<a>" )

                            .text( "reload" )

                            .attr( "href", "#" )

                            .click( function () { document.location.reload( true ); } ) )

                        .append( ")" );

        		} else {

        			showStatus( "Couldn't save due to error: " + JSON.stringify( data ) );

        		}

        	} ).fail( function ( error ) {

        		showStatus( "Couldn't save due to error: " + JSON.stringify( error ) );

        	} );

        };

    } );

}( jQuery, mediaWiki ) );

//</nowiki>
From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.

//<nowiki>

( function ( $, mw ) {

    mw.loader.load( "jquery.chosen" );

    mw.loader.load( "mediawiki.ui.input", "text/css" );



    if ( mw.config.get( "wgNamespaceNumber" ) !== 2 ) return;



    const WIKIPROJECT_LIST_AFCH = "User:Theo's Little Bot/afchwikiproject.js";

    const WIKIPROJECT_LIST_IBX = "User:Enterprisey/ibx-wproj-map.js";

    const STUBLIST = "User:Kb.au/StubSort-templates.js";



    var portletLink = mw.util.addPortletLink('p-cactions', '#', 'StubSort', 'pt-draftsort', 'Add stub tags');

    $( portletLink ).click( function ( e ) {

        e.preventDefault();



        // If it's already there, don't duplicate

        if ( $( "#draft-sorter-wrapper" ).length ) return;



        // Construct the form

        var form = $( "<div>" )

            .attr( "id", "draft-sorter-wrapper" )

            .css( { "background-image": "url(https://upload.wikimedia.org/wikipedia/commons/b/b8/OOjs_UI_icon_tag-progressive.svg)",

                    "background-repeat": "no-repeat",

                    "background-position-y": "center",

                    "background-size": "50px",

                    "margin": "1em auto",

                    "border": "thin solid #BBB",

                    "padding": "0.5em 0",

                    "padding-left": "50px",

                    "display": "inline-block",

                    "border-radius": "0.25em"

            } )

            .append( $( "<span>" )

                .text( "Loading form..." )

                .css( "color", "gray" ) );



        // Now, make two JSON calls to the WikiProject lists

        var select = $( "<select>" )

            .attr( "id", "draft-sorter-form" )

            .attr( "multiple", "multiple" );

        var wikiprojects = {}; // maps names to template names

        $.when(

            $.getJSON( mw.config.get( 'wgServer' ) + "/?title=" +

                STUBLIST + "&action=raw&ctype=text/javascript" ).done( function ( data ) {

                console.log( "got afch" );

                $.each( data, function ( name, template ) {

                    wikiprojectsname = template;

                } );

            } )

        ).then( function ( a, b ) {

            console.log( wikiprojects );

            console.log( arguments );

            $.each( wikiprojects, function ( name, template ) {

            	select.append( $( "<option>" )

            	    .attr( "value", template )

            	    .text( name ) );

            } );

            form.hide();

            form.empty();

            form.append( $( "<span>" )

                .text( "Tag WikiProjects: " )

                .css( {

                	"font-size": "115%",

                	"font-weight": "bold"

                } ) );

            form.append( select );

            form.append( $( "<button>" )

                .text( "Submit" )

                .addClass( "mw-ui-button" )

                .addClass( "mw-ui-progressive" )

                .addClass( "mw-ui-big" )

                .css( "margin-left", "0.25em" )

                .click( submit ) );

            form.append( $( "<button>" )

                        .addClass( "mw-ui-button mw-ui-destructive mw-ui-quiet" )

                        .text( "Cancel" )

                        .click( function ( e ) {

                                $( "#draft-sorter-wrapper" ).remove();

                        } ) );

            form.show();

            $( select ).chosen( {

            	"placeholder_text_multiple": "Select a stub template"

            } );

        } ).catch(function(e){console.log(e);});

        

        // Add the form to the page

        form.insertAfter( "#jump-to-nav" );

                        

        // The submission function

        var submit = function () {

        	var newTags = $( "#draft-sorter-form").val();

        	console.log( newTags );

        	var statusList = $( "<ul>" )

        	    .appendTo( "#draft-sorter-wrapper" )

        	    .append( $( "<li>" ).text( "Saving " + newTags.length + " new tags." ) );

        	var showStatus = function ( status ) {

        		return $( "<li>" )

        		    .text( status )

        		    .appendTo( statusList );

        	};

        	var newText = "";

        	newTags.forEach( function ( element ) {

        		newText += "{{" + element + "}}";

        	} );

        	$.ajax( {

                url: mw.util.wikiScript( 'api' ),

                type: 'POST',

                dataType: 'json',

                data: {

                    format: 'json',

                    action: 'edit',

                    title: mw.config.get( 'wgPageName' ),

                    summary: "Adding stub template ([[User:Kb.au/StubSort|StubSort]])",

                    token: mw.user.tokens.get( 'editToken' ),

                    appendtext: newText

                }

        	} ).done( function ( data ) {

        		if ( data && data. && data..result && data..result === "Success" ) {

        			showStatus( "Edit saved successfully! (" )

                        .append( $( "<a>" )

                            .text( "reload" )

                            .attr( "href", "#" )

                            .click( function () { document.location.reload( true ); } ) )

                        .append( ")" );

        		} else {

        			showStatus( "Couldn't save due to error: " + JSON.stringify( data ) );

        		}

        	} ).fail( function ( error ) {

        		showStatus( "Couldn't save due to error: " + JSON.stringify( error ) );

        	} );

        };

    } );

}( jQuery, mediaWiki ) );

//</nowiki>

Videos

Youtube | Vimeo | Bing

Websites

Google | Yahoo | Bing

Encyclopedia

Google | Yahoo | Bing

Facebook