Jump to content

User:PerfektesChaos/js/externalLinkProblem/d.js

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.
/// User:PerfektesChaos/js/externalLinkProblem/d.js
/// 2018-09-03 PerfektesChaos@de.wikipedia
// Problems with broken or undesired external links
// ResourceLoader:  compatible;  dependencies: *NONE at this stage*
/// Documentation:  [[w:en:User:PerfektesChaos/js/externalLinkProblem]]
/// Fingerprint: #0#0#
/// @license GPL [//www.mediawiki.org/w/COPYING] (+GFDL, LGPL, CC-BY-SA)
/// <nowiki>
/* global window:false                                                 */
/* jshint bitwise:true, curly:true, eqeqeq:true, latedef:true,
          laxbreak:true,
          nocomma:true, strict:true, undef:true, unused:true           */



( function ( mw ) {
   "use strict";
   var Version  =  -2.92,
       ELP      =  "externalLinkProblem",
       featuring, feed;
   if ( typeof mw.libs[ ELP ]  !==  "object"   ||   ! mw.libs[ ELP ] ) {
      mw.libs[ ELP ]  =  { };
   }
   mw.libs[ ELP ].type  =  ELP;
   ELP                  =  mw.libs[ ELP ];
   if ( typeof ELP.vsn  ===  "undefined" ) {
      // 2015-11-23
      if ( typeof ELP.config  !==  "object"   ||   ! ELP.config ) {
         ELP.config  =  { };
      }
      ELP.config.wikis  =   // 2015-11-27
          { "dewiki":
            { idHTTPstat: 1378713,
              idNonASCII: 9063042,
              idPipe:     9063048,
              idSpec:     9063045,
              list:       true,
              raw:        { old:   [ "{{Defekter Weblink Bot}}",
                                     "\n== Toter Weblink ==\n",
                                     "\n== Toter Weblink 2 ==\n",
                                     "\n== Defekter Weblink ==\n" ] },
              say:        "Defekter Weblink (Bot)",
              service:    "GiftBot",
              talk:       { scratch: "alle erledigt",
                            signing: "efekt",
                            suite:   "Wikipedia:Defekte Weblinks/Bot" },
              template:   { scan:    "Wikipedia:Defekte Weblinks/Bot",
                            section: [ "id", "Defekte_Weblinks" ],
                            seek:    "Defekter Weblink",
                            sign:    "Lauf",
                            stamp:   "2015-10" },
              trigger:    [ "talk", 0 ]
                         // "talk" (wmflabs; advanced)
                         // "query" (wmflabs)
            }
      };
      ELP.vsn        =  Version;
      ELP.signature  =  "ext.gadget." + ELP.type;
      ELP.support    =  "User:PerfektesChaos/js/" + ELP.type;
      ELP.doc        =  "[[w:en:" + ELP.support + "]]";
   }



   /*
    * This program is free software; you can redistribute it and/or
    * modify it under the terms of the GNU General Public License as
    * published by the Free Software Foundation; either version 2 of the
    * License, or (at your option) any later version.
    *
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    * GNU General Public License for more details.
    *
    * You should have received a copy of the GNU General Public License
    * along with this program;
    * if not, write to the Free Software Foundation, Inc.,
    * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
    * http://www.gnu.org/copyleft/gpl.html
    */



   function factory( ask, age, appoint ) {
      // Load resource (poor man's implement method)
      // Precondition:
      //    ask      -- specification
      //    age      -- maxage
      //    appoint  -- signature
      // Uses:
      //    >  .vsn
      //    >  .debug
      //    >  window.location.search
      //    mw.loader.getState()
      //    mw.loader.state()
      //    mw.loader.load()
      // 2018-08-24 PerfektesChaos@de.wikipedia
      var large, rls;
      if ( ! mw.loader.getState( appoint ) ) {
         rls = { };
         rls[ appoint ] = "loading";
         mw.loader.state( rls );
         if ( ELP.vsn < 0 ) {
            large  =  true;
         } else if ( typeof ELP.debug  ===  "boolean" ) {
            large  =  ELP.debug;
         } else if ( window.location.search ) {
            large  =  /\bdebug=true\b/.test( window.location.search );
         } else {
            large  =  false;
         }
         mw.loader.load( "https://en.wikipedia.org"
                         + "/w/index.php?title="
                         + "User:PerfektesChaos/js/"
                         + ask
                         + "/"
                         + ( large ? "d" : "r" )
                         + ".js"
                         + "&bcache=1&maxage=" + ( large ? "0" : age )
                         + "&action=raw&ctype=text/javascript",
                         "text/javascript" );
      }
   }   // factory()



   function features() {
      // Establish user configured appearance
      // Precondition:
      //    prego with user.options available
      // Uses:
      //    this
      //    >  .lazy
      //    >  .levels
      //    >  .lone
      //    >  .lookup
      //    >  .loose
      //    >  .low
      //    >  .mode
      //    >  .prego
      //    >  .prego.supply
      //    >< .prego.listen
      //     < .prego.loading
      //     < .config.last
      //     < .config.later
      //     < .config.lazy
      //     < .config.levels
      //     < .config.list
      //     < .config.lone
      //     < .config.lookup
      //     < .config.loose
      //     < .config.low
      //     < .config.mode
      //     < .prego.lib
      // 2016-10-07 PerfektesChaos@de.wikipedia
      var i, n, pars, s, v, vals;
      if ( typeof ELP.prego  ===  "object"
           &&     ELP.prego.listen ) {
         ELP.prego.listen   =  false;
         ELP.prego.loading  =  false;
         pars  =  [ [ "last",   "boolean" ],
                    [ "later",  "boolean" ],
                    [ "lazy",   "boolean" ],
                    [ "levels", "boolean" ],
                    [ "list",   "boolean" ],
                    [ "lone",   "boolean" ],
                    [ "lookup", "boolean" ],
                    [ "loose",  "boolean" ],
                    [ "low",    "boolean" ],
                    [ "mode",   "number"  ] ];
         n     =  pars.length;
         for ( i = 0;  i < n;  i++ ) {
            v  =  pars[ i ];
            s  =  v[ 0 ];
            if ( typeof ELP[ s ]  ===  v[ 1 ] ) {
               ELP.config[ s ]  =  ELP[ s ];
            } else {
               ELP.config[ s ]  =  false;
            }
         }   // for i
         if ( typeof ELP.prego.supply  ===  "string" ) {
            ELP.prego.lib  =  mw.libs[ ELP.prego.supply ];
            if ( typeof ELP.prego.lib  ===  "object"   &&
                 typeof ELP.prego.lib.fetch  ===  "function" ) {
               vals  =  ELP.prego.lib.fetch( ELP.type );
               if ( vals   &&   typeof vals  ===  "object" ) {
                  for ( i = 0;  i < n;  i++ ) {
                     v  =  pars[ i ];
                     s  =  v[ 0 ];
                     if ( typeof vals[ s ]  ===  v[ 1 ] ) {
                        ELP.config[ s ]  =  vals[ s ];
                     }
                  }   // for i
               }
            }
         }
      }
   }   // features()



   featuring  =  function ( action ) {
      // Prepare user configured appearance
      // Precondition:
      //    action  -- callback function to continue, or false
      // Postcondition:
      //    Executing action
      // Uses:
      //    >< .prego
      //    >< .prego.loading
      //     < .prego.listen
      //     < .prego.supply
      //     < .prego.starter
      //    factory()
      //    mw.hook()
      //    (features)
      // 2015-10-22 PerfektesChaos@de.wikipedia
      if ( typeof ELP.prego  !==  "object" ) {
         ELP.prego  =  { };
      }
      if ( typeof ELP.prego.loading  ===  "undefined" ) {
         ELP.prego.loading  =  true;
         ELP.prego.listen   =  true;
         ELP.prego.supply   =  "preferencesGadgetOptions";
         ELP.prego.starter  =  ELP.prego.supply + ".ready";
         factory( ELP.prego.supply,
                  604808,
                  "ext.gadget." + ELP.prego.supply );
         mw.hook( ELP.prego.starter ).add( features );
      }
      if ( action ) {
         mw.hook( ELP.prego.starter )
           .add( function () {
                    features();
                    action();
                 } );
      }
   };   // featuring()



   feed  =  function ( access, action ) {
      // Run subscript
      // Precondition:
      //    access  -- subscript
      //    action  -- callback function, or false
      // Uses:
      //    >  .signature
      //    >  .type
      //     < .request
      //    featuring()
      //    mw.loader.getState()
      //    mw.log()
      //    factory()
      //    mw.hook()
      // 2015-11-22 PerfektesChaos@de.wikipedia
      var maxage     =  ( ELP.vsn >= 1  ?  86400  :  2015 ),
          sub        =  "/" + access,
          signature  =  ELP.signature + sub,
          lucky, part;
      if ( typeof ELP[ access ]  ===  "object" ) {
         part =  ELP[ access ];
         if ( part   &&  typeof part.fire  ===  "function" ) {
            featuring( function () {
                          part.fire( action );
                       } );
            lucky  =  true;
         }
      }
      if ( ! lucky ) {
         if ( mw.loader.getState( signature )  ===  "ready" ) {
            mw.log( { loud: true },
                    ELP.type + " *** Error .feed() " + access,
                    3,
                    ELP );
         } else {
            featuring();
            factory( ELP.type + sub,  maxage,  signature );
            if ( action ) {
               mw.hook( ELP.type + sub + ".ready" )
                 .add( function () {
                          features();
                          action();
                       } );
            }
         }
      }
   };   // feed()



   function fire() {
      // Start possible actions on current page
      // Uses:
      //    >  .features
      //    >  window.location.search
      //    >  .type
      //     < .request
      //     < .project
      //     < .special
      //     < .scope
      //    mw.config.get()
      //    featuring()
      //    feed()
      // Remark: May be used as event handler -- 'this' is not ELP
      // 2016-11-18 PerfektesChaos@de.wikipedia
      var f, i, k, launch, liaison, ns, profile, re, show, site, source;
      if ( typeof ELP.project  ===  "object"
           &&     ELP.project ) {
         ns  =  mw.config.get( "wgNamespaceNumber" );
         if ( ns === -1 ) {
            source  =  mw.config.get( "wgCanonicalSpecialPageName" );
            switch ( source ) {
               case "Blankpage" :
               case "Gadgets" :
                  ELP.request  =  "prego";
                  featuring();
                  f  =  ELP.features;
                  break;
               case "Recentchanges" :
               case "Watchlist" :
                  if ( typeof ELP.project.list  ===  "boolean"
                       &&     ELP.project.list ) {
                     ELP.request  =  "watchlist";
                  }
                  break;
            }   // switch wgCanonicalSpecialPageName
            if ( ELP.request ) {
               ELP.special  =  source;
               feed( ELP.request, f );
            }
         } else {
            if ( typeof ELP.project.trigger  ===  "object"
                 &&     ELP.project.trigger ) {
               profile  =  ELP.project.trigger;
               source   =  profile[ 0 ];
               liaison  =  ( source === "talk" );
               if ( liaison   &&
                    ns === 14   &&
                    typeof ELP.project.talk  ===  "object"
                    &&     ELP.project.talk   &&
                    typeof ELP.project.talk.suite  ===  "string" ) {
                  re  =   mw.config.get( [ "wgAction",
                                           "wgTitle" ] );
                  if ( re.wgAction === "view"   &&
                       ! re.wgTitle.indexOf( ELP.project.talk.suite ) ) {
                     ELP.request  =  "category";
                     feed( ELP.request );
                  }
               } else {
                  for ( i = 1;  i < profile.length;  i++ ) {
                     k  =  profile[ i ];
                     if ( k === ns ) {
                        ELP.request  =  [ k, true ];
                        break;
                     } else if ( liaison   &&   k + 1  ===  ns ) {
                        ELP.request  =  [ k, false ];
                        break;
                     }
                  }   // for i
                  if ( ELP.request ) {
                     ELP.scope  =  mw.config.get( "wgAction" );
                     show       =  "|edit|info|submit|view|";
                     launch     =  ( show.indexOf( ELP.scope )  >  0 );
                     if ( launch  &&  window.location.search ) {
                        site    =  window.location.search;
                        launch  =  ( site.indexOf( "&oldid=" )  <  0 );
                        if ( launch  &&  ELP.scope === "view" ) {
                           re      =  "\\b(diff|history|printable)=";
                           re      =  new RegExp( re );
                           launch  =  ! re.test( site );
                        }
                     }
                     if ( launch ) {
                        feed( source );
                     }
                  }
               }
            }
         }
      }
   }   // fire()



   function first() {
      // Autorun
      // Uses:
      //    >  .signature
      //    >  .config.wikis
      //    >  featuring
      //    >  feed
      //     < .request
      //     < .featuring
      //     < .feed
      //     < .project
      //    mw.loader.getState()
      //    mw.loader.state()
      //    mw.config.get()
      //    fire()
      //    mw.hook()
      // 2018-09-03 PerfektesChaos@de.wikipedia
      var rls, site;
      if ( mw.loader.getState( ELP.signature ) !== "ready" ) {
         rls = { };
         rls[ ELP.signature ] = "loading";
         mw.loader.state( rls );
         ELP.request    =  false;
         ELP.featuring  =  featuring;
         ELP.feed       =  feed;
         if ( typeof ELP.project  ===  "undefined" ) {
            site  =  mw.config.get( "wgDBname" );
            if ( typeof ELP.config.wikis[ site ]  ===  "object" ) {
               ELP.project  =  ELP.config.wikis[ site ];
            } else {
               ELP.project  =  false;
            }
         }
         fire();
         rls[ ELP.signature ] = "ready";
         mw.loader.state( rls );
         mw.hook( ELP.type + ".ready" ).fire();
      }
   }   // first()
   first();
}( window.mediaWiki ) );



// Emacs
// Local Variables:
// coding: iso-8859-1-dos
// End:

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