User:PerfektesChaos/js/lintHint/d.js: Difference between revisions

Content deleted Content added
-3.2
-3.3
Line 1:
/// User:PerfektesChaos/js/lintHint/d.js
// Show LintErrors analysis live
/// 2018-0607-06 PerfektesChaos@de.wikipedia
// ResourceLoader: compatible;
// dependencies: user, mw.API, mediawiki.storage, mediawiki.util
Line 17:
( function ( mw, $ ) {
"use strict";
var Version = -3.23,
Signature = "lintHint",
HINT = { cmodels: { "wikitext": true,
Line 55:
using: [ "mediawiki.api",
"mediawiki.storage",
"mediawiki.util" ],
"user.options" ],
$body: false,
$page: false,
Line 83 ⟶ 84:
$table: false,
$top: false },
CODMIRROR = { cm: false },
EDIT = { listen: false,
live: false,
Line 109 ⟶ 111:
sub: "/r.js" },
REPOS = { },
TEACHTMPLXPAND = { live: = {false },
WIKITEXTUPDATE = { live:= false{ };,
WIKED = { };
 
 
Line 346 ⟶ 349:
// fair()
// mw.hook()
// (WIKITEXTTMPLXPAND.first)
// (LINTER.first)
// (features)
Line 379 ⟶ 382:
case "ExpandTemplates":
PREGO.fire();
fair( WIKITEXTTMPLXPAND.first );
break;
case "LintErrors":
Line 437 ⟶ 440:
}
}
// mw.hook( "CodeMirror.enabled" ).add( CODMIRROR.fire );
break;
} // switch wgAction
Line 798 ⟶ 802:
// > HINT.launched
// > EDIT.live
// TEACHUPDATE.fetch()
// API.full()
// mw.hook()
// (BOX.flip)
// 2018-05-20 PerfektesChaos@de.wikipedia
TEACHUPDATE.fetch();
if ( HINT.launch && ! HINT.launched && ! EDIT.live ) {
API.full();
Line 933 ⟶ 937:
// >< BOX.$other
// mw.message()
// TEACHUPDATE.feed()
// BOX.future()
// (BOX.find)
Line 946 ⟶ 950:
s = mw.message( s ).text();
} else {
TEACHUPDATE.feed( e.type );
if ( HINT.later ) {
s = e.type;
Line 1,253 ⟶ 1,257:
// > BOX.fgcRun
// > GUIDER.live
// > HINT.source
// > HINT.$page
// > WIKITEXT.live
// >< API.errors
// >< API.single
// >< EDIT.live
// >< EDIT.source
// >< EDIT.$source
// < EDIT.listen
// < HINT.launch
// < HINTBOX.$textareacollapsed.hide()
// EDIT.fire()
// API.full()
// 2018-0507-2006 PerfektesChaos@de.wikipedia
if ( HINT.live ) {
if ( BOX.$box ) {
Line 1,289 ⟶ 1,288:
}
if ( EDIT.live ) {
if ( ! EDIT.$source fire() {;
if ( ! EDIT.source ) {
switch ( HINT.source ) {
case "wikitext":
case "proofread-page":
EDIT.source = "#wpTextbox1";
break;
} // switch HINT.source
}
if ( EDIT.source ) {
EDIT.$source = HINT.$page.find( EDIT.source );
if ( ! ( EDIT.$source.length || WIKITEXT.live ) ) {
BOX.$collapsed.hide();
EDIT.live = false;
}
} else {
EDIT.live = false;
}
}
if ( EDIT.live && EDIT.$source && EDIT.$source.length ) {
EDIT.listen = false;
API.fire( EDIT.$source.val() );
HINT.$textarea = EDIT.$source;
}
} else {
HINT.launch = true;
Line 1,356 ⟶ 1,332:
}
}; // BOX.future()
 
 
 
CODMIRROR.fetch = function () {
// Retrieve CodeMirror contents
// Postcondition:
// Returns contents, if present
// Uses:
// > CODMIRROR.cm
// 2018-07-06 PerfektesChaos@de.wikipedia
var r;
if ( CODMIRROR.first() ) {
r = CODMIRROR.cm.doc.getValue();
}
return r;
}; // CODMIRROR.fetch()
 
 
 
CODMIRROR.first = function () {
// Uses:
// > window.CodeMirror
// >< CODMIRROR.cm
// mw.user.options.get()
// 2018-07-06 PerfektesChaos@de.wikipedia
var r, uo;
if ( ! CODMIRROR.cm &&
typeof window.CodeMirror === "function" &&
typeof window.CodeMirror.doc === "object" ) {
CODMIRROR.cm = window.CodeMirror;
}
if ( CODMIRROR.cm ) {
uo = mw.user.options.get( "usecodemirror" );
if ( typeof uo === "number"
&& uo > 0 ) {
r = CODMIRROR.cm;
}
}
return r;
}; // CODMIRROR.first()
 
 
 
/*
CODMIRROR.fire = function ( app ) {
}; // CODMIRROR.fire()
*/
 
 
 
EDIT.fetch = function () {
// Retrieve HTML textarea contents
// Postcondition:
// Returns textarea contents, if present
// Uses:
// > HINT.source
// > HINT.$page
// >< EDIT.selector
// >< EDIT.$source
// < EDIT.listen
// < HINT.$textarea
// 2018-07-06 PerfektesChaos@de.wikipedia
var r;
if ( ! EDIT.$source ) {
if ( ! EDIT.selector ) {
switch ( HINT.source ) {
case "wikitext":
case "proofread-page":
EDIT.selector = "#wpTextbox1";
break;
} // switch HINT.source
}
if ( EDIT.selector ) {
EDIT.$source = HINT.$page.find( EDIT.selector );
if ( ! EDIT.$source.length ) {
EDIT.live = false;
}
} else {
EDIT.live = false;
}
}
if ( EDIT.live && EDIT.$source && EDIT.$source.length ) {
HINT.$textarea = EDIT.$source;
r = EDIT.$source.val();
}
return r;
}; // EDIT.fetch()
 
 
Line 1,374 ⟶ 1,437:
}
}; // EDIT.fine()
 
 
 
EDIT.fire = function () {
// Anaysis of source text area requested
// Uses:
// > TMPLXPAND.live
// CODMIRROR.fetch()
// WIKED.fetch()
// EDIT.fetch()
// API.fire()
// BOX.$collapsed.hide()
// 2018-07-06 PerfektesChaos@de.wikipedia
var source;
if ( ! TMPLXPAND.live ) {
source = CODMIRROR.fetch();
if ( ! source ) {
WIKED.fetch();
}
}
if ( ! source ) {
source = EDIT.fetch();
}
if ( source ) {
EDIT.listen = false;
API.fire( source );
} else {
BOX.$collapsed.hide();
}
}; // EDIT.fire()
 
 
Line 1,676 ⟶ 1,769:
// Uses:
// >< API.Api
// TEACHUPDATE.fetch()
// mw.Api.loadMessagesIfMissing()
// (GUIDER.form)
Line 1,687 ⟶ 1,780:
API.Api = new mw.Api();
}
TEACHUPDATE.fetch();
for ( i = 0; i < HINT.errors.length; i++ ) {
req.push( "linter-category-" + HINT.errors[ i ] );
Line 1,967 ⟶ 2,060:
// > PREGO.maxage
// mw.loader.getState()
// mw.loader.state()
// REPOS.fire()
// 2018-0507-2006 PerfektesChaos@de.wikipedia
var s = "ext.gadget." + PREGO.signature;
if ( ! mw.loader.getState( s ) !== "ready" ) {
mw.loader.state( s, "loading" );
REPOS.fire( PREGO.site,
PREGO.store + PREGO.signature + PREGO.sub,
Line 2,194 ⟶ 2,289:
 
 
TEACHTMPLXPAND.feedfirst = function ( apply ) {
// Initialize ExpandTemplates
// Uses:
// > HINT.using
// < TMPLXPAND.live
// < HINT.live
// < EDIT.live
// < EDIT.selector
// (TMPLXPAND.further)
// 2018-07-06 PerfektesChaos@de.wikipedia
TMPLXPAND.live = true;
HINT.live = true;
EDIT.live = true;
EDIT.selector = "#output";
mw.loader.using( HINT.using, TMPLXPAND.further );
}; // TMPLXPAND.first()
 
 
 
TMPLXPAND.further = function () {
// Prepare ExpandTemplates
// Precondition:
// Resources available
// Uses:
// mw.hook()
// (BOX.flip)
// 2018-05-20 PerfektesChaos@de.wikipedia
mw.hook( "wikipage.content" ).add( BOX.flip );
}; // TMPLXPAND.first()
 
 
 
UPDATE.feed = function ( apply ) {
// Memorize unknown category
// Uses:
// >< TEACHUPDATE.o
// TEACHUPDATE.flush()
// 2018-05-20 PerfektesChaos@de.wikipedia
if ( typeof TEACHUPDATE.o !== "object" ) {
TEACHUPDATE.o = { };
}
if ( typeof TEACHUPDATE.o.unknown !== "object" ) {
TEACHUPDATE.o.unknown = [ ];
}
if ( $.inArray( apply, HINT.errors ) < 0 ) {
HINT.errors.push( apply );
TEACHUPDATE.o.unknown.push( apply );
}
TEACHUPDATE.flush();
}; // TEACHUPDATE.feed()
 
 
 
TEACHUPDATE.fetch = function () {
// Consider memorized categories
// Precondition:
Line 2,222 ⟶ 2,349:
// > Signature
// >< HINT.errors
// < TEACHUPDATE.o
// TEACHUPDATE.flush()
// 2018-05-20 PerfektesChaos@de.wikipedia
var storage = mw.storage.get( Signature ),
Line 2,234 ⟶ 2,361:
if ( typeof parsed.translations === "object"
&& parsed.translations ) {
TEACHUPDATE.o = { translations: parsed.translations };
}
if ( typeof parsed.unknown === "object"
Line 2,255 ⟶ 2,382:
} // for i
if ( unknown.length ) {
if ( typeof TEACHUPDATE.o === "object" ) {
TEACHUPDATE.o.unknown = unknown;
} else {
TEACHUPDATE.o = { unknown: unknown };
}
}
if ( unknown.length !== parsed.unknown.length ) {
TEACHUPDATE.flush();
}
}
Line 2,268 ⟶ 2,395:
} catch (e) {
}
if ( typeof TEACHUPDATE.o !== "object" ) {
TEACHUPDATE.flush();
}
}
}; // TEACHUPDATE.fetch()
 
 
 
TEACHUPDATE.flush = function () {
// Update unknown categories memory
// Precondition:
Line 2,282 ⟶ 2,409:
// Uses:
// > Signature
// > TEACHUPDATE.o
// 2018-05-20 PerfektesChaos@de.wikipedia
var storage;
if ( typeof TEACHUPDATE.o === "object" ) {
storage = JSON.stringify( TEACHUPDATE.o );
}
if ( storage ) {
Line 2,293 ⟶ 2,420:
mw.storage.remove( Signature );
}
}; // TEACHUPDATE.flush()
 
 
 
WIKITEXTWIKED.firstfetch = function () {
// InitializeUpdate ExpandTemplatestext area from wikEd contents
// Uses:
// > HINTwindow.usingwikEd
// >< WIKITEXTWIKED.livewikEd
// 2018-07-06 < HINTPerfektesChaos@de.livewikipedia
//if ( ! WIKED.wikEd < EDIT.live&&
// <( EDITtypeof window.sourcewikEd === "function" ||
// (WIKITEXT typeof window.further)wikEd === "object"
&& window.wikEd ) ) &&
// 2018-05-20 PerfektesChaos@de.wikipedia
typeof window.wikEd.disabled === "boolean" &&
WIKITEXT.live = true;
typeof window.wikEd.highlightSyntax === "boolean" &&
HINT.live = true;
typeof window.wikEd.turnedOn === "boolean" &&
EDIT.live = true;
EDIT typeof window.sourcewikEd.useWikEd === "#outputboolean"; ) {
WIKED.wikEd = window.wikEd;
mw.loader.using( HINT.using, WIKITEXT.further );
}; // WIKITEXT.first()}
if ( WIKED.wikEd &&
! WIKED.wikEd.disabled &&
WIKED.wikEd.useWikEd &&
WIKED.wikEd.turnedOn &&
WIKED.wikEd.highlightSyntax ) {
WIKED.wikEd.UpdateTextarea();
}
}; // WIKED.fetch()
 
 
 
/*
WIKITEXT.further = function () {
WIKED.fire = function () {
// Prepare ExpandTemplates
var script = document.createElement('script');
// Precondition:
script.src = '//en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd.js&action=raw&ctype=text/javascript';
// Resources available
script.async = true;
// Uses:
document.getElementsByTagName('head')[0].appendChild(script);
// mw.hook()
}; // WIKED.fire(BOX.flip)
*/
// 2018-05-20 PerfektesChaos@de.wikipedia
mw.hook( "wikipage.content" ).add( BOX.flip );
}; // WIKITEXT.first()