SpecialVersion.js – MediaWiki
Jump to navigation
Jump to search
Fred Gandt (talk | contribs) (Sry, need to test) |
Fred Gandt (talk | contribs) (Almost done) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 20: | Line 20: | ||
function checkExtensionVersions() { | function checkExtensionVersions() { | ||
var mwve = tbls[0].getElementsByTagName( "tr" )[1].getElementsByTagName( "td" )[1], | var mwve = tbls[0].getElementsByTagName( "tr" )[1].getElementsByTagName( "td" )[1], | ||
exts = tbls[2].getElementsByTagName( "em" ), | |||
mwaddr = "www.mediawiki.org", | |||
mwcurv = mwve.textContent, | mwcurv = mwve.textContent, | ||
extso = {}; | |||
extso = {} | |||
fetchData = function( ns, n, fnc ) { | fetchData = function( ns, n, fnc ) { | ||
$.ajax( { | $.ajax( { | ||
url: "https:// | url: "https://" + mwaddr + "/w/api.php", | ||
data: { | data: { | ||
action: "query", | action: "query", | ||
prop: "revisions", | prop: "revisions", | ||
rvprop: "content", | rvprop: "content", | ||
titles: ns | titles: ns + n, | ||
format: "json", | format: "json", | ||
redirects: "" | redirects: "" | ||
Line 39: | Line 40: | ||
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]["*"], | var ttl = !!data.query.redirects ? data.query.redirects[0].from : pgs[pg].title; | ||
fnc( pgs[pg].revisions[0]["*"], ttl.replace( / /g, "_" ).replace( ns, "" ).toLowerCase() ); | |||
break; | break; | ||
} | } | ||
Line 50: | Line 49: | ||
}; | }; | ||
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(), | ||
mwrnaddr = "Release_notes/" + mwlurv; | |||
if ( mwlurv > mwcurv ) { | if ( mwlurv > mwcurv ) { | ||
mwve.innerHTML + | fetchData( | ||
"", | |||
mwrnaddr, | |||
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><b><span style='color:#0a0;'>Latest stable version: " + mwlurv + "</span>" + | |||
"<br>Compatibility <a href='https://" + mwaddr + "/wiki/" + mwrnaddr + "'>release notes for " + mwlurv + "</a>:</b>" + | |||
"<p style='margin-left:1em;white-space:pre-wrap;'>" + mwcmpt[1].trim() + "</p>"; | |||
} | |||
} | |||
); | |||
} | } | ||
} | } | ||
Line 64: | Line 76: | ||
if ( ev[0] ) { | if ( ev[0] ) { | ||
var en; | var en; | ||
if ( exts[ext].firstChild.nodeType === Node.ELEMENT_NODE ) { | if ( exts[ext].firstChild.nodeType === Node.ELEMENT_NODE && exts[ext].firstChild.hasAttribute( "href" ) ) { | ||
en = exts[ext].firstChild.getAttribute( "href" ); | en = exts[ext].firstChild.getAttribute( "href" ); | ||
en = en.substring( en.indexOf( "Extension:" ) + 10 ); | if ( en.indexOf( mwaddr ) > 0 ) { | ||
en = en.substring( en.indexOf( "Extension:" ) + 10 ); | |||
} else { | |||
en = exts[ext].firstChild.textContent.trim(); | |||
} | |||
} else { | } else { | ||
en = exts[ext].firstChild.textContent.trim(); | en = exts[ext].firstChild.textContent.trim(); | ||
} | } | ||
extso[en.toLowerCase()] = [ | extso[en.toLowerCase().replace( / /g, "_" )] = [ | ||
exts[ext], | exts[ext], | ||
ev[0].textContent.replace( /[^ | ev[0].textContent.replace( /[^\d\. ]/g, "" ).trim() | ||
]; | ]; | ||
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 = | bndl = []; | ||
if ( !!stts && !!lurv ) { | if ( !!stts && !!lurv ) { | ||
stts = stts[1].toLowerCase(); | stts = stts[1].toLowerCase(); | ||
lurv = lurv[1]; | lurv = lurv[1].replace( /<.*>/g, "" ).trim(); | ||
if ( !!bndl ) { | bndl = /\|.*(?=\bbundled\b).*(?=\bmediawiki\b).*(?=\s([\d\.]+)).*/i.exec( txt ); | ||
} else { | |||
} | bndl = /\s*\{\{\s*archived(?: |_)extension\s*\|\s*\d+\s*\|\s*reason\s*=.*(?=\bmerged\b).*(?=\bcore\b).*(?=\bmediawiki\b).*(?=\bversion\s*([\d\.]+)).*/i.exec( txt ); | ||
} | |||
if ( !!bndl ) { | |||
stts = "bundled since"; | |||
lurv = bndl[1].replace(/[^\d]*$/g, ""); | |||
stts === "archive" ? | curv = mwcurv; | ||
} | |||
if ( lurv != curv ) { // todo: latest version is greater than current version | |||
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;" : | |||
stts === "bundled since" ? "#0a0;font-weight:bold;" : | |||
"#f00;" | |||
) + "'>" + stts.charAt( 0 ).toUpperCase() + stts.slice( 1 ) + ": " + lurv + "</span>"; | |||
} | } | ||
} | } |
Latest revision as of 03:42, 22 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],
exts = tbls[2].getElementsByTagName( "em" ),
mwaddr = "www.mediawiki.org",
mwcurv = mwve.textContent,
extso = {};
fetchData = function( ns, n, fnc ) {
$.ajax( {
url: "https://" + mwaddr + "/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( / /g, "_" ).replace( ns, "" ).toLowerCase() );
break;
}
}
}
} );
};
fetchData(
"Template:",
"MW_stable_branch_number",
function( txt, ttl ) {
var mwlurv = txt.substring( 0, txt.indexOf( "<noinclude>" ) ).trim(),
mwrnaddr = "Release_notes/" + mwlurv;
if ( mwlurv > mwcurv ) {
fetchData(
"",
mwrnaddr,
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><b><span style='color:#0a0;'>Latest stable version: " + mwlurv + "</span>" +
"<br>Compatibility <a href='https://" + mwaddr + "/wiki/" + mwrnaddr + "'>release notes for " + mwlurv + "</a>:</b>" +
"<p style='margin-left:1em;white-space:pre-wrap;'>" + mwcmpt[1].trim() + "</p>";
}
}
);
}
}
);
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( mwaddr ) > 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( / /g, "_" )] = [
exts[ext],
ev[0].textContent.replace( /[^\d\. ]/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 = [];
if ( !!stts && !!lurv ) {
stts = stts[1].toLowerCase();
lurv = lurv[1].replace( /<.*>/g, "" ).trim();
bndl = /\|.*(?=\bbundled\b).*(?=\bmediawiki\b).*(?=\s([\d\.]+)).*/i.exec( txt );
} else {
bndl = /\s*\{\{\s*archived(?: |_)extension\s*\|\s*\d+\s*\|\s*reason\s*=.*(?=\bmerged\b).*(?=\bcore\b).*(?=\bmediawiki\b).*(?=\bversion\s*([\d\.]+)).*/i.exec( txt );
}
if ( !!bndl ) {
stts = "bundled since";
lurv = bndl[1].replace(/[^\d]*$/g, "");
curv = mwcurv;
}
if ( lurv != curv ) { // todo: latest version is greater than current version
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;" :
stts === "bundled since" ? "#0a0;font-weight:bold;" :
"#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