MediaWiki:Common.js
From EncyclopAtys
Revision as of 13:57, 14 November 2009 by CeNobiteElf (talk | contribs) (Created page with ' →<nowiki>: →* additional scripts *: if ( wgIsArticle || window.location.href.indexOf( 'action=submit' ) > -1 ) { addScript( 'MediaWiki:CollapsibleTables.js' ); hookEvent…')
/*<nowiki>*/
/** additional scripts **/
if ( wgIsArticle || window.location.href.indexOf( 'action=submit' ) > -1 )
{
addScript( 'MediaWiki:CollapsibleTables.js' );
hookEvent( 'load', function()
{
new CollapsibleTables();
diffwithFix();
// Feedback namespace, user related additions
if ( ( wgNamespaceNumber == 202 || wgNamespaceNumber == 203 ) )
{
var regExp = /^Feedback(?:_talk)?:User\/([^\/]+)(\/.*?)?$/;
if ( ( obj = document.getElementById( 'catlinks' ) ) && obj.innerHTML.match( 'Category:Staff feedback pages' ) )
regExp = /^Feedback_talk:([^\/]+)(\/.*?)?$/;
if ( ( match = wgPageName.match( regExp ) ) && ( obj = document.getElementById( 'p-tb' ) ) && ( obj = obj.getElementsByTagName( 'ul' )[0] ) )
{
match[1] = encodeURIComponent( match[1] );
obj.innerHTML = obj.innerHTML.replace( /^([\s\S]*?<li id="t-recentchangeslinked".*?\/li>)([\s\S]+)$/i, '$1<li id="t-contributions"><a title="View the list of contributions of this user" href="/wiki/Special:Contributions/' + match[1] + '">User contributions</a></li>\n<li id="t-log"><a href="/index.php?title=Special:Log&user=' + match[1] + '">Logs</a></li>\n<li id="t-emailuser"><a title="Send an e-mail to this user" href="/wiki/Special:EmailUser/' + match[1] + '">E-mail this user</a></li>\n$2' );
}
delete obj, regExp, match;
}
// Extension for the deletion drop down list
if ( wgAction == 'delete' && ( delReasonBtn = document.getElementById( 'wpConfirmB' ) ) )
{
var delReasonList = document.getElementById( 'wpDeleteReasonList' );
var delLink = document.createElement( 'a' );
delLink.href = 'javascript:void(0);'
delLink.title = document.getElementById( 'wpReason' ).value;
delLink.style.fontSize = '0.9em';
delLink.style.marginLeft = '1em';
delLink.onclick = function()
{
document.getElementById( 'wpReason' ).value = this.title;
}
delReasonList.onchange = function ()
{
document.getElementById( 'wpReason' ).value = '';
this.onchange = null;
}
delLink.appendChild( document.createTextNode( 'restore default reason' ) );
delReasonBtn.parentNode.appendChild( delLink );
delete delLink, delReasonList, delReasonBtn;
}
} );
}
if ( wgPageName == 'Special:Upload' && document.getElementById( 'mw-upload-form' ) !== 'undefined' )
{
addScript( 'MediaWiki:UploadForm.js' );
hookEvent( 'load', function()
{
new UploadForm();
} );
}
/**** function addScript.js
* by Patrick Westerhoff [poke]
*/
function addScript ( pagename )
{
var script = document.createElement( 'script' );
pagename = encodeURI( pagename.replace( ' ', '_' ) );
script.src = '/index.php?title=' + pagename + '&action=raw&ctype=text/javascript';
script.type = 'text/javascript';
document.getElementsByTagName( 'head' )[0].appendChild( script );
}
/**** function diffwithFix.js
* by Patrick Westerhoff [poke]
*/
function diffwithFix ()
{
var diffSpan = document.getElementById( 'diffwith' );
if ( diffSpan == undefined )
return;
var diffLink = diffSpan.getElementsByTagName( 'a' )[0];
var diffTitle = diffSpan.title;
var xmlHttp;
try
{
xmlHttp = new XMLHttpRequest();
}
catch ( e )
{
try
{
xmlHttp = new ActiveXObject( 'Msxml2.XMLHTTP' );
}
catch ( e )
{
try
{
xmlHttp = new ActiveXObject( 'Microsoft.XMLHTTP' );
}
catch ( e )
{
diffSpan.style.fontSize = '90%';
diffSpan.innerHTML = '(Automated diff <b>not available</b>.)';
return;
}
}
}
xmlHttp.onreadystatechange = function ()
{
if ( xmlHttp.readyState != 4 )
return;
revs = xmlHttp.responseXML.getElementsByTagName( 'rev' );
if ( revs.length > 0 )
{
diffLink.href += '&oldid=' + revs[0].getAttribute( 'revid' );
diffSpan.title = '';
}
}
xmlHttp.open( 'GET', '/api.php?format=xml&action=query&prop=revisions&rvprop=ids&rvlimit=1&titles=' + diffTitle, true );
xmlHttp.send( null );
}
/*</nowiki>*/