SpecialVersion.js – MediaWiki
Jump to navigation
Jump to search
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/*****************************************************************************************
* JavaScript here will be loaded by MediaWiki:Common.js when viewing "Special:Version".
*
*****************************************************************************************/
(function() { // BEGIN WRAPPER
/*****************************************************************************************
* Variables required by all functions below
*/
var foo = ""; // Every script needs a "foo"
/*****************************************************************************************
* Check extension versions and indicate available updates.
* Maintainer: BIKI User:Fred Gandt
*/
function checkExtensionVersions() {
var tbls = document.getElementsByTagName( "table" ),
mw_version = tbls[0].getElementsByTagName( "tr" )[1].getElementsByTagName( "td" )[1].textContent,
exts = tbls[2].getElementsByTagName( "em" );
extso = {};
for ( var ext in exts ) {
if ( typeof exts[ext] == "object" ) {
var ev = exts[ext].getElementsByClassName( "mw-version-ext-version" );
if ( ev[0] ) {
var en;
if ( exts[ext].firstChild ) {
en = exts[ext].firstChild.getAttribute( "href" );
en = en.substring( en.indexOf( "Extension:" ) + 10 );
} else {
en = exts[ext].textContent;
}
extso[en] = [
exts[ext],
ev[0].textContent.replace( /[^0-9\.\s]/g, "" ).trim()
];
$.ajax( {
url: "https://www.mediawiki.org/w/api.php",
data: {
action: "query",
prop: "revisions",
rvprop: "content",
titles: "Extension:" + encodeURIComponent( en ),
format: "json"
},
dataType: "jsonp",
success: function( data ) {
var pgs = data.query.pages;
for ( var pg in pgs ) {
if ( pgs[pg].hasOwnProperty( "revisions" ) ) {
var txt = pgs[pg].revisions[0]["*"],
ttl = pgs[pg].title.replace( " ", "_" ).replace( "Extension:", "" ),
curv = extso[ttl][1];
txt = txt.substring( txt.indexOf( "|version" ) + 8 );
txt = txt.substring( 0, txt.indexOf( "|" ) ).replace( /[^0-9\.\s]/g, "" ).trim() || "Continuous updates";
if ( curv != txt ) {
extso[ttl][0].innerHTML += "<br><span style='color:red;'>" + txt + " available</span>";
}
}
}
}
} );
}
}
}
}
/*****************************************************************************************/
/*****************************************************************************************
* Next ***
*/
// code code code
/*****************************************************************************************/
/*****************************************************************************************
* Call the functions above
*/
checkExtensionVersions();
}()); // END WRAPPER