Jump to content

User:PerfektesChaos/js/filesMetaData/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/filesMetaData/d.js
//  List metadata of media files
/// 2018-08-24 PerfektesChaos@de.wikipedia
//  ResourceLoader:  compatible;
//    dependencies: mediawiki.api, mediawiki.user, mediawiki.util, oojs.*
/// Fingerprint: #0#0#
/// @license GPL [//www.mediawiki.org/w/COPYING] (+GFDL, LGPL, CC-BY-SA)
/// <nowiki>
/* global window: false                                                */
/* jshint forin: false,
          bitwise:true, curly:true, eqeqeq:true, latedef:true,
          laxbreak:true,
          nocomma:true, strict:true, undef:true, unused:true           */



( function ( mw, $ ) {
   "use strict";
   var Version   = -1.1,
       Signature = "filesMetaData",
       FILMED    = { doc:    "en:User:PerfektesChaos/js/" + Signature,
                     list:   false,
                     loaded: false,
                     using:  [ "mediawiki.api",
                               "mediawiki.user",
                               "mediawiki.util",
                               "oojs",
                               "oojs-ui-core",
                               "oojs-ui-widgets" ] },
       CODES     = { maxage:    86400,
                     site:      "w:en",
                     sign:      "lib",
                     store:     "User:PerfektesChaos/js/" },

       PREGO     = { app:       false,
                     maxage:    604814,
                     signature: "preferencesGadgetOptions",
                     site:      "w:en",
                     store:     "User:PerfektesChaos/js/",
                     sub:       "/r.js" },
       REPOS     = { },
       GADGET;



   function face() {
      // Page orientation
      // Precondition:
      //    DOM ready
      // Uses:
      //    >< FILMED.$body
      //     < FILMED.ltr
      // 2017-08-19 PerfektesChaos@de.wikipedia
      if ( ! FILMED.$body ) {
         FILMED.$body = $( "body" );
         FILMED.ltr   = ( $( "html" ).attr( "dir" )  !==  "rtl" );
      }
   }   // face()



   function fair() {
      // Adapt to special conditions (mobile)
      // Uses:
      //    >< FILMED.using
      //     < FILMED.list
      //    mw.config.get()
      // 2018-05-20 PerfektesChaos@de.wikipedia
      FILMED.list = ( mw.config.get( "skin" ) !== "minerva" );
      if ( FILMED.list ) {   // T49858
         FILMED.using.push( "jquery.tablesorter" );
      }
   }   // fair()



   function first() {
      // Autorun on loading
      // Uses:
      //    >  Signature
      //    >  FILMED.doc
      //    >  Version
      //     < FILMED.signature
      //     < FILMED.pub
      //    mw.loader.getState()
      //    mw.loader.state()
      //    mw.config.get()
      //    FILMED.first()
      //    mw.hook()
      // 2018-08-24 PerfektesChaos@de.wikipedia
      var i, rls, s;
      FILMED.signature = "ext.gadget." + Signature;
      if ( mw.loader.getState( FILMED.signature )  !==  "ready" ) {
         rls = { };
         rls[ FILMED.signature ] = "ready";
         mw.loader.state( rls );
         s = mw.config.get( "wgCanonicalSpecialPageName" );
         if ( s === "Blankpage" ) {
            s = mw.config.get( "wgTitle" );
            i = s.indexOf( "/" );
            if ( i > 1   &&   s.substr( i + 1 )  ===  Signature ) {
               FILMED.first();
            }
         }
         FILMED.pub = { doc:  "[[" + FILMED.doc + "]]",
                        type: Signature,
                        vsn:  Version };
         mw.hook( Signature + ".ready" ).fire( FILMED.pub );
      }
   }   // first()



   FILMED.fed = function () {
      // Resources arrived
      // Uses:
      //    >  GADGET
      //     < FILMED.loaded
      //    FILMED.finish()
      // 2018-05-20 PerfektesChaos@de.wikipedia
      if ( GADGET ) {
         FILMED.finish();
      } else {
         FILMED.loaded = true;
      }
   };   // FILMED.fed()



   FILMED.finish = function () {
      // All prerequisites ready
      // Precondition:
      //    DOM ready
      //    Resources arrived
      //    Code arrived
      // Uses:
      //    >  GADGET
      //    >  GADGET.vsn
      //    >  FILMED.$vsn
      //    >  FILMED.$page
      //    >  FILMED.ltr
      //    >  FILMED.list
      //    >  PREGO.signature
      //    >< REPOS
      //    >< FILMED.$doc
      //     < FILMED.vsn
      //     < GADGET.$page
      //     < GADGET.ltr
      //     < GADGET.list
      //     < GADGET.head.$doc
      //     < GADGET.head.vsn
      //     < CODES
      //     < PREGO
      //    mw.hook()
      //    (GADGET.first)
      // 2018-06-03 PerfektesChaos@de.wikipedia
      if ( REPOS ) {
         REPOS      = false;
         FILMED.vsn = Version + " * " + GADGET.vsn;
         FILMED.$vsn.text( FILMED.vsn );
         GADGET.$page     = FILMED.$page;
         GADGET.ltr       = FILMED.ltr;
         GADGET.list      = FILMED.list;
         GADGET.head.$doc = FILMED.$doc;
         FILMED.$doc      = false;
         mw.hook( PREGO.signature + ".ready" ).add( GADGET.first );
         CODES = false;
         PREGO = false;
      }
   };   // FILMED.finish()



   FILMED.fire = function ( application ) {
      // Code arrived
      // Precondition:
      //    application  -- code library
      // Uses:
      //    >  FILMED.loaded
      //     < GADGET
      //    FILMED.finish()
      // 2018-05-20 PerfektesChaos@de.wikipedia
      GADGET = application;
      if ( FILMED.loaded ) {
         FILMED.finish();
      }
   };   // FILMED.fire()



   FILMED.first = function () {
      // Start application
      // Uses:
      //    >  FILMED.using
      //    >  Signature
      //    >  CODES.sign
      //     < CODES.signature
      //    PREGO.feed()
      //    fair()
      //    mw.loader.load()
      //    mw.hook()
      //    CODES.feed()
      //    (FILMED.fire)
      //    (FILMED.furnish)
      // 2018-06-03 PerfektesChaos@de.wikipedia
      PREGO.feed();
      fair();
      mw.loader.load( FILMED.using );
      CODES.signature = Signature + "." + CODES.sign;
      mw.hook( CODES.signature + ".ready" ).add( FILMED.fire );
      CODES.feed();
      mw.hook( "wikipage.content" ).add( FILMED.furnish );
   };   // FILMED.first()



   FILMED.furnish = function ( $area ) {
      // Equip page with docpage and intro
      // Precondition:
      //    $area  -- mw-content-text
      //    DOM ready
      // Uses:
      //    >  Signature
      //    >  FILMED.$body
      //    >  FILMED.ltr
      //    >  FILMED.using
      //     < FILMED.$page
      //     < FILMED.$doc
      //     < FILMED.$vsn
      //    face()
      //    mw.loader.using()
      //    (FILMED.fed)
      // 2018-06-03 PerfektesChaos@de.wikipedia
      var $v = $( "head" ),
          $e = $v.find( "title" );
      $e.remove();
      $e = $( "<title>" );
      $e.text( Signature );
      $v.prepend( $e );
      FILMED.$page = $area;
      FILMED.$page.empty();
      face();
      $v = FILMED.$body.find( "#firstHeading,#section_0" );
      if ( ! $v.length ) {
         $v = $( "h1" );
      }
      $v.eq( 0 ).text( Signature );
      $v = $( "<div>" );
      $v.css( { "clear":  "both" } );
      FILMED.$doc = $( "<a>" );
      FILMED.$doc.text( Signature + "@PerfektesChaos" );
      FILMED.$vsn = $( "<span>" );
      FILMED.$vsn.css( { "font-size": "smaller" } )
            .css( "margin-" + ( FILMED.ltr ? "left": "right" ),
                  "2em" )
            .text( Version );
      $v.append( FILMED.$doc, FILMED.$vsn );
      FILMED.$page.append( $v );
      mw.loader.using( FILMED.using, FILMED.fed );
   };   // FILMED.furnish()



   CODES.feed = function () {
      // Provide PREGO
      // Uses:
      //    >  CODES.signature
      //    >  CODES.store
      //    >  Signature
      //    >  CODES.sign
      //    >  Version
      //    >  CODES.site
      //    >  CODES.maxage
      //    mw.loader.getState()
      //    REPOS.fire()
      // 2018-06-03 PerfektesChaos@de.wikipedia
      var s = "ext.gadget." + CODES.signature;
      if ( mw.loader.getState( s )  !==  "ready" ) {
         s = CODES.store + Signature + "/" + CODES.sign + "/"
             +   ( Version < 1  ?  "d"  :  "r" )   +   ".js";
         REPOS.fire( CODES.site,
                     s,
                     false,
                     { action: "raw",
                       ctype:  "text/javascript",
                       bcache: 1,
                       maxage: ( Version < 1  ?  0  :  CODES.maxage )
                     } );
      }
   };   // CODES.feed()



   PREGO.feed = function () {
      // Provide PREGO
      // Uses:
      //    >  PREGO.signature
      //    >  PREGO.site
      //    >  PREGO.store
      //    >  PREGO.sub
      //    >  PREGO.maxage
      //    mw.loader.getState()
      //    REPOS.fire()
      // 2018-05-20 PerfektesChaos@de.wikipedia
      var s = "ext.gadget." + PREGO.signature;
      if ( mw.loader.getState( s )  !==  "ready" ) {
         REPOS.fire( PREGO.site,
                     PREGO.store + PREGO.signature + PREGO.sub,
                     false,
                     { action: "raw",
                       ctype:  "text/javascript",
                       bcache: 1,
                       maxage: PREGO.maxage } );
      }
   };   // PREGO.feed()



   REPOS.fire = function ( at, access, append, alter ) {
      // Load from external URL
      // Precondition:
      //    at      -- Wikimedia Foundation site code, or not
      //    access  -- string with basic page name
      //    append  -- string with subpage, or not
      //    alter   -- parameter object, or MIME string, or not
      // Uses:
      //    >< REPOS.requests
      //    REPOS.foundation()
      //    mw.loader.load()
      // 2018-03-21 PerfektesChaos@de.wikipedia
      var source, syntax;
      if ( typeof REPOS.requests  !==  "object" ) {
         REPOS.requests = { };
      }
      if ( typeof REPOS.requests[ access ]  !==  "boolean" ) {
         REPOS.requests[ access ] = true;
         if ( append ) {
            source = access + append;
         } else {
            source = access;
         }
         if ( at ) {
            source = REPOS.foundation( at, source, alter );
            if ( typeof alter  ===  "object"
                 &&     alter   &&
                 typeof alter.ctype  ===  "string" ) {
               syntax = alter.ctype;
            }
         } else {
            syntax = alter;
         }
         mw.loader.load( source, syntax );
      }
   };   // REPOS.fire()



   REPOS.foundation = function ( at, access, alter ) {
      // Create URL within Wikimedia Foundation
      // Precondition:
      //    at      -- site code, or not
      //    access  -- string with page name
      //    alter   -- parameter object, or not
      // Postcondition:
      //    Returns full URL
      // 2018-03-21 PerfektesChaos@de.wikipedia
      var s = access,
          r = encodeURI( s );
      if ( typeof alter  ===  "object"
           &&     alter ) {
         r = "/w/index.php?title=" + r;
         if ( access.substr( -3 ) === ".js" ) {
            alter.ctype = "text/javascript";
         } else if ( access.substr( -4 ) === ".css" ) {
            alter.ctype = "text/css";
         }
         alter.action = "raw";
         for ( s in alter ) {
            r = r + "&" + s + "=" + encodeURI( alter[ s ] );
         }   // for s in alter
      } else {
         r = "/wiki/" + r;
      }
      if ( typeof at  ===  "string"
           &&     at ) {
         switch ( at ) {
            case "meta":
               r = "meta.wikimedia.org" + r;
               break;
            case "mw":
               r = "www.mediawiki.org" + r;
               break;
            case "w:en":
               r = "en.wikipedia.org" + r;
               break;
            default:
               r = window.location.host + r;
         }   // switch at
         r = "https://" + r;
      }
      return r;
   };   // REPOS.foundation()



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



// Emacs
// Local Variables:
// fill-column: 80
// End:

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