User:Enterprisey/user-tabs-on-contribs.js and User:Andrybak/user-tabs-on-contribs.js: Difference between pages

From Wikipedia, the free encyclopedia
(Difference between pages)
Content deleted Content added
m Maintenance: mw:RL/MGU - Updated deprecated module name
 
add Vector 2022 CSS classes
 
Line 5: Line 5:
* whether the page exists or not. */
* whether the page exists or not. */
function utocMakeTab( label, pageName, redlink, accesskey, id ) {
function utocMakeTab( label, pageName, redlink, accesskey, id ) {
var tab = $( "<li>" ).append( $( "<span>" ).append( $( "<a>" )
var tab = $( "<li>" ).append( $( "<a>" )
.text( label )
.text( label )
.attr( "accesskey", accesskey )
.attr( "accesskey", accesskey )
.attr( "title", pageName + " (access key " + accesskey + ")" )
.attr( "title", pageName + " (access key " + accesskey + ")" )
.attr( "href", mw.util.getUrl( pageName ) ) ) )
.attr( "href", mw.util.getUrl( pageName ) ) )
.attr( "id", id );
.attr( "id", id );
if( redlink ) tab.addClass( "new" );
if( redlink ) tab.addClass( "new" );
tab.addClass('vector-tab-noicon mw-list-item');
return tab;
return tab;
}
}
Line 31: Line 32:
else userTalkPageExists = v.hasOwnProperty( "missing" );
else userTalkPageExists = v.hasOwnProperty( "missing" );
} );
} );
$( "#p-namespaces ul" )
$('#p-associated-pages').removeClass('emptyPortlet');
$( "#left-navigation nav ul" )
.append( utocMakeTab( "User page", "User:" + username, userPageExists, "c", "ca-nstab-user" ) )
.append( utocMakeTab( "User page", "User:" + username, userPageExists, "c", "ca-nstab-user" ) )
.append( utocMakeTab( "Talk", "User talk:" + username, userTalkPageExists, "t", "ca-nstab-talk" ) );
.append( utocMakeTab( "Talk", "User talk:" + username, userTalkPageExists, "t", "ca-nstab-talk" ) );

Revision as of 19:49, 3 March 2024

if( mw.config.get( "wgPageName" ).indexOf( "Special:Contributions/" ) === 0 ||
        mw.config.get( "wgPageName" ).indexOf( "Special:Contributions" ) === 0 && mw.util.getParamValue( "target" ) ) {

    /** Makes a tab linking to the given page name. redlink is a boolean indicating
     * whether the page exists or not. */
    function utocMakeTab( label, pageName, redlink, accesskey, id ) {
        var tab = $( "<li>" ).append( $( "<a>" )
                    .text( label )
                    .attr( "accesskey", accesskey )
                    .attr( "title", pageName + " (access key " + accesskey + ")" )
                    .attr( "href", mw.util.getUrl( pageName ) ) )
                .attr( "id", id );
        if( redlink ) tab.addClass( "new" );
        tab.addClass('vector-tab-noicon mw-list-item');
        return tab;
    }

    $.when(
        mw.loader.using( [ "mediawiki.api", "mediawiki.util" ] ),
        $.ready
    ).then( function () {
        var username = mw.config.get( "wgTitle" ).substring( 14 ) || mw.util.getParamValue( "target" );
        new mw.Api().get( {
             action: "query",
             titles: "User:" + username + "|User talk:" + username,
             formatversion: "2"
        } ).done( function ( data ) {
            if( data && data.query && data.query.pages ) {
                var userPageExists = true, userTalkPageExists = true;
                Object.values( data.query.pages ).forEach( function ( v ) {
                    if( v.title.startsWith( "User:" ) ) userPageExists = v.hasOwnProperty( "missing" );
                    else userTalkPageExists = v.hasOwnProperty( "missing" );
                } );
                $('#p-associated-pages').removeClass('emptyPortlet');
                $( "#left-navigation nav ul" )
                    .append( utocMakeTab( "User page", "User:" + username, userPageExists,     "c", "ca-nstab-user" ) )
                    .append( utocMakeTab( "Talk", "User talk:" + username, userTalkPageExists, "t", "ca-nstab-talk" ) );
            }
        } );
    } );
}