User:Ale jrb/Scripts/Nforcer.js

/* ======================================================== *\ \* ======================================================== */
 * Nforcer JavaScript cache/version manager
 * Nforcer is a system designed for complex JavaScript
 * applications. JavaScript versioning and updating can be
 * difficult because of browser caching - Nforcer allows
 * version changes to be enforced, even when the JavaScript
 * it runs on remains the same.
 * Nforcer JavaScript cache/version manager for Wikipedia
 * created by Alex Barley User:Ale_jrb
 * copyright (c) Alex Barley - Some Rights Reserved
 * You may copy, modify and distribute this software as
 * desired, providing that all previous contributors retain
 * correct attribution.
 * tracker: User:Ale_jrb/Scripts
 * You may copy, modify and distribute this software as
 * desired, providing that all previous contributors retain
 * correct attribution.
 * tracker: User:Ale_jrb/Scripts
 * tracker: User:Ale_jrb/Scripts
 * tracker: User:Ale_jrb/Scripts
 * tracker: User:Ale_jrb/Scripts

// class -- nforcer // constructors: // nf_versionPage: location of versioning function nforcer( nf_versionPage, nf_versionVarName, nf_versionVarValue, nf_settings ) { // init if ( (nf_versionPage == null) || (nf_versionVarName == null) || (nf_versionVarValue == null) ) return false; this.versionPage = nf_versionPage; this.versionVarName = nf_versionVarName; this.versionVarValue = nf_versionVarValue; this.settings = parseSettings(nf_settings); // modules - public // {object}.check // returns: validity of cache; success [as] boolean. this.check = function { var me = this; // retrieve the wiki page this.pageReq = new wa_mediawikiApi; this.pageReq.onCompleteAction = function { me.check_int; return true; }; this.pageReq.getPage(this.versionPage, 1, 'content'); }		this.check_int = function { var regVar = this.versionVarName.replace(/\./g, '\\.'); var regTest = new RegExp('(?:var\\s+)?' + regVar + '\\s+=\\s+\'?(.+?)\'?;'); var result = regTest.exec(this.pageReq.data['page']['revisions'][0]['content']); if (result == null) { this.onStatusChange( false ); return false; } var versionMatch = (this.versionVarValue == result[1]); if ( versionMatch == true ) { this.onStatusChange( true ); return true; } else if ( ( versionMatch == false ) && ( this.settings['permission-block'] == 'true' ) ) { this.onStatusChange( false ); return false; } else if ( ( versionMatch == false ) && ( this.settings['permission-block'] == 'false' ) ) { this.onStatusChange( true ); return true; }		}		// {object}.onStatusChange( nf_currentStatus ) // returns: N/A. user defined function. called on status change. this.onStatusChange = function( nf_currentStatus ) { return true; } // modules - private function parseSettings ( toParse ) { var settingGroups = toParse.split('|'); var settings = new Object; for (var i = 0; i < settingGroups.length; i ++) { var t = settingGroups[i].split(':'); var nTest = parseInt(t[1]); if (isNaN(nTest)) { var v = t[1]; } else { var v = nTest; } settings[t[0]] = v;			} return settings; }	}		importScript('User:Ale_jrb/Scripts/waLib.js');