Jump to content

User:PerfektesChaos/js/WikiSyntaxTextMod/dW.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.
/// PerfektesChaos/js/WikiSyntaxTextMod/dW.js
/// 2023-05-10 PerfektesChaos@de.wikipedia
/// Fingerprint: #0#0#
/// @license: CC-by-sa/4.0 GPLv3
/// <nowiki>
// WikiSyntaxTextMod:  Wiki syntax specific code
/* global mw:true, mediaWiki:false, window:false                       */
/* jshint forin:false,
          bitwise:true, curly:true, eqeqeq:true, latedef:true,
          laxbreak:true,
          nocomma:true, strict:true, undef:true, unused:true           */


if ( typeof mediaWiki  !==  "object" ) {   // disconnected
   mw  =  { libs:   { WikiSyntaxTextMod:  { }
                    },
            log:    function () {"use strict";}
          };
}
( function ( mw ) {
   "use strict";
   var version  =  -7.67,
       sign     =  "WikiSyntaxTextMod",
       sub      =  "W",
       rls, self, WSTM;
   if ( typeof mw.loader  ===  "object" ) {
      rls   =  { };
      self  =  "user:PerfektesChaos/" + sign + "/" + sub;
      rls[ self ] = "loading";
      mw.loader.state( rls );
   }
   if ( typeof mw.libs[ sign ]  !==  "object" ) {   // isolated
      mw.libs[ sign ]  =  { };
   }
   WSTM  =  mw.libs[ sign ];
   if ( typeof WSTM.w  !==  "object" ) {
      WSTM.w  =  { };
   }
   WSTM.w.vsn   =  version;
   WSTM.w.self  =  self;
   if ( typeof WSTM.bb  !==  "object" ) {
      WSTM.bb  =  { };
   }
   if ( typeof WSTM.debugging  !==  "object" ) {
      WSTM.debugging  =  { };
   }
} ( mw ) );



/*
Requires: JavaScript 1.3  (String.charCodeAt String.replace)
          JavaScript 1.5  RegExp non-capturing parenthese
 */



//-----------------------------------------------------------------------



mw.libs.WikiSyntaxTextMod.bb.bbW  =  function (WSTM) {
   // Building block and run environment support
   // 2012-05-18 PerfektesChaos@de.wikipedia
   "use strict";
   if ( typeof WSTM.util  !==  "object" ) {
      WSTM.util  =  { };
   }


   if ( typeof WSTM.util.fiatObjects  !==  "function" ) {
      WSTM.util.fiatObjects  =  function (adult, activate, assign) {
         // Ensure existence of at least empty object
         // Precondition:
         //    adult     -- parent object
         //    activate  -- String with name of child object
         //    assign    -- optional object with initial definition
         //                 if containing object components,
         //                 they will be asserted as well
         // Postcondition:
         //    adult has been extended
         // Uses:
         //    .util.fiatObjects()  -- recursive
         // 2012-05-18 PerfektesChaos@de.wikipedia
         var elt,
             obj,
             s;
         if ( typeof adult[ activate ]  !==  "object" ) {
            adult[ activate ]  =  ( assign  ?  assign  :  { } );
         }
         if ( assign ) {
            obj  =  adult[ activate ];
            for ( s in assign ) {
               elt  =  assign[ s ];
               if ( typeof elt  ===  "object" ) {
                  WSTM.util.fiatObjects( obj, s, elt );
               }
            }  // for s in obj
         }
      };   // .util.fiatObjects()
   }


   WSTM.util.fiatObjects(WSTM,  "debugging",  { loud: false });


};   // .bb.bbW()
mw.libs.WikiSyntaxTextMod.bb.bbW(mw.libs.WikiSyntaxTextMod);
delete mw.libs.WikiSyntaxTextMod.bb.bbW;



//-----------------------------------------------------------------------



mw.libs.WikiSyntaxTextMod.bb.W  =  function (WSTM) {
   // Wiki specific localization
   // Uses:
   //    .util.fiatObjects()
   // 2013-03-18 PerfektesChaos@de.wikipedia
   "use strict";
   WSTM.util.fiatObjects(WSTM,  "g",
                         { learnt: false,
                           re:     { },
                           s:      {  re: { }  }
                         } );
   // WikiRegExp_URLfragmt       =  false;   // ??
   // WikiRegExp_URLarticle      =  false;



   if ( typeof mw.libs.WikiSyntaxTextMod.str  !==  "object" ) {
      mw.libs.WikiSyntaxTextMod.str  =  { };
   }
   WSTM.str.locateEntities  =  false;
   WSTM.str.sortLang        =  false;



};   // .bb.W()
mw.libs.WikiSyntaxTextMod.bb.W(mw.libs.WikiSyntaxTextMod);
delete mw.libs.WikiSyntaxTextMod.bb.W;



//-----------------------------------------------------------------------



mw.libs.WikiSyntaxTextMod.bb.apiW  =  function (WSTM) {
   // Detected syntax error handling
   // 2012-08-26 PerfektesChaos@de.wikipedia
   "use strict";
   if ( typeof WSTM.api  !==  "object" ) {
      WSTM.api  =  { };
   }



WSTM.api.textMod  =  function (adjust) {
   // Main task for modifications of wikitext string
   // Precondition:
   //    adjust  -- string with entire wikitext
   // Postcondition:
   //    Returns  false     if nothing to do
   //             array[2]  [0] modified string
   //                       [1] true if minor edits only (not userdef)
   // Uses:
   //    >  .str.spaces
   //    >  WikisyntaxTextMod_UserHook
   //    >  .mod.comment
   //    >  .mod.lock
   //    >  .w.chr.detected.exchange
   //    >  .w.chr.detected.nbHyphen
   //    >  .w.chr.detected.ordMasc
   //    >  .mod.plain
   //    >  .mod.plain.raw
   //    >  .mod.plain.name
   //    >  .mod.lenient
   //    >  .text.learnt
   //    >  .w.chr.detected.tabEOL
   //    >  .config.mod.hook
   //    >< .mod.plain.stm
   //     < .w.encountered
   //     < .str.locateEntities
   //     < .text
   //     < .mod.lazy
   //    .w.errors.first()
   //    .w.elem.furnish()
   //    .mod.furnish()
   //    .g.factory()
   //    .w.tags.frozen()
   //    .o.WikiTom()
   //    .w.chr.filter()
   //    .o.WikiTom().fold()
   //    .w.elem.hashmagic()
   //    .w.tags.fire()
   //    .w.chr.flip()
   //    .w.elem.tables.furnish()
   //    .util.translate.further()
   //    .w.template.findISBN()
   //    .w.template.fire()
   //    .w.elem.fire()
   //    .w.link.fire()
   //    .w.elem.fixed()
   //    .w.elem.finishing()
   //    .hooks.finalize()
   //    .o.WikiTom().replace()
   //    .o.WikiTom().toString()
   //    (.config.mod.hook)
   // Requires: JavaScript 1.3   charCodeAt()
   // 2023-05-10 PerfektesChaos@de.wikipedia
   var r      =  false,
       re     =  new RegExp("\n[ " + WSTM.str.spaces + "]+\n", "g"),
       score  =  adjust,
       ext, s;
   if ( typeof window  ===  "object"   &&
        typeof WSTM.debugging  ===  "object"   &&
        WSTM.debugging.loud   &&
        typeof window.console  ===  "object"
        &&     window.console ) {
      if ( typeof window.console.clear  ===  "function" ) {
         window.console.clear();
      }
      if (WSTM.xDebug) {
         mw.log(WSTM.debugging,".api.textMod()",0);
      }
   } else {
      WSTM.xDebug  =  false;
   }
   WSTM.errors.first();
   WSTM.w.elem.furnish();
   WSTM.mod.furnish();
   WSTM.g.factory();
   WSTM.w.encountered       =  { bidichar:     false,
                                 biditemplate: false,
                                 cats:         false,
                                 indent:       false,
                                 isbn:         false,
                                 iwiki:        false,
                                 refgroups:    false,
                                 table:        false };
   WSTM.str.locateEntities  =  true;
   if (WSTM.mod.comment) {
      WSTM.w.tags.frozen();
   }
   WSTM.text  =  new WSTM.o.WikiTom(adjust, null);
   WSTM.w.chr.filter(WSTM.text);
   if (WSTM.Z) {   // development hook
      WSTM.Z.fire();
   }
   WSTM.text.fold(-1, -1, false, true);
   WSTM.w.elem.hashmagic();
   WSTM.w.tags.fire(WSTM.text);
   WSTM.w.chr.flip(WSTM.text);
   WSTM.mod.lock  =  (WSTM.mod.lock
                      || WSTM.w.chr.detected.exchange
                      || WSTM.w.chr.detected.nbHyphen
                      || WSTM.w.chr.detected.ordMasc);
   if ( WSTM.mod.table ) {   // TEMPORARY
      WSTM.w.elem.tables.furnish();
   }   // TEMPORARY
   if ( WSTM.mod.plain  &&
        ! WSTM.mod.plain.stm ) {
      WSTM.mod.plain.stm  =  WSTM.util.translate.further(
                                                     WSTM.mod.plain.raw,
                                                     false,
                                                     WSTM.mod.plain.name,
                                                     WSTM.mod.lenient );
   }   // _Text
   WSTM.w.template.findISBN();
   WSTM.w.template.fire( WSTM.text, true );
   WSTM.w.link.fire( WSTM.text, true, WSTM.mod.lock, false );
   WSTM.w.elem.fire();
   if ( WSTM.mod.lock && WSTM.w.encountered.indent ) {
      WSTM.w.elem.fixed( WSTM.text, true );
   }
   WSTM.w.elem.finishing();
   WSTM.hooks.finalize( false );
   if ( WSTM.mod.plain  &&
        WSTM.mod.plain.stm ) {
      WSTM.text.replace( WSTM.mod.plain.stm, false );
   }   // _Text
   if ( WSTM.text.learnt || WSTM.w.chr.detected.tabEOL ) {
      score  =  WSTM.text.toString();
   }
   if ( typeof WSTM.mod.hook  ===  "function" ) {
      s  =  WSTM.mod.hook( score );
      if ( s !== score   &&   typeof s  ===  "string" ) {
         score          =  s;
         WSTM.mod.lazy  =  false;
      }
   }
   if ( typeof WSTM.config  ===  "object"
        &&     WSTM.config   &&
        typeof WSTM.config.mod  === "object"
        &&     WSTM.config.mod   &&
        typeof WSTM.config.mod.hook  ===  "function" ) {
      s  =  WSTM.config.mod.hook( score );
      if ( s !== score ) {
         if ( typeof s  ===  "string" ) {
            score          =  s;
            WSTM.mod.lazy  =  false;
         }
      }
   }
   if ( score !== adjust ) {
      // remove trailing whitespace on this occasion:
      re  =  new RegExp("([^=\\]|[^=]= |==)[ " + WSTM.str.spaces + "]+"
                        + "\n",
                        "g");
      // Chemiker: Vorlagen behalten Leerzeichen bei leeren Parametern
      score  =  score.replace(re, "$1\n");
      ext    =  score.length - 1;
      if (score.charCodeAt(ext) === 10) {
         while (score.charCodeAt(ext - 1)  ===  10) {
            score  =  score.substr(0, ext);
            ext--;
         }   // while
      }   // score terminated by \n
   }   // changes
/*
   if (WSTM.xDebug) {
      WSTM.text.DEBUGparent();
mw.log(WSTM.debugging,".api.textMod() ==================",0,WSTM.X);
mw.log(WSTM.debugging,".api.textMod()",0,WSTM.text);
mw.log(WSTM.debugging,".api.textMod()",0,WSTM.w.encountered);
mw.log(WSTM.debugging,".api.textMod()",0,WSTM.w.chr.detected);
mw.log(WSTM.debugging,".api.textMod()",0,WSTM.mod);
   }
*/
   if (score !== adjust) {
      r  =  [score, WSTM.mod.lazy];
   }   // changes
   return  r;
};   // .api.textMod()



};   // .bb.apiW()
mw.libs.WikiSyntaxTextMod.bb.apiW(mw.libs.WikiSyntaxTextMod);
delete mw.libs.WikiSyntaxTextMod.bb.apiW;



//-----------------------------------------------------------------------



( function ( WSTM ) {
   "use strict";
   var sub      =  "W",
       self     =  WSTM.w.self,
       version  =  WSTM.w.vsn,
       rls;
   if ( typeof WSTM.main  !==  "object" ) {
      WSTM.main  =  { };
   }
   if ( ! WSTM.main.bb ) {
      WSTM.main.bb  =  { };
   }
   WSTM.main.bb[ sub ]  =  { load: true,
                             vsn:  version };
   if ( typeof WSTM.main.wait  ===  "function" ) {
      // Start on import: callback to waiting ...
      WSTM.main.wait( sub, version );
   }
   if ( typeof mw.loader  ===  "object"   &&
        typeof mw.hook  !==  "undefined" ) {
      rls = { };
      rls[ self ] = "ready";
      mw.loader.state( rls );
      mw.hook( "WikiSyntaxTextMod/" + sub + ".ready" )
        .fire( [ sub, version ] );
   }
} ( mw.libs.WikiSyntaxTextMod ) );



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

/// EOF </nowiki>   WikiSyntaxTextMod/dW.js