r97367 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97366‎ | r97367 | r97368 >
Date:03:03, 17 September 2011
Author:krinkle
Status:resolved (Comments)
Tags:
Comment:
[ResourceLoader] Set default options for gadgets that are enabled by default, otherwise they can't be disabled from the preferences (bug 30941)
* Uses the new hook in User:getDefaultOptions (bug 30940; r97365)
* This revision is based on a similar one for RL2 in the branch (r97366). Needs to be back ported as the bug occurs in 1.18 as well
Modified paths:
  • /trunk/extensions/Gadgets/Gadgets.php (modified) (history)
  • /trunk/extensions/Gadgets/Gadgets_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Gadgets/Gadgets_body.php
@@ -31,6 +31,24 @@
3232 }
3333
3434 /**
 35+ * UserGetDefaultOptions hook handler
 36+ * @param $defaultOptions Array of default preference keys and values
 37+ */
 38+ public static function userGetDefaultOptions( &$defaultOptions ) {
 39+ $gadgets = Gadget::loadStructuredList();
 40+ if (!$gadgets) return true;
 41+
 42+ foreach( $gadgets as $section => $thisSection ) {
 43+ foreach( $thisSection as $gadgetId => $gadget ) {
 44+ if ( $gadget->isOnByDefault() ) {
 45+ $defaultOptions['gadget-' . $gadgetId] = 1;
 46+ }
 47+ }
 48+ }
 49+ return true;
 50+ }
 51+
 52+ /**
3553 * GetPreferences hook handler.
3654 * @param $user User
3755 * @param $preferences Array: Preference descriptions
Index: trunk/extensions/Gadgets/Gadgets.php
@@ -17,8 +17,8 @@
1818 die( 1 );
1919 }
2020
21 -if ( version_compare( $wgVersion, '1.17alpha', '<' ) ) {
22 - die( "This version of Extension:Gadgets requires MediaWiki 1.17+\n" );
 21+if ( version_compare( $wgVersion, '1.18', '<' ) ) {
 22+ die( "This version of Extension:Gadgets requires MediaWiki 1.18+\n" );
2323 }
2424
2525 $wgExtensionCredits['other'][] = array(
@@ -31,6 +31,7 @@
3232
3333 $wgHooks['ArticleSaveComplete'][] = 'GadgetHooks::articleSaveComplete';
3434 $wgHooks['BeforePageDisplay'][] = 'GadgetHooks::beforePageDisplay';
 35+$wgHooks['UserGetDefaultOptions'][] = 'GadgetHooks::userGetDefaultOptions';
3536 $wgHooks['GetPreferences'][] = 'GadgetHooks::getPreferences';
3637 $wgHooks['ResourceLoaderRegisterModules'][] = 'GadgetHooks::registerModules';
3738 $wgHooks['UnitTestsList'][] = 'GadgetHooks::unitTestsList';

Follow-up revisions

RevisionCommit summaryAuthorDate
r97380Per r97367 CR. Add 'alpha'. 1.18alpha is less than 1.18, and it works in that...krinkle16:34, 17 September 2011
r974131.18: MFT r97367, r97380catrope11:21, 18 September 2011
r97887Replaced use of wfEmptyMsg() with new Message class. The underlying implement...aaron05:43, 23 September 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r97365(bug 30940) Add a hook in User:getDefaultOptions....krinkle02:42, 17 September 2011
r97366[ResourceLoader2] Set default options for gadgets that are enabled by default...krinkle02:46, 17 September 2011

Comments

#Comment by MaxSem (talk | contribs)   03:59, 17 September 2011

It will actually refuse to work with current 1.18 because 1.18alpha is less than 1.18 in terms of version_compare().

#Comment by Krinkle (talk | contribs)   16:33, 17 September 2011

Oh, interesting. I'll add 'alpha' to it then :)

#Comment by Aaron Schulz (talk | contribs)   03:49, 21 September 2011

Unstub loop detected on call of $wgLang->getCode from MessageCache::get

Backtrace:

  1. 0 C:\wamp\www\MW_trunk\includes\StubObject.php(57): StubObject->_unstub('getCode', 5)
  2. 1 C:\wamp\www\MW_trunk\includes\StubObject.php(147): StubObject->_call('getCode', Array)
  3. 2 [internal function]: StubUserLang->__call('getCode', Array)
  4. 3 C:\wamp\www\MW_trunk\includes\cache\MessageCache.php(606): StubUserLang->getCode()
  5. 4 C:\wamp\www\MW_trunk\includes\GlobalFunctions.php(1355): MessageCache->get('gadgets-definit...', true, false)
  6. 5 C:\wamp\www\MW_trunk\extensions\Gadgets\Gadgets_body.php(510): wfEmptyMsg('gadgets-definit...', '== interface-ga...')
  7. 6 C:\wamp\www\MW_trunk\extensions\Gadgets\Gadgets_body.php(38): Gadget::loadStructuredList()
  8. 7 [internal function]: GadgetHooks::userGetDefaultOptions(Array)
  9. 8 C:\wamp\www\MW_trunk\includes\Hooks.php(216): call_user_func_array('GadgetHooks::us...', Array)
  10. 9 C:\wamp\www\MW_trunk\includes\GlobalFunctions.php(3642): Hooks::run('UserGetDefaultO...', Array)
  11. 10 C:\wamp\www\MW_trunk\includes\User.php(1217): wfRunHooks('UserGetDefaultO...', Array)
  12. 11 C:\wamp\www\MW_trunk\includes\User.php(2150): User::getDefaultOptions()
  13. 12 C:\wamp\www\MW_trunk\includes\context\RequestContext.php(192): User->getOption('language')
  14. 13 C:\wamp\www\MW_trunk\includes\StubObject.php(151): RequestContext->getLang()
  15. 14 C:\wamp\www\MW_trunk\includes\StubObject.php(103): StubUserLang->_newObject()
  16. 15 C:\wamp\www\MW_trunk\includes\StubObject.php(57): StubObject->_unstub('getCode', 5)
  17. 16 C:\wamp\www\MW_trunk\includes\StubObject.php(147): StubObject->_call('getCode', Array)
  18. 17 [internal function]: StubUserLang->__call('getCode', Array)
  19. 18 C:\wamp\www\MW_trunk\includes\cache\MessageCache.php(606): StubUserLang->getCode()
  20. 19 C:\wamp\www\MW_trunk\includes\GlobalFunctions.php(1355): MessageCache->get('gadgets-definit...', true, false)
  21. 20 C:\wamp\www\MW_trunk\extensions\Gadgets\Gadgets_body.php(510): wfEmptyMsg('gadgets-definit...', '== interface-ga...')
  22. 21 C:\wamp\www\MW_trunk\extensions\Gadgets\Gadgets_body.php(38): Gadget::loadStructuredList()
  23. 22 [internal function]: GadgetHooks::userGetDefaultOptions(Array)
  24. 23 C:\wamp\www\MW_trunk\includes\Hooks.php(216): call_user_func_array('GadgetHooks::us...', Array)
  25. 24 C:\wamp\www\MW_trunk\includes\GlobalFunctions.php(3642): Hooks::run('UserGetDefaultO...', Array)
  26. 25 C:\wamp\www\MW_trunk\includes\User.php(1217): wfRunHooks('UserGetDefaultO...', Array)
  27. 26 C:\wamp\www\MW_trunk\includes\User.php(2150): User::getDefaultOptions()
  28. 27 C:\wamp\www\MW_trunk\includes\context\RequestContext.php(192): User->getOption('language')
  29. 28 C:\wamp\www\MW_trunk\includes\StubObject.php(151): RequestContext->getLang()
  30. 29 C:\wamp\www\MW_trunk\includes\StubObject.php(103): StubUserLang->_newObject()
  31. 30 C:\wamp\www\MW_trunk\includes\StubObject.php(57): StubObject->_unstub('getCode', 5)
  32. 31 C:\wamp\www\MW_trunk\includes\StubObject.php(147): StubObject->_call('getCode', Array)
  33. 32 [internal function]: StubUserLang->__call('getCode', Array)
  34. 33 C:\wamp\www\MW_trunk\includes\cache\HTMLFileCache.php(111): StubUserLang->getCode()
  35. 34 C:\wamp\www\MW_trunk\includes\Wiki.php(601): HTMLFileCache::useFileCache()
  36. 35 C:\wamp\www\MW_trunk\includes\Wiki.php(530): MediaWiki->main()
  37. 36 C:\wamp\www\MW_trunk\index.php(58): MediaWiki->run()
  38. 37 {main}
#Comment by Catrope (talk | contribs)   22:04, 26 September 2011

Aaron says this is fixed in r97887.

Status & tagging log