SpecialVersion.js – MediaWiki

From Bohemia Interactive Community
Jump to navigation Jump to search
(Getting there - slowly. Testing before continuing on this path.)
(Should work)
Line 3: Line 3:
  *
  *
  *****************************************************************************************/
  *****************************************************************************************/
 
(function() { // BEGIN WRAPPER
(function() { // BEGIN WRAPPER
   
   
Line 21: Line 21:
mw_version = tbls[0].getElementsByTagName( "tr" )[1].getElementsByTagName( "td" )[1].textContent,
mw_version = tbls[0].getElementsByTagName( "tr" )[1].getElementsByTagName( "td" )[1].textContent,
exts = tbls[2].getElementsByTagName( "em" );
exts = tbls[2].getElementsByTagName( "em" );
for ( var i in exts ) {
extso = {};
if ( typeof exts[i] == "object" ) {
for ( var ext in exts ) {
var ev = exts[i].getElementsByClassName( "mw-version-ext-version" );
if ( typeof exts[ext] == "object" ) {
var ev = exts[ext].getElementsByClassName( "mw-version-ext-version" );
if ( ev[0] ) {
if ( ev[0] ) {
var en = exts[i].firstChild.textContent.trim();
var en = exts[ext].firstChild.getAttribute( "href" );
$.getJSON( "https://www.mediawiki.org/w/api.php?action=query&titles=Extension:" +
en = en.substring( en.indexOf( "Extension:" ) + 10 );
encodeURIComponent( en ) + "&format=json&callback=?", function( data ) {
extso[en] = [
console.log( ev[0].textContent.replace( /[^0-9\.\s]/g, "" ).trim() ); // still just testing
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( "=", "" ).trim();
if ( curv != txt ) {
extso[ttl][0].innerHTML += "<br><span style='color:red;'>" + txt + " available</span>";
}
//console.log( ttl + " - Current version: " + extso[ttl.replace( "Extension:", "" )] + " | Latest version: " + txt );
}
}
}
}
);
} );
}
}
}
}

Revision as of 16:45, 17 June 2014

/*****************************************************************************************
 * 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 = exts[ext].firstChild.getAttribute( "href" );
					en = en.substring( en.indexOf( "Extension:" ) + 10 );
					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( "=", "" ).trim();
									if ( curv != txt ) {
										extso[ttl][0].innerHTML += "<br><span style='color:red;'>" + txt + " available</span>";
									}
									//console.log( ttl + " - Current version: " + extso[ttl.replace( "Extension:", "" )] + " | Latest version: " + txt );
								}
							}
						}
					} );
				}
			}
		}
	}
 
/*****************************************************************************************/
 
/*****************************************************************************************
 * Next ***
 */
 
	// code code code
 
/*****************************************************************************************/
 
/*****************************************************************************************
 * Call the functions above
 */
 
	checkExtensionVersions();

}()); // END WRAPPER