MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
Want an adless experience? Log in or Create an account.
mNo edit summary |
No edit summary |
||
Line 57: | Line 57: | ||
addOnloadHook(highlightRedirects.install); | addOnloadHook(highlightRedirects.install); | ||
} | |||
// | |||
// -------------------------------------------------------- | |||
// Rank Coloring | |||
// (adapted from http://en.wikipedia.org/wiki/User:Ais523/adminrights.js) | |||
// This script changes the color of links to admins' and patrollers' userpages in the bodyContent of Special, History pages, diff pages, | |||
// and old page revisions. | |||
// ("bodyContent" being everything but the tabs,personal links at the top of the screen and sidebar). | |||
// -------------------------------------------------------- | |||
var patrollerrights=new Array(); | |||
importScript('MediaWiki:Patrollerlist.js'); | |||
//Highlighting script. Based on [[User:ais523/highlightmyname.js]]. | |||
function highlightpatrollers(n,p) //node, parent node | |||
{ | |||
while(n!=null) | |||
{ | |||
if(n.nodeType==1&&n.tagName.toLowerCase()=="a") //anchor | |||
{ | |||
if(n.href.indexOf("/User:")!=-1) | |||
{ | |||
var u=n.href.split("/User:")[1]; | |||
if(patrollerrights[u.split("_").join("%20")]==1) | |||
{ | |||
n.style.color="#E99216"; | |||
} | |||
} | |||
else if(n.href.indexOf("/index.php?title=User:")!=-1) | |||
{ | |||
var u=n.href.split("/index.php?title=User:")[1]; | |||
if(patrollerrights[u.split("_").join("%20")]==1) | |||
{ | |||
n.style.color="#E99216"; | |||
} | |||
} | |||
else | |||
{ | |||
if(n.firstChild!=null) highlightpatrollers(n.firstChild,n); | |||
} | |||
} | |||
else | |||
{ | |||
if(n.firstChild!=null) highlightpatrollers(n.firstChild,n); | |||
} | |||
n=n.nextSibling; | |||
} | |||
} | |||
if (wgCanonicalNamespace == 'Special' || wgAction == 'history' || document.URL.indexOf('diff=') > 0 || document.URL.indexOf('oldid=') > 0) | |||
{ | |||
addOnloadHook(function() { | |||
highlightpatrollers(document.getElementById('bodyContent').firstChild, | |||
document.getElementById('bodyContent')); | |||
}); | |||
} | |||
var adminrights=new Array(); | |||
importScript('MediaWiki:Adminlist.js'); | |||
//Highlighting script. Based on [[User:ais523/highlightmyname.js]]. | |||
function highlightadmins(n,p) //node, parent node | |||
{ | |||
while(n!=null) | |||
{ | |||
if(n.nodeType==1&&n.tagName.toLowerCase()=="a") //anchor | |||
{ | |||
if(n.href.indexOf("/User:")!=-1) | |||
{ | |||
var u=n.href.split("/User:")[1]; | |||
if(adminrights[u.split("_").join("%20")]==1) | |||
{ | |||
n.style.color="#2BA206"; | |||
} | |||
} | |||
else if(n.href.indexOf("/index.php?title=User:")!=-1) | |||
{ | |||
var u=n.href.split("/index.php?title=User:")[1]; | |||
if(adminrights[u.split("_").join("%20")]==1) | |||
{ | |||
n.style.color="#2BA206"; | |||
} | |||
} | |||
else | |||
{ | |||
if(n.firstChild!=null) highlightadmins(n.firstChild,n); | |||
} | |||
} | |||
else | |||
{ | |||
if(n.firstChild!=null) highlightadmins(n.firstChild,n); | |||
} | |||
n=n.nextSibling; | |||
} | |||
} | |||
if (wgCanonicalNamespace == 'Special' || wgAction == 'history' || document.URL.indexOf('diff=') > 0 || document.URL.indexOf('oldid=') > 0) | |||
{ | |||
addOnloadHook(function() { | |||
highlightadmins(document.getElementById('bodyContent').firstChild, | |||
document.getElementById('bodyContent')); | |||
}); | |||
} | } | ||
// | // |
Revision as of 00:45, October 19, 2011
/* Any JavaScript here will be loaded for all users on every page load. */ // -------------------------------------------------------- // addPurge // adds a "purge" tab (after "watch") // -------------------------------------------------------- addOnloadHook(function () { if (wgAction != 'edit' && wgCanonicalNamespace != 'Special' && wgAction != 'history' && wgAction != 'delete' && wgAction != 'watch' && wgAction != 'unwatch' && wgAction != 'protect' && wgAction != 'markpatrolled' && wgAction != 'rollback' && document.URL.indexOf('diff=') <= 0 && document.URL.indexOf('oldid=') <=0) { var hist; var url; if (!(hist = document.getElementById('ca-history') )) return; if (!(url = hist.getElementsByTagName('a')[0] )) return; if (!(url = url.href )) return; addPortletLink('p-cactions', url.replace(/([?&]action=)history([&#]|$)/, '$1purge$2'), 'Purge', 'ca-purge', 'Purge server cache for this page', '0'); } }); // // -------------------------------------------------------- // redirects // adds a tab to the top of pages, when clicked it highlights all links on the page that are redirects. // -------------------------------------------------------- if (wgCanonicalNamespace != 'Special' && wgAction != 'history' && wgAction != 'delete' && wgAction != 'watch' && wgAction != 'unwatch' && wgAction != 'protect' && wgAction != 'markpatrolled' && wgAction != 'rollback' && document.URL.indexOf('diff=') <= 0) { var highlightRedirects = { tab_redirects : null, addStylesheetRule : function(tag, style) { var ss = document.styleSheets[0]; if (ss.insertRule) { ss.insertRule(tag + '{' + style + '}', ss.cssRules.length); } else if (ss.addRule) { ss.addRule(tag, style); } }, run : function() { highlightRedirects.addStylesheetRule('a.mw-redirect', 'color:red'); highlightRedirects.addStylesheetRule('a.mw-redirect:visited', 'color:hotpink'); }, install : function() { with(highlightRedirects) { addPortletLink ('p-cactions', 'javascript:highlightRedirects.run();', 'Redirects', 'ca-redirects', 'Highlights all links which are redirects', 'r') || addPortletLink ('views', 'javascript:highlightRedirects.run();', 'Redirects', 'ca-redirects', 'Highlights all links which are redirects', 'r'); } } }; addOnloadHook(highlightRedirects.install); } // // -------------------------------------------------------- // Rank Coloring // (adapted from http://en.wikipedia.org/wiki/User:Ais523/adminrights.js) // This script changes the color of links to admins' and patrollers' userpages in the bodyContent of Special, History pages, diff pages, // and old page revisions. // ("bodyContent" being everything but the tabs,personal links at the top of the screen and sidebar). // -------------------------------------------------------- var patrollerrights=new Array(); importScript('MediaWiki:Patrollerlist.js'); //Highlighting script. Based on [[User:ais523/highlightmyname.js]]. function highlightpatrollers(n,p) //node, parent node { while(n!=null) { if(n.nodeType==1&&n.tagName.toLowerCase()=="a") //anchor { if(n.href.indexOf("/User:")!=-1) { var u=n.href.split("/User:")[1]; if(patrollerrights[u.split("_").join("%20")]==1) { n.style.color="#E99216"; } } else if(n.href.indexOf("/index.php?title=User:")!=-1) { var u=n.href.split("/index.php?title=User:")[1]; if(patrollerrights[u.split("_").join("%20")]==1) { n.style.color="#E99216"; } } else { if(n.firstChild!=null) highlightpatrollers(n.firstChild,n); } } else { if(n.firstChild!=null) highlightpatrollers(n.firstChild,n); } n=n.nextSibling; } } if (wgCanonicalNamespace == 'Special' || wgAction == 'history' || document.URL.indexOf('diff=') > 0 || document.URL.indexOf('oldid=') > 0) { addOnloadHook(function() { highlightpatrollers(document.getElementById('bodyContent').firstChild, document.getElementById('bodyContent')); }); } var adminrights=new Array(); importScript('MediaWiki:Adminlist.js'); //Highlighting script. Based on [[User:ais523/highlightmyname.js]]. function highlightadmins(n,p) //node, parent node { while(n!=null) { if(n.nodeType==1&&n.tagName.toLowerCase()=="a") //anchor { if(n.href.indexOf("/User:")!=-1) { var u=n.href.split("/User:")[1]; if(adminrights[u.split("_").join("%20")]==1) { n.style.color="#2BA206"; } } else if(n.href.indexOf("/index.php?title=User:")!=-1) { var u=n.href.split("/index.php?title=User:")[1]; if(adminrights[u.split("_").join("%20")]==1) { n.style.color="#2BA206"; } } else { if(n.firstChild!=null) highlightadmins(n.firstChild,n); } } else { if(n.firstChild!=null) highlightadmins(n.firstChild,n); } n=n.nextSibling; } } if (wgCanonicalNamespace == 'Special' || wgAction == 'history' || document.URL.indexOf('diff=') > 0 || document.URL.indexOf('oldid=') > 0) { addOnloadHook(function() { highlightadmins(document.getElementById('bodyContent').firstChild, document.getElementById('bodyContent')); }); } //