diff --git a/extension.json b/extension.json index 5dd9e49d..433c7220 100644 --- a/extension.json +++ b/extension.json @@ -24,13 +24,18 @@ "MediaWiki\\Extension\\TemplateData\\": "includes/" }, "Hooks": { - "EditPage::showEditForm:fields": "MediaWiki\\Extension\\TemplateData\\Hooks::onEditPageShowEditFormFields", - "ParserFirstCallInit": "MediaWiki\\Extension\\TemplateData\\Hooks::onParserFirstCallInit", - "MultiContentSave": "MediaWiki\\Extension\\TemplateData\\Hooks::onMultiContentSave", - "ResourceLoaderRegisterModules": "MediaWiki\\Extension\\TemplateData\\Hooks::onResourceLoaderRegisterModules", - "EditPage::showEditForm:initial": "MediaWiki\\Extension\\TemplateData\\Hooks::onEditPage", - "ParserFetchTemplateData": "MediaWiki\\Extension\\TemplateData\\Hooks::onParserFetchTemplateData", - "OutputPageBeforeHTML": "MediaWiki\\Extension\\TemplateData\\Hooks::onOutputPageBeforeHTML" + "EditPage::showEditForm:fields": "main", + "ParserFirstCallInit": "main", + "MultiContentSave": "main", + "ResourceLoaderRegisterModules": "main", + "EditPage::showEditForm:initial": "main", + "ParserFetchTemplateData": "main", + "OutputPageBeforeHTML": "main" + }, + "HookHandlers": { + "main": { + "class": "MediaWiki\\Extension\\TemplateData\\Hooks" + } }, "MessagesDirs": { "TemplateData": [ diff --git a/includes/Hooks.php b/includes/Hooks.php index 3cc36072..4cbc6d5d 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -1,5 +1,7 @@ getRequest()->getBool( 'TemplateDataGeneratorUsed' ) ) { // Recreate the dynamically created field after the user clicked "preview" @@ -45,7 +62,7 @@ class Hooks { * Register parser hooks * @param Parser $parser */ - public static function onParserFirstCallInit( Parser $parser ) { + public function onParserFirstCallInit( $parser ) { $parser->setHook( 'templatedata', [ __CLASS__, 'render' ] ); } @@ -53,9 +70,9 @@ class Hooks { * Conditionally register the jquery.uls.data module, in case they've already been * registered by the UniversalLanguageSelector extension or the VisualEditor extension. * - * @param ResourceLoader &$resourceLoader + * @param ResourceLoader $resourceLoader */ - public static function onResourceLoaderRegisterModules( ResourceLoader &$resourceLoader ) { + public function onResourceLoaderRegisterModules( ResourceLoader $resourceLoader ): void { $resourceModules = $resourceLoader->getConfig()->get( 'ResourceModules' ); $name = 'jquery.uls.data'; if ( !isset( $resourceModules[$name] ) && !$resourceLoader->isModuleRegistered( $name ) ) { @@ -81,8 +98,8 @@ class Hooks { * @param Status $hookStatus * @return bool */ - public static function onMultiContentSave( - RenderedRevision $renderedRevision, UserIdentity $user, CommentStoreComment $summary, $flags, Status $hookStatus + public function onMultiContentSave( + $renderedRevision, $user, $summary, $flags, $hookStatus ) { $revisionRecord = $renderedRevision->getRevision(); $contentModel = $revisionRecord @@ -163,7 +180,7 @@ class Hooks { * @param EditPage $editPage * @param OutputPage $output */ - public static function onEditPage( EditPage $editPage, OutputPage $output ) { + public function onEditPage__showEditForm_initial( $editPage, $output ) { global $wgTemplateDataUseGUI; if ( $wgTemplateDataUseGUI ) { if ( $output->getTitle()->inNamespace( NS_TEMPLATE ) ) { @@ -234,7 +251,7 @@ class Hooks { * @param OutputPage $output * @param string &$text */ - public static function onOutputPageBeforeHTML( $output, &$text ) { + public function onOutputPageBeforeHTML( $output, &$text ) { $services = MediaWikiServices::getInstance(); $props = $services->getPageProps()->getProperties( $output->getTitle(), 'templatedata' ); if ( !empty( $props ) ) { @@ -260,8 +277,9 @@ class Hooks { * * @param array $tplTitles * @param \stdClass[] &$tplData + * @return bool */ - public static function onParserFetchTemplateData( array $tplTitles, array &$tplData ): void { + public function onParserFetchTemplateData( array $tplTitles, array &$tplData ): bool { $tplData = []; $pageProps = MediaWikiServices::getInstance()->getPageProps(); @@ -318,6 +336,7 @@ class Hooks { $tplData[$tplTitle] = $tdb->getData(); } + return true; } }