Jump to content

User:PerfektesChaos/js/localEdit/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/localEdit/d.js
/// 2018-08-24 PerfektesChaos@de.wikipedia
// Edit local file in Wiki environment, collaborate with browser add-on
// ResourceLoader:  compatible;
//    dependencies: user, mediawiki.user, mediawiki.util
/// 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 vsn  =  -0.3,
       WLE;
   if ( typeof mw.libs.localEdit  !==  "object"   ||
        ! mw.libs.localEdit ) {
      mw.libs.localEdit  =  { };
   }
   WLE         =  mw.libs.localEdit;
   WLE.vsn     =  vsn;
   WLE.type    =  "localEdit";
   WLE.scan    =  "*.txt; *.text; *.wiki";
   WLE.suffix  =  "txt";
   if ( ! WLE.lang ) {
      WLE.lang  =  { };
   }
   if ( ! WLE.pageImport ) {
      WLE.pageImport  =  { };
   }


   // User options:
   //   .scan    pattern for text file selection
   //   .suffix  default file extension
   //   .mid     number of minutes for scheduled autosaves

if ( typeof WLE.debugging  !==  "object" ) {
   WLE.debugging  =  { loud: true,
                       say:  "localEdit" };
}


   /*
    * 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
    */


   // Requires: JavaScript  1.3   (String.replace)
   //           MediaWiki   1.18  (mw.libs, jQuery core)



   WLE.lang.texts  =  {
      // 2012-12-11 PerfektesChaos@de.wikipedia
      "BrowserType":     {"en": "Browser type",
                          "de": "Browser-Typ"},
//    "Abort":           {"en": "Abort",
//                        "de": "Abbruch"},
      "AddOn":           {"en": "Add-on",
                          "de": "Add-On"},
      "ConfirmLosses":   {"en": "Really loose edits?",
                          "de": "Wirklich Änderungen verlieren?"},
      "DirBase":         {"en": "Base directory (local)",
                          "de": "Stammverzeichnis (lokal)"},
      "DirSub":          {"en": "Sub directory for project",
                          "de": "Unterverzeichnis für Projekt"},
      "Edit":            {"en": "Start editing local file",
                          "de": "Bearbeitung lokaler Dateien beginnen"},
//    "Exit":            {"en": "Exit",
//                        "de": "Exit"},
      "FileExtFilter":   {"en": "File extensions (Filter)",
                          "de": "Datei-Erweiterungen (Filter)"},
      "FileExtNew":      {"en": "File extension (create)",
                          "de": "Datei-Erweiterung (Neuanlage)"},
      "HeadlineConfig":  {"en": "Personal options",
                          "de": "Persönliche Einstellungen"},
      "ImportPage":      {"en": "Import from page",
                          "de": "Seitentext importieren"},
      "ImportPageAbort": {"en": "Abort",
                          "de": "Abbrechen"},
      "ImportPageClear": {"en": "Empty edit area first",
                          "de": "Erst Bearbeitungsfeld leeren"},
      "ImportPageFire":  {"en": "Import",
                          "de": "Importieren"},
      "installed-false": {"en": "Not active",
                          "de": "Nicht aktiv"},
      "installed-true":  {"en": "Active",
                          "de": "Aktiviert"},
      "NamePage":        {"en": "Page name:",
                          "de": "Seitenname:"},
      "OldID":           {"en": "Optional revision",
                          "de": "Optional/alternativ Version"},
      "OpenFile":        {"en": "Open file",
                          "de": "Datei öffnen"},
      "SaveFile":        {"en": "Save file",
                          "de": "Datei speichern"},
      "SaveFileAs":      {"en": "Save file as",
                          "de": "Datei speichern unter"},
      "URLform":         {"en": "URL format",
                          "de": "URL-Format"},
      "URLformfix":      {"en": "Fix it",
                          "de": "Verbessern"}
   };   // .lang.texts



   WLE.lang.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"
   };   // .lang.trans



   WLE.pageImport.fault  =  function () {
      // Postprocess after ajax request failure
      // Uses:
      //    .pageImport.flop()
      // Remark: Used as event handler -- 'this' is not WLE
      // 2012-12-12 PerfektesChaos@de.wikipedia
      WLE.pageImport.flop();
   };   // .pageImport.fault()



   WLE.lang.favorite  =  function () {
      // Guess user language
      // Uses:
      //    this
      //    >  .lang.trans
      //    >< .lang.slang
      //    mw.config.get()
      // 2012-11-30 PerfektesChaos@de.wikipedia
      var s;
      if ( ! this.slang ) {
         s  =  mw.config.get( "wgUserLanguage" ).toLowerCase();
         s  =  this.trans[ s ];
         if ( s ) {
            this.slang  =  s;
         } else {
            this.slang  =  "en";
         }
      }
   };   // .lang.favorite()



   WLE.lang.feature  =  function ( apply ) {
      // Wrap message text access for user language
      // Precondition:
      //    apply  -- text keyword
      // Postcondition:
      //    Return text closest to user language
      // Uses:
      //    this
      //    >  .lang.slang
      //    >  .lang.texts
      //    .lang.favorite()
      // Remark: To be replaced
      //         if one day ResourceLoader3 gives access to
      //         gadget@translatewiki
      // 2012-11-30 PerfektesChaos@de.wikipedia
      var e, r;
      if ( ! this.slang ) {
         this.favorite();
      }
      e  =  this.texts[ apply ];
      if ( e ) {
         r  =  e[ this.slang ];
         if ( ! r ) {
            r  =  e.en;
            if ( ! r ) {
               r  =  "???" + apply + "???";
            }
         }
      } else {
         r  =  "***" + apply + "***";
      }
      return r;
   };   // .lang.feature()



   WLE.pageImport.fiat  =  function () {
      // Perform "ImportPage" action
      // Uses:
      //    this
      //    >  .pageImport.$throbber
      //     < .pageImport.source
      //    mw.loader.using()
      //    (.pageImport.find)
      // 2012-12-12 PerfektesChaos@de.wikipedia
      this.$throbber.attr( "style", "display:block;float:right;" );
      mw.loader.using( [ "mediawiki.api" ],
                       this.find );
   };   // .pageImport.fiat()



   WLE.pageImport.fill  =  function () {
      // Content of name or revID field may have been changed
      // Uses:
      //    >  .pageImport.$name
      //    >  .pageImport.$vsn
      //    >  .pageImport.$fire
      //    >< .reTrim
      //    >< .reNum
      // Remark: Used as event handler -- 'this' is not WLE.pageImport
      // 2012-12-12 PerfektesChaos@de.wikipedia
      var g,
          l  =  true,
          s  =  WLE.pageImport.$name.val();
      if ( ! WLE.reTrim ) {
         WLE.reTrim  =  new RegExp( "^[ \t]*(.+[^ \t])?[ \t]*$",  "" );
      }
      if ( s ) {
         g   =  WLE.reTrim.exec( s );
         if ( g ) {
            s  =  g[ 1 ];
            WLE.pageImport.$name.val( s );
            l  =  false;
         }
      }
      s  =  WLE.pageImport.$vsn.val();
      if ( s ) {
         g   =  WLE.reTrim.exec( s );
         if ( g ) {
            s  =  g[ 1 ];
            WLE.pageImport.$vsn.val( s );
            if ( ! WLE.reNum ) {
               WLE.reNum  =  new RegExp( "^[1-9][0-9]*$",  "" );
            }
            l  =  (! WLE.reNum.test( s ) );
         }
      }
      WLE.pageImport.$fire.prop( "disabled", l );
   };   // .pageImport.fill()



   WLE.pageImport.find  =  function () {
      // Start API request
      // Uses:
      //    >  mw.Api
      //    >  .pageImport.$vsn
      //    >  .pageImport.$name
      //    >< .pageImport.reSpU
      //    (.pageImport.found)
      //    (.pageImport.fault)
      // Remark: Used as event handler -- 'this' is not WLE.pageImport
      // 2012-12-12 PerfektesChaos@de.wikipedia
      var q  =  new mw.Api(),
          s  =  WLE.pageImport.$vsn.val(),
          w  =  { action:  "query",
                  prop:    "revisions",
                  rvlimit: "1",
                  rvprop:  "content" };
      if ( s ) {
         w.revids  =  s;
      } else {
         if ( ! WLE.pageImport.reSpU ) {
            WLE.pageImport.reSpU  =  new RegExp( " ", "g" );
         }
         s         =  WLE.pageImport.$name.val();
         s         =  s.replace( WLE.pageImport.reSpU, "_" );
         w.titles  =  s;
      }
      q.get( w ).done( WLE.pageImport.found )
                .fail( WLE.pageImport.fault );
   };   // .pageImport.find()



   WLE.pageImport.found  =  function ( arrived ) {
      // Postprocess page content after ajax request
      // Precondition:
      //    arrived  -- JSON result of ajax query
      // Uses:
      //     < .suggest
      //    .feed()
      // Remark: Used as event handler -- 'this' is not WLE.pageImport
      // 2012-12-12 PerfektesChaos@de.wikipedia
      var pid,
          q    =  ( typeof arrived   ===  "object" );
      if ( q ) {
         q  =  arrived.query;
         if ( q ) {
            q  =  q.pages;
            if ( q ) {
               for ( pid in q ) {
                  q  =  q[ pid ];
                  if ( q ) {
                     WLE.feed( q.revisions[ 0 ][ "*" ] );
                     WLE.suggest  =  q.title;
                  }
                  break;   // for pid
               }   // for pid in q
            }
         }
      }
      WLE.pageImport.flop();
   };   // .pageImport.found()



   WLE.pageImport.flop  =  function () {
      // Remove "ImportPage" form
      // Uses:
      //    this
      //    >  .pageImport.$div
      // 2012-12-12 PerfektesChaos@de.wikipedia
      this.$div.attr( "style", "display:none" );
   };   // .pageImport.flop()



   WLE.pageImport.form  =  function () {
      // Button "ImportPage" has been pressed; build form
      // Uses:
      //    this
      //    >  .$editform
      //    >  .$textarea
      //    >< .reWS
      //    >< .pageImport.$div
      //    >< .pageImport.$form
      //    >< .pageImport.$throbber
      //     < .pageImport.$name
      //     < .pageImport.$vsn
      //     < .pageImport.$fire
      //    jQuery().find()
      //    .lang.feature()
      //    .forward()
      //    .pageImport.fill()
      // 2012-12-12 PerfektesChaos@de.wikipedia
      var launch  =  true,
          s       =  WLE.feed( false );
      if ( s ) {
         if ( ! WLE.reWS ) {
            WLE.reWS  =  new RegExp( "[^ \t\n]", "" );
         }
         launch  =  ( !  WLE.reWS.test( s ) );
      }
      if ( launch ) {
         this.$div  =  WLE.$editform.find( "#LocalEditPageImportDiv" );
         if ( this.$div.length ) {
            this.$form  =  this.$div.find( "#LocalEditPageImportForm" );
            if ( ! this.$form.length ) {
               s           =  "<span id='LocalEditPageImportForm'>"
                              + "<label for='pageImportName'>"
                                 + WLE.lang.feature( "NamePage" )
                              + "</label> "
                              + "<input name='pageImportName'"
                                    + " id='pageImportName'"
                                    + " type='text'"
                                    + " size='66' />"
                              + "&nbsp; &nbsp;"
                              + WLE.forward( "ImportPageFire", false )
                              + "<br />"
                              + "<label for='pageImportVsn'>"
                                 + WLE.lang.feature( "OldID" )
                              + "</label> "
                              + " <code>oldid=</code>"
                              + " <input name='pageImportVsn'"
                                     + " type='text'"
                                     + " size='15' />"
                              + "<br />"
                              + WLE.forward( "ImportPageAbort", true )
                              + "</span>";
               this.$form  =  $( s );
               this.$div.append( this.$form );
               s               =  "//upload.wikimedia.org/"
                                  + "wikipedia/commons"
                                  + "/d/de/Ajax-loader.gif";
               s               =  "<img name='pageImportThrobber'"
                                  + " src='" + s + "' />";
               this.$throbber  =  $( s );
               this.$div.prepend( this.$throbber );
               this.$name  =  this.$form.find( "#pageImportName" );
               this.$name.mouseleave( this.fill );
               this.$name.blur( this.fill );
               this.$vsn  =  this.$form.find( "#pageImportVsn" );
               this.$vsn.mouseleave( this.fill );
               this.$vsn.blur( this.fill );
               this.$fire  =  this.$div.find( "#WLE_select_"
                                               + "ImportPageFire" );
            }
            this.$form.attr( "style", "display:block" );
            this.$throbber.attr( "style", "display:none" );
            this.$div.attr( "style",
                            "border: solid 3px #0000FF;" +
                            "padding: 0.4em;" );
            this.fill();
         }
      } else {
         window.alert( WLE.lang.feature( "ImportPageClear" ) );
      }
   };   // .pageImport.form()



   WLE.face  =  function () {
      // Write on static page table with content
      // Uses:
      //    document
      //    >  .vsn
      //    >  .opt
      //     < .specific
      //     < .scan
      //     < .suffix
      //    .flat()
      //    jQuery()
      //    .first()
      //    jQuery.client()
      //    jQuery().find()
      //    mw.config.get()
      //    .lang.feature()
      //    .fix()
      //    .factory()
      //    .folder()
      //    jQuery().prepend()
      // Remark: Used as event handler -- 'this' is not WLE
      // 2013-01-12 PerfektesChaos@de.wikipedia
      var icon    =  -1,
          s,
          scan    =  "",
          start   =  "",
          suffix  =  "",
          system  =  "",
          $div, $edit, $table;
      WLE.flat( false );
      $div  =  $( "<div id='LocalEditDiv' />" );
      WLE.first( $div );
      if ( $.client ) {
         system  =  $.client.profile().layout;
         if ( "gecko".indexOf( system )  >= 0  ) {
            icon  =  1;
         }
      }
      if ( WLE.opt   &&   typeof WLE.opt  ===  "object" ) {
         if ( typeof WLE.opt.scan  ===  "string" ) {
            WLE.scan  =  WLE.opt.scan;
         }
         if ( typeof WLE.opt.suffix  ===  "string" ) {
            WLE.suffix  =  WLE.opt.suffix;
         }
      }
      $edit  =  $( window.document ).find( "#ca-edit" );
      if ( $edit.length ) {
         $edit  =  $edit.find( "a" );
         if ( $edit.length ) {
            start  =  $edit.attr( "href" );
            if ( start ) {
               start  =  start.replace( /\x27/g, "&#39;")
                              .replace( /</g, "&#60;");
               start  =  "<a class='WLE.buttons'"
                         + " id='WLE.startEdit'"
                         + " style='display:none'"
                         + " href='" + start + "'>"
                         + WLE.lang.feature( "Edit" )
                         + "</a>";
            }
         }
      }
      WLE.specific  =  mw.config.get( "wgDBname" )  +  "."  +
                       mw.config.get( "wgUserName" );
      s  =  "<table id='LocalEditTable' "
                 + "class='wikitable'>\n"
            + "<caption>LocalEdit " + WLE.vsn + "</caption>\n"
            + "<tbody>\n"
            + "<tr>\n<td>"
               + WLE.lang.feature( "BrowserType" )
            + "</td>\n<td>"
               + system
            + "</td>\n<td>"
               + WLE.factory( icon, "WLE.client" )
            + "</td>\n</tr>\n"
            + "<tr>\n<td>"
               + WLE.lang.feature( "URLform" )
            + "</td>\n<td>"
               + WLE.fix( false )
            + "</td>\n<td>"
               + WLE.factory( WLE.fix( true ),  "WLE.URL" )
            + "</td>\n</tr>\n"
            + "<tr>\n<td>"
               + WLE.lang.feature( "AddOn" )
            + "</td>\n<td>"
               + "<span id='WLE.inactive'>"
               + WLE.lang.feature( "installed-false" ) + "</span>"
               + "<span id='WLE.active' style='display:none'>"
               + WLE.lang.feature( "installed-true" ) + "</span>"
            + "</td>\n<td>"
               + WLE.factory( -1, "WLE.stateIMG" )
            + "</td>\n</tr>\n"
            + "<tr>\n<th colspan='3'>"
               + WLE.lang.feature( "HeadlineConfig" )
            + "</th>\n</tr>\n"
            + "<tr>\n<td>"
               + WLE.lang.feature( "DirBase" )
            + "</td>\n<td>"
               + "<span id='WLE.dirbase'></span>"
            + "</td>\n<td>"
               + WLE.folder( "DirBase" )
            + "</td>\n</tr>\n"
            + "<tr>\n<td>"
               + WLE.lang.feature( "DirSub" )
            + "</td>\n<td>"
               + "<span id='WLE.specific' style='display:none'>"
               + WLE.specific + "</span>"
               + "<span id='WLE.dirsub' />"
            + "</td>\n<td>"
               + WLE.folder( "DirSub" )
            + "</td>\n</tr>\n"
            + "<tr>\n<td>"
               + WLE.lang.feature( "FileExtFilter" )
            + "</td>\n<td>"
               + "<span id='WLE.filextScan'>" + scan + "</span>"
            + "</td>\n<td>&nbsp;</td>\n</tr>\n"
            + "<tr>\n<td>"
               + WLE.lang.feature( "FileExtNew" )
            + "</td>\n<td>"
               + "<span id='WLE.filextNew'>" + suffix + "</span>"
            + "</td>\n<td>&nbsp;</td>\n</tr>\n"
            + "<tr>\n<th colspan='2'>" + start + "</th>\n</tr>\n"
            + "</tbody>\n</table>";
      $table  =  $( s );
      $div.prepend( $table );
   };   // .face()



   WLE.factory  =  function ( access, assign ) {
      // Retrieve IMG element
      // Precondition:
      //    access  -- image identifier
      //                     -1  Red x
      //                      0  Neutral
      //                     +1  Yes check
      //    assign  -- element identifier
      // Postcondition:
      //    Return html string
      // 2012-12-11 PerfektesChaos@de.wikipedia
      var pictures  =  [ [ "Red_x",     "ba" ],
                         [ "Neutral",   "bd" ],
                         [ "Yes_check", "fb" ] ],
          picture   =  pictures[ access + 1 ],
          symbol    =  picture[ 0 ],
          sucks     =  picture[ 1 ];
      return  "<img src='"
              +  "//upload.wikimedia.org/wikipedia/commons/thumb/"
              +  sucks.substr( 0, 1 )  +  "/"  +  sucks  +  "/"
              +  symbol  +  ".svg/16px-"  +  symbol  +  ".svg.png"
              +  "' id='"  +  assign  +  "' />";
   };   // .factory()



   WLE.feed  =  function ( apply ) {
      // Retrieve content of text area
      // Precondition:
      //    document.ready
      //    apply  -- false:   retrieve content
      //              string:  insert
      //              true:    just update
      // Postcondition:
      //    Return textarea string; or false
      // Uses:
      //    this
      //    >  .$textarea
      //    >  wikEd
      //    >  mw.util.$content
      //    jQuery().val()
      //    .wikEd()
      //    wikEd.UpdateFrame()
      //    wikEd.UpdateTextarea()
      // 2013-09-01 PerfektesChaos@de.wikipedia
      var r  =  false;
      if ( this.$textarea ) {   // editing
         if ( typeof apply  ===  "string" ) {
            this.$textarea.val( apply );
            r  =  apply;
         }
         if ( this.wikEd()
              &&  window.wikEd.turnedOn
              &&  window.wikEd.useWikEd
              &&  window.wikEd.UpdateFrame
              &&  window.wikEd.UpdateTextarea ) {
            if ( apply ) {
               window.wikEd.UpdateFrame();
            } else {
               window.wikEd.UpdateTextarea();
            }
         }
         if ( ! apply ) {
            r             =  this.$textarea.val();
            this.suggest  =  false;
         }
      }   // editing
      return r;
   };   // .feed()



   WLE.fetch  =  function ( action, add ) {
      // Send event to extension after button action
      // Precondition:
      //    action  -- identifier
      //    add     -- Array with additional information pairs, or false
      // Postcondition:
      //    Event dispatched to privileged chrome:// level.
      // Uses:
      //    document
      //    DOM.getElementById()
      //    DOM.createEvent()
      //    DOM.initEvent()
      //    DOM.setAttribute()
      //    DOM.dispatchEvent()
      // 2012-11-30 PerfektesChaos@de.wikipedia
      var i, n,
          elemt  =  window.document.getElementById( "LocalEditDiv" ),
          event  =  window.document.createEvent( "Events" );
      event.initEvent( "wikilocaleditButton", true, false );
      elemt.setAttribute( "action", action );
      if ( add ) {
         n  =  add.length;
         for ( i = 0;  i < n;  i++ ) {
            elemt.setAttribute( add[ i ][ 0 ],  add[ i ][ 1 ] );
         }   // for i
      }
      elemt.dispatchEvent( event );
   };   // .fetch()



   WLE.filled  =  function () {
      // Hook function if content of text area changed
      // Uses:
      //    .feed()
      // Remark: Used as event handler -- 'this' is not WLE
      // 2012-12-14 PerfektesChaos@de.wikipedia
      WLE.feed( true );
   };   // .filled()



   WLE.fire  =  function () {
      // Start page processing; check whether situation is interesting
      // Uses:
      //    mw.config.get()
      //    mw.loader.using()
      //    .form()
      //    DOM.addEventListener()
      //    (.face)
      // Remark: Used as event handler -- 'this' is not WLE
      // 2012-12-12 PerfektesChaos@de.wikipedia
      var s  =  mw.config.get( "wgAction" );
      switch ( s ) {
         case "view" :
            mw.loader.using( [ "user",
                               "mediawiki.user",
                               "mediawiki.util",
                               "jquery.client" ],
                             WLE.face );
            break;
         case "edit" :
         case "submit" :
            WLE.form( s );
            window.document.addEventListener( "wikilocaleditFilled",
                                              WLE.filled,
                                              true );
            /*
            window.document.addEventListener( "wikilocaleditSaved",
                                              WLE.flushed,
                                              true );
            */
            break;
      }   // switch wgAction
   };   // .fire()



   WLE.fired  =  function ( action ) {
      // Execute button action
      // Precondition:
      //    action  -- identifier
      // Postcondition:
      //    Local processing and event dispatched to privileged level.
      // Uses:
      //    >  mw.util.$content
      //    >  .scan
      //    >  .suffix
      //    >< .specific
      //    .pageImport.form()
      //    .pageImport.flop()
      //    .pageImport.fiat()
      //    .feed()
      //    mw.config.get()
      //    .fetch()
      // Remark: Used as event handler -- 'this' is not WLE
      // 2012-12-12 PerfektesChaos@de.wikipedia
      var cb, low,
          plus  =  [ ];
      switch ( action ) {
         case "ImportPage" :
            WLE.pageImport.form();
            break;
         case "ImportPageAbort" :
            WLE.pageImport.flop();
            break;
         case "ImportPageFire" :
            WLE.pageImport.fiat();
            break;
         case "OpenFile" :
            WLE.feed( false );
            low  =  false;
            cb   =  mw.util.$content.find( "#ANSI" );
            if ( cb.length ) {
               low  =  cb.prop( "checked" );
            }
            plus.push( [ "lowcode", low ] );
         case "SaveFileAs" :
            if ( WLE.scan ) {
               plus.push( [ "scan", WLE.scan ] );
            }
            if ( WLE.suffix ) {
               plus.push( [ "suffix", WLE.suffix ] );
            }
            if ( WLE.suggest ) {
               plus.push( [ "suggest", WLE.suggest ] );
            }
         case "DirSub" :   // fall through
            if ( ! WLE.specific ) {
               WLE.specific  =  mw.config.get( "wgDBname" )  +  "."  +
                                mw.config.get( "wgUserName" );
            }
            plus.push( [ "specific", WLE.specific ] );
         case "Abort" :   // fall through
         case "SaveFile" :
            switch ( action ) {
               case "Abort" :
               case "SaveFile" :
               case "SaveFileAs" :
                  WLE.feed( false );
               break;
            }   // switch wgAction
            break;
      }   // switch wgAction
      if ( ! plus.length ) {
         plus  =  false;
      }
      WLE.fetch( action, plus );
   };   // .fired()



   WLE.first  =  function ( $assign ) {
      // Detect high level page content element and place element there
      // Precondition:
      //    $assign  -- element
      // Postcondition:
      //    Local processing and event dispatched to privileged level.
      // Uses:
      //    this
      //    >  mw.util.$content
      //    >< .$top
      //    jQuery().prepend()
      //    jQuery().before()
      // 2012-11-30 PerfektesChaos@de.wikipedia
      this.$top  =  $( "#mw-content-text" );
      if ( this.$top.length ) {
         this.$top.prepend( $assign );
      } else {
         this.$top  =  $( "#bodyContent" );
         if ( ! this.$top.length ) {
            this.$top  =  $( "#article" );
            if ( ! this.$top.length ) {
               this.$top  =  $( "#content" );
               if ( ! this.$top.length ) {
                  this.$top  =  mw.util.$content;
               }
            }
         }
         this.$top.before( $assign );
      }
   };   // .first()



   WLE.fix  =  function ( aim ) {
      // Check URL format
      // Precondition:
      //    aim  -- true: return symbol key
      //            false: return link to correct page, or "&nbsp;"
      // Uses:
      //    this
      //    window
      //    >< .iconURL
      //    mw.config.get()
      //    mw.util.getUrl()
      //    .lang.feature()
      // 2014-09-28 PerfektesChaos@de.wikipedia
      var r;
      if ( aim ) {
         r  =  this.iconURL;
      } else if ( window.location.pathname.substr(0, 6)
                  ===  "/wiki/" ) {
         this.iconURL  =  1;
         r  =  "&nbsp;";
      } else {
         this.iconURL  =  -1;
         r  =  "<a href='"
                   + mw.util.getUrl( mw.config.get( "wgPageName" ) )
                      + "'>"  +  this.lang.feature( "URLformfix" )
               + "</a>";
      }
      return r;
   };   // .fix()



   WLE.flat  =  function ( after ) {
      // Hide undesired content from regular page
      // Precondition:
      //    after  -- true: dynamic, else static
      // Uses:
      //    this
      //    .wikEd()
      //    mw.util.addCSS()
      // 2013-09-01 PerfektesChaos@de.wikipedia
      var s  =    ".cn-fundraiser-banner,"
                + "#mw-js-message,"
                + "#siteNotice,"
                + "#fundraising\n"
                + "#ca-nstab-user,"
                + "#ca-edit,"
                + "#ca-view,"
                + "#ca-history,"
                + "#ca-move,"
                + ".noarticletext,"
                + "#newarticletext\n"
                + "{display: none ! important;}";
      if ( after ) {
         s  =  ".editOptions\n"
               + "{margin-top: 10px;"
               + ( this.wikEd()
                   ? "background-color: transparent;" : "" )
               + " margin-bottom: 10px;}"
               + "#editnotice-ns-2,"
               + ".previewnote,\n"
               + "DIV.mw-tos-summary,"
               + "SPAN#wpSummaryLabel,"
               + "DIV#editpage-copywarn,"
               + "A#mw-editform-cancel,"
               + ".editHelp,"
               + "A[target=\"helpwindow\"],\n"
               + "INPUT#wpDiff,"
               + "INPUT#wpSave,"
               + "INPUT#wpSummary,"
               + ".editCheckboxes,"
               + ".cancelLink,"
               + "#enhanced-diff-live-button,"
               + "#wikEdEditHelp,"
               + "#wikEdLocalDiff,"
               + "#wikEdSummaryInputWrapper,"
               + "#thresholdSave,\n"
               + s;
      }
      mw.util.addCSS( s );
   };   // .flat()



   WLE.folder  =  function ( action ) {
      // Create button for directory selection, initially invisible
      // Precondition:
      //    action  -- identifier
      // Postcondition:
      //    Return html string
      // Uses:
      //    this
      //    .force()
      // 2012-11-30 PerfektesChaos@de.wikipedia
      var show  =  "<span style='font-size: 200%;"
                             + " font-weight: bold;'>*</span>";
      return  "<div class='WLE.buttons'"
                + " id='WLE." + action + "'"
                + " style='display:none'>"
              +  this.force( action, show, true )  +  "</div>";
   };   // .folder()



   WLE.force  =  function ( action, assign, able ) {
      // Create button
      // Precondition:
      //    action  -- identifier
      //    assign  -- label
      //    able    -- false: disabled
      // Postcondition:
      //    Return html string
      // 2012-11-30 PerfektesChaos@de.wikipedia
      return  "<button type='button'"
                   + " id='WLE_select_" + action + "'"
                   + " style='background-color: #80FFFF'"
                   + " onclick='mw.libs.localEdit.fired(\"" + action
                                                                 + "\")'"
                        +  ( able ? "" : " disabled" )
                   + ">" + assign + "</button>";
   };   // .force()



   WLE.form  =  function ( action ) {
      // Start edit page processing
      // Precondition:
      //    action  -- "edit" or "submit"
      // Uses:
      //    this
      //    >  mw.util.$content
      //    >  .wgTitle
      //     < .$editform
      //     < .$textarea
      //    .flat()
      //    jQuery().find()
      //    jQuery().attr()
      //    jQuery().text()
      //    .forward()
      //    jQuery()
      //    jQuery().after()
      //    jQuery().css()
      //    .first()
      // 2012-12-14 PerfektesChaos@de.wikipedia
      var s, $elt, $form, $h1, $ta;
      this.flat( true );
      $form  =  mw.util.$content.find( "#editform" );
      if ( $form.length ) {
         $ta  =  $form.find( "#wpTextbox1" );
         if ( $ta.length ) {   // textarea
            if ( ! $ta.attr( "readonly" ) ) {   // modifiable
               this.$editform  =  $form;
               this.$textarea  =  $ta;
               if ( action === "edit" ) {
                  $ta.text( "" );
               }
               $elt  =  $form.find( "#wpPreview" );
               if ( $elt.length ) {
                  s  =  "<span id='LocalEditDiv'"
                           + " style='border: solid 3px #0000FF;"
                                  + " margin-left: 5px;"
                                  + " padding: 0.4em;'>\n"
                           + "ANSI:"
                           + "<input type='checkbox'"
                                 + " name='ANSI'"
                                 + " id='ANSI' />"
                           + WLE.forward( "OpenFile", true )
                           + WLE.forward( "ImportPage", true )
                           + WLE.forward( "SaveFile", false )
                           + WLE.forward( "SaveFileAs", true )
                        + "</span>"
                        + "<div id='LocalEditPageImportDiv'"
                            + " style='display:none' />";
                  $elt.after( $( s ) );
               }
            }
         }   // textarea
      }
      $h1  =  mw.util.$content.find( "#firstHeading" );
      if ( $h1.length ) {
         $h1.text( this.wgTitle );
         $h1.css( "border", "solid 2px #0000FF" );
         $h1.css( "text-align", "center" );
         $h1.css( "background-color", "#D0FFFF" );
      }
      s  =  "<div id='LocalEditFileDiv'>"
               + "<span id='LocalEditFilePath'"
                    + " style='background-color: #D0FFFF;' />"
            + "</div>";
      this.first( $( s ) );
   };   // .form()



   WLE.forward  =  function ( action, able ) {
      // Create button for file selection or canceling
      // Precondition:
      //    action  -- identifier
      //    able    -- initially enabled
      // Postcondition:
      //    Return html string
      // Uses:
      //    this
      //    .lang.feature()
      //    .force()
      // 2012-11-30 PerfektesChaos@de.wikipedia
      return  this.force( action,  this.lang.feature( action ),  able );
   };   // .forward()



   WLE.wikEd  =  function () {
      // Check whether wikEd is active
      // Postcondition:
      //    Return true iff wikEd is active
      // Uses:
      //    >  wikEd
      // 2013-09-01 PerfektesChaos@de.wikipedia
      return ( window.wikEd
               &&  typeof window.wikEd  ===  "object"
               &&  ! window.wikEd.disabled );
   };   // .wikEd()



   if ( ! WLE.loaded ) {
      WLE.loaded  =  true;
      if ( mw.config.get( "wgNamespaceNumber" )  ===  2 ) {
         WLE.wgTitle  =  mw.config.get( "wgTitle" );
         if ( WLE.wgTitle   ===
              mw.config.get( "wgUserName" )  +  "/LocalEdit" ) {
            $( WLE.fire );
         }
      }
      mw.loader.state( { "ext.gadget.localEdit": "ready" } );
   }
}( window.mediaWiki, window.jQuery ) );



// Emacs
// Local Variables:
// coding: utf-8-dos
// fill-column: 80
// End:

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