User:PerfektesChaos/js/pageLinkHelper/d.js

This is an old revision of this page, as edited by PerfektesChaos (talk | contribs) at 19:36, 1 January 2015 (-1.91). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
/// Gadget-pageLinkHelper.js
//  Some minor link helpers
// ResourceLoader:  compatible;  dependencies: user, mediawiki.util
/// 2014-12-30 PerfektesChaos@de.wikipedia
/// Fingerprint: #0#0#
/// [[w:en:User:PerfektesChaos/js/pageLinkHelper]]
/// <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.91,
       Sign      = "pageLinkHelper",
       Signature = "ext.gadget." + Sign,
       Shop      = "w:en:User:PerfektesChaos/js/",
       Config, Env, PLH;



   Config = { PermanentLink: { "*": "PermaLink" },
              Redirect:      { de: "Weiterleitung" },
              permTitle:     { "*": "PermaLink" },
              purgeLUtip:    { en: "PURGE this page"
                                   + " and force link update",
                               de: "PURGE mit rekursivem Linkupdate" },
              purgeLUtitle:  { en: "PURGE/linkupdate",
                               de: "PURGE/linkupdate" },
              purgeLURtip:   { en: "PURGE this page"
                                   + " and force recursive link update",
                               de: "PURGE mit rekursivem Linkupdate" },
              purgeLURtitle: { en: "PURGE/recursive",
                               de: "PURGE/rekursiv" },
              purgeTip:      { en: "PURGE this page from server cache",
                               de: "PURGE:"
                                   + " Diese Seite"
                                   + " im Server-Cache aktualisieren" },
              purgeTitle:    { en: "Purge cache",
                               de: "Seite purgen" },
              qqxTip:        { en: "Reload"
                                   + " and show interface element IDs" },
              qqxTitle:      { en: "lang=qqx" },
              translate:     { "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" }
            };   // 2014-12-22 PerfektesChaos@de.wikipedia



   function $factory( access ) {
      // Create <div> for upper right corner
      // Precondition:
      //    access  -- distinguishing selector ID
      // Uses:
      //    >  Sign
      // 2014-12-19 PerfektesChaos@de.wikipedia
      var space = "4px",
          style = "#B0C4DE 1px solid",
          $r    = $( "<div>" );
      $r.attr( { "class": Sign,
                 "id":    access } );
      $r.css( { "border-bottom":    style,
                "border-left":      style,
                "background-color": "#FFFFFF",
                "background":       "rgba(255, 255, 255, 0.5)",
                "float":            "right",
                "font-family":      "monospace",
                "margin-bottom":    "1em",
                "margin-left":      "1em",
                "margin-top":       space,
                "padding-bottom":   space,
                "padding-right":    space,
                "padding-left":     space } );
      return $r;
   }   // $factory()



   function $float( $apply ) {
      // Insert/exchange upper right corner element
      // Precondition:
      //    $apply  -- jQuery element to insert
      //               false to check availability
      // Postcondition:
      //    Returns true, if insertion possible
      // Uses:
      //    >  Sign
      //    >< Env
      // 2014-12-19 PerfektesChaos@de.wikipedia
      var r,   // = undefined
          sequence, suitable, $anchor, $clear;
      if ( typeof Env.$corner  ===  "undefined" ) {
         Env.$corner = $( "<div>" );
         Env.$corner.attr( { "class": Sign,
                             "id":    Sign + "Corner" } );
         if ( ! Env.skin ) {
            Env.skin = mw.config.get( "skin" );
         }
         switch ( Env.skin ) {
            case "cologneblue" :
               suitable = "firstHeading";
               sequence = "after";
               break;
            case "modern" :
               suitable = "contentSub";
               sequence = "before";
               break;
            case "monobook" :
            case "vector" :
               suitable = "bodyContent";
               sequence = "prepend";
               break;
         }   // switch Env.skin
         $anchor = $( "#" + suitable );
         if ( ! $anchor.length ) {
            $anchor  = $( "#firstHeading" );
            sequence = "after";
         }
         if ( $anchor.length ) {
            $anchor[ sequence ]( Env.$corner );
            $clear = $( "<div>" );
            $clear.css( { "clear": "left" } );
            Env.$corner.after( $clear );
         } else {
            Env.$corner = false;
         }
      }
      if ( Env.$corner ) {
         Env.$corner.empty();
         Env.$corner.prepend( $apply );
         r = true;
      }
      return r;
   }   // $float()



   function face() {
      // Initialize environment and application object, if user defined
      // Precondition:
      //    module 'user' loaded
      // Postcondition:
      //
      // Uses:
      //    >  mw.libs
      //    >  Sign
      //    >  Version
      //    >  Shop
      //    >< PLH
      // 2014-12-22 PerfektesChaos@de.wikipedia
      if ( typeof mw.libs[ Sign ]  ===  "object"   &&
           mw.libs[ Sign ]   &&
           ! PLH ) {
         PLH     = mw.libs[ Sign ];
         PLH.vsn = Version;
         PLH.doc = "[[" + Shop + Sign + "]]";
      }
   }   // face()



   function facet( applied ) {
      // Check for user option
      // Precondition:
      //    applied  -- option keyword
      //    module 'user' loaded
      // Postcondition:
      //    Returns value, or undefined
      // Uses:
      //    >  PLH
      //    face()
      // 2014-12-19 PerfektesChaos@de.wikipedia
      var r;   // = undefined
      face();
      if ( PLH   &&   typeof PLH[ applied ]  !==  "undefined" ) {
         r = PLH[ applied ];
      }
      return r;
   }   // facet()



   function facility( available ) {
      // Localize in user language, GUI only
      // Precondition:
      //    available  -- translation object
      // Postcondition:
      //    Returns string, or undefined
      // Uses:
      //    >  Config
      //    >< Env
      //    mw.config.get()
      // 2014-12-16 PerfektesChaos@de.wikipedia
      var i, r, slang;
      if ( ! Env.userLang ) {
         Env.userLang = mw.config.get( "wgUserLanguage" ).toLowerCase();
      }
      slang = Env.userLang;
      if ( typeof available[ slang ]  ===  "string" ) {
         r = available[ slang ];
      } else {
         i = slang.indexOf( "-", 2 );
         if ( i > 0 ) {
            slang = slang.substr( 0, i );
            if ( typeof available[ slang ]  ===  "string" ) {
               r = available[ slang ];
            }
         }
      }
      if ( ! r ) {
         if ( typeof Config.translate[ slang ]  ===  "string" ) {
            slang = Config.translate[ slang ];
            if ( typeof available[ slang ]  ===  "string" ) {
               r = available[ slang ];
            }
         }
         if ( ! r ) {
            r = available.en;
         }
      }
      return r;
   }   // facility()



   function fair( access, adapt, alter ) {
      // Localization
      // Precondition:
      //    access  -- configuration keyword
      //    adapt   -- false, if project (language) dependant
      //               else user language dependant
      //    alter   -- default string (en)
      // Postcondition:
      //    Returns value, or keyword 'access'
      // Uses:
      //    >  PLH
      //    >  Config
      //    >< Env
      //    face()
      //    facility()
      //    mw.config.get()
      // 2014-12-20 PerfektesChaos@de.wikipedia
      var el, r, say;
      if ( alter ) {
         r = alter;
      } else {
         r = access;
      }
      face();
      if ( PLH   &&
           typeof PLH.config  ===  "object"   &&
           PLH.config   &&
           typeof PLH.config[ access ]  ===  "object" ) {
         el = PLH.config[ access ];
      }
      if ( ! el ) {
         el = Config[ access ];
      }
      if ( el ) {
         if ( adapt ) {
            say = facility( el );
            if ( say ) {
               r = say;
            } else if ( typeof alter  !==  "string" ) {
               r = "???" + access + "???";
            }
         } else {
            if ( ! Env.wgDBname ) {
               Env.wgDBname = mw.config.get( "wgDBname" );
            }
            if ( typeof el[ Env.wgDBname ]  ===  "string" ) {
               r = el[ Env.wgDBname ];
            } else {
               if ( ! Env.wgContentLanguage ) {
                  Env.wgContentLanguage
                                  = mw.config.get( "wgContentLanguage" );
               }
               if ( typeof el[ Env.wgContentLanguage ]  ===  "string" ) {
                  r = el[ Env.wgContentLanguage ];
               }
            }
         }
      } else if ( adapt ) {
         r = "???" + access + "???";
      }
      return r;
   }   // fair()



   function favorite( apply ) {
      // Insert portlet link, if appropriate
      // Precondition:
      //    apply  -- object
      //              .signature  -- user option keyword
      //              .skins      -- default skins, if any
      //                             true; or "|vector|" etc.
      //              .fun        -- callback for link generation
      //              .show       -- link title keyword
      //              .support    -- tooltip keyword
      //              OPTIONAL:
      //              .suffix     -- selector creation
      //    DOM.ready
      //    mediawiki.util loaded
      //    user resources loaded
      // Postcondition:
      //    Returns DOM of portlet, or undefined
      // Uses:
      //    >< Env
      //    facet()
      //    mw.config.get()
      //    fair()
      //    mw.util.addPortletLink()
      //    (apply.fun)
      // 2014-12-19 PerfektesChaos@de.wikipedia
      var opt   = facet( apply.signature ),
          seed  = null,
          slot  = "p-cactions",
          start = "ca",
          got, r, re, skins, suffix, swap;
      switch ( typeof opt ) {
         case "boolean" :
            if ( opt ) {
               seed  = false;
               skins = true;
            } else {
               slot = false;
            }
            break;
         case "string" :
            seed = opt;
            re   = /^([a-z]+)-(.+)$/;
            got  = re.exec( seed );
            if ( got ) {
               switch ( got[ 1 ] ) {
                  case "p" :
                     slot = seed;
                     seed = false;
                     switch ( got[ 2 ] ) {
                        case "navigation" :
                           start = "n";
                           break;
                        case "tb" :
                           start = "t";
                           break;
                     }   // switch got.2
                     break;
                  case "ca" :
                     break;
                  case "n" :
                     slot = "p-navigation";
                     break;
                  case "t" :
                     slot = "p-tb";
                     break;
               }   // switch got.1
            }
            break;
      }   // switch typeof opt
      if ( slot  &&  seed === null ) {
         if ( ! skins ) {
            switch ( typeof apply.skins ) {
               case "boolean" :
               case "string" :
                  skins = apply.skins;
                  break;
            }   // switch typeof apply.skins
         }
         if ( skins === true ) {
            skins = "|vector|";
         }
         if ( skins ) {
            if ( ! Env.skin ) {
               Env.skin = mw.config.get( "skin" );
            }
            if ( skins.indexOf( Env.skin )  <  0 ) {
               if ( opt ) {
                  slot  = "p-tb";
                  start = "t";
               } else {
                  slot = false;
               }
            }
         } else {
            slot = false;
         }
      }
      if ( slot ) {
         swap = apply.fun();
         if ( typeof apply.suffix  ===  "string" ) {
            suffix = apply.suffix;
         } else {
            suffix = apply.signature;
         }
         if ( seed ) {
            seed = "#" + seed;
         }
         r = mw.util.addPortletLink( slot,
                                     swap,
                                     fair( apply.show, true ),
                                     start + "-" + suffix,
                                     fair( apply.support, true ),
                                     null,
                                     seed );
      }
      return r;
   }   // favorite()



   function fiat( apply, at ) {
      // Equip diffpage revision with wikilink for permalink c&p
      // Precondition:
      //    apply  -- revision ID, or some keyword
      //    at     -- revision column; "n" or "o"
      //    DOM.ready
      //    Diffpage
      // Uses:
      //    >  Sign
      //    >  Env.spcNS
      //    mw.config.get()
      //    mw.util.getParamValue()
      // 2014-12-16 PerfektesChaos@de.wikipedia
      var $div  = $( "#mw-diff-" + at + "title1" ),
          id, s, $a, $span;
      if ( $div.length ) {
         if ( apply ) {
            id = apply;
            if ( apply === "cur" ) {
               id = mw.config.get( "wgCurRevisionId" );
            } else if ( typeof apply  === "string"   &&
                        ! /^\d+$/.test( apply ) ) {   // "next"
               id = false;
            }
         }
         if ( ! id ) {
            $a = $div.find( "a" ).eq( 0 );
            s  = $a.attr( "href" );
            id = mw.util.getParamValue( "oldid", s );
         }
         if ( id ) {
            s     = "[[" + Env.spcNS + ":PermanentLink/" + id + "]]";
            $span = $( "<span>" );
            $span.attr( { "class":  Sign + " " + Sign + "DiffRev" } );
            $span.css( { "font-family": "monospace",
                         "margin-left": "1em" } );
            $span.text( s );
            $div.append( $span );
         }
      }
   }   // fiat()



   function flat( ahead ) {
      // Provide "uselang=qqx" link
      // Precondition:
      //    ahead  -- true if initializing, false to link
      //    DOM.ready
      //    mediawiki.util loaded
      //    user resources loaded
      // Postcondition:
      //    Returns link, or undefined
      // Uses:
      //    >  ___location
      //    favorite()
      //    (flat)
      // 2014-12-19 PerfektesChaos@de.wikipedia
      var r;
      if ( ahead ) {
         favorite( { signature: "slangQQX",
                     skins:     false,
                     fun:       flat,
                     show:      "qqxTitle",
                     support:   "qqxTip",
                     suffix:    "langQQX"
                   } );
      } else {
         r = window.___location.href;
         r = r.replace( /^(.+)#.+$/, "$1" )
              .replace( /([?&])uselang=[^&]*(&.*)?$/, "$1$2" );
         if ( ! /[?&]$/.test( r ) ) {
            if ( r.indexOf( "?" )  >  0 ) {
               r = r + "&";
            } else {
               r = r + "?";
            }
         }
         r = r + "uselang=qqx";
      }
      return r;
   }   // flat()



   function flip() {
      // Equip diffpage with wikilink for c&p
      // Precondition:
      //    DOM.ready
      //    mediawiki.util loaded
      // Uses:
      //    >  Sign
      //    >  ___location
      //    >  history
      //    >  document
      //    >< Env
      //    mw.config.get()
      //    $float()
      //    $factory()
      //    fiat()
      //    history.___replaceState()
      //    mw.util.wikiUrlencode()
      //    freezer()
      // 2014-12-29 PerfektesChaos@de.wikipedia
      var sign = Sign + "Difflink",
          $div = $( "#" + sign ),
          caused, got, i, id1, id2, j, re, show, story, state, $span;
      if ( ! $div.length  &&  $float() ) {
         if ( Env.wgCanonicalSpecialPageName ) {
            // 2014 redirected to &diff=
            re  = /\/wiki\/[^:]+:[^\/]+\/(\d+)(?:\/(\.+))?$/;
            got = re.exec( window.___location.pathname );
            if ( got ) {
               id1 = got[ 1 ];
               id2 = got[ 2 ];
            }
         } else {
            id1 = Env.diff;
            id2 = Env.oldid;
         }
         if ( id1 ) {
            i = parseInt( id1, 10 );
            if ( id2 ) {
               j = parseInt( id2, 10 );
               if ( isNaN( i ) ) {
                  if ( isNaN( j ) ) {
                     id2 = false;
                  } else {
                     id2 = id1;
                     id1 = j;
                  }
               } else {
                  id1 = i;
                  if ( ! isNaN( j )  &&  i > j ) {
                     id2 = i;
                     id1 = j;
                  }
               }
               if ( id2 === "prev" ) {
                  id2 = false;
               }
            } else if ( isNaN( i ) ) {
               id1 = false;
            } else {
               id1 = i;
            }
         }
         if ( id1 ) {
            Env.spcNS = mw.config.get( "wgFormattedNamespaces" )[ "-1" ];
            story     = ":Diff/" + id1
                        + ( id2  ?  "/" + id2  :  "" );
            show      = "[[" + Env.spcNS + story + "]]";
            $span     = $( "<span>" );
            $span.text( show );
            $div = $factory( sign );
            $div.append( $span );
            $float( $div );
            if ( id2 ) {
               fiat( id1, "o" );
               fiat( id2, "n" );
            } else {
               fiat( false, "o" );
               fiat( false, "n" );
            }
            if ( typeof window.history.___replaceState  ===  "function" ) {
               if ( ! Env.wgPageName ) {
                  Env.wgPageName = mw.config.get( "wgPageName" );
               }
               state  = "/wiki/"
                        + mw.util.wikiUrlencode( Env.spcNS ) + story
                        + "?title="
                        + mw.util.wikiUrlencode( Env.wgPageName );
               caused = { caused: Sign };
               window.history.___replaceState( caused,
                                            window.document.title,
                                            state );
            }
         }
      }
      freezer( true );
   }   // flip()



   function freeze() {
      // Equip page with wikilink to perma for c&p
      // Precondition:
      //    DOM.ready
      //    mediawiki.util loaded
      // Uses:
      //    >  Sign
      //    >< Env
      //    mw.config.get()
      //    $float()
      //    $factory()
      //    mw.util.wikiUrlencode()
      //    mw.util.getUrl()
      //    fair()
      //    freezer()
      // 2014-12-29 PerfektesChaos@de.wikipedia
      var sign = Sign + "Permalink",
          $div = $( "#" + sign ),
          show, special, swift, $a, $br, $spanBeg, $spanEnd;
      if ( ! $div.length  &&  $float() ) {
         if ( ! Env.wgPageName ) {
            Env.wgPageName = mw.config.get( "wgPageName" );
         }
         if ( Env.curid ) {
            Env.curid = parseInt( Env.curid, 10 );
         } else {
            Env.curid = mw.config.get( "wgArticleId" );
         }
         if ( Env.oldid ) {
            Env.oldid = parseInt( Env.oldid, 10 );
         } else {
            Env.oldid = mw.config.get( "wgCurRevisionId" );
         }
         $div     = $factory( sign );
         special  = mw.config.get( "wgFormattedNamespaces" )[ "-1" ]
                    + ":";
         swift    = "?title="
                    + mw.util.wikiUrlencode( Env.wgPageName );
         $spanBeg = $( "<span>" );
         $spanBeg.text( "[[" );
         $spanEnd = $( "<span>" );
         $spanEnd.text( "]]" );
         $a = $( "<a>" );
         if ( Env.oldid ) {
            $div.append( $spanBeg.clone() );
            show = special
                   + fair( "PermanentLink", false, "PermaLink" )
                   + "/" + Env.oldid;
            $a.attr( { "href":  mw.util.getUrl( show ) + swift } );
            $a.text( show );
            $div.append( $a );
            $div.append( $spanEnd.clone() );
            $br = $( "<br />" );
            $div.append( $br );
            $a = $( "<a>" );
         }
         $div.append( $spanBeg );
         show = special
                + fair( "Redirect", false )
                + "/page/" + Env.curid;
         $a.attr( { "href":  mw.util.getUrl( show ) + swift } );
         $a.text( show );
         $div.append( $a );
         $div.append( $spanEnd );
         $float( $div );
         freezer( false );
      }
   }   // freeze()



   function freezer( assign ) {
      // Change portlet for permalink
      // Precondition:
      //    assign  -- true if link to be diverted, false to gray out
      //    DOM.ready
      // Uses:
      //    >  Sign
      //    >  Version
      //    fair()
      //    (freeze)
      // 2014-12-19 PerfektesChaos@de.wikipedia
      var $portlet = $( "#t-permalink" ),
          show, support, $a, $span;
      if ( $portlet.length ) {
         support = Sign + " " + Version;
         if ( assign ) {
            $a = $( "<a>" );
            $a.attr( { "title": support } );
            $a.click( freeze );
            $a.text( fair( "permTitle", false, "PermaLink" ) );
            $portlet.empty();
            $portlet.append( $a );
         } else {
            $a   = $portlet.find( "a" );
            show = $a.text();
            if ( show ) {
               $span = $( "<span>" );
               $span.css( { "color": "#808080" } );
               $span.text( show );
               $span.attr( { "title": support } );
               $portlet.empty();
               $portlet.append( $span );
            }
         }
      }
   }   // freezer()



   function fresh( ahead ) {
      // Provide purge link
      // Precondition:
      //    ahead  -- true if initializing, false to link
      //    DOM.ready
      //    mediawiki.util loaded
      //    user resources loaded
      // Postcondition:
      //    Returns link, or undefined
      // Uses:
      //    >< Env
      //    favorite()
      //    mw.config.get()
      //    mw.util.getUrl()
      //    (fresh)
      // 2014-12-29 PerfektesChaos@de.wikipedia
      var r;
      if ( ahead ) {
         favorite( { signature: "purge",
                     skins:     true,
                     fun:       fresh,
                     show:      "purgeTitle",
                     support:   "purgeTip",
                     suffix:    "purge"
                   } );
      } else {
         if ( ! Env.wgPageName ) {
            Env.wgPageName = mw.config.get( "wgPageName" );
         }
         r = mw.util.getUrl( Env.wgPageName,
                             { action: "purge" } );
      }
      return r;
   }   // fresh()



   function fresher( ahead ) {
      // Provide forcelinkupdate purge link
      // Precondition:
      //    ahead  -- true if initializing, false to link
      //    DOM.ready
      //    mediawiki.util loaded
      //    user resources loaded
      // Postcondition:
      //    Returns link, or undefined
      // Uses:
      //    >< Env
      //    favorite()
      //    mw.config.get()
      //    mw.util.wikiScript()
      //    (fresher)
      // 2014-12-28 PerfektesChaos@de.wikipedia
      var r;
      if ( ahead ) {
         if ( typeof Env.curid  !==  "number" ) {
            Env.curid = mw.config.get( "wgArticleId" );
         }
         if ( Env.curid ) {
            favorite( { signature: "forcelinkupdate",
                        skins:     false,
                        fun:       fresher,
                        show:      "purgeLUtitle",
                        support:   "purgeLUtip",
                        suffix:    "purgeLinkUpd"
                      } );
         }
      } else {
         r = mw.util.wikiScript( "api" )
             + "?action=purge&pageids=" + Env.curid
             + "&forcelinkupdate";
      }
      return r;
   }   // fresher()



   function freshest( ahead ) {
      // Provide forcerecursivelinkupdate purge link
      // Precondition:
      //    ahead  -- true if initializing, false to link
      //    DOM.ready
      //    mediawiki.util loaded
      //    user resources loaded
      // Postcondition:
      //    Returns link, or undefined
      // Uses:
      //    >< Env
      //    favorite()
      //    mw.config.get()
      //    mw.util.wikiScript()
      //    (freshest)
      // 2014-12-28 PerfektesChaos@de.wikipedia
      var r;
      if ( ahead ) {
         if ( typeof Env.curid  !==  "number" ) {
            Env.curid = mw.config.get( "wgArticleId" );
         }
         if ( Env.curid ) {
            favorite( { signature: "forcerecursivelinkupdate",
                        skins:     false,
                        fun:       freshest,
                        show:      "purgeLURtitle",
                        support:   "purgeLURtip",
                        suffix:    "purgeLinkUpdRec"
                      } );
         }
      } else {
         r = mw.util.wikiScript( "api" )
             + "?action=purge&pageids=" + Env.curid
             + "&forcerecursivelinkupdate";
      }
      return r;
   }   // freshest()



   function from() {
      // Redirected from somewhere
      // Precondition:
      //    mediawiki.util loaded
      // Uses:
      //    >  history
      //    >  ___location
      //    >  document
      //    >  Sign
      //    >< Env
      //    mw.util.getUrl()
      //    facet()
      //    history.___pushState()
      //    history.___replaceState()
      // 2014-12-07 PerfektesChaos@de.wikipedia
      var caused, opts, last, legacy, show, showed, state, swap;
      if ( typeof window.history.___pushState  ===  "function"  &&
           typeof window.history.___replaceState  ===  "function" ) {
         swap = mw.util.getUrl( Env.wgRedirectedFrom,
                                { redirect: "no" } );
         if ( window.history.previous ) {
            // should actually not cause wgRedirectedFrom, but avoid
            last = ( window.history.previous.indexOf( swap )  >=  0 );
         }
         if ( ! last ) {
            opts = facet( "redirect" );
            if ( opts   &&
                 typeof opts  ===  "object"   &&
                 typeof opts.legacy  ===  "boolean" ) {
               legacy = opts.legacy;
            }
            showed = window.document.title;
            caused = { caused: Sign };
            if ( legacy ) {
               state = mw.util.getUrl( Env.wgRedirectedFrom );
            } else {
               state = window.___location.href;
            }
            show = "#REDIRECT " + Env.wgRedirectedFrom;
            window.history.___replaceState( caused, show, swap );
            window.history.___pushState( caused, showed, state );
         }
      }
   }   // from()



   function further( amount ) {
      // Convert links on page into Special: format
      // Precondition:
      //    amount  -- number of links per item to inspect
      //    DOM.ready
      //    mediawiki.util loaded
      // Uses:
      //    mw.util.getParamValue()
      // 2014-12-14 PerfektesChaos@de.wikipedia
      var $results = $( "#mw-content-text li" ),
          n        = $results.length,
          i, j, shift, special, start, strip, $a, $li;
      if ( n ) {
         special  = "/wiki/"
                    + mw.config.get( "wgFormattedNamespaces" )[ "-1" ]
                    + ":";
         for ( i = 0;  i < n;  i++ ) {
            $li = $results.eq( i ).find( "a" );
            for ( j = 0;  j < amount;  j++ ) {
               $a    = $li.eq( j );
               strip = $a.attr( "href" );
               start = mw.util.getParamValue( "oldid", strip );
               if ( start ) {
                  strip = strip.replace( /&oldid=\d+\b/, "" )
                               .replace( /&curid=\d+\b/, "" );
                  shift = mw.util.getParamValue( "diff", strip );
                  if ( shift ) {
                     strip = strip.replace( /&diff=\d+\b/, "" );
                     shift = "Diff/" + start + "/" + shift;
                  } else {
                     shift = "PermanentLink/" + start;
                  }
                  shift = special + shift + "$1";
                  strip = strip.replace( /^.+(\?title=.+)$/,
                                         shift );
                  $a.attr( "href", strip );
               }
            }   // for j
         }   // for i
      }
   }   // further()



   function fire() {
      // Autorun on load
      // Precondition:
      //    mediawiki.util loaded
      // Uses:
      //     < Env
      //    mw.config.get()
      //    mw.util.getParamValue()
      //    further()
      //    flip()
      //    freeze()
      //    freezer()
      //    fresh()
      //    from()
      //    facet()
      //    fresher()
      //    freshest()
      //    flat()
      // 2014-12-30 PerfektesChaos@de.wikipedia
      var linkUpdate;
      Env = { skin:                       false,
              wgCanonicalSpecialPageName:
                           mw.config.get( "wgCanonicalSpecialPageName" ),
              wgPageName:                 false
          };
      if ( Env.wgCanonicalSpecialPageName ) {
         switch ( Env.wgCanonicalSpecialPageName ) {
            case "Contributions" :
               further( 2 );
               break;
            case "Diff" :
               flip();
               break;
            case "Recentchanges" :
            case "Watchlist" :
               further( 1 );
               break;
            case "Gadgets" :
               // form();
               break;
         }   // switch wgCanonicalSpecialPageName
      } else {
         Env.diff  = mw.util.getParamValue( "diff" );
         Env.oldid = mw.util.getParamValue( "oldid" );
         if ( Env.diff ) {
            flip();
         } else {
            linkUpdate   = true;
            Env.wgAction = mw.config.get( "wgAction" );
            switch ( Env.wgAction ) {
               case "history" :
                  further( 3 );
                  break;
               case "view" :
                  Env.curid = mw.util.getParamValue( "curid" );
                  if ( Env.curid || Env.oldid ) {
                     freeze( true );
                  } else {
                     freezer( true );
                  }
                  fresh( true );
                  Env.wgRedirectedFrom
                                   = mw.config.get( "wgRedirectedFrom" );
                  if ( Env.wgRedirectedFrom ) {
                     from();
                  }
                  break;
               case "info" :
                  fresh( true );
                  break;
               case "edit" :
               case "submit" :
                  linkUpdate = false;
                  // fall through
               default:
                  freezer( true );
            }   // switch wgAction
            if ( linkUpdate ) {
               if ( facet( "forcelinkupdate" ) ) {
                  fresher( true );
               }
               if ( facet( "forcerecursivelinkupdate" ) ) {
                  freshest( true );
               }
            }
         }
      }
      if ( facet( "slangQQX" ) ) {
         flat( true );
      }
   }   // fire()



   if ( mw.loader.getState( Signature )  !==  "ready" ) {
      mw.loader.state( Signature, "ready" );
      mw.loader.using( [ "mediawiki.util",
                         "user" ],
                       function () {
                          $( fire );   // don't hurry
                       } );
   }
}( window.mediaWiki, window.jQuery ) );
/// EOF </nowiki>   pageLinkHelper.js