SpecialVersion.js – MediaWiki
Jump to navigation
Jump to search
Fred Gandt (talk | contribs) (Another step - in the right direction?) |
Fred Gandt (talk | contribs) (Another little push.) |
||
Line 30: | Line 30: | ||
prop: "revisions", | prop: "revisions", | ||
rvprop: "content", | rvprop: "content", | ||
titles: ns | titles: ns + n, | ||
format: "json", | format: "json", | ||
redirects: "" | redirects: "" | ||
Line 40: | Line 40: | ||
if ( pgs[pg].hasOwnProperty( "revisions" ) ) { | if ( pgs[pg].hasOwnProperty( "revisions" ) ) { | ||
var ttl = !!data.query.redirects ? data.query.redirects[0].from : pgs[pg].title; | var ttl = !!data.query.redirects ? data.query.redirects[0].from : pgs[pg].title; | ||
fnc( pgs[pg].revisions[0]["*"], ttl.replace( /\s+/g, "_" ).replace( ns | fnc( pgs[pg].revisions[0]["*"], ttl.replace( /\s+/g, "_" ).replace( ns, "" ).toLowerCase() ); | ||
break; | break; | ||
} | } | ||
Line 48: | Line 48: | ||
}; | }; | ||
fetchData( | fetchData( | ||
"Template", | "Template:", | ||
"MW_stable_branch_number", | "MW_stable_branch_number", | ||
function( txt, ttl ) { | function( txt, ttl ) { | ||
var mwlurv = txt.substring( 0, txt.indexOf( "<noinclude>" ) ) | var mwlurv = txt.substring( 0, txt.indexOf( "<noinclude>" ) ).trim(); | ||
if ( mwlurv > mwcurv ) { | if ( mwlurv > mwcurv ) { | ||
mwve.innerHTML + | fetchData( | ||
"", | |||
"Release_notes/" + mwlurv, | |||
function( txt, ttl ) { | |||
var mwcmpt = /={2,}\s*compatibility\s*={2,}([^]+)={2,}\s*[\w]+\s*={2,}/i.exec( txt ); | |||
if ( !!mwcmpt ) { | |||
mwve.innerHTML = "Current version: " + mwcurv + | |||
"<br><span style='color:#0a0;'>Latest stable: " + mwlurv + | |||
"</span><br><span style='white-space:pre-wrap;'>Compatibility release notes:<br>" + mwcmpt[1].trim() + "</span>"; | |||
} | |||
} | |||
); | |||
} | } | ||
} | } | ||
Line 77: | Line 88: | ||
]; | ]; | ||
fetchData( | fetchData( | ||
"Extension", | "Extension:", | ||
en, | en, | ||
function( txt, ttl ) { | function( txt, ttl ) { | ||
var curv = extso[ttl][1], | var curv = extso[ttl][1], | ||
stts = /\|\s*status\s*=\s*(.+)\s*\|/ | stts = /\|\s*status\s*=\s*(.+)\s*\|/i.exec( txt ), | ||
lurv = /\|\s*version\s*=\s*(.+)\s*\|/ | lurv = /\|\s*version\s*=\s*(.+)\s*\|/i.exec( txt ), | ||
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 ) { // todo: might be archived and thus might be merged aka bundled | ||
stts = stts[1].toLowerCase(); | stts = stts[1].toLowerCase(); | ||
lurv = lurv[1].replace( /<.*>/g, "" ).trim(); | lurv = lurv[1].replace( /<.*>/g, "" ).trim(); | ||
if ( !!bndl ) { | if ( !!bndl ) { | ||
bndl = bndl[1]; // todo: what's bundled with what? | bndl = bndl[1]; // todo: what's bundled with what? | ||
console.log(ttl + " -- " + bndl + " -- " + lurv); | |||
} | } | ||
if ( lurv != curv ) { | if ( lurv != curv ) { |
Revision as of 11:39, 20 June 2014
/*****************************************************************************************
* JavaScript here will be loaded by MediaWiki:Common.js when viewing "Special:Version".
*
*****************************************************************************************/
(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" ),
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 ) {
var pgs = data.query.pages;
for ( var pg in pgs ) {
if ( pgs[pg].hasOwnProperty( "revisions" ) ) {
var ttl = !!data.query.redirects ? data.query.redirects[0].from : pgs[pg].title;
fnc( pgs[pg].revisions[0]["*"], ttl.replace( /\s+/g, "_" ).replace( ns, "" ).toLowerCase() );
break;
}
}
}
} );
};
fetchData(
"Template:",
"MW_stable_branch_number",
function( txt, ttl ) {
var mwlurv = txt.substring( 0, txt.indexOf( "<noinclude>" ) ).trim();
if ( mwlurv > mwcurv ) {
fetchData(
"",
"Release_notes/" + mwlurv,
function( txt, ttl ) {
var mwcmpt = /={2,}\s*compatibility\s*={2,}([^]+)={2,}\s*[\w]+\s*={2,}/i.exec( txt );
if ( !!mwcmpt ) {
mwve.innerHTML = "Current version: " + mwcurv +
"<br><span style='color:#0a0;'>Latest stable: " + mwlurv +
"</span><br><span style='white-space:pre-wrap;'>Compatibility release notes:<br>" + mwcmpt[1].trim() + "</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 && exts[ext].firstChild.hasAttribute( "href" ) ) {
en = exts[ext].firstChild.getAttribute( "href" );
if ( en.indexOf( "www.mediawiki.org" ) > 0 ) {
en = en.substring( en.indexOf( "Extension:" ) + 10 );
} else {
en = exts[ext].firstChild.textContent.trim();
}
} else {
en = exts[ext].firstChild.textContent.trim();
}
extso[en.toLowerCase().replace( /\s+/g, "_" )] = [
exts[ext],
ev[0].textContent.replace( /[^0-9\.\s]/g, "" ).trim()
];
fetchData(
"Extension:",
en,
function( txt, ttl ) {
var curv = extso[ttl][1],
stts = /\|\s*status\s*=\s*(.+)\s*\|/i.exec( txt ),
lurv = /\|\s*version\s*=\s*(.+)\s*\|/i.exec( txt ),
bndl = /\|\s*bundled\s*with\s*MediaWiki\s*([\d\.]+)\s*\]\]/i.exec( txt );
if ( !!stts && !!lurv ) { // todo: might be archived and thus might be merged aka bundled
stts = stts[1].toLowerCase();
lurv = lurv[1].replace( /<.*>/g, "" ).trim();
if ( !!bndl ) {
bndl = bndl[1]; // todo: what's bundled with what?
console.log(ttl + " -- " + bndl + " -- " + lurv);
}
if ( lurv != curv ) {
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