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

Content deleted Content added
2.15
3.0
Line 1:
/// User:PerfektesChaos/js/lintHint/r.js
/// 2018-0205-0809 PerfektesChaos@de.wikipedia
/// Fingerprint:#0#2BABF1EA3015094E#
/// @license GPL [//www.mediawiki.org/w/COPYING](+GFDL,LGPL,CC-BY-SA)
///<nowiki>
(function(mw,$){
"use strict";
var Version=23.150,Signature="lintHint",HINT={cmodels:{"wikitext":true,
"proofread-index":true,"proofread-page":true},doc:"en:User:PerfektesChaos/js/"+Signature,errors:["bogus-image-options","deletable-table-tag","fostered","html5-misnesting","ignored-table-attr","misc-tidy-replacement-issues","misnested-tag","missing-end-tag","missing-start-tag","mixed-content","multi-colon-escape","multiline-html-table-in-list","multiple-unclosed-formatting-tags","obsolete-tag","pwrap-bug-workaround","self-closed-tag","stripped-tag","tidy-font-bug","tidy-whitespace-bug","unclosed-quotes-in-heading"],idRev:0,last:true,later:false,launch:false,launched:false,layer:falsenull,lazy:false,live:false,ltr:true,source:false,
using:["mediawiki.api","mediawiki.api.messages","mediawiki.util"],$body:false,$page:false,$textarea:false},API={Api:false,errors:false,scream:false,serviceserver:"api/rest_v1/",scanner:"transform/wikitext/to/lint",swift:"page/lint"},BOX={bgc:"FFFF00",bgcErr:"FFE4E1",bgcOk:"ADFF2F",bgcRun:"C0C0C0",boc:"808080",fgc:"000000",fgcRun:"A0A0A0",swift:false,$box:false,$collapsed:false,$failure:false,$null:false,$other:false,$pagename:false,$swift:false,$tbody:false,$table:false,$top:false},EDIT={listen:false,live:false,$source:false},GUIDER={last:false,live:false,reTrim:false,using:["jquery.textSelection","mediawiki.ui.button","mediawiki.ui.input"],$pagename:false},LINTER={live:false},PREGO={app:false,live:false,pars:[["last","boolean"],["later","boolean"],["launch","boolean"],["layer","boolean"],["lazy","boolean"],["spaces","string"]],signature:"preferencesGadgetOptions",site:"w:en",store:"User:PerfektesChaos/js/",sub:"/r.js"},REPOS={},TEACH={};
HINT.texts={
"desc":{"en":"Show LintErrors analysis live.","de":"Zeige LintErrors-Analyse live."},
"it":"Mostra analisi degli errori di Lint in diretta."},"___domain":{"en":"en.wikipedia.org","de":"de.wikipedia.org"},
"de":"de.wikipedia.org"},"howTo":{"en":"Fill balanced wikitext into first input area and press adjacent submit button, or enter page name into second input field.","de":"Füge ausgeglichenen(might Wikitextbe infollowed dasby obererevision Eingabefeld ein, oder einen Seitennamen in das untere, und betätige die jeweilige SchaltflächeID)."},
"de":"Füge ausgeglichenen Wikitext in das obere Eingabefeld ein, oder einen Seitennamen in das untere (ggf. gefolgt von einer Versionsnummer), und betätige die jeweilige Schaltfläche.","it":"Inserisci il wikitesto nella prima area di input e premi il tasto di invio adiacente, oppure scrivi il titolo della pagina nel secondo campo (potrebbe essere seguito dall’ID della revisione)."},
"mark":{"en":"select problem in source text","de":"Problem im Quelltext selektieren"},
"noPagemark":{"en":"Wikitextselect pageproblem notin foundsource text","de":"Wikitext-SeiteProblem im nichtQuelltext gefundenselektieren"},
"it":"Seleziona un problema nel testo sorgente"},"noPage":{"en":"Wikitext page not found",
"other":{"en":"Future problems detected.","de":"Zukünftige Probleme detektiert."}
"de":"Wikitext-Seite nicht gefunden","it":"Pagina di wikitesto non trovata"},
"other":{"en":"Future problems detected.","de":"Zukünftige Probleme detektiert.",
"it":"Futuri problemi individuati."},"^suffix":{"en":"&#8211; linter error analysis support",
"de":"&#8211; Unterstützung der Analyse von Linter-Fehlern","it":"&#8211; Supporto per l’analisi degli errori di Lint"},
"^^last":{"en":"Analyze previous revisions, too.","de":"Analysiere auch frühere Seitenversionen.",
"it":"Analizza anche le revisioni precedenti."},"^^launch":{"en":"Run analysis automatically in namespaces on visit rather than manually triggered by button.",
"de":"Löse die Analyse automatisch beim Seitenbesuch in den Namensräumen aus, statt sie manuell über den angebotenen Knopf zu starten.","it":"Esegui automaticamente l’analisi nei namespace all’accesso, piuttosto che avviandola manualmente tramite bottone."},
"^^layer":{"en":"Convert all source edit links on LintErrors special page into ParserMigration tool edit.","de":"Wandle auf der LintErrors-Spezialseite alle Verlinkungen zur Quelltextbearbeitung in das Migrationswerkzeug um.",
"it":"Converti tutti i link di modifica sorgente presenti sulla pagina speciale Errori di Lint nello strumento di modifica ParserMigration."},"^^lazy":{"en":"Suppress small label if no error detected.",
"de":"Unterdrücke das kleine grüne Feld, falls bei einer Seitendarstellung kein Problem gefunden wurde.","it":"Nascondi l’etichetta in assenza di errori rilevati."},
"^^spaces":{"en":"Space separated list of namespace numbers, for automatized analysis or - for none or * for all","de":"Namensraum-Nummern für automatische Analyse, durch Leerzeichen getrennt, oder - für keine oder * für alle",
"it":"Lista di namespace, in formato numerico separati da spazi, dove effettuare l’analisi. Usare - per la lista vuota e * per indicarli tutti."}
};
function face(){
Line 32 ⟶ 44:
if(typeof apply.rooms==="object"&&apply.rooms&&typeof apply.rooms.length==="number"){
live=false;
if(HINT.nsn>=0){
for(i=0;i<apply.rooms.length;i++){
if(apply.rooms[i]===HINT.nsn){
live=true;
break;}}}
}else if(typeof apply.rooms==="string"&&apply.rooms==="*"){
live=true(HINT.nsn>=0);
}else{
live=false;}
Line 57 ⟶ 70:
HINT.live=true;
if(HINT.launch&&!HINT.launched){
mw.loader.using(HINT.using,API.feedfull);
}else{
mw.loader.using(HINT.using,BOX.feed);}
Line 63 ⟶ 76:
BOX.flat();}}}
function first(){
var i,listen,live,re,s;
HINT.signature="ext.gadget."+Signature;
if(mw.loader.getState(HINT.signature)!=="ready"){
Line 76 ⟶ 89:
case "Blankpage":
s=mw.config.get("wgTitle");
if(i=s.indexOf("/"+Signature)>0){;
if(i>1){
switch(s.substr(i+1)){
case Signature:
TEACH.fetch();
GUIDER.first();}
listen=true;
break;
case PREGO.signature:
PREGO.live=true;
PREGO.fire();
break;}}
break;
case "LintErrors":
LINTER.live=true;
PREGO.fire();
fair(LINTER.first);
break;}
Line 129 ⟶ 152:
listen=live;}
if(listen){
if(HINT.nsn===0){
HINT.live=true;}
mw.hook(Signature+".config").add(features);}
if(live){
PREGO.feed();
fair();
TEACH.fetch();
PREGO.fire();}
if(HINT.live){
mw.loader.using(HINT.using,BOX.feed);}}
HINT.pub={doc:"[["+HINT.doc+"]]",type:Signature,vsn:Version};
mw.hook(Signature+".ready").fire(HINT.pub);}}
Line 166 ⟶ 185:
API.errors=false;
mw.hook("wikipage.content").add(BOX.fault);
};
API.feed=function(access){
var w={action:"query",prop:"revisions"};
if(typeof access==="string"){
API.single=access;}
if(HINT.nsn<0){
w.rvprop="content|contentmodel";
}else{
w.rvprop="content";
if(!HINT.idRev){
HINT.idRev=mw.config.get("wgRevisionId");}
HINT.launched=true;}
if(HINT.idRev){
w.revids=HINT.idRev;
}else if(API.single){
w.titles=API.single;
}else{
w=false;}
if(w){
if(!API.Api){
API.Api=new mw.Api();}
API.Api.get(w).done(API.feeder).fail(API.fault);}
};
API.feeder=function(arrived){
var id,q,s,w;
if(typeof arrived==="object"&&typeof arrived.query==="object"&&typeof arrived.query.pages==="object"){
q=arrived.query.pages;
for(id in q){
q=q[id];
if(q&&q.revisions){
q=q.revisions[0];
if(typeof q.contentmodel!=="string"||typeof HINT.cmodels[q.contentmodel]==="boolean"){
s=q["*"];
if(/\{\{/.test(s)){
w={action:"expandtemplates",prop:"wikitext|volatile",text:s};
if(API.single){
w.title=API.single;}
if(HINT.idRev){
w.revid=HINT.idRev;}
if(w){
API.Api.post(w).done(API.fed).fail(API.fault);}
}else{
API.fire(s);}}}
break;}}
if(!s){
if(PREGO.app){
s=PREGO.app.translation(HINT.texts.noPage);
}else{
s=HINT.texts.noPage.en;}
if(API.single){
s=s+" * "+API.single;}
API.fault(null,"Missing",s);}
};
API.fed=function(arrived){
if(typeof arrived==="object"&&typeof arrived.expandtemplates==="object"&&typeof arrived.expandtemplates.wikitext==="string"){
API.fire(arrived.expandtemplates.wikitext);}
};
API.fine=function(arrived){
Line 240 ⟶ 203:
dataType:"json"
};
API.site=window.___location.protocol+"//"+window.___location.hostname+"/";
if(local){
API.first();
API.site=API.site+"api/rest_v1/"+API.service;
API.query.type="POST";
API.query.url=API.site+API.server+API.scanner;}}
if(local){
API.query.data={wikitext:ask};}
$.ajax(API.query).done(API.fine).fail(API.fault);
};
API.first=function(){
if(!API.Api){
API.Api=new mw.Api();}
if(typeof API.site!=="string"){
API.site=window.___location.protocol+"//"+window.___location.hostname+"/";}
};
API.full=function(access,actual){
var idRev=actual,subject=access;
HINT.launched=true;
if(typeof subject==="string"){
subject=subject.trim();
}else{
if(!API.single){
API.single=mw.config.get("wgPageName");}
subject=API.single;
if(!HINT.idRev){
HINT.idRev=mw.config.get("wgRevisionId");}
idRev=HINT.idRev;}
if(typeof API.page!=="object"){
API.first();
API.page={
dataType:"json"
};
API.solver=API.site+API.server+API.swift+"/";}
if(subject.indexOf(" ")>0){
if(typeof API.reSpace!=="object"){
API.reSpace=new RegExp(" +","g");}
subject=subject.replace(API.reSpace,"_");}
API.page.url=API.solver+encodeURIComponent(subject);
if(idRev){
API.page.url=API.page.url+"/"+idRev;}
$.ajax(API.page).done(API.fine).fail(API.fault);
};
BOX.facet=function($activate){
if($activate){
$activate.css({"float":(HINT.ltr?"right":"left")});
BOX.$box.append($activate);}
};
BOX.factory=function($area){
Line 277:
"font-weight":"bolder"}).css("margin-"+(HINT.ltr?"right":"left"),"6px").text("X");
BOX.$box.append($e);
BOX.focus(BOX.$box);}
if(!GUIDER.live){
mw.hook(PREGO.signature+".$button").fire(BOX.facet,Signature);}}
}else{
BOX.flat();}
Line 297 ⟶ 299:
};
BOX.feed=function(){
if(HINT.launch&&!HINT.launched&&!EDIT.live){
API.feedfull();
}else{
mw.hook("wikipage.content").add(BOX.flip);}
Line 378 ⟶ 380:
if(typeof e.params==="object"){
par=e.params;
if(Version<0){
for(s in par){
if(s!=="child"&&s!=="items"&&s!=="name"&&s!=="root"){
console.log(s,par)}}}
if(typeof par.name==="string"){
$td.text(par.name);
Line 515 ⟶ 513:
BOX.$collapsed.attr({disabled:true}).css({"background-color":"#"+BOX.bgcRun,"color":"#"+BOX.fgcRun});}
if(!API.single&&!GUIDER.live){
API.single=mw.config.get("wgTitlewgPageName");}
if(EDIT.live){
if(!EDIT.$source){
Line 536 ⟶ 534:
}else{
HINT.launch=true;
API.feedfull(API.single);}
}else{
BOX.$collapsed.hide();}
Line 566 ⟶ 564:
EDIT.listen=false;}
};
LINTER.fire=function($area){
LINTER.live=true;
mw.hook("wikipage.content").add(LINTER.form);
};
LINTER.first=function(){
if(mw.config.get("wgTitle").indexOf("/")>0&&!LINTER.live){
fair(LINTER.fire);}
};
LINTER.form=function($area){
var $table=$area.find(".TablePager");
if($table.length){
if(typeof $table.tablesorter==="function"){
$table.tablesorter();}
if(typeof HINT.layer==="boolean"){
if(HINT.layer){
LINTER.reEdit=new RegExp("([?&]action=)edit(&.+)?$");
LINTER.seek="action=edit";
LINTER.subst="$1parsermigration-edit$2";
}else{
LINTER.reEdit=new RegExp("([?&]action=)parsermigration-edit(&.+)?$");
LINTER.seek="action=parsermigration-edit";
LINTER.subst="$1edit$2";}
$table.find("a").each(LINTER.further);}}
};
LINTER.first=function(){
if(mw.config.get("wgTitle").indexOf("/")>0){
mw.hook("wikipage.content").add(LINTER.fire);}
};
LINTER.further=function(any,a){
var $a=$(a),s=$a.attr("href");
if(s.indexOf("action=edit"LINTER.seek)>0){
$a.attr("href",s.replace(LINTER.reEdit,"$1parsermigration-edit$2"LINTER.subst));}
};
GUIDER.facet=function($activate){
if($activate){
$activate.css({"float":(HINT.ltr?"right":"left"),"margin-top":"1em"});
GUIDER.$desc.before($activate);}
};
GUIDER.figure=function(){
var s=GUIDER.$rev.val().trim();
if(!GUIDER.reNaN){
GUIDER.reNaN=new RegExp("[^0-9]","g");}
s=s.replace(GUIDER.reNaN,"");
GUIDER.$rev.val(s);
};
GUIDER.filled=function(){
var s=GUIDER.$input.val().trim();
GUIDER.$rev.attr({disabled:(s?false:true)});
};
GUIDER.find=function(){
var s=GUIDER.$input.val().trim();
GUIDER.$input.val(s);
GUIDER.fired();
GUIDER.last=true;
if(!GUIDER.reTrim.test(s)){
API.single=s;
API.feedfull(APIs,GUIDER.single$rev.val());}
};
GUIDER.finish=function(application){
Line 619 ⟶ 645:
GUIDER.first=function(){
var i;
PREGO.feedfire();
for(i=0;i<GUIDER.using.length;i++){
HINT.using.push(GUIDER.using[i]);}
Line 657 ⟶ 683:
.click(GUIDER.flat).css({"float":(HINT.ltr?"right":"left")});
GUIDER.$formText.append($b);
$b=$div.css({"<span>clear":"both"});
GUIDER.$formPage.append($div);
$b.addClass("mw-ui-button mw-ui-progressive").click(GUIDER.find).css({"color":"#FFFFFF"},{"float":(HINT.ltr?"right":"left")}).text(submit);
$div.append($b);
$b=$("<input>");
$b.addClass("mw-ui-button").append($x.clone()).attr({type:"reset"})
.click(GUIDER.flat).click(GUIDER.filled).css({"float":(HINT.ltr?"right":"left")});
GUIDER.$formPage.append($b);
$div.append($b).css({"float":(HINT.ltr?"right":"left")});
$b=$("<span>");
GUIDER.$formPage.append($div);
$b.addClass("mw-ui-button mw-ui-progressive").click(GUIDER.find).css({"color":"#FFFFFF"})
.text(submit);
GUIDER.$formPage.append($b);
mw.hook(PREGO.signature+".ready").add(GUIDER.finish);
};
Line 714 ⟶ 742:
GUIDER.$input=$("<input>");
GUIDER.$input.addClass("mw-ui-input").attr({maxlength:255,name:"pagename",size:50,type:"text"}).css({"float":(HINT.ltr?"left":"right"),
"width":"auto","max-width":"auto"});
.keyup(GUIDER.filled).mouseup(GUIDER.filled);
GUIDER.$formPage.append(GUIDER.$input);
GUIDER.$rev=$("<input>");
GUIDER.$rev.addClass("mw-ui-input").attr({disabled:true,inputmode:"numeric",maxlength:12,name:"revision",placeholder:"oldid",size:8,type:"text"}).css({"display":"inline-block",
"margin-left":"1.5em","margin-right":"1.5em",
"width":"auto","max-width":"auto"})
.keyup(GUIDER.figure).mouseup(GUIDER.figure);
GUIDER.$formPage.append(GUIDER.$rev);
HINT.$page.append(GUIDER.$formText,GUIDER.$formPage);
GUIDER.$pagename=$("<div>");
Line 724 ⟶ 759:
HINT.$textarea=GUIDER.$textarea;
mw.loader.using(HINT.using,GUIDER.foreign);
mw.hook(PREGO.signature+".$button").fire(GUIDER.facet,Signature);
};
PREGO.features=function(applied){
var i,n,s,v,vals;
if(typeof applied==="object"&&applied){
n=PREGO.pars.length;
for(i=0;i<n;i++){
v=PREGO.pars[i];
s=v[0];
if(typeof applied[s]===v[1]){
HINT[s]=applied[s];}}}
if(HINT.spaces){
HINT.spaces=HINT.spaces.trim();}
if(PREGO.live){
PREGO.form();
}else if(LINTER.live){
LINTER.live=false;
LINTER.first();
}else{
if(HINT.spaces){
if(HINT.spaces==="*"){
HINT.live=true;
}else if(HINT.spaces!=="-"){
vals=HINT.spaces.split(" ");
s=HINT.nsn+"";
for(i=0;i<vals.length;i++){
if(s===vals[i]){
HINT.live=true;
break;}}}
}else if(HINT.nsn===0){
HINT.live=true;}
if(HINT.live&&HINT.nsn>=0){
mw.loader.using(HINT.using,BOX.feed);}}
};
PREGO.feed=function(){
var s="ext.gadget."+PREGO.signature;
if(mw.loader.getState(s)!=="ready"){
mwREPOS.loader.loadfire("https://enPREGO.wikipediasite,PREGO.org/w/index.php?title=User:PerfektesChaos/js/"store+PREGO.signature+"/rPREGO.js&bcache=1&maxage=604812&sub,false,{action=:"raw&",ctype=:"text/javascript",bcache:1,maxage:604813});}
};
PREGO.fiat=function(){
var s=PREGO.$spaces.val(),i,k,got,rooms;
if(s.indexOf("-")>=0){
s="-";
}else if(s.indexOf("*")>=0){
s="*";
}else{
got=s.trim().split(" ");
s="";
if(got.length>0){
if(typeof PREGO.rooms!=="object"){
PREGO.follow=function(a,b){
return(a<b?-1:1);
};
PREGO.reNum=new RegExp("^[0-9]+$");
PREGO.rooms=mw.config.get("wgFormattedNamespaces");}
rooms=[];
for(i=0;i<got.length;i++){
if(PREGO.reNum.test(got[i])){
k=parseInt(got[i],10);
if((k===0||PREGO.rooms[k])&&$.inArray(k,rooms)<0){
rooms.push(k);}}}
if(rooms.length>0){
rooms.sort(PREGO.follow);
s=rooms.join(" ");}}}
PREGO.$spaces.val(s);
};
PREGO.field=function($applying){
PREGO.$spaces=$applying;
PREGO.$spaces.change(PREGO.fiat);
};
PREGO.fire=function(){
PREGO.feed();
mw.hook(PREGO.signature+".fetch").fire(Signature,PREGO.features);
};
PREGO.form=function(){
var support=".wikipedia.org/wiki/"+HINT.doc.substr(3),docs={"en":"//en"+support,
"de":"//de"+support},dialog,opts;
opts=[{signature:"spaces",type:"text",show:HINT.texts["^^spaces"],val:(HINT.spaces?HINT.spaces:""),field:PREGO.field},{signature:"launch",type:"checkbox",show:HINT.texts["^^launch"],val:HINT.launch},{signature:"last",type:"checkbox",show:HINT.texts["^^last"],val:HINT.last},{signature:"lazy",type:"checkbox",show:HINT.texts["^^lazy"],val:HINT.lazy},{signature:"layer",type:"checkbox",show:HINT.texts["^^layer"],val:HINT.layer}];
dialog={script:Signature,support:docs,suffix:HINT.texts["^suffix"],opts:opts};
mw.hook(PREGO.signature+".form").fire(dialog);
};
REPOS.fire=function(at,access,append,alter){
var source,syntax;
if(typeof REPOS.requests!=="object"){
REPOS.requests={};}
if(typeof REPOS.requests[access]!=="boolean"){
REPOS.requests[access]=true;
if(append){
source=access+append;
}else{
source=access;}
if(at){
source=REPOS.foundation(at,source,alter);
if(typeof alter==="object"&&alter&&typeof alter.ctype==="string"){
syntax=alter.ctype;}
}else{
syntax=alter;}
mw.loader.load(source,syntax);}
};
REPOS.foundation=function(at,access,alter){
var s=access,r=encodeURI(s);
if(typeof alter==="object"&&alter){
r="/w/index.php?title="+r;
if(access.substr(-3)===".js"){
alter.ctype="text/javascript";
}else if(access.substr(-4)===".css"){
alter.ctype="text/css";}
alter.action="raw";
for(s in alter){
r=r+"&"+s+"="+encodeURI(alter[s]);}
}else{
r="/wiki/"+r;}
if(typeof at==="string"&&at){
switch(at){
case "meta":
r="meta.wikimedia.org"+r;
break;
case "mw":
r="www.mediawiki.org"+r;
break;
case "w:en":
r="en.wikipedia.org"+r;
break;
default:
r=window.___location.host+r;}
r="https://"+r;}
return r;
};
TEACH.feed=function(apply){