SpecialVersion.js – MediaWiki
Jump to navigation
Jump to search
Fred Gandt (talk | contribs) (Sry, need to test) |
Fred Gandt (talk | contribs) (console.log( "All the things!!" );) |
||
Line 3: | Line 3: | ||
* | * | ||
*****************************************************************************************/ | *****************************************************************************************/ | ||
var extso = {}; // for tests only | |||
(function() { // BEGIN WRAPPER | (function() { // BEGIN WRAPPER | ||
Line 21: | Line 21: | ||
var mwve = tbls[0].getElementsByTagName( "tr" )[1].getElementsByTagName( "td" )[1], | var mwve = tbls[0].getElementsByTagName( "tr" )[1].getElementsByTagName( "td" )[1], | ||
mwcurv = mwve.textContent, | mwcurv = mwve.textContent, | ||
exts = tbls[2].getElementsByTagName( "em" ); | exts = tbls[2].getElementsByTagName( "em" ); /* for tests only | ||
extso = {} | extso = {}; */ | ||
fetchData = function( ns, n, fnc ) { | fetchData = function( ns, n, fnc ) { | ||
$.ajax( { | $.ajax( { | ||
Line 36: | Line 36: | ||
dataType: "jsonp", | dataType: "jsonp", | ||
success: function( data ) { | success: function( data ) { | ||
console.log( [data] ); // for tests only | |||
var pgs = data.query.pages; | var pgs = data.query.pages; | ||
for ( var pg in pgs ) { | for ( var pg in pgs ) { | ||
if ( pgs[pg].hasOwnProperty( "revisions" ) ) { | if ( pgs[pg].hasOwnProperty( "revisions" ) ) { | ||
fnc( pgs[pg].revisions[0]["*"], pgs[pg].title.replace( " ", "_" ).replace( ns + ":", "" ).toLowerCase() ); | fnc( pgs[pg].revisions[0]["*"], pgs[pg].title.replace( " ", "_" ).replace( ns + ":", "" ).toLowerCase() ); | ||
break; | break; | ||
} | } | ||
Line 78: | Line 76: | ||
en, | en, | ||
function( txt, ttl ) { | function( txt, ttl ) { | ||
console.log( ttl ); // for tests only | |||
var curv = extso[ttl][1], | var curv = extso[ttl][1], | ||
stts = /\|\s*status\s*=\s*(.+)\s*\|/im.exec( txt ), | stts = /\|\s*status\s*=\s*(.+)\s*\|/im.exec( txt ), | ||
lurv = /\|\s*version\s*=\s*(.+)\s*\|/im.exec( txt ), | lurv = /\|\s*version\s*=\s*(.+)\s*\|/im.exec( txt ), // todo: more robust test for version statement | ||
bndl = /\|\s*bundled\s*with\s*MediaWiki\s*([\d\.]+)\s*\]\]/i.exec( txt ); | bndl = /\|\s*bundled\s*with\s*MediaWiki\s*([\d\.]+)\s*\]\]/i.exec( txt ); | ||
if ( !!stts && !!lurv ) { | if ( !!stts && !!lurv ) { | ||
Line 86: | Line 85: | ||
lurv = lurv[1]; | lurv = lurv[1]; | ||
if ( !!bndl ) { | if ( !!bndl ) { | ||
bndl = bndl[1]; | bndl = bndl[1]; // todo: what's bundled with what? | ||
} | } | ||
if ( lurv != curv ) { | if ( lurv != curv ) { // todo: comparison of non standardised versioning | ||
extso[ttl][0].innerHTML += "<br><span style='color:" + ( | extso[ttl][0].innerHTML += "<br><span style='color:" + ( | ||
stts === "unmaintained" ? | stts === "unmaintained" ? |
Revision as of 01:16, 19 June 2014
/*****************************************************************************************
* JavaScript here will be loaded by MediaWiki:Common.js when viewing "Special:Version".
*
*****************************************************************************************/
var extso = {}; // for tests only
(function() { // BEGIN WRAPPER
/*****************************************************************************************
* Variables required by all functions below
*/
// All tables on "Special:Version"
var tbls = document.getElementsByTagName( "table" );
/*****************************************************************************************
* Check extension versions and indicate available updates.
* Maintainer: BIKI User:Fred Gandt
*/
function checkExtensionVersions() {
var mwve = tbls[0].getElementsByTagName( "tr" )[1].getElementsByTagName( "td" )[1],
mwcurv = mwve.textContent,
exts = tbls[2].getElementsByTagName( "em" ); /* for tests only
extso = {}; */
fetchData = function( ns, n, fnc ) {
$.ajax( {
url: "https://www.mediawiki.org/w/api.php",
data: {
action: "query",
prop: "revisions",
rvprop: "content",
titles: ns + ":" + n,
format: "json",
redirects: ""
},
dataType: "jsonp",
success: function( data ) {
console.log( [data] ); // for tests only
var pgs = data.query.pages;
for ( var pg in pgs ) {
if ( pgs[pg].hasOwnProperty( "revisions" ) ) {
fnc( pgs[pg].revisions[0]["*"], pgs[pg].title.replace( " ", "_" ).replace( ns + ":", "" ).toLowerCase() );
break;
}
}
}
} );
};
fetchData(
"Template",
"MW_stable_branch_number",
function( txt, ttl ) {
var mwlurv = txt.substring( 0, txt.indexOf( "<noinclude>" ) )
if ( mwlurv > mwcurv ) {
mwve.innerHTML += "<br><span style='color:#0a0;'>Latest stable: " + mwlurv + "</span>"
}
}
);
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.nodeType === Node.ELEMENT_NODE ) {
en = exts[ext].firstChild.getAttribute( "href" );
en = en.substring( en.indexOf( "Extension:" ) + 10 );
} else {
en = exts[ext].firstChild.textContent.trim();
}
extso[en.toLowerCase()] = [
exts[ext],
ev[0].textContent.replace( /[^0-9\.\s]/g, "" ).trim()
];
fetchData(
"Extension",
en,
function( txt, ttl ) {
console.log( ttl ); // for tests only
var curv = extso[ttl][1],
stts = /\|\s*status\s*=\s*(.+)\s*\|/im.exec( txt ),
lurv = /\|\s*version\s*=\s*(.+)\s*\|/im.exec( txt ), // todo: more robust test for version statement
bndl = /\|\s*bundled\s*with\s*MediaWiki\s*([\d\.]+)\s*\]\]/i.exec( txt );
if ( !!stts && !!lurv ) {
stts = stts[1].toLowerCase();
lurv = lurv[1];
if ( !!bndl ) {
bndl = bndl[1]; // todo: what's bundled with what?
}
if ( lurv != curv ) { // todo: comparison of non standardised versioning
extso[ttl][0].innerHTML += "<br><span style='color:" + (
stts === "unmaintained" ?
"#aaa;" :
stts === "archive" ?
"#aaa;" :
stts === "milestone" ?
"#aaa;" :
stts === "unstable" ?
"#f00;" :
stts === "experimental" ?
"#f00;" :
stts === "beta" ?
"#d80;" :
stts === "stable" ?
"#0a0;" :
stts === "magic" ?
"#aaa;" :
"#f00;"
) + "'>" + stts.charAt( 0 ).toUpperCase() + stts.slice( 1 ) + ": " + lurv + "</span>";
}
}
}
);
}
}
}
}
function initCheckExtensionVersions() {
var btn = document.createElement( "button" );
btn.setAttribute( "style", "vertical-align: -6px;" );
btn.innerHTML = "Check Versions";
btn.addEventListener( "click", checkExtensionVersions, false );
tbls[0].setAttribute( "style", "display: inline-table;" );
tbls[0].parentElement.insertBefore( btn, tbls[0].nextSibling );
}
/*****************************************************************************************/
/*****************************************************************************************
* Next ***
*/
// code code code
/*****************************************************************************************/
/*****************************************************************************************
* Call the functions above
*/
if ( mw.config.get( "wgUserGroups" ).indexOf( "sysop" ) >= 0 ) {
initCheckExtensionVersions();
}
}()); // END WRAPPER