Jump to content

User:PC-XT/common.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by PC-XT (talk | contribs) at 08:14, 2 December 2014 (use RefLinks' site parsing; format fix). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
popupFixDabs=true;

p=mw.config.get('wgPageName');
/*ns=mw.config.get('wgNamespaceNumber');
//for(t in wgNamespaceIds)if(wgNamespaceIds[t]==ns){Ns=t;break;}//{media:-2, special:-1, '':0, talk:1, user:2, user_talk:3, wikipedia:4, wikipedia_talk:5, file:6, file_talk:7, mediawiki:8, mediawiki_talk:9, template:10, template_talk:11, help:12, help_talk:13, category:14, category_talk:15, portal:100, portal_talk:101, book:108, book_talk:109, draft:118, draft_talk:119, education_program:446, education_program_talk:447, timedtext:710, timedtext_talk:711, module:828, module_talk:829, topic:2600, wp:4, wt:5, image:6, image_talk:7, project:4, project_talk:5}
p_ext=p.split("/");p_ext=p_ext[p_ext.length-1].split(".");p_ext=p_ext.length>1?p_ext[p_ext.length-1].toLowerCase():"";*/

mw.util.addPortletLink('p-tb','/wiki/Special:PrefixIndex/'+p,'PrefixIndex','Special-PrefixIndex');
t=p.split('/');t.length--;
if(t.length)mw.util.addPortletLink('p-tb','/wiki/Special:PrefixIndex/'+t.join('/')+'/','PrefixIndex/../','Special-PrefixIndex2');
mw.util.addPortletLink('p-tb','http://dispenser.homenet.org/~dispenser/cgi-bin/webchecklinks.py?page='+p,'CheckLinks','Checklinks');
mw.util.addPortletLink('p-tb','http://dispenser.homenet.org/~dispenser/cgi-bin/webreflinks.py?page='+p,'RefLinks','Reflinks');
mw.util.addPortletLink('p-tb','http://wikipedia.ramselehof.de/wikiblame.php?user_lang=en&lang=en&project=wikipedia&article='+p,'WikiBlame','WikiBlame');
mw.util.addPortletLink('p-tb','http://dispenser.homenet.org/~dispenser/cgi-bin/dabfix.py?page='+p,'Fix DAB page','FixDABpage');
//can use other DAB fixing tools, so just bookmark dispenser's other tools for powerfixing
//can use Page info, instead... mw.util.addPortletLink('p-tb','http://stats.grok.se/en/latest/'+p,'Traffic','traffic');

if(wgAction=="edit"||wgAction=="submit"){
//function rvs(r,v,s){if(document.editform.wpTextbox1.value.search(r)<0)return;document.editform.wpTextbox1.value=document.editform.wpTextbox1.value.replace(r,v);document.editform.wpSummary.value+=(document.editform.wpSummary.value&&document.editform.wpSummary.value.search(/\*\/ $/)<0?";":"")+s;}
//mw.util.addPortletLink('p-tb','javascript:rvs(/([^\\[])\\[([^\\[\\]][^ \\]]*) ([^\\]]+)\\]([^\\]])/g,"$1\x7b{cite web|url=$2|title=$3}}$4","cite web")','Titled links → cite web','citeweballtitledlinks');
//function langiconcv(){if(document.editform.wpTextbox1.value.search(/\{\{[Ee]n/)<0)return;document.editform.wpTextbox1.value=document.editform.wpTextbox1.value.replace(/\{\{([Ee]n)\|/g,"\x7b{lang-$1|").replace(/\{\{([Ee][ns]|[Cc]a|[Dd]e|[Ff][ri]|[Dd]a|[Nn]l|[Ss][rv]|[Jj]a|[Ii][dt]|[Kk]o)\}\}/g,"\x7b{$1 icon}}");document.editform.wpSummary.value+=(document.editform.wpSummary.value?";":"")+"lang icons";}
//mw.util.addPortletLink('p-tb','javascript:langiconcv()','\x7b{xx}} → \x7b{xx icon}}','langicons');
function dewhitesp(){document.editform.wpTextbox1.value=document.editform.wpTextbox1.value.replace(/[ \t]+$/gm,"");ct.scan();}
mw.util.addPortletLink('p-tb','javascript:dewhitesp()','rm trailing whitespace','dewhitelink');
function authorfl(s,n){var a=s.replace(/(^\s+|\s+$)/g,"").replace(/\s*,?\s+(and|&)\s+/gi,";").split(/\s*;\s*/),r="",i,j;for(i=0;i<a.length;i++)if(a[i])r+=(j=a[i].split(",")).length==2?"|last"+(i+n)+"="+j[0]+"|first"+(i+n)+"="+j[1]:(j=a[i].split(" ")).length==2?"|first"+(i+n)+"="+j[0]+"|last"+(i+n)+"="+j[1]:"|author"+(i+n)+"="+a[i];return r+(i+n<10?"":"|displayauthors="+(i+n-1));}
//mw.util.addPortletLink('p-tb','javascript:alert(authorfl(prompt("coauthors="),2))','cite|coauthor→suggestion','coauthsug');
mw.util.addPortletLink('p-tb','javascript:alert(authorfl(prompt("authors="),1))','cite|authors→suggestion','authsug');
function monthp(m){return wgMonthNames[(parseInt(m)||{jan:1,feb:2,mar:3,apr:4,may:5,jun:6,jul:7,aug:8,sep:9,oct:10,nov:11,dec:12}[m.toString().substring(0,3).toLowerCase()])]||m;}
//importScript("User:PC-XT/JSubst.js");/*linkback: [[User:PC-XT/JSubst]]*/
//mw.util.addPortletLink('p-tb','javascript:JSubst.subst(list:[["",function(p){return p(0);}]])','Convert lang icons','langicons');
//if(/*ns!=828&&(p.substring(0,11)!="User:PC-XT/"||(p_ext!="js"&&p_ext!="css"))*/!mw.config.get('wgCodeEditorCurrentLanguage')){//others could have own suggestion set, if add option to not include default rules
switch(mw.config.get('wgCodeEditorCurrentLanguage')){
case"javascript":
break;
ct={noscroll:true,noDefaultRules:1,rules:[
]};importScript('User:PC-XT/Advisor.js');
break;//end javascript
case"css":
break;
ct={noscroll:true,noDefaultRules:1,rules:[
]};importScript('User:PC-XT/Advisor.js');
break;//end css
case"lua":
break;
ct={noscroll:true,noDefaultRules:1,rules:[
]};importScript('User:PC-XT/Advisor.js');
break;//end lua
default://wikicode assumed
ct={noscroll:true,rules:[
    // A ``rule'' is a JavaScript function that accepts a string as a
    // parameter (the wikitext of the page being edited) and returns an array
    // of ``suggestion'' objects.

    // A ``suggestion'' object must have the following properties:
    //     * start---the 0-based inclusive index of the first character to be replaced
    //     * end---analogous to start, but exclusive
    //     * (optional) replacement---the proposed wikitext, if any
    //     * name---this is what appears at the top of the page
    //     * description---used as a tooltip for the name of the suggestion
    //     * (optional) help---an HTML fragment as a string, it will appear in a yellow
    //                         box when a suggestion is double-clicked
function(s){var matches=ct.getAllMatches(/\.(google)\.([a-z]{2})([^m])/i,s),suggestions=[],i,m;
for(i=0;i<matches.length;i++){m=matches[i];suggestions.push({
start:m.start+1,end:m.end,
name:"[[Globalize]] "+m[1]+"."+m[2]+" → "+m[1]+".com",
description:"You may want to check the link before and after to make sure it works globalized",
replacement:m[1]+".com"+m[3]
});}return suggestions;},
function(s){var matches=ct.getAllMatches(/([^\[])\[(\/\/[^ \]]*|[^\[\]][^ \]]*\/\/[^ \]]*) ([^\]]+)\]([^\]])( ([^ ]+)( \([-0-9]+\)|)\. Retrieved on ([-0-9]+)\..)?/g,s),suggestions=[],i,m,cite,t,url,archive,archivedate;
for(i=0;i<matches.length;i++){m=matches[i];archive='';
url=m[2].replace('"',"%22").replace("'","%27").replace('<',"%3c").replace('>',"%3e").replace('[',"%5b").replace('|',"%7c").replace('}',"%7d");//too late to escape ] and sp
cite=m[0].search(/press release/i)>=0?"press release":m[0].search(/news/i)>=0?"news":url.indexOf("books.google.co")>=0?"book":"web";
if(url.indexOf(".archive.org/")>=0&&(t=url.match(/\.archive\.org\/[a-z/]*([0-9]{4})([0-9][0-9])([0-9][0-9])[0-9]+\/(.+)$/i))){archive=url.indexOf("//");if(archive>12||archive<0)archive="//"+url;else archive=url.substring(archive);t=url.match(/[\/.]archive\.org\/[a-z/]*([0-9]{4})([0-9][0-9])([0-9][0-9])[0-9]+\/(.+)$/i);archivedate=1*t[3]+" "+wgMonthNames[1*t[2]]+" "+t[1];url=t[4];}
suggestions.push({start:m.start+1,end:m.end-1,
replacement:"\x7b{cite "+cite+"|url="+url+(archive?"|archiveurl="+archive+"|archivedate="+archivedate:"")+"|title="+m[3].replace(/\|/g,"&#124;")+"|work="+(m[6]||(url.match(/\/\/(www.|)([A-Za-z0-9\-\.]+)(\/|$)/)||[0,"",""])[2])+(url.search(/\.pdf\s*$/i)>=0?"|format=PDF":"")+(m.length>6&&m[7]?"|date="+m[7].substring(2).split(")")[0]:"")+(m.length>7?"|accessdate="+m[8]:"")+"}}",
name:"link→cite "+cite+(archive?' (archive)':''),
description:"If this is not in prose, but a reference or in a list of links, possibly use \x7b{cite "+cite+"}}"+m
});}return suggestions;},
/*function(s){var matches=ct.getAllMatches(/\{\{([Ee]n)\|/g,s),suggestions=[],i,m;
for(i=0;i<matches.length;i++){m=matches[i];suggestions.push({start:m.start,end:m.end,
replacement:"\x7b{lang-"+m[1]+"|",
name:"\x7b{"+m[1]+"}}→\x7b{lang-"+m[1]+"}}"
});}return suggestions;},*/
function(s){var matches=ct.getAllMatches(/\{\{([Ee][ns]|[Cc]a|[Dd]e|[Ff][ri]|[Dd]a|[Nn]l|[Ss][rv]|[Jj]a|[Ii][dt]|[Kk]o)\}\}/g,s),suggestions=[],i,m;
for(i=0;i<matches.length;i++){m=matches[i];suggestions.push({start:m.start,end:m.end,
replacement:"\x7b{"+m[1]+" icon}}",
name:"\x7b{"+m[1]+"}}→\x7b{"+m[1]+" icon}}"
});}return suggestions;},
function(s){var matches=ct.getAllMatches(/\|\s*coauthors?\s*=\s*([^|}]*)[|}]/g,s),suggestions=[],k,m;
for(k=0;k<matches.length;k++){m=matches[k];
suggestions.push({start:m.start,end:m.end-1,
replacement:authorfl(m[1],2),
name:"cite|coauthors=deprecated"
});}return suggestions;},
function(s){var matches=ct.getAllMatches(/(\{\{cite[^}<]*)(\|\s*accessdate\s*=\s*[^|}]*)([^}]*\}\})/g,s),suggestions=[],k,m;//[^<] to avoid comments, as tags not often used in a cite
for(k=0;k<matches.length;k++){m=matches[k];if((m[1]+m[3]).search(/\|\s*url\s*=\s*[^|]{6}/)<0){
suggestions.push({start:m.start,end:m.end,
name:"cite|accessdate without url",
replacement:m[1]+"<!--"+m[2]+" -->"+m[3],
description:"accessdate is only needed for urls"
});}}return suggestions;},
function(s){var matches=ct.getAllMatches(/(\{\{cite[^}<]*)(\|\s*format\s*=\s*[^|}]*)([^}]*\}\})/g,s),suggestions=[],k,m;//[^<] to avoid comments, as tags not often used in a cite
for(k=0;k<matches.length;k++){m=matches[k];if((m[1]+m[3]).search(/\|\s*url\s*=\s*[^|]{6}/)<0){
suggestions.push({start:m.start,end:m.end,
name:"cite|format without url",
replacement:m[1]+"<!--"+m[2]+" -->"+m[3],
description:"format only applies to urls"
});}}return suggestions;},
function(s){var matches=ct.getAllMatches(/(\{\{cite[^}<]*)\|\s*month\s*=\s*([^|]*)\|\s*year\s*=\s*([^|}]*)[|}]/g,s),suggestions=[],k,m;
for(k=0;k<matches.length;k++){m=matches[k];
suggestions.push({start:m.start,end:m.end-1,
name:"cite|month=deprecated",
replacement:m[1]+"|date="+(monthp(m[2])+" "+m[3]).replace(/  /g," ").replace(/  /g," "),
description:"If this is in a cite, fix it and check for CS1 date error"
});}return suggestions;},
function(s){var matches=ct.getAllMatches(/(\{\{cite[^}<]*)\|\s*year\s*=\s*([^|]*)\|\s*month\s*=\s*([^|}]*)[|}]/g,s),suggestions=[],k,m;
for(k=0;k<matches.length;k++){m=matches[k];
suggestions.push({start:m.start,end:m.end-1,
name:"cite|month=deprecated",
replacement:m[1]+"|date="+(monthp(m[3])+" "+m[2]).replace(/  /g," ").replace(/  /g," "),
description:"If this is in a cite, fix it and check for CS1 date error"
});}return suggestions;},
function(s){var matches=ct.getAllMatches(/(\{\{cite[^}<]*)\|\s*(month|day)\s*=\s*([^|}]*)[|}]/g,s),suggestions=[],k,m;
for(k=0;k<matches.length;k++){m=matches[k];
suggestions.push({start:m.start,end:m.end-1,
name:"deprecated parameter"
});}return suggestions;}
//template rules should go in here, too, since they may be used in main space, as well
]};importScript('User:PC-XT/Advisor.js');
importScript('User:Scottywong/diffconverter.js'); //[[User:Scottywong/diffconverter.js]]
mw.util.addPortletLink('p-tb','javascript:keydetect({keyCode:68,altKey:1,ctrlKey:1})','selected link→\x7b{diff}} (Ctrl+Alt+D)','Ctrl+Alt+D');
importScript('User:Ohconfucius/script/Sources.js'); // [[User:Ohconfucius/script/Sources.js]]
importScript('User:Ohconfucius/script/formatgeneral.js'); // [[User:Ohconfucius/script/formatgeneral.js]]
importScript('User:Ohconfucius/script/MOSNUM dates.js');  //[[User:Ohconfucius/script/MOSNUM dates.js]]
if(p.substring(0,21)=="Wikipedia:WikiProject")importScript('User:PC-XT/ParticipantSort.js');
}//end wikicode editor
importScript('User:Anomie/ajaxpreview.js'); // Linkback: [[User:Anomie/ajaxpreview.js]]
var ajaxPreviewPos = 'bottom'; //buttons on the bottom, replacing standard
var ajaxPreviewFull = true; //always update interwikis, categories and templates as well
// code to execute after each preview update
window.ajaxPreviewExec = function(previewArea) {
  if (window.setupTooltips) {
    setupTooltips(previewArea);
    previewArea.ranSetupTooltipsAlready = false;
  }
  mw.loader.using( [
    'jquery.tablesorter',
    'jquery.makeCollapsible'
  ], function(){
    $( 'table.sortable' ).tablesorter();
    $( '#wikiPreview .collapsible' ).makeCollapsible();
  } );
}
importScript('User:Js/ajaxPreview.js'); // [[user:js/ajaxPreview]]
}else{//end editor, start reading tools
importScript('User:Anomie/linkclassifier.js'); // Linkback: [[User:Anomie/linkclassifier.js]]
importStylesheet('User:Anomie/linkclassifier.css'); // Linkback: [[User:Anomie/linkclassifier.css]]
LinkClassifierOnDemand=true;
function PCxtLinkClassifierGo(){
LinkClassifier.onDemand();
var t=document.getElementById('linkclassifier'),d=document.createElement("div");
d.style.fontSize="9pt";
d.innerHTML='linkclassifier:<br><a href="/wiki/User:Anomie/linkclassifier">link</a><br><a href="/wiki/Special:NewPages" class="new">new</a><br><a href="/wiki/Special:Redirects" class="redirect">redirect</a><br><a href="/wiki/Special:RandomRedirect" class="self-redirect">self-redirect</a><br><a href="/wiki/Special:Disambiguations" class="disambiguation">disambiguation</a><br><a href="/wiki/Special:Disambiguations" class="intentional-disambiguation">intentional-disambiguation</a><br><a href="/wiki/Special:Categories" class="soft-redirect-cats">soft-redirect-cats</a><br><a href="/w/index.php?title=Special%3ALog&type=delete" class="deletion">deletion</a><br><a href="/wiki/Special:BrokenRedirects" class="broken-redirect">broken-redirect</a><br><a href="/wiki/CAT:NFM" class="image.nonfree-media"><img alt="nonfree-media" src="https://bits.wikimedia.org/favicon/wikipedia.ico" /></a><br><a href="/w/index.php?title=Special%3ALog&type=delete" class="image.deletion"><img alt="deletion" src="https://bits.wikimedia.org/static-1.22wmf8/skins/vector/images/search-ltr.png?303-4" /></a>';
t.parentNode.removeChild(t);
document.getElementById('p-tb').appendChild(d);
}
addOnloadHook(function(){mw.util.addPortletLink('p-tb'/*'p-cactions'*/, 'javascript:PCxtLinkClassifierGo()', 'linkclassifier','linkclassifier');});
mw.util.addPortletLink('p-tb','/wiki/Special:DisambiguationPageLinks','Disambig list','Special-Disambiguations');
importScript('User:Splarka/dabfinder.js');
}
importScript('User:Jackmcbarn/editProtectedHelper.js'); // Linkback: [[User:Jackmcbarn/editProtectedHelper.js]]
/**
 * Anzahl der Beobachter für Artikel in einem Tab
 * oben rechts anzeigen lassen mit Verweis auf
 * Artikel-Informationsseite
 *
 * Nutzbar für den Vector- und Monobook-Skin
 *
 * Author: Benutzer:Nightfly85 [[User:Nightfly85/common.js]]
 */
(function($, mw) {
 
    function placeTab(text, url, title, isSelected) {
        var liClass = isSelected ? 'selected' : '',
            $liElement = $('<li style="display:none" class="' + liClass +'" ><span><a title="' + title + '" href="' + url + '">' + text + '</a></span></li>');
        $('#ca-history').after($liElement);
        $liElement.slideDown();
    }
 
    var isInfoPage = (mw.config.get('wgAction') == 'info'),
        articleName = mw.util.wikiUrlencode(mw.config.get('wgPageName')),
        wikiBaseUrl = mw.config.get('wgServer') + mw.config.get('wgScriptPath'),
        infoUrl = wikiBaseUrl + '/index.php?action=info&title=' + articleName,
        apiUrl  = wikiBaseUrl + '/api.php?action=query&prop=info&inprop=watchers&format=xml&titles=' + articleName;
 
    if(isInfoPage) {
        // The info tab is selected, so highlight the tab and forget the ajax stuff
        placeTab('Info', infoUrl, 'Article information', true);
    } else {
        if(false === mw.config.get('wgIsArticle') ) {
            return; // Generated page 
        }
        $.ajax({ url: apiUrl }).done(function(xmlData) {
            var numViewer = $(xmlData).find('page').attr('watchers'),
                numViewerText  = (numViewer > 0) ? '<strong>' + numViewer + '</strong>' : 'Marginal';
            placeTab(numViewerText + ' watchers', infoUrl, 'Show Article info', false);
 
        });
    }
})(jQuery, mediaWiki);