http://www.mediawiki.org/wiki/Special:Code/MediaWiki/90875
Revision: 90875 Author: janpaul123 Date: 2011-06-27 14:04:15 +0000 (Mon, 27 Jun 2011) Log Message: ----------- Circumvented problem of local config breaking when debug=true and filed ResourceLoader bug: https://bugzilla.wikimedia.org/show_bug.cgi?id=29608 Modified Paths: -------------- trunk/extensions/WikiLove/WikiLove.hooks.php trunk/extensions/WikiLove/WikiLove.local.php trunk/extensions/WikiLove/WikiLove.php trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.defaultOptions.js Removed Paths: ------------- trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.init.js Modified: trunk/extensions/WikiLove/WikiLove.hooks.php =================================================================== --- trunk/extensions/WikiLove/WikiLove.hooks.php 2011-06-27 13:48:01 UTC (rev 90874) +++ trunk/extensions/WikiLove/WikiLove.hooks.php 2011-06-27 14:04:15 UTC (rev 90875) @@ -49,7 +49,7 @@ * @param $skin Skin */ public static function beforePageDisplay( $out, $skin ) { - global $wgWikiLoveGlobal, $wgUser; + global $wgWikiLoveGlobal, $wgWikiLoveEnableLocalConfig, $wgUser; if ( !$wgWikiLoveGlobal && !$wgUser->getOption( 'wikilove-enabled' ) ) { return true; } @@ -57,7 +57,17 @@ $title = self::getUserTalkPage( $skin->getTitle() ); if ( !is_null( $title ) ) { $out->addModules( 'ext.wikiLove.icon' ); - $out->addModules( 'ext.wikiLove.init' ); + + // it is much better to have a chain like: startup -> default -> local -> init, + // but because of this bug that isn't possible right now: https://bugzilla.wikimedia.org/29608 + $optionsTitle = Title::newFromText( "MediaWiki:WikiLove.js" ); + if( $optionsTitle->exists() && $optionsTitle->isCssOrJsPage() ) { + $out->addModules( 'ext.wikiLove.local' ); + } + else { + $out->addModules( 'ext.wikiLove.defaultOptions' ); + } + self::$recipient = $title->getText(); } return true; Modified: trunk/extensions/WikiLove/WikiLove.local.php =================================================================== --- trunk/extensions/WikiLove/WikiLove.local.php 2011-06-27 13:48:01 UTC (rev 90874) +++ trunk/extensions/WikiLove/WikiLove.local.php 2011-06-27 14:04:15 UTC (rev 90875) @@ -14,4 +14,9 @@ 'ext.wikiLove.startup', ); } + + public function getMessages() { + global $wgWikiLoveOptionMessages; + return $wgWikiLoveOptionMessages; + } } Modified: trunk/extensions/WikiLove/WikiLove.php =================================================================== --- trunk/extensions/WikiLove/WikiLove.php 2011-06-27 13:48:01 UTC (rev 90874) +++ trunk/extensions/WikiLove/WikiLove.php 2011-06-27 14:04:15 UTC (rev 90875) @@ -77,7 +77,15 @@ 'remoteExtPath' => 'WikiLove/modules/ext.wikiLove', ); +// messages for default options, because we want to use them in the default +// options module, but also for the user in the user options module +$wgWikiLoveOptionMessages = array( + 'wikilove-type-makeyourown', +); + // resources +// it is much better to have a chain like: startup -> default -> local -> init, +// but because of this bug that isn't possible right now: https://bugzilla.wikimedia.org/29608 $wgResourceModules += array( 'ext.wikiLove.icon' => $extWikiLoveTpl + array( 'styles' => 'ext.wikiLove.icon.css', @@ -86,7 +94,6 @@ 'ext.wikiLove.startup' => $extWikiLoveTpl + array( 'scripts' => array( 'ext.wikiLove.core.js', - 'ext.wikiLove.defaultOptions.js', ), 'styles' => 'ext.wikiLove.css', 'messages' => array( @@ -107,7 +114,6 @@ 'wikilove-preview', 'wikilove-notify', 'wikilove-button-send', - 'wikilove-type-makeyourown', 'wikilove-err-header', 'wikilove-err-title', 'wikilove-err-msg', @@ -125,15 +131,15 @@ 'ext.wikiLove.local' => array( 'class' => 'WikiLoveLocal', /* for information only, this is actually in the class! - 'dependencies' => array( - 'ext.wikiLove.startup', - ), + 'messages' => $wgWikiLoveOptionMessages, + 'dependencies' => 'ext.wikiLove.startup' */ ), - 'ext.wikiLove.init' => $extWikiLoveTpl + array( - 'scripts' => 'ext.wikiLove.init.js', - 'dependencies' => array( - 'ext.wikiLove.local', + 'ext.wikiLove.defaultOptions' => $extWikiLoveTpl + array( + 'scripts' => array( + 'ext.wikiLove.defaultOptions.js', ), + 'messages' => $wgWikiLoveOptionMessages, + 'dependencies' => 'ext.wikiLove.startup' ), ); Modified: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js =================================================================== --- trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js 2011-06-27 13:48:01 UTC (rev 90874) +++ trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js 2011-06-27 14:04:15 UTC (rev 90875) @@ -11,8 +11,6 @@ gallery = {}; return { - optionsHook: function() { return {}; }, // hook that can be overridden by the user to modify options - /* * Opens the dialog and builds it if necessary. */ @@ -532,9 +530,12 @@ /* * Init function which is called upon page load. Binds the WikiLove icon to opening the dialog. */ - init: function() { - options = $.wikiLove.optionsHook(); - $( '#ca-wikilove' ).find( 'a' ).click( function( e ) { + init: function( ) { + if( typeof $.wikiLoveOptions == 'function' ) options = $.wikiLoveOptions(); + + var $wikiLoveLink = $( '#ca-wikilove' ).find( 'a' ); + $wikiLoveLink.unbind( 'click' ); + $wikiLoveLink.click( function( e ) { $.wikiLove.openDialog(); e.preventDefault(); }); @@ -636,4 +637,6 @@ }; }()); + +$( document ).ready( $.wikiLove.init ); } ) ( jQuery ); Modified: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.defaultOptions.js =================================================================== --- trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.defaultOptions.js 2011-06-27 13:48:01 UTC (rev 90874) +++ trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.defaultOptions.js 2011-06-27 14:04:15 UTC (rev 90875) @@ -1,5 +1,5 @@ ( function( $ ) { -$.wikiLove.optionsHook = function() { return { +$.wikiLoveOptions = function() { return { defaultText: '{| style="background-color: $5; border: 1px solid $6;"\n\ |rowspan="2" style="vertical-align: middle; padding: 5px;" | [[$3|$4]]\n\ |style="font-size: x-large; padding: 3px; height: 1.5em;" | \'\'\'$2\'\'\'\n\ @@ -356,4 +356,9 @@ } } }; }; + +if( typeof $.wikiLove != 'undefined' ) $.wikiLove.init(); // this is required when copying this file to MediaWiki:WikiLove.js +// because of https://bugzilla.wikimedia.org/29608 ; please leave it here as it does no harm being executed in defaultOptions.js +// and it may be confusing if it is required to uncomment it when copying this to MediaWiki:WikiLove.js + } )( jQuery ); Deleted: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.init.js =================================================================== --- trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.init.js 2011-06-27 13:48:01 UTC (rev 90874) +++ trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.init.js 2011-06-27 14:04:15 UTC (rev 90875) @@ -1,3 +0,0 @@ -( function( $ ) { -$( document ).ready( $.wikiLove.init ); -} )( jQuery ); _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs