* Added Ryan Grove's jsmin.php and wrote a maintenance script wrapper called minify.php
* Added a makefile to rebuild skins/common
* Rebuilt jquery.min.js
'Interwiki' => 'includes/Interwiki.php',
'IP' => 'includes/IP.php',
'Job' => 'includes/JobQueue.php',
+ 'JSMin' => 'includes/JSMin.php',
'LCStore_DB' => 'includes/LocalisationCache.php',
'LCStore_CDB' => 'includes/LocalisationCache.php',
'LCStore_Null' => 'includes/LocalisationCache.php',
--- /dev/null
+<?php
+/**
+ * jsmin.php - PHP implementation of Douglas Crockford's JSMin.
+ *
+ * This is pretty much a direct port of jsmin.c to PHP with just a few
+ * PHP-specific performance tweaks. Also, whereas jsmin.c reads from stdin and
+ * outputs to stdout, this library accepts a string as input and returns another
+ * string as output.
+ *
+ * PHP 5 or higher is required.
+ *
+ * Permission is hereby granted to use this version of the library under the
+ * same terms as jsmin.c, which has the following license:
+ *
+ * --
+ * Copyright (c) 2002 Douglas Crockford (www.crockford.com)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * The Software shall be used for Good, not Evil.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ * --
+ *
+ * @package JSMin
+ * @author Ryan Grove <ryan@wonko.com>
+ * @copyright 2002 Douglas Crockford <douglas@crockford.com> (jsmin.c)
+ * @copyright 2008 Ryan Grove <ryan@wonko.com> (PHP port)
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 1.1.1 (2008-03-02)
+ * @link http://code.google.com/p/jsmin-php/
+ */
+
+class JSMin {
+ const ORD_LF = 10;
+ const ORD_SPACE = 32;
+
+ protected $a = '';
+ protected $b = '';
+ protected $input = '';
+ protected $inputIndex = 0;
+ protected $inputLength = 0;
+ protected $lookAhead = null;
+ protected $output = '';
+
+ // -- Public Static Methods --------------------------------------------------
+
+ public static function minify($js) {
+ $jsmin = new JSMin($js);
+ return $jsmin->min();
+ }
+
+ // -- Public Instance Methods ------------------------------------------------
+
+ public function __construct($input) {
+ $this->input = str_replace("\r\n", "\n", $input);
+ $this->inputLength = strlen($this->input);
+ }
+
+ // -- Protected Instance Methods ---------------------------------------------
+
+ protected function action($d) {
+ switch($d) {
+ case 1:
+ $this->output .= $this->a;
+
+ case 2:
+ $this->a = $this->b;
+
+ if ($this->a === "'" || $this->a === '"') {
+ for (;;) {
+ $this->output .= $this->a;
+ $this->a = $this->get();
+
+ if ($this->a === $this->b) {
+ break;
+ }
+
+ if (ord($this->a) <= self::ORD_LF) {
+ throw new JSMinException('Unterminated string literal.');
+ }
+
+ if ($this->a === '\\') {
+ $this->output .= $this->a;
+ $this->a = $this->get();
+ }
+ }
+ }
+
+ case 3:
+ $this->b = $this->next();
+
+ if ($this->b === '/' && (
+ $this->a === '(' || $this->a === ',' || $this->a === '=' ||
+ $this->a === ':' || $this->a === '[' || $this->a === '!' ||
+ $this->a === '&' || $this->a === '|' || $this->a === '?')) {
+
+ $this->output .= $this->a . $this->b;
+
+ for (;;) {
+ $this->a = $this->get();
+
+ if ($this->a === '/') {
+ break;
+ } elseif ($this->a === '\\') {
+ $this->output .= $this->a;
+ $this->a = $this->get();
+ } elseif (ord($this->a) <= self::ORD_LF) {
+ throw new JSMinException('Unterminated regular expression '.
+ 'literal.');
+ }
+
+ $this->output .= $this->a;
+ }
+
+ $this->b = $this->next();
+ }
+ }
+ }
+
+ protected function get() {
+ $c = $this->lookAhead;
+ $this->lookAhead = null;
+
+ if ($c === null) {
+ if ($this->inputIndex < $this->inputLength) {
+ $c = substr($this->input, $this->inputIndex, 1);
+ $this->inputIndex += 1;
+ } else {
+ $c = null;
+ }
+ }
+
+ if ($c === "\r") {
+ return "\n";
+ }
+
+ if ($c === null || $c === "\n" || ord($c) >= self::ORD_SPACE) {
+ return $c;
+ }
+
+ return ' ';
+ }
+
+ protected function isAlphaNum($c) {
+ return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1;
+ }
+
+ protected function min() {
+ $this->a = "\n";
+ $this->action(3);
+
+ while ($this->a !== null) {
+ switch ($this->a) {
+ case ' ':
+ if ($this->isAlphaNum($this->b)) {
+ $this->action(1);
+ } else {
+ $this->action(2);
+ }
+ break;
+
+ case "\n":
+ switch ($this->b) {
+ case '{':
+ case '[':
+ case '(':
+ case '+':
+ case '-':
+ $this->action(1);
+ break;
+
+ case ' ':
+ $this->action(3);
+ break;
+
+ default:
+ if ($this->isAlphaNum($this->b)) {
+ $this->action(1);
+ }
+ else {
+ $this->action(2);
+ }
+ }
+ break;
+
+ default:
+ switch ($this->b) {
+ case ' ':
+ if ($this->isAlphaNum($this->a)) {
+ $this->action(1);
+ break;
+ }
+
+ $this->action(3);
+ break;
+
+ case "\n":
+ switch ($this->a) {
+ case '}':
+ case ']':
+ case ')':
+ case '+':
+ case '-':
+ case '"':
+ case "'":
+ $this->action(1);
+ break;
+
+ default:
+ if ($this->isAlphaNum($this->a)) {
+ $this->action(1);
+ }
+ else {
+ $this->action(3);
+ }
+ }
+ break;
+
+ default:
+ $this->action(1);
+ break;
+ }
+ }
+ }
+
+ return $this->output;
+ }
+
+ protected function next() {
+ $c = $this->get();
+
+ if ($c === '/') {
+ switch($this->peek()) {
+ case '/':
+ for (;;) {
+ $c = $this->get();
+
+ if (ord($c) <= self::ORD_LF) {
+ return $c;
+ }
+ }
+
+ case '*':
+ $this->get();
+
+ for (;;) {
+ switch($this->get()) {
+ case '*':
+ if ($this->peek() === '/') {
+ $this->get();
+ return ' ';
+ }
+ break;
+
+ case null:
+ throw new JSMinException('Unterminated comment.');
+ }
+ }
+
+ default:
+ return $c;
+ }
+ }
+
+ return $c;
+ }
+
+ protected function peek() {
+ $this->lookAhead = $this->get();
+ return $this->lookAhead;
+ }
+}
+
+// -- Exceptions ---------------------------------------------------------------
+class JSMinException extends Exception {}
+?>
\ No newline at end of file
--- /dev/null
+<?php
+/**
+ * Minify a file or set of files
+ */
+
+require_once( dirname( __FILE__ ) . '/Maintenance.php' );
+
+class MinifyScript extends Maintenance {
+ var $outDir;
+
+ public function __construct() {
+ parent::__construct();
+ $this->addOption( 'outfile',
+ 'File for output. Only a single file may be specified for input.',
+ false, true );
+ $this->addOption( 'outdir',
+ "Directory for output. If this is not specified, and neither is --outfile, then the\n" .
+ "output files will be sent to the same directories as the input files.",
+ false, true );
+ $this->mDescription = "Minify a file or set of files.\n\n" .
+ "If --outfile is not specified, then the output file names will have a .min extension\n" .
+ "added, e.g. jquery.js -> jquery.min.js.";
+
+ }
+
+ public function execute() {
+ if ( !count( $this->mArgs ) ) {
+ $this->error( "minify.php: At least one input file must be specified." );
+ exit( 1 );
+ }
+
+ if ( $this->hasOption( 'outfile' ) ) {
+ if ( count( $this->mArgs ) > 1 ) {
+ $this->error( '--outfile may only be used with a single input file.' );
+ exit( 1 );
+ }
+
+ // Minify one file
+ $this->minify( $this->getArg( 0 ), $this->getOption( 'outfile' ) );
+ return;
+ }
+
+ $outDir = $this->getOption( 'outdir', false );
+
+ foreach ( $this->mArgs as $arg ) {
+ $inPath = realpath( $arg );
+ $inName = basename( $inPath );
+ $inDir = dirname( $inPath );
+
+ if ( strpos( $inName, '.min.' ) !== false ) {
+ echo "Skipping $inName\n";
+ continue;
+ }
+
+ if ( !file_exists( $inPath ) ) {
+ $this->error( "File does not exist: $arg" );
+ exit( 1 );
+ }
+
+ $extension = $this->getExtension( $inName );
+ $outName = substr( $inName, 0, -strlen( $extension ) ) . 'min.' . $extension;
+ if ( $outDir === false ) {
+ $outPath = $inDir . '/' . $outName;
+ } else {
+ $outPath = $outDir . '/' . $outName;
+ }
+
+ $this->minify( $inPath, $outPath );
+ }
+ }
+
+ public function getExtension( $fileName ) {
+ $dotPos = strrpos( $fileName, '.' );
+ if ( $dotPos === false ) {
+ $this->error( "No file extension, cannot determine type: $arg" );
+ exit( 1 );
+ }
+ return substr( $fileName, $dotPos + 1 );
+ }
+
+ public function minify( $inPath, $outPath ) {
+ $extension = $this->getExtension( $inPath );
+ echo basename( $inPath ) . ' -> ' . basename( $outPath ) . '...';
+
+ $inText = file_get_contents( $inPath );
+ if ( $inText === false ) {
+ $this->error( "Unable to open file $inPath for reading." );
+ exit( 1 );
+ }
+ $outFile = fopen( $outPath, 'w' );
+ if ( !$outFile ) {
+ $this->error( "Unable to open file $outPath for writing." );
+ exit( 1 );
+ }
+
+ switch ( $extension ) {
+ case 'js':
+ $outText = JSMin::minify( $inText );
+ break;
+ default:
+ $this->error( "No minifier defined for extension \"$extension\"" );
+ }
+
+ fwrite( $outFile, $outText );
+ fclose( $outFile );
+ echo " ok\n";
+ }
+}
+
+$maintClass = 'MinifyScript';
+require_once( DO_MAINTENANCE );
--- /dev/null
+jquery.min.js: jquery.js
+ php ../../maintenance/minify.php $< --outfile $@
});
})();
-/* JavaScript for MediaWIki JS2 */
-
-/**
- * This is designed to be directly compatible with (and is essentially taken
- * directly from) the mv_embed code for bringing internationalized messages into
- * the JavaScript space. As such, if we get to the point of merging that stuff
- * into the main branch this code will be uneeded and probably cause issues.
- */
-
/**
- * Mimics the no-conflict method used by the js2 stuff
+ * Add a suitable MW-specific alias
*/
$j = jQuery.noConflict();
-/**
- * Provides js2 compatible mw functions
- */
-if( typeof mw == 'undefined' || !mw ){
- mw = { };
- /**
- * Provides js2 compatible onload hook
- * @param func Function to call when ready
- */
- mw.ready = function( func ) {
- $j(document).ready( func );
- }
- // Define a dummy mw.load function:
- mw.load = function( deps, callback ) { callback(); };
-
- // Deinfe a dummy mw.loadDone function:
- mw.loadDone = function( className ) { };
-
- // Creates global message object if not already in existence
- if ( !gMsg ) var gMsg = {};
-
- /**
- * Caches a list of messages for later retrieval
- * @param {Object} msgSet Hash of key:value pairs of messages to cache
- */
- mw.addMessages = function ( msgSet ){
- for ( var i in msgSet ){
- gMsg[ i ] = msgSet[i];
- }
- }
- /**
- * Retieves a message from the global message cache, performing on-the-fly
- * replacements using MediaWiki message syntax ($1, $2, etc.)
- * @param {String} key Name of message as it is in MediaWiki
- * @param {Array} args Array of replacement arguments
- */
- function gM( key, args ) {
- var ms = '';
- if ( key in gMsg ) {
- ms = gMsg[ key ];
- if ( typeof args == 'object' || typeof args == 'array' ) {
- for ( var v in args ){
- var rep = '\$'+ ( parseInt(v) + 1 );
- ms = ms.replace( rep, args[v]);
- }
- } else if ( typeof args =='string' || typeof args =='number' ) {
- ms = ms.replace( /\$1/, args );
- }
- return ms;
- } else {
- return '[' + key + ']';
- }
- }
-
-}
+
top+=Math.max(docElem.scrollTop,body.scrollTop),left+=Math.max(docElem.scrollLeft,body.scrollLeft);return{top:top,left:left};};jQuery.offset={initialize:function(){if(this.initialized)return;var body=document.body,container=document.createElement('div'),innerDiv,checkDiv,table,td,rules,prop,bodyMarginTop=body.style.marginTop,html='<div style="position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;"><div></div></div><table style="position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;" cellpadding="0" cellspacing="0"><tr><td></td></tr></table>';rules={position:'absolute',top:0,left:0,margin:0,border:0,width:'1px',height:'1px',visibility:'hidden'};for(prop in rules)container.style[prop]=rules[prop];container.innerHTML=html;body.insertBefore(container,body.firstChild);innerDiv=container.firstChild,checkDiv=innerDiv.firstChild,td=innerDiv.nextSibling.firstChild.firstChild;this.doesNotAddBorder=(checkDiv.offsetTop!==5);this.doesAddBorderForTableAndCells=(td.offsetTop===5);innerDiv.style.overflow='hidden',innerDiv.style.position='relative';this.subtractsBorderForOverflowNotVisible=(checkDiv.offsetTop===-5);body.style.marginTop='1px';this.doesNotIncludeMarginInBodyOffset=(body.offsetTop===0);body.style.marginTop=bodyMarginTop;body.removeChild(container);this.initialized=true;},bodyOffset:function(body){jQuery.offset.initialized||jQuery.offset.initialize();var top=body.offsetTop,left=body.offsetLeft;if(jQuery.offset.doesNotIncludeMarginInBodyOffset)
top+=parseInt(jQuery.curCSS(body,'marginTop',true),10)||0,left+=parseInt(jQuery.curCSS(body,'marginLeft',true),10)||0;return{top:top,left:left};}};jQuery.fn.extend({position:function(){var left=0,top=0,results;if(this[0]){var offsetParent=this.offsetParent(),offset=this.offset(),parentOffset=/^body|html$/i.test(offsetParent[0].tagName)?{top:0,left:0}:offsetParent.offset();offset.top-=num(this,'marginTop');offset.left-=num(this,'marginLeft');parentOffset.top+=num(offsetParent,'borderTopWidth');parentOffset.left+=num(offsetParent,'borderLeftWidth');results={top:offset.top-parentOffset.top,left:offset.left-parentOffset.left};}
return results;},offsetParent:function(){var offsetParent=this[0].offsetParent||document.body;while(offsetParent&&(!/^body|html$/i.test(offsetParent.tagName)&&jQuery.css(offsetParent,'position')=='static'))
-offsetParent=offsetParent.offsetParent;return jQuery(offsetParent);}});jQuery.each(['Left','Top'],function(i,name){var method='scroll'+name;jQuery.fn[method]=function(val){if(!this[0])return null;return val!==undefined?this.each(function(){this==window||this==document?window.scrollTo(!i?val:jQuery(window).scrollLeft(),i?val:jQuery(window).scrollTop()):this[method]=val;}):this[0]==window||this[0]==document?self[i?'pageYOffset':'pageXOffset']||jQuery.boxModel&&document.documentElement[method]||document.body[method]:this[0][method];};});jQuery.each(["Height","Width"],function(i,name){var tl=i?"Left":"Top",br=i?"Right":"Bottom",lower=name.toLowerCase();jQuery.fn["inner"+name]=function(){return this[0]?jQuery.css(this[0],lower,false,"padding"):null;};jQuery.fn["outer"+name]=function(margin){return this[0]?jQuery.css(this[0],lower,false,margin?"margin":"border"):null;};var type=name.toLowerCase();jQuery.fn[type]=function(size){return this[0]==window?document.compatMode=="CSS1Compat"&&document.documentElement["client"+name]||document.body["client"+name]:this[0]==document?Math.max(document.documentElement["client"+name],document.body["scroll"+name],document.documentElement["scroll"+name],document.body["offset"+name],document.documentElement["offset"+name]):size===undefined?(this.length?jQuery.css(this[0],type):null):this.css(type,typeof size==="string"?size:size+"px");};});})();$j=jQuery.noConflict();if(typeof mw=='undefined'||!mw){mw={};mw.ready=function(func){$j(document).ready(func);}
-mw.load=function(deps,callback){callback();};mw.loadDone=function(className){};if(!gMsg)var gMsg={};mw.addMessages=function(msgSet){for(var i in msgSet){gMsg[i]=msgSet[i];}}
-function gM(key,args){var ms='';if(key in gMsg){ms=gMsg[key];if(typeof args=='object'||typeof args=='array'){for(var v in args){var rep='\$'+(parseInt(v)+1);ms=ms.replace(rep,args[v]);}}else if(typeof args=='string'||typeof args=='number'){ms=ms.replace(/\$1/,args);}
-return ms;}else{return'['+key+']';}}}
\ No newline at end of file
+offsetParent=offsetParent.offsetParent;return jQuery(offsetParent);}});jQuery.each(['Left','Top'],function(i,name){var method='scroll'+name;jQuery.fn[method]=function(val){if(!this[0])return null;return val!==undefined?this.each(function(){this==window||this==document?window.scrollTo(!i?val:jQuery(window).scrollLeft(),i?val:jQuery(window).scrollTop()):this[method]=val;}):this[0]==window||this[0]==document?self[i?'pageYOffset':'pageXOffset']||jQuery.boxModel&&document.documentElement[method]||document.body[method]:this[0][method];};});jQuery.each(["Height","Width"],function(i,name){var tl=i?"Left":"Top",br=i?"Right":"Bottom",lower=name.toLowerCase();jQuery.fn["inner"+name]=function(){return this[0]?jQuery.css(this[0],lower,false,"padding"):null;};jQuery.fn["outer"+name]=function(margin){return this[0]?jQuery.css(this[0],lower,false,margin?"margin":"border"):null;};var type=name.toLowerCase();jQuery.fn[type]=function(size){return this[0]==window?document.compatMode=="CSS1Compat"&&document.documentElement["client"+name]||document.body["client"+name]:this[0]==document?Math.max(document.documentElement["client"+name],document.body["scroll"+name],document.documentElement["scroll"+name],document.body["offset"+name],document.documentElement["offset"+name]):size===undefined?(this.length?jQuery.css(this[0],type):null):this.css(type,typeof size==="string"?size:size+"px");};});})();$j=jQuery.noConflict();
\ No newline at end of file
if ( ie6_bugs ) {
importScriptURI( stylepath + '/common/IEFixes.js' );
}
+
+// For future use.
+mw = {};
+
+