User:Codeispoetry/helperFunctions.js
Jump to navigation
Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
Documentation for this user script can be added at User:Codeispoetry/helperFunctions. |
- Report page listing warnings and errors.
// <nowiki>
function getParamValue(paramName) {
var cmdRe=RegExp('[&?]'+paramName+'=([^&]*)');
var h=document.location;
var m=cmdRe.exec(h);
if (m) {
try {
return decodeURIComponent(m[1]);
} catch (someError) {}
}
return null;
}
function insertText(text, wo, subject, autoedit)
{
autoedit = autoedit || false;
//wo=1 : Text austauschen
//wo=2 : Text vorne Einfügen
//wo=3 etc : Text am Ende anhängen
if (isEdit) {
if (subject > "") {
if (document.getElementById('wpSummary').value > "") document.getElementById('wpSummary').value += ", ";
document.getElementById('wpSummary').value = document.getElementById('wpSummary').value + subject;
}
switch (wo) {
case 1 :
document.getElementById('wpTextbox1').value=text+'\n';
break;
case 2 :
document.getElementById('wpTextbox1').value=text+'\n'+document.getElementById('wpTextbox1').value;
break;
default :
document.getElementById('wpTextbox1').value=document.getElementById('wpTextbox1').value+'\n'+text;break;
}
if (autoedit)
{
document.getElementById('wpSave').click();
}
else
{
document.getElementById('wpTextbox1').focus();
}
}
else {
location.href = wgScript + '?title=' + encodeURIComponent(getLemma()) + '&action=edit' + '&subject=' + encodeURIComponent(subject) + '&text=' + encodeURIComponent(text) + '&wo=' + encodeURIComponent(wo) + '&autoedit=' + autoedit;
}
}
function getLemma () { //Littl
var lemma;
if (isContrib && (getParamValue("target") > "" ))
lemma = getParamValue("target");
else if ( getParamValue("title") > "" )
lemma = getParamValue("title");
else {
lemma = decodeURIComponent(location.href.substring(location.href.indexOf("/wiki/") + 6)).split('#')[0];
// fix linky links (?redirect=no)
//lemma = lemma.split['\x3F'][0];
if (lemma.indexOf("redirect=no")!=-1)
lemma=lemma.substring(0,lemma.indexOf("redirect=no")-1);
}
// if (lemma.substring(0, 5) == "Bild:") lemma=lemma.slice(5);
// if (lemma.substring(0, 10) == "Kategorie:") lemma=lemma.slice(10);
if (isPHP) lemma=lemma.split('+').join('_');
return lemma;
}
function openWindow(url) {
var res = window.open(url, '_blank');
if (!res) alert("openWindow: window.open() returned null");
}
function getUploader() {
// Get uploader from first point in the list under "File history"
// Uploader is stored in second A tag in UL tag under "File history"
// Returns title of user page (without name space) in URL form
var el = document.getElementById('filehistory')
if (!el) {
var req;
if (req = newRequest()) {
req.open("GET", document.getElementById('ca-history').firstChild.href.match(/http:\/\/commons.wikimedia.org(.+)/)[1], false);
req.send("");
var history = document.createElement('ul');
history.innerHTML = req.responseText.match(/<ul\s+id="pagehistory">([^]*<\/LI>)\s<\/UL>/i)[1];
return encodeURIComponent(history.lastChild.getElementsByTagName('span')[0].getElementsByTagName('a')[0].innerHTML);
}
alert("getUploader: Cannot find filehistory ... exiting");
return null;
}
while (el.nextSibling) {
el = el.nextSibling;
if (el.tagName && el.tagName.toLowerCase() == 'table')
break;
}
if (!el) {
alert("getUploader: Cannot find table tag ... exiting");
return null;
}
var as = el.getElementsByTagName('a');
var re1 = new RegExp((mw.config.get('wgServer') + mw.config.get('wgArticlePath').substr(0, wgArticlePath.length-2) ).replace(/\./g, '\\.') + 'User:(.*)$');
var re2 = new RegExp((wgServer + wgScript).replace(/\./g, '\\.') + '\\?title=User:([^&]*)');
var m;
for (var k=0; k<as.length; k++) {
m = re1.exec(as[k].href);
if (m) return m[1];
m = re2.exec(as[k].href);
if (m) return m[1];
}
alert("getUploader: Cannot find uploader ... exiting");
return null;
}
function newRequest()
{
try {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else {
return new ActiveXObject("MSXML2.XMLHTTP");
}
} catch (e) {
return false;
}
}
////////////////////////////////////////////////////////////////////////////////////////
// trim()
// Leerzeichen am Anfang und Ende entfernen
function trim(str) {
return str.replace(/^\s*|\s*$/g,"");
}
/*
* Stringlänge überprüfen für Zusammenfassungszeile
*/
function EditCommentLength(str) {
return (199-str.length);
}
// ------------
// Param PDD
// page type variables: namespaces
var isArticle = (wgNamespaceNumber == 0);
var isArticleTalk = (wgNamespaceNumber == 1);
var isImage = (wgCanonicalNamespace == "Image");
var isCategory = (wgCanonicalNamespace == "Category");
var isTemplate = (wgCanonicalNamespace == "Template");
var isGeneric = false;
if ((!isImage) && (!isCategory) && (!isTemplate))
isGeneric = true;
var isProject = (wgCanonicalNamespace == "Project");
var isUser = (wgCanonicalNamespace == "User");
var isUserTalk = (wgCanonicalNamespace == "User_talk");
var isHelp = (wgCanonicalNamespace == "Help");
// page type variables: namespace == -1
var isSpecial = (wgCanonicalNamespace == "Special");
var isRestore = (isSpecial && (wgCanonicalSpecialPageName == "Undelete"));
var isContrib = (isSpecial && (wgCanonicalSpecialPageName == "Contributions"));
var isWatchlist = (isSpecial && (wgCanonicalSpecialPageName == "Watchlist"));
// page type variables: namespace == -1
var isTalk = (!isSpecial && (wgNamespaceNumber % 2 == 1));
// page type variables: other stuff
var isPHP = (document.URL.indexOf('index.php') > 0);
var isDiff = getParamValue('diff');
var isEdit = ((getParamValue('action')=='edit') || (getParamValue('action')=='submit'));
var isHistory = (getParamValue('action')=='history');
// /param
// ------------
//</nowiki>