Merge "Hook handlers don't always need to return something"

This commit is contained in:
jenkins-bot 2019-07-26 15:09:44 +00:00 committed by Gerrit Code Review
commit 9d4d4b0a67
2 changed files with 16 additions and 28 deletions

View file

@ -30,23 +30,20 @@ class GadgetHooks {
* @param WikiPage $wikiPage
* @param User $user
* @param Content $content New page content
* @return bool
*/
public static function onPageContentSaveComplete( WikiPage $wikiPage, $user, $content ) {
// update cache if MediaWiki:Gadgets-definition was edited
GadgetRepo::singleton()->handlePageUpdate( $wikiPage->getTitle() );
return true;
}
/**
* UserGetDefaultOptions hook handler
* @param array &$defaultOptions Array of default preference keys and values
* @return bool
*/
public static function userGetDefaultOptions( &$defaultOptions ) {
public static function userGetDefaultOptions( array &$defaultOptions ) {
$gadgets = GadgetRepo::singleton()->getStructuredList();
if ( !$gadgets ) {
return true;
return;
}
/**
@ -59,20 +56,17 @@ class GadgetHooks {
}
}
}
return true;
}
/**
* GetPreferences hook handler.
* @param User $user
* @param array &$preferences Preference descriptions
* @return bool
*/
public static function getPreferences( $user, &$preferences ) {
public static function getPreferences( User $user, array &$preferences ) {
$gadgets = GadgetRepo::singleton()->getStructuredList();
if ( !$gadgets ) {
return true;
return;
}
$options = [];
@ -129,16 +123,13 @@ class GadgetHooks {
'default' => $default,
'noglobal' => true,
];
return true;
}
/**
* ResourceLoaderRegisterModules hook handler.
* @param ResourceLoader &$resourceLoader
* @return bool
*/
public static function registerModules( &$resourceLoader ) {
public static function registerModules( ResourceLoader &$resourceLoader ) {
$repo = GadgetRepo::singleton();
$ids = $repo->getGadgetIds();
@ -148,20 +139,17 @@ class GadgetHooks {
'id' => $id,
] );
}
return true;
}
/**
* BeforePageDisplay hook handler.
* @param OutputPage $out
* @return bool
*/
public static function beforePageDisplay( $out ) {
public static function beforePageDisplay( OutputPage $out ) {
$repo = GadgetRepo::singleton();
$ids = $repo->getGadgetIds();
if ( !$ids ) {
return true;
return;
}
$lb = new LinkBatch();
@ -220,8 +208,6 @@ class GadgetHooks {
$strings[] = self::makeLegacyWarning( $id );
}
$out->addHTML( WrappedString::join( "\n", $strings ) );
return true;
}
private static function makeLegacyWarning( $id ) {
@ -245,7 +231,11 @@ class GadgetHooks {
* @throws Exception
* @return bool
*/
public static function onEditFilterMergedContent( $context, $content, $status, $summary ) {
public static function onEditFilterMergedContent( IContextSource $context,
Content $content,
Status $status,
$summary
) {
$title = $context->getTitle();
if ( !$title->inNamespace( NS_GADGET_DEFINITION ) ) {
@ -325,11 +315,9 @@ class GadgetHooks {
/**
* Add the GadgetUsage special page to the list of QueryPages.
* @param array &$queryPages
* @return bool
*/
public static function onwgQueryPages( &$queryPages ) {
public static function onwgQueryPages( array &$queryPages ) {
$queryPages[] = [ 'SpecialGadgetUsage', 'GadgetUsage' ];
return true;
}
/**
@ -339,7 +327,7 @@ class GadgetHooks {
* @param string[] &$where Array of where clause conditions to add to.
* @param IDatabase $db
*/
public static function onDeleteUnknownPreferences( &$where, IDatabase $db ) {
public static function onDeleteUnknownPreferences( array &$where, IDatabase $db ) {
$where[] = 'up_property NOT' . $db->buildLike( 'gadget-', $db->anyString() );
}
}

View file

@ -226,6 +226,7 @@ class GadgetTest extends MediaWikiTestCase {
// Force usage of a MediaWikiGadgetsDefinitionRepo
GadgetRepo::setSingleton( $repo );
/** @var MediaWikiGadgetsDefinitionRepo $repo */
$gadgets = $repo->fetchStructuredList( '* foo | foo.js
==keep-section1==
* bar| bar.js
@ -236,8 +237,7 @@ class GadgetTest extends MediaWikiTestCase {
$this->assertGreaterThanOrEqual( 2, count( $gadgets ), "Gadget list parsed" );
$repo->definitionCache = $gadgets;
$this->assertTrue( GadgetHooks::getPreferences( $this->user, $prefs ),
'GetPrefences hook should return true' );
GadgetHooks::getPreferences( $this->user, $prefs );
$options = $prefs['gadgets']['options'];
$this->assertArrayNotHasKey( '⧼gadget-section-remove-section⧽', $options,