Revision 137468 of "User:PerfektesChaos/js/WikiSyntaxTextMod/d.js" on testwiki/// PerfektesChaos/js/WikiSyntaxTextMod/?.js /// 2012-06-13 [email protected] /// Fingerprint: #0#0# /// <nowiki> /* jshint curly:true, latedef:true, laxbreak:true, trailing:true, undef:true, white:false */ /* global jQuery: true, mw: true, mediaWiki: false, WikiSyntaxTextMod: true, Exclude_WikisyntaxTextMod: true, Include_WikisyntaxTextMod: true, OnRequest_WikisyntaxTextMod: true, loadingReady: true */ /*jslint browser: true, plusplus: true, regexp: true, sloppy: true, unparam: true, vars: true, white: true, maxerr: 50 */ /*globals jQuery: true, mw: true, mediaWiki: false, WikiSyntaxTextMod: true, Exclude_WikisyntaxTextMod: true, Include_WikisyntaxTextMod: true, OnRequest_WikisyntaxTextMod: true, loadingReady: true */ if (typeof(mediaWiki) !== "object") { // disconnected mw = { config: false, libs: { }, log: function () {}, str: { }, util: { } }; } if (typeof(mw.libs.WikiSyntaxTextMod) !== "object") { mw.libs.WikiSyntaxTextMod = { bb: { } }; } if ( ! mw.libs.WikiSyntaxTextMod.vsn) { mw.libs.WikiSyntaxTextMod.vsn = -4.54; } // This is the main script of a suite of 5...6 modules // External access: // WikiSyntaxTextMod_About() // WikiSyntaxTextMod_Run() if (typeof(mw.libs.WikiSyntaxTextMod.bb) !== "object") { mw.libs.WikiSyntaxTextMod.bb = { }; } if (typeof(mw.libs.WikiSyntaxTextMod.api) !== "object") { mw.libs.WikiSyntaxTextMod.api = { }; } // Requires: JavaScript 1.3 // (String.charCodeAt String.fromCharCode String.replace) // JavaScript 1.5 RegExp non-capturing parenthese // Requires: MediaWiki 1.18 // (mw.libs; 1.17: mw.config mw.loader mw.util // jQuery/core jQuery.cookie) // Uses: // mediaWiki:: mw:: // > .config // > .loader // > .util // jQuery:: // .browser() // .cookie() // .isArray() // .ready() // .trigger() // .trim() // wikEd:: // > .disabled // .UpdateFrame() // .Setup() // .UpdateTextarea() mw.libs.WikiSyntaxTextMod.bb.util = function (WSTM) { // From general utility package // 2012-05-18 [email protected] if (typeof(WSTM.util) !== "object") { WSTM.util = { }; } 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 [email protected] var elt; var obj; var s; if (typeof( adult[activate] ) !== "object") { adult[activate] = (assign ? assign : { } ); } if (assign) { obj = adult[activate]; for (s in assign) { if (assign.hasOwnProperty(s)) { elt = assign[s]; if (typeof(elt) === "object") { WSTM.util.fiatObjects(obj, s, elt); } } } // for s in obj } }; // .util.fiatObjects() WSTM.util.yymmddhhmmss = function (align) { // Build date and time stamp // Precondition: // align -- Date object // Postcondition: // Returns string formatted // Uses: // .str.substrEnd() // 2012-03-28 [email protected] var s = (align.getFullYear() % 100) * 10000 + (align.getMonth() + 1) * 100 + align.getDate(); var t = align.getHours() * 10000 + align.getMinutes() * 100 + align.getSeconds(); return (WSTM.str.fromNum(s) + WSTM.str.fromNum(t)); }; // .util.yymmddhhmmss() WSTM.util.fiatObjects(WSTM, "debugging", { loud: false }); }; // .bb.util() mw.libs.WikiSyntaxTextMod.bb.util(mw.libs.WikiSyntaxTextMod); delete mw.libs.WikiSyntaxTextMod.bb.util; //----------------------------------------------------------------------- mw.libs.WikiSyntaxTextMod.bb.config = function (WSTM) { // Variables for global usage in WSTM // 2012-03-27 [email protected] if (typeof(WSTM.g) !== "object") { WSTM.g = { learnt: false, mediaWiki : false, wDBname : undefined, wNsNames : undefined, wNsNumber : undefined, wPageName : undefined, wServer : undefined, wTitle : undefined, wUserLang : undefined, // wgUserLanguage projLang : undefined, // ~ wgContentLanguage projSpace : undefined, // Project: projType : undefined, // ~ wgSiteName downcased userLang : undefined // ~ wgUserLanguage }; WSTM.ia = false; WSTM.type = "WikiSyntaxTextMod"; } // multiple loading? WSTM.g.fetch = function (assign, access) { // Set WSTM global variable by retrieving from mediaWiki context // Precondition: // assign -- variable // undefined for .mediaWiki // access -- string with name // false for .mediaWiki // Postcondition: // Returns undefined if no value found // Uses: // > window // > mediaWiki // < .g.mediaWiki // < .g.wDBname // < .g.wNsNames // < .g.wNsNumber // < .g.wPageName // < .g.wServer // < .g.wTitle // < .g.wUserLang // 2012-02-04 [email protected] var r = assign; var v; if (assign === undefined) { if (! this.mediaWiki) { if (typeof(window) === "object") { if (window !== null) { if (typeof(window.mediaWiki) === "object") { this.mediaWiki = window.mediaWiki; r = this.mediaWiki; } // object } // !== null } // window } // this.mediaWiki if (this.mediaWiki) { if (access) { v = mw.config.get(access); if (v !== null && access) { switch (access) { case "wgDBname" : this.wDBname = v; break; case "wgNamespaceIds" : this.wNsNames = v; break; case "wgNamespaceNumber" : this.wNsNumber = v; break; case "wgPageName" : this.wPageName = v; break; case "wgServer" : this.wServer = v; break; case "wgTitle" : this.wTitle = v; break; case "wgUserLanguage" : this.wUserLang = v; break; } // switch access r = v; } // val } else { r = this.mediaWiki; } // access } // mediaWiki } // undefined return r; }; // .g.fetch() // Possible user configuration // Uses: // .util.fiatObjects() // 2012-05-25 [email protected] WSTM.util.fiatObjects(WSTM, "config", { diffPage: true, load: { }, // mod: { }, // portlet: false, page: { } }); if (typeof(WSTM.config.load) !== "object") { WSTM.config.load = { after: false, inhibit: false, updater: false }; } if (typeof(WSTM.config.page) !== "object") { WSTM.config.page = { exclude: false, include: false, oldid: false, support: false }; } if (typeof(WSTM.config.load.after) !== "function") { WSTM.config.load.after = false; } }; // .bb.config() mw.libs.WikiSyntaxTextMod.bb.config(mw.libs.WikiSyntaxTextMod); delete mw.libs.WikiSyntaxTextMod.bb.config; //----------------------------------------------------------------------- mw.libs.WikiSyntaxTextMod.bb.str = function (WSTM) { // Copied from string utility package. // Uses: // .util.fiatObjects() // 2012-05-18 [email protected] WSTM.util.fiatObjects(WSTM, "str", { }); WSTM.str.substrEnd = function (apply, amount, after) { /** Retrieve last characters from string like Mozilla substr(-n, n) @version 2011-09-10 [email protected] @param apply string @param amount position counted from end @param after optional: number of chars, if not amount @return string at end */ var n = amount; if (typeof(after) === "number") { n = after; } return apply.substr(apply.length - amount, n); }; // .str.substrEnd() WSTM.str.fromNum = function (adjust) { /** Format number as string @version 2011-10-09 [email protected] @param adjust number to be formatted @return adjust as string */ return adjust.toString(); }; // .str.fromNum() }; // .bb.str() mw.libs.WikiSyntaxTextMod.bb.str(mw.libs.WikiSyntaxTextMod); delete mw.libs.WikiSyntaxTextMod.bb.str; //----------------------------------------------------------------------- mw.libs.WikiSyntaxTextMod.bb.api = function (WSTM) { // API recommended to users // Uses: // .util.fiatObjects() // 2012-05-18 [email protected] WSTM.util.fiatObjects(WSTM, "api", { }); WSTM.api.isAppropriate = function (advanced) { // Check whether WikisyntaxTextMod is appropriate // Precondition: // advanced -- true: interactive request // Wikiserver environment -- not wgIsArticle // Postcondition: // Returns true iff current page is appropriate. // Uses: // >< .g.wNsNumber // >< .g.wTitle // >< .config.page.oldid // >< .config.page.exclude // >< .config.page.include // >< .config.page.support // .g.fetch() // .str.substrEnd() // .main.isEditable() // .main.isPageMatch() // > Include_WikisyntaxTextMod // > Exclude_WikisyntaxTextMod // > OnRequest_WikisyntaxTextMod // mw.util.getParamValue() // 2012-02-19 [email protected] var leeway; var legal; var r = false; var select; WSTM.g.fetch(WSTM.g.wNsNumber, "wgNamespaceNumber"); WSTM.g.fetch(WSTM.g.wTitle, "wgTitle"); if (typeof(WSTM.g.wNsNumber) === "number" && typeof(WSTM.g.wTitle) === "string") { leeway = false; legal = (WSTM.g.wNsNumber === 0); if (WSTM.g.wNsNumber >= 0 && WSTM.g.wNsNumber % 2 === 0) { leeway = true; if (mw.util.getParamValue("oldid")) { if (typeof(WSTM.config.page.oldid) !== "boolean") { WSTM.config.page.oldid = false; } leeway = WSTM.config.page.oldid; legal = leeway; } // not the standard version if (WSTM.g.wNsNumber > 0) { if ((WSTM.str.substrEnd(WSTM.g.wTitle, 4) === ".css") || (WSTM.str.substrEnd(WSTM.g.wTitle, 3) === ".js")) { leeway = false; legal = false; } // suppress JavaScript and CSS } // maybe user namespace if (! WSTM.main.isEditable()) { leeway = false; legal = false; } // restriction } // no discussion or special page if (! legal && leeway) { // generally possible if (typeof(Include_WikisyntaxTextMod) === "object") { WSTM.config.page.include = Include_WikisyntaxTextMod; } if (typeof(WSTM.config.page.include) === "object") { legal = WSTM.main.isPageMatch(WSTM.config.page.include); } // defined if (! legal && advanced === true) { select = typeof(OnRequest_WikisyntaxTextMod); if (select === "object" || select === "boolean") { WSTM.config.page.support = OnRequest_WikisyntaxTextMod; } else { select = typeof(WSTM.config.page.support); } if (select === "object") { legal = WSTM.main.isPageMatch(WSTM.config.page.support); } else if (select === "boolean") { legal = WSTM.config.page.support; } } // interactive? } // leeway if (legal) { // bail out? if (typeof(Exclude_WikisyntaxTextMod) === "object") { WSTM.config.page.exclude = Exclude_WikisyntaxTextMod; } if (typeof(WSTM.config.page.exclude) === "object") { legal = ! WSTM.main.isPageMatch(WSTM.config.page.exclude); } // defined } r = legal; } else { mw.log(WSTM.debugging, ".api.isAppropriate() failed g.fetch", 3); } return r; }; // .api.isAppropriate() mw.libs.WikiSyntaxTextMod.api.load = function (action) { // Request loading of outsourced modules // Precondition: // action -- user defined external callback function // true: run automatic // false: do nothing than updating // Any Wikimedia project // Postcondition: // Loading of all dependencies is initiated // Remark: May be used as event handler -- 'this' is not accessed // Uses: // > .debugging // > .debugging.feeder // > .main.subs // > .debugging.loud // > .main.loaded // > .main.score // > .main.server // > .main.site // > .main.self // > .main.subdir // >< .main.bb // >< .main.vsn // >< mw.libs.VersionControl.proj.* // >< .main.loading // < .main.fiat // < .main.sister // < .main.vc // .util.yymmddhhmmss() // .main.fire() // (.main.fetchCacheRev) // mw.loader.load() // .main.freezeGet() // Requires: JavaScript 1.3 charCodeAt() // 2012-03-23 [email protected] var b; var i; var k; var lazy = (action !== false && ! WSTM.main.loaded); var local = false; var n = WSTM.main.subs.length; var s; var saver; var script; var stamp; var store; if ( ! WSTM.main.bb) { WSTM.main.bb = { }; for (i = 0; i < n; i++) { s = WSTM.main.subs.substr(i, 1); WSTM.main.bb[s] = { load: false, vsn: 0 }; } // for i } if (lazy) { if (typeof(WSTM.debugging) === "object") { if (typeof(WSTM.debugging.feeder) === "function") { WSTM.main.loading = true; local = WSTM.debugging.feeder(WSTM.main.subs); } else if (WSTM.debugging.loud) { lazy = false; } } } if (action) { b = typeof(action); if (b === "function" || b === "boolean") { WSTM.main.fiat = action; } // action } // action if (WSTM.main.loaded && action) { WSTM.main.fire(); } else if ( ! local) { k = (WSTM.main.site === "test" ? 9 : 7); saver = false; script = "//"; stamp = WSTM.util.yymmddhhmmss(new Date()); WSTM.vsn = WSTM.vsn + "*"; n = (action ? n : 0); script = script + WSTM.main.server + "/w/index.php?action=raw" + "&ctype=text/javascript" + "&title=" + WSTM.main.self + "/"; store = script + "js/" + WSTM.main.subdir + "/" + WSTM.main.score; stamp = stamp.substr(0, k); for (i = 0; i < n; i++) { s = WSTM.main.subs.substr(i, 1); saver = WSTM.main.freezeGet(s); if (! saver) { saver = stamp; } WSTM.main.loading = true; mw.loader.load(store + s + ".js&" + saver, "text/javascript"); } // for i if (action && ! WSTM.main.loading) { WSTM.main.fire(); } // already loaded, continue right now if (WSTM.main.server.indexOf(".wikipedia.org") > 0) { saver = (lazy ? stamp.substr(0, 8) : stamp); WSTM.main.sister = (WSTM.main.site ? WSTM.main.site : "en") + "wiki"; if (typeof(mw.libs.VersionControl) !== "object") { mw.libs.VersionControl = { "proj": { } }; } WSTM.main.vc = mw.libs.VersionControl; if (typeof(WSTM.main.vc.proj) !== "object") { WSTM.main.vc.proj = { }; } WSTM.main.vc = WSTM.main.vc.proj; if (typeof(WSTM.main.vc[WSTM.main.sister]) !== "object") { WSTM.main.vc[WSTM.main.sister] = { "PerfektesChaos": { } }; } WSTM.main.vc = WSTM.main.vc[WSTM.main.sister]; if (typeof(WSTM.main.vc.PerfektesChaos) !== "object") { WSTM.main.vc.PerfektesChaos = { }; } WSTM.main.vc = WSTM.main.vc.PerfektesChaos; if (typeof(WSTM.main.vc.rv) !== "object") { WSTM.main.vc.fire = WSTM.main.fetchCacheRev; mw.loader.load(script + "versionControl.js&" + saver + "&maxage=1800&smaxage=300", "text/javascript"); } } } }; // .api.load() WSTM.api.run = function () { // Launch syntax and user defined replacement manually // Precondition: // Wikiserver environment for editpage with "editform" // Postcondition: // Returns void(0), as required in GUI action. // wpTextbox1 value of "editform" is modified, if appropriate. // Remark: May be used as event handler -- 'this' is not accessed // Uses: // .api.isAppropriate() // .api.load() // 2012-02-12 [email protected] if (WSTM.api.isAppropriate(true)) { // fool proof WSTM.api.load(true); } return void(0); }; // .api.run() }; // .bb.api() mw.libs.WikiSyntaxTextMod.bb.api(mw.libs.WikiSyntaxTextMod); delete mw.libs.WikiSyntaxTextMod.bb.api; //----------------------------------------------------------------------- mw.libs.WikiSyntaxTextMod.bb.errors = function (WSTM) { // Detected syntax error handling // Uses: // .util.fiatObjects() // 2012-05-18 [email protected] WSTM.util.fiatObjects(WSTM, "errors", { }); WSTM.errors.fault = function () { // Wrap external function for presenting error list // Remark: Used as event handler -- 'this' is not WSTM.errors // Uses: // .errors.format() // 2011-12-23 [email protected] WSTM.errors.format(); }; // .errors.fault() WSTM.errors.frozen = function () { // Retrieve standardized identifier for error message summaries // Postcondition: // Return standardized identifier // 2011-12-23 [email protected] var s = " ##"; // hide from dumps return "<!-- " + "WikisyntaxTextMod" + s + " ERROR in PAGE" + s; }; // .errors.frozen() }; // .bb.errors() mw.libs.WikiSyntaxTextMod.bb.errors(mw.libs.WikiSyntaxTextMod); delete mw.libs.WikiSyntaxTextMod.bb.errors; //----------------------------------------------------------------------- mw.libs.WikiSyntaxTextMod.bb.main = function (WSTM) { // Top level functions (internal) // 2012-03-28 [email protected] if (typeof(WSTM.main) !== "object") { WSTM.main = { bb: false, fiat: false, loaded: false, loading: false, scheme: false, score: "r", self: "User:PerfektesChaos", seal: "user:PerfektesChaos/WikiSyntaxTextMod", server: "en.wikipedia.org", site: "", store: false, subdir: "WikisyntaxTextMod", swift: "WikiSyntaxTextMod_rvIDs" }; if (typeof(WSTM.debugging.site) === "string") { WSTM.main.site = WSTM.debugging.site; switch (WSTM.main.site) { case "file:/" : WSTM.main.server = "localhost"; break; case "test" : WSTM.main.server = "test.wikipedia.org"; if (typeof(WSTM.debugging.self) === "string") { WSTM.main.self = WSTM.debugging.self; } break; } // switch .main.site } if (typeof(WSTM.vsn) === "number") { if (typeof(WSTM.debugging.prefix) === "string") { WSTM.main.score = WSTM.debugging.prefix; } else if (WSTM.vsn < 0) { WSTM.main.score = "d"; } // no debugging package defined WSTM.vsn = WSTM.main.site + "(" + WSTM.main.score + ")" + " Run=" + WSTM.vsn; } // multiple loading? if (typeof(WSTM.debugging.subdir) === "string") { WSTM.main.subdir = WSTM.debugging.subdir; } if (typeof(WSTM.debugging.subs) === "string") { WSTM.main.subs = WSTM.debugging.subs; } else { WSTM.main.subs = "MOTLU"; if (WSTM.main.site.length > 3 && WSTM.main.site === "file:/") { // "test" "file:/" WSTM.main.subs = WSTM.main.subs + "X"; WSTM.main.subs = "MQSNLVX"; } } } WSTM.main.actionSubmit = function () { // Perform action=submit mode: Possible error msg to be displayed // Precondition: // Interactive mode (web form) with wgAction==submit // Remark: Used as event handler -- 'this' is not WSTM.main // Uses: // < .errors.story // .main.textarea() // .errors.frozen() // .api.load() // (.errors.fault) // Requires: JavaScript 1.3 charCodeAt() // 2012-01-16 [email protected] var i; var n; var j; var s = WSTM.main.textarea(false, false); var scan; var story; var k; if (typeof(s) === "string") { scan = WSTM.errors.frozen(); i = s.indexOf(scan); if (i >= 0) { n = scan.length; j = s.indexOf("-->", i + n); if (j >= 0) { story = s.slice(i + n, j); k = story.indexOf("\n"); j += 3; if (s.charCodeAt(j) === 10) { // \n j++; } s = (i > 0 ? s.substr(0, i) : "") + s.substr(j); WSTM.main.textarea(s, true); if (k >= 0) { WSTM.errors.story = story.substr(k); WSTM.api.load(WSTM.errors.fault); } } } // ErrorMsgID } else { mw.log(WSTM.debugging, ".main.actionSubmit() Textarea failed", 3); } }; // .main.actionSubmit() WSTM.main.features = function (arrange, alter) { // Handle external scripts, e.g. WikEd // Precondition: // arrange -- undefined: before load // true: initialize, no decoration // false: update // alter -- if arrange: show pretty changes, not only diffpage // Remark: Used as event handler -- 'this' is not WSTM.main // Uses: // >< .ia // (.main.features) // > window // > editToolStrIns:: // >< .off // .update() // > wikEd:: // > .disabled // >< .turnedOn // >< .useWikEd // .Setup() // .UpdateFrame() // .UpdateTextarea() // .util.fiatObjects() // Notes: // editToolStrIns: // ... // WikEd -- six cases: // 1. First beginning, then major change // -> WSTM, Diff // true, false // 2. First beginning, then minor changes // -> WSTM, Setup // true, true // 3. First beginning, no changes // -> WSTM, Setup // true, true // 4. Later started, then major change // -> Setup?, UpdateTextarea, WSTM, Diff // false, false // 5. Later started, then minor changes // -> Setup?, UpdateTextarea, WSTM, UpdateFrame // false, true // 6. Later started, no changes // -> Setup?, UpdateTextarea, WSTM // false, false // 2012-05-18 [email protected] if (typeof(window) === "object") { // online interactive WSTM.util.fiatObjects(WSTM, "ia", { ext: false, $editform: false, $textarea: false }); if (typeof(arrange) !== "boolean") { // before load WSTM.util.fiatObjects(WSTM.ia, "ext", { }); if (typeof(mw.libs.editToolStrIns) === "object") { WSTM.ia.ext.editToolStrIns = false; } if (typeof(window.wikEd) === "object" && window.wikEd && window.wikEd.UpdateTextarea && ! WSTM.ia.ext.wikEd) { WSTM.ia.ext.wikEd = { skipWSTM: true, setupWSTM: false, beginWSTM: false, disabled: window.wikEd.disabled, highlightSyntax: window.wikEd.highlightSyntax, turnedOn: window.wikEd.turnedOn, useWikEd: window.wikEd.useWikEd }; if (document.getElementsByName("wikEdStartupFlag")[0]) { if (window.wikEd.origVersion === window.wikEd.lastVersion) { WSTM.ia.ext.wikEd.beginWSTM = true; window.wikEd.highlightSyntax = false; window.wikEd.disabled = true; } } else if (typeof(window.wikEd.Setup) === "function") { try { window.wikEd.RemoveEventListener(window, "load", window.wikEd.Setup, false); } catch (e) { } try { window.wikEd.RemoveEventListener(document, "DOMContentLoaded", window.wikEd.Setup, false); } catch (e) { } } } // wikEd } else if (WSTM.ia.ext) { // after load, any if (WSTM.ia.ext.wikEd) { if (arrange) { if (WSTM.ia.ext.wikEd.beginWSTM) { if (typeof(WSTM.ia.ext.wikEd.disabled) === "boolean") { WSTM.ia.ext.wikEd.setupWSTM = true; } } if ( ! WSTM.ia.ext.wikEd.setupWSTM && ! WSTM.ia.ext.wikEd.beginWSTM) { // asynchronous overrun if (WSTM.ia.ext.wikEd.flag) { WSTM.ia.ext.wikEd.flag.removeAttribute("name"); WSTM.ia.ext.wikEd.flag = false; } window.wikEd.Setup(); WSTM.ia.ext.wikEd.disabled = window.wikEd.disabled; window.wikEd.disabled = false; WSTM.ia.ext.wikEd.setupWSTM = true; } } if ( ! window.wikEd.disabled && ! WSTM.ia.ext.wikEd.beginWSTM) { if (arrange) { window.wikEd.UpdateTextarea(null); window.wikEd.config.onHook.push(WSTM.main.features); } else { if (alter) { window.wikEd.highlightSyntax = WSTM.ia.ext.wikEd.highlightSyntax; window.wikEd.useWikEd = WSTM.ia.ext.wikEd.useWikEd; if (window.wikEd.useWikEd) { window.wikEd.UpdateFrame(null); } } else { window.wikEd.disabled = true; window.wikEd.useWikEd = false; } } WSTM.ia.ext.wikEd.beginWSTM = false; } } // "wikEd" } } // window }; // .main.features() WSTM.main.fetchCacheRev = function () { // Memorize revision IDs of outsourced modules as cookies // Remark: Used as event handler -- 'this' is not WSTM.main // Uses: // > .main.sister // > .main.vc // > .main.subs // > .main.score // > .main.subdir // .main.freezePut() // 2012-03-28 [email protected] var e; var i; var j; var n = WSTM.main.vc.rv.length; var s; var seek; var set; for (i = 0; i < WSTM.main.subs.length; i++) { set = false; s = WSTM.main.subs[i]; seek = "js/" + WSTM.main.subdir + "/" + WSTM.main.score + s + ".js"; for (j = 0; j < n; j++) { e = WSTM.main.vc.rv[j]; if (e[0] === seek) { set = e[1]; break; // for j } // found } // for j if (set) { WSTM.main.freezePut(s, set); } } // for i }; // .main.fetchCacheRev() WSTM.main.fire = function () { // Execute appropriate major entry function in interactive environment // Precondition: // Loading of outsourced modules complete // Postcondition: // .main.full() aut idem started // Remark: May be used as event handler -- 'this' is not accessed // Uses: // > (.main.full) // >< .main.fiat // .main.features // (.main.fiat) // jQuery().ready() // 2012-02-14 [email protected] if (WSTM.main.fiat) { if (typeof(WSTM.main.fiat) !== "function") { WSTM.main.fiat = WSTM.main.full; } WSTM.main.features(); jQuery(document).ready(WSTM.main.features); jQuery(document).ready(WSTM.main.fiat); } }; // .main.fire() WSTM.main.force = function () { // Decorate skin with portlet link to Run() // Precondition: // Decoration is suitable and desired. // Remark: Used as event handler -- 'this' is not WSTM.main // Uses: // > .vsn // > .config.portlet // < .main.portlet // jQuery:: // .trim() // ().get() // ().find() // mw:: // > .util.$content // .util.addPortletLink() // 2012-03-12 [email protected] var s; var say = "Start WikiSyntaxTextMod * Version: " + WSTM.vsn; var scope = false; var select = "ca-WSTM-run"; var shoot = "javascript" + ":" + "window.mw.libs.WikiSyntaxTextMod.api.load(true);" + "void(0);"; var show = "WikiSyntaxTextMod"; var stick = false; var swift = null; var $li; if (typeof(WSTM.config.portlet) === "object") { s = WSTM.config.portlet.scope; if (typeof(s) === "string") { s = jQuery.trim(s); if (s.charCodeAt(0) === 35) { // '#' s = s.substr(1); } if (s.length) { scope = s; } } s = WSTM.config.portlet.show; if (typeof(s) === "string") { s = jQuery.trim(s); if (s.length) { show = s; } } s = WSTM.config.portlet.stick; if (typeof(s) === "string") { s = jQuery.trim(s); if (s.length) { stick = s; } } s = WSTM.config.portlet.swift; if (typeof(s) === "string") { s = jQuery.trim(s); if (s.length) { swift = s; } } } else { WSTM.config.portlet = { }; } if (! scope) { if (mw.config.get("skin") === "vector") { scope = "p-cactions"; } } if (scope === "p-cactions") { $li = jQuery(document).find("#p-cactions .menu li"); if ( $li.length ) { stick = $li.get(0); } else { stick = "#"; } } else if (! scope) { scope = "p-tb"; } if (! stick) { if (scope === "p-tb") { stick = "#t-whatlinkshere"; } } if (WSTM.main.portlet) { mw.util.$content.remove("#" + select); } WSTM.main.portlet = mw.util.addPortletLink(scope, shoot, show, select, say, swift, stick); }; // .main.force() WSTM.main.freezeFormat = function (about, assign) { // Format revision ID of outsourced module for cookie // Precondition: // about -- module type (single letter) // assign -- revision ID (number or RE string) // Postcondition: // Returns string to be appended // Uses: // > .main.score // > .main.site // 2012-01-14 [email protected] var r; r = this.score + about + "_" + assign + "~"; if (this.site.length) { r = this.site + "-" + r; } return r; }; // .main.freezeFormat() WSTM.main.freezeGet = function (about) { // Query revision IDs of outsourced modules // Precondition: // about -- module type (single letter) // Postcondition: // Returns false if unknown // string with revision ID // Uses: // > .main.swift // >< .main.store // jQuery.cookie() // .main.freezeFormat() // 2012-01-14 [email protected] var got; var re; var r = false; if (! this.store) { this.store = jQuery.cookie(this.swift); } if (this.store) { re = "~" + this.freezeFormat(about, "([0-9]+)"); re = new RegExp(re); got = re.exec(this.store); if (got !== null) { r = got[1]; } } return r; }; // .main.freezeGet() WSTM.main.freezePut = function (about, assign) { // Put revision ID of outsourced module into cookie // Precondition: // about -- module type (single letter) // assign -- revision ID as string or number // Postcondition: // Uses: // > .main.swift // >< .main.store // .main.freezeGet() // .main.freezeFormat() // .str.fromNum() // jQuery.cookie() // 2012-03-12 [email protected] var shift; var stack = this.freezeGet(about); var learn = (! stack); if (learn) { if (! this.store) { this.store = "~"; } this.store = this.store + this.freezeFormat(about, assign); } else { shift = assign; if (typeof(assign) === "number") { shift = WSTM.str.fromNum(assign); } learn = (stack !== shift); if (learn) { this.store = this.store.replace("_" + stack + "~", "_" + shift + "~"); } } if (learn) { jQuery.cookie(this.swift, this.store, { expires: 7, path: "/" }); } }; // .main.freezePut() WSTM.main.isEditable = function () { // Is the current user permitted to edit this page? // Postcondition: // Return true iff no restriction detected // Uses: // mw.config.get() // 2012-05-16 [email protected] var dont = mw.config.get("wgRestrictionEdit"); var groups; var i; var j; var m; var n; var ng; var p; var r = true; if (dont) { if (typeof(dont) === "object") { n = dont.length; if (n) { groups = mw.config.get("wgUserGroups"); r = false; if (groups) { ng = groups.length; if (ng) { m = n; for (i = 0; i < n; i++) { p = dont[i]; if (p) { for (j = 0; j < ng; j++) { if (p === groups[j]) { m--; break; // for j } } // for j } else { // may contain "" or null m--; } } // for i r = (m === 0); } } } } } return r; }; // .main.isEditable WSTM.main.isPageMatch = function (accomplish) { // Does current page accomplish? // Precondition: // accomplish -- array of rules // Each rule is a string to be interpreted as RegExp // Generally any matching of article / page name // If starting with ':', it is full qualified // Full qualified starts with ":DB:" // DB is a project name like // "enwiki", "dewiki", "commonswiki", "svwikisource" // Postcondition: // Returns true // iff current page is matched by any rule in accomplish. // Uses: // >< .g.wDBname // >< .g.wPageName // .g.fetch() // jQuery.isArray() // Requires: JavaScript 1.3 charCodeAt() // 2011-12-23 [email protected] var e; var i; var k; var n; var f = false; var r; if (jQuery.isArray(accomplish)) { WSTM.g.fetch(WSTM.g.wDBname, "wgDBname"); WSTM.g.fetch(WSTM.g.wPageName, "wgPageName"); if (WSTM.g.wDBname !== null && WSTM.g.wPageName !== null) { n = accomplish.length; for (i = 0; i < n; i++) { e = accomplish[i]; if (typeof(e) === "string") { if (e.charCodeAt(0) === 58) { // ':' k = WSTM.g.wDBname.length; if (e.charCodeAt(k+1) !== 58) { // ':' k = false; } else if (e.substr(1, k) !== WSTM.g.wDBname) { k = false; } else { e = "^" + e.substr(k + 2); } if (! k) { k = e.substr(1).indexOf(":"); r = "^" + accomplish.substr(1, k) + "$"; r = new RegExp(r, "i"); if (r.test(WSTM.g.wDBname)) { e = "^" + e.substr(k + 1); } else { e = false; } } } // full qualified if (e) { r = new RegExp(e, "i"); f = r.test(WSTM.g.wPageName); if (f) { break; // for i } // match } // wgDBname match } // string } // for i } // crash-safe global } // isArray return f; }; // .main.isPageMatch() WSTM.main.ready = function (all) { // Declare ResourceLoader state, trigger loadWikiScript event // Precondition: // all -- false: head module only true: including any sub-module // Uses: // > .main.seal // < .main.loaded // .g.fetch() // mw.loader.state() // jQuery().trigger() // 2012-02-08 [email protected] var sign = this.seal + (all ? "/*" : ""); if (all) { this.loaded = true; } try { if (typeof(loadingReady) === "function") { loadingReady(sign); } else if (WSTM.g.fetch(undefined, false)) { // WMF context mw.loader.state(sign, "ready"); } } catch (e) { // repeated loading } // register and ready if (typeof(jQuery) !== "undefined") { // WMF context jQuery(document).trigger("loadWikiScript", [ sign ]); } }; // .main.ready() WSTM.main.textarea = function (alter, advance) { // Retrieve or replace wikitext using edit area // Precondition: // Interactive mode (web form) // alter -- false or undefined: Retrieve wikitext // string: Modified wikitext to be stored // advance -- true: no formatting required, // quick update; diffpage will be shown next // Postcondition: // Return string: wpTextbox1 content if ! alter // false: if alter // if ! alter: editform unavailable // or area not modifiable // Uses: // > .ia // > .ia.$editform // > .ia.$textarea // .main.features() // jQuery() // "editform" // >< .wpTextbox1 // 2012-02-14 [email protected] var r = false; var $box; var $form; if (WSTM.ia) { // online interactive and initialized if ( ! WSTM.ia.$editform ) { $form = jQuery("#editform"); if ($form.length) { // editing $box = jQuery("#wpTextbox1"); if ($box.length) { // textarea if (! $box.attr("readonly")) { // modifiable WSTM.ia.$editform = $form; WSTM.ia.$textarea = $box; } // modifiable } // textarea } // editing } // editing if (WSTM.ia.$textarea) { this.features(true); if (typeof(alter) === "string") { // replace WSTM.ia.$textarea.val(alter); this.features(false, ! advance); } else { // retrieve r = WSTM.ia.$textarea.val(); } // mode } // $textarea } // online return r; }; // .main.textarea() WSTM.main.wait = function (aware, aged) { // Wait for loading of outsourced modules // Precondition: // aware -- letter of module finished loading: "L", "U", ... // aged -- version number of module // Loading of _L and _U and ... in progress // Postcondition: // .main.full() aut idem started, when all ready // else wait (do nothing) // Uses: // > .main.subs // >< .main.bb // >< .vsn // < .main.loading // .main.ready() // .main.fire() // 2012-06-13 [email protected] var e; var i; var launch = true; var n = this.subs.length; var s; for (i = 0; i < n; i++) { s = this.subs.substr(i, 1); e = this.bb[ s ]; if (s === aware) { if (! e.load) { e.vsn = aged; e.load = true; WSTM.vsn = WSTM.vsn + ", " + aware + "=" + aged; } // still working } else if (! e.load) { launch = false; } // missing } // for i if (launch) { this.loading = false; this.ready(true); this.fire(); } // all modules loaded }; // .main.wait() }; // .bb.main() mw.libs.WikiSyntaxTextMod.bb.main(mw.libs.WikiSyntaxTextMod); delete mw.libs.WikiSyntaxTextMod.bb.main; //----------------------------------------------------------------------- function WikiSyntaxTextMod_About() { // Pop up message box with version information, or return version // Postcondition: // Message box is displayed. // Returns void(0), as required in GUI action, if browser window. // Uses: // > .vsn // mw.util.jsMessage() // 2012-02-16 [email protected] var r = mw.libs.WikiSyntaxTextMod.vsn; if (typeof(window) === "object") { // online if (typeof(window.alert) === "function") { // standard window.alert(r); } else { mw.util.jsMessage(jQuery("<div style='border: solid 1px'>" + r + "</div>"), "WikiSyntaxTextMod.vsn"); } if (typeof(window.console) === "object") { if (typeof(window.console.info) === "function") { window.console.info(r); } } r = void(0); } return r; } // WikiSyntaxTextMod_About() function WikisyntaxTextMod_About() { return WikiSyntaxTextMod_About(); } // WikisyntaxTextMod_About() function WikisyntaxTextMod_IsAppropriate(advanced) { // DEPRECATED: Check whether WikisyntaxTextMod is appropriate // Precondition: // advanced -- true: interactive request // Wikiserver environment -- not wgIsArticle // Postcondition: // Returns true iff current page is appropriate. // Uses: // .api.isAppropriate() // 2011-09-08 [email protected] return mw.libs.WikiSyntaxTextMod.api.isAppropriate(advanced); } // WikisyntaxTextMod_IsAppropriate() function WikisyntaxTextMod_Load(action) { alert("Veraltete Function:\n WikisyntaxTextMod_Load()\n\nNeu:\n" + " mw.libs.WikiSyntaxTextMod.api.load()"); mw.libs.WikiSyntaxTextMod.api.load(action); } // WikisyntaxTextMod_Load() function WikiSyntaxTextMod_Run() { // External access (API): Launch replacement manually // Uses: // .api.run() // 2012-02-12 [email protected] mw.libs.WikiSyntaxTextMod.api.run(); return void(0); } // WikiSyntaxTextMod_Run() function WikisyntaxTextMod_Run() { // DEPRECATED lowercase 's' // 2012-02-12 [email protected] mw.libs.WikiSyntaxTextMod.api.run(); return void(0); } // WikisyntaxTextMod_Run() //----------------------------------------------------------------------- mw.libs.WikiSyntaxTextMod.bb.auto = function (WSTM) { // Start execution on import // 2012-03-28 [email protected] WSTM.autoRun = function () { // Load and start WikiSyntaxTextMod, if appropriate // Precondition: // Wikiserver environment // Postcondition: // Returns void(0), as required in GUI action, if browser window. // Remark: Used as event handler -- 'this' is not WSTM // Uses: // > .config.load.urlPar // > .config.load.inhibit // > .config.load.updater // > .config.portlet // >< .g.wPageName // < .main.lockAuto // .g.fetch() // .api.isAppropriate() // .api.load() // .main.features() // .main.actionSubmit() // .main.force() // mw.util.getParamValue() // mw.config.get() // jQuery().ready() // 2012-05-19 [email protected] var later; var launch = false; var learn; var load; var lock = false; var lookup = false; var re; var start; WSTM.main.lockAuto = true; WSTM.config.load.urlPar = mw.util.getParamValue("wstm"); if (typeof(WSTM.config.load.urlPar) === "string") { if (/^(0|false$|n|inhibit)/.test(WSTM.config.load.urlPar)) { lock = true; } } // &wstm= if (typeof(WSTM.config.load.inhibit) === "boolean") { lock = WSTM.config.load.inhibit; } load = ! lock; if (load) { if (WSTM.g.fetch(undefined, false)) { load = ! mw.config.get("wgIsArticle"); } // mediaWiki } // ! wgIsArticle if (load) { start = mw.util.getParamValue("action"); learn = false; if (start === "edit") { learn = (! (mw.util.getParamValue("undo") || mw.util.getParamValue("undoafter"))); } else if (start === "submit") { lookup = true; } if (learn || lookup) { WSTM.g.fetch(WSTM.g.wNsNumber, "wgNamespaceNumber"); load = WSTM.api.isAppropriate(false); launch = learn; if (lookup) { lookup = (WSTM.g.wNsNumber % 2 === 0); if (lookup) { lookup = WSTM.api.isAppropriate(true); } } } } // "edit" is always a non-regular page, never IsArticle if (! load) { if (typeof(WSTM.config.load.updater) === "string") { if (WSTM.config.load.updater.length) { WSTM.g.fetch(WSTM.g.wPageName, "wgPageName"); if (WSTM.g.wPageName !== null) { re = new RegExp(WSTM.config.load.updater, "i"); load = (re.test(WSTM.g.wPageName)); } // wgPageName } else { load = true; } } // config.load.updater } // .config.load.inhibit if (load) { WSTM.api.load(launch); } // Do it! if (lookup) { WSTM.main.features(); jQuery(document).ready(WSTM.main.actionSubmit); } if (WSTM.config.portlet) { later = (load || lookup); if ( ! later && launch) { later = WSTM.api.isAppropriate(true); } if (later) { jQuery(document).ready(WSTM.main.force); } } return void(0); }; // .autoRun() if (typeof(window) === "object") { // online if (WSTM.main.lockAuto !== true) { WSTM.main.ready(false); mw.loader.using( [ "mediawiki.util", "jquery.cookie" ], WSTM.autoRun); } } if (typeof(WSTM.config.load) === "object") { if (typeof(WSTM.config.load.after) === "function") { WSTM.config.load.after(); } } }; // .bb.auto() mw.libs.WikiSyntaxTextMod.bb.auto(mw.libs.WikiSyntaxTextMod); delete mw.libs.WikiSyntaxTextMod.bb.auto; void(0); // Emacs // Local Variables: // encoding: iso-8859-1-dos // fill-column: 80 // End: /// EOF </nowiki> WikiSyntaxTextMod/?.js All content in the above text box is licensed under the Creative Commons Attribution-ShareAlike license Version 4 and was originally sourced from https://test.wikipedia.org/w/index.php?oldid=137468.
![]() ![]() This site is not affiliated with or endorsed in any way by the Wikimedia Foundation or any of its affiliates. In fact, we fucking despise them.
|