User:PerfektesChaos/js/userspaceLinks/d.js

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/// mw:User:PerfektesChaos/js/userspaceLinks/d.js
/// 2018-08-24 PerfektesChaos@de.wikipedia
//  Add specific tbox links if visiting a page related to particular user
// ResourceLoader:  compatible;
//    dependencies: user, mediawiki.util
//    namespaces:   -1, 2, 3
//    doc:          mw:User:PerfektesChaos/js/userspaceLinks
/// Fingerprint: #0#0#
/// @license GPL [//www.mediawiki.org/w/COPYING] (+GFDL, LGPL, CC-BY-SA)
/// <nowiki>
/*jshint bitwise:true, curly:true, eqeqeq:true, latedef:true,
         laxbreak:true, strict:true, trailing:true, undef:true,
         unused:true, white:false                                      */
/*global window:false                                                  */



( function ( mw, $ ) {
   "use strict";
   var Version   = -1.3,
       Sign      = "userspaceLinks",
       URSLI;
   if ( typeof mw.libs[ Sign ]  !==  "object"   ||
        !  mw.libs[ Sign ] ) {
      mw.libs[ Sign ] = { };
   }
   URSLI            =  mw.libs[ Sign ];
   URSLI.vsn        =  Version;
   URSLI.doc        =  "[[mw:User:PerfektesChaos/js/userspaceLinks]]";
   URSLI.type       =  Sign;
   URSLI.signature  =  "ext.gadget." + URSLI.type;



   // Requires: JavaScript  1.3



   URSLI.texts  =  {
      // 2014-12-15 PerfektesChaos@de.wikipedia
      "global":    {"en": "meta:/global.*"},
      "globals":   {"en": "meta:/global.* (CSS, JS) of this user",
                    "de": "meta:/global.* (CSS, JS) dieses Benutzers"},
      "subpage":   {"en": "Subpages",
                    "de": "Unterseiten"},
      "subpages":  {"en": "All subpages of this user below this page",
                    "de": "Alle Benutzer-Unterseiten dieser Seite"}
   };   // .texts



   URSLI.trans  =  {
      // 2012-11-30 PerfektesChaos@de.wikipedia
      "de" :        "de",
      "de-at" :     "de",
      "de-ch" :     "de",
      "de-formal" : "de",
      "als" :       "de",
      "bar" :       "de",
      "dsb" :       "de",
      "frr" :       "de",
      "gsw" :       "de",
      "hsb" :       "de",
      "ksh" :       "de",
      "lb" :        "de",
      "nds" :       "de",
      "pdc" :       "de",
      "pdt" :       "de",
      "pfl" :       "de",
      "sli" :       "de",
      "stq" :       "de",
      "vmf" :       "de"
   };   // .trans



   function feature( apply ) {
      // Wrap message text access for user or project language
      // Precondition:
      //    apply  -- text keyword
      // Postcondition:
      //    Return text closest to user language
      // Uses:
      //    >  .trans
      //    >  .texts
      //    >< .slang
      // Remark: To be replaced
      //         if one day ResourceLoader3 gives access to
      //         gadget@translatewiki
      // 2013-01-31 PerfektesChaos@de.wikipedia
      var e, r, s;
      if ( ! URSLI.slang ) {
         s           =  mw.config.get( "wgUserLanguage" ).toLowerCase();
         s           =  URSLI.trans[ s ];
         URSLI.slang  =  ( s ? s : "en" );
      }
      e  =  URSLI.texts[ apply ];
      if ( e ) {
         r  =  e[ URSLI.slang ];
         if ( ! r ) {
            r  =  e.en;
            if ( ! r ) {
               r  =  "???" + apply + "???";
            }
         }
      } else {
         r  =  "***" + apply + "***";
      }
      return r;
   }   // feature()



   function fiat() {
      // Equip page
      // Precondition:
      //    document has been loaded
      // Uses:
      //    >  .scope
      //    mw.config.get()
      //    feature()
      //    mw.util.wikiUrlencode()
      //    mw.util.addPortletLink()
      // 2014-12-15 PerfektesChaos@de.wikipedia
      var script    =  mw.config.get( "wgScript" ),
          subpages  =  script
                       + "?namespace=2&title=Special:Prefixindex/"
                       + mw.util.wikiUrlencode( URSLI.scope ),
          local     =  false;
      mw.util.addPortletLink( "p-tb",
                              subpages,
                              feature( "subpage" ),
                              "t-subpages",
                              feature( "subpages" ),
                              "g",
                              null );
      if ( typeof URSLI.local  ===  "boolean" ) {
         local  =  URSLI.local;
      }
      if ( ! local ) {
         subpages  =  "//meta.wikimedia.org"
                      + script
                      + "?namespace=2&title=Special:Prefixindex/"
                      + mw.util.wikiUrlencode( URSLI.scope )
                      + "/global.";
         mw.util.addPortletLink( "p-tb",
                                 subpages,
                                 feature( "global" ),
                                 "t-global",
                                 feature( "globals" ),
                                 null,
                                 null );
      }
   }   // fiat()



   function fire() {
      // Start processing, if appropriate
      // Uses:
      //    >  .signature
      //     < .nsN
      //     < .scope
      //    mw.loader.getState()
      //    mw.loader.state()
      //    mw.config.get()
      //    mw.loader.using()
      //    (fiat)
      // 2018-08-24 PerfektesChaos@de.wikipedia
      var i, rls, scope;
      if ( mw.loader.getState( URSLI.signature )  !==  "ready" ) {
         rls = { };
         rls[ URSLI.signature ] = "ready";
         mw.loader.state( rls );
         URSLI.nsN  =  mw.config.get( "wgNamespaceNumber" );
         switch ( URSLI.nsN ) {
            case -1 :   // Special
               scope  =  mw.config.get( "wgRelevantUserName" );
               if ( scope ) {
                  URSLI.scope  =  "User:" + scope;
               }
               break;
            case 2 :
            case 3 :
               URSLI.scope  =  mw.config.get( "wgTitle" );
               i            =  URSLI.scope.indexOf( "/" );
               if ( i > 1 ) {
                  URSLI.scope  =  URSLI.scope.substr( 0,  i - 1 );
               }
               break;
         }   // switch wgNamespaceNumber
         if ( URSLI.scope ) {
            mw.loader.using( [ "user",
                               "mediawiki.util" ],
                             function () {
                                $( fiat );
                             } );
         }
      }
   }   // fire()



   fire();
}( window.mediaWiki, window.jQuery ) );

/// EOF </nowiki>   userspaceLinks/d.js