jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/332150 )
Change subject: Removed deprecated ContentHandler hooks. ...................................................................... Removed deprecated ContentHandler hooks. Plus removed unused "ContentHandler::runLegacyHooks" Bug: T154498 Change-Id: Ie398fd4e06d3e286fe8e24112d0c8b4ac7d883dc --- M RELEASE-NOTES-1.29 M docs/contenthandler.txt M docs/hooks.txt M includes/EditPage.php M includes/Title.php M includes/content/ContentHandler.php M includes/page/WikiPage.php M maintenance/findHooks.php M tests/phpunit/includes/content/ContentHandlerTest.php 9 files changed, 23 insertions(+), 182 deletions(-) Approvals: Reedy: Looks good to me, approved TTO: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/RELEASE-NOTES-1.29 b/RELEASE-NOTES-1.29 index fac6f7e..e404940 100644 --- a/RELEASE-NOTES-1.29 +++ b/RELEASE-NOTES-1.29 @@ -152,8 +152,9 @@ were removed. * Article::getAutosummary() and WikiPage::getAutosummary() (deprecated in 1.21) were removed. -* Hooks ArticleViewCustom, EditPageGetDiffText and ShowRawCssJs (deprecated in 1.21) - were removed. +* Hook ArticleViewCustom (deprecated in 1.21) was removed. Use ArticleContentViewCustom + instead. +* Hooks EditPageGetDiffText and ShowRawCssJs (deprecated in 1.21) were removed. * Class RevisiondeleteAction (deprecated in 1.25) was removed. * WikiPage::prepareTextForEdit() (deprecated in 1.21) was removed. * WikiPage::getText() (deprecated in 1.21) was removed. @@ -184,6 +185,22 @@ RewriteEngine On RewriteBase / RewriteRule ^/w/wiki\.phtml$ /w/index.php [R=301,L] +* Hook ArticleAfterFetchContent (deprecated in 1.21) was removed. + Use ArticleAfterFetchContentObject instead. +* Hook ArticleInsertComplete (deprecated in 1.21) was removed. + Use PageContentInsertComplete instead. +* Hook ArticleSave (deprecated in 1.21) was removed. + Use PageContentSave instead. +* Hook ArticleSaveComplete (deprecated in 1.21) was removed. + Use PageContentSaveComplete instead. +* Hook EditFilterMerged (deprecated in 1.21) was removed. + Use EditFilterMergedContent instead. +* Hook EditPageGetPreviewText (deprecated in 1.21) was removed. + Use EditPageGetPreviewContent instead. +* Hook TitleIsCssOrJsPage (deprecated in 1.21) was removed. + Use ContentHandlerDefaultModelFor instead. +* Hook TitleIsWikitextPage (deprecated in 1.21) was removed. + Use ContentHandlerDefaultModelFor instead. == Compatibility == diff --git a/docs/contenthandler.txt b/docs/contenthandler.txt index 6209b14..5f379e7 100644 --- a/docs/contenthandler.txt +++ b/docs/contenthandler.txt @@ -21,10 +21,6 @@ * The hook ContentHandlerDefaultModelFor may be used to override the page's default model. * Pages in NS_MEDIAWIKI and NS_USER default to the CSS or JavaScript model if they end in .css or .js, respectively. Pages in NS_MEDIAWIKI default to the wikitext model otherwise. -* The hook TitleIsCssOrJsPage may be used to force a page to use the CSS or JavaScript model. - This is a compatibility feature. The ContentHandlerDefaultModelFor hook should be used instead if possible. -* The hook TitleIsWikitextPage may be used to force a page to use the wikitext model. - This is a compatibility feature. The ContentHandlerDefaultModelFor hook should be used instead if possible. * Otherwise, the wikitext model is used. Note that is currently no mechanism to convert a page from one content model to another, and there is no guarantee that diff --git a/docs/hooks.txt b/docs/hooks.txt index adfb128..4057cce 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -603,12 +603,6 @@ AND in the final query) $logTypes: Array of log types being queried -'ArticleAfterFetchContent': DEPRECATED! Use ArticleAfterFetchContentObject -instead. -After fetching content of an article from the database. -&$article: the article (object) being loaded from the database -&$content: the content (string) of the article - 'ArticleAfterFetchContentObject': After fetching content of an article from the database. &$article: the article (object) being loaded from the database @@ -677,18 +671,6 @@ &$article: Article (object) that will be returned $context: IContextSource (object) -'ArticleInsertComplete': DEPRECATED! Use PageContentInsertComplete. -After a new article is created. -$wikiPage: WikiPage created -$user: User creating the article -$text: New content -$summary: Edit summary/comment -$isMinor: Whether or not the edit was marked as minor -$isWatch: (No longer used) -$section: (No longer used) -$flags: Flags passed to WikiPage::doEditContent() -$revision: New Revision of the article - 'ArticleMergeComplete': After merging to article using Special:Mergehistory. $targetTitle: target title (object) $destTitle: destination title (object) @@ -739,31 +721,6 @@ $user: the user who did the rollback $revision: the revision the page was reverted back to $current: the reverted revision - -'ArticleSave': DEPRECATED! Use PageContentSave instead. -Before an article is saved. -$wikiPage: the WikiPage (object) being saved -$user: the user (object) saving the article -$text: the new article text -$summary: the article summary (comment) -$isminor: minor flag -$iswatch: watch flag -$section: section # - -'ArticleSaveComplete': DEPRECATED! Use PageContentSaveComplete instead. -After an article has been updated. -$wikiPage: WikiPage modified -$user: User performing the modification -$text: New content -$summary: Edit summary/comment -$isMinor: Whether or not the edit was marked as minor -$isWatch: (No longer used) -$section: (No longer used) -$flags: Flags passed to WikiPage::doEditContent() -$revision: New Revision of the article -$status: Status object about to be returned by doEditContent() -$baseRevId: the rev ID (or false) this edit was based on -$undidRevId: the rev ID (or 0) this edit undid 'ArticleUndelete': When one or more revisions of an article are restored. &$title: Title corresponding to the article restored @@ -1334,12 +1291,6 @@ &$error: Error message to return $summary: Edit summary for page -'EditFilterMerged': DEPRECATED! Use EditFilterMergedContent instead. -Post-section-merge edit filter. -$editor: EditPage instance (object) -$text: content of the edit box -&$error: error message to return -$summary: Edit summary for page 'EditFilterMergedContent': Post-section-merge edit filter. This may be triggered by the EditPage or any other facility that modifies page @@ -1447,13 +1398,6 @@ types using the ContentHandler facility. $editPage: EditPage object &$content: Content object to be previewed (may be replaced by hook function) - -'EditPageGetPreviewText': DEPRECATED! Use EditPageGetPreviewContent instead. -Allow modifying the wikitext that will be previewed. Note that it is preferable -to implement previews for different data types using the ContentHandler -facility. -$editPage: EditPage object -&$toparse: wikitext that will be parsed 'EditPageNoSuchSection': When a section edit request is given for an non-existent section @@ -3315,13 +3259,6 @@ $title: Title object that is being checked &$isKnown: Boolean|null; whether MediaWiki currently thinks this page is known -'TitleIsCssOrJsPage': DEPRECATED! Use ContentHandlerDefaultModelFor instead. -Called when determining if a page is a CSS or JS page. -$title: Title object that is being checked -&$result: Boolean; whether MediaWiki currently thinks this is a CSS/JS page. - Hooks may change this value to override the return value of - Title::isCssOrJsPage(). - 'TitleIsMovable': Called when determining if it is possible to move a page. Note that this hook is not called for interwiki pages or pages in immovable namespaces: for these, isMovable() always returns false. @@ -3330,13 +3267,6 @@ Hooks may change this value to override the return value of Title::isMovable(). -'TitleIsWikitextPage': DEPRECATED! Use ContentHandlerDefaultModelFor instead. -Called when determining if a page is a wikitext or should -be handled by separate handler (via ArticleViewCustom). -$title: Title object that is being checked -&$result: Boolean; whether MediaWiki currently thinks this is a wikitext page. - Hooks may change this value to override the return value of - Title::isWikitextPage() 'TitleMove': Before moving an article (title). $old: old title diff --git a/includes/EditPage.php b/includes/EditPage.php index 05fa366..de08880 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1621,15 +1621,7 @@ */ protected function runPostMergeFilters( Content $content, Status $status, User $user ) { // Run old style post-section-merge edit filter - if ( !ContentHandler::runLegacyHooks( 'EditFilterMerged', - [ $this, $content, &$this->hookError, $this->summary ], - '1.21' - ) ) { - # Error messages etc. could be handled within the hook... - $status->fatal( 'hookaborted' ); - $status->value = self::AS_HOOK_ERROR; - return false; - } elseif ( $this->hookError != '' ) { + if ( $this->hookError != '' ) { # ...or the hook could be expecting us to produce an error $status->fatal( 'hookaborted' ); $status->value = self::AS_HOOK_ERROR_EXPECTED; @@ -3779,7 +3771,6 @@ } $hook_args = [ $this, &$content ]; - ContentHandler::runLegacyHooks( 'EditPageGetPreviewText', $hook_args, '1.25' ); Hooks::run( 'EditPageGetPreviewContent', $hook_args ); $parserResult = $this->doPreviewParse( $content ); diff --git a/includes/Title.php b/includes/Title.php index 65b69a2..5cf911f 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1233,12 +1233,6 @@ && ( $this->hasContentModel( CONTENT_MODEL_CSS ) || $this->hasContentModel( CONTENT_MODEL_JAVASCRIPT ) ); - # @note This hook is also called in ContentHandler::getDefaultModel. - # It's called here again to make sure hook functions can force this - # method to return true even outside the MediaWiki namespace. - - Hooks::run( 'TitleIsCssOrJsPage', [ $this, &$isCssOrJsPage ], '1.25' ); - return $isCssOrJsPage; } diff --git a/includes/content/ContentHandler.php b/includes/content/ContentHandler.php index db20f51..5862bf1 100644 --- a/includes/content/ContentHandler.php +++ b/includes/content/ContentHandler.php @@ -198,9 +198,6 @@ $ext = $m[1]; } - // Hook can force JS/CSS - Hooks::run( 'TitleIsCssOrJsPage', [ $title, &$isCodePage ], '1.21' ); - // Is this a user subpage containing code? $isCodeSubpage = NS_USER == $ns && !$isCodePage @@ -212,9 +209,6 @@ // Is this wikitext, according to $wgNamespaceContentModels or the DefaultModelFor hook? $isWikitext = is_null( $model ) || $model == CONTENT_MODEL_WIKITEXT; $isWikitext = $isWikitext && !$isCodePage && !$isCodeSubpage; - - // Hook can override $isWikitext - Hooks::run( 'TitleIsWikitextPage', [ $title, &$isWikitext ], '1.21' ); if ( !$isWikitext ) { switch ( $ext ) { @@ -1093,65 +1087,6 @@ */ public function supportsDirectApiEditing() { return $this->supportsDirectEditing(); - } - - /** - * Call a legacy hook that uses text instead of Content objects. - * Will log a warning when a matching hook function is registered. - * If the textual representation of the content is changed by the - * hook function, a new Content object is constructed from the new - * text. - * - * @param string $event Event name - * @param array $args Parameters passed to hook functions - * @param string|null $deprecatedVersion Emit a deprecation notice - * when the hook is run for the provided version - * - * @return bool True if no handler aborted the hook - */ - public static function runLegacyHooks( $event, $args = [], - $deprecatedVersion = null - ) { - - if ( !Hooks::isRegistered( $event ) ) { - return true; // nothing to do here - } - - // convert Content objects to text - $contentObjects = []; - $contentTexts = []; - - foreach ( $args as $k => $v ) { - if ( $v instanceof Content ) { - /* @var Content $v */ - - $contentObjects[$k] = $v; - - $v = $v->serialize(); - $contentTexts[$k] = $v; - $args[$k] = $v; - } - } - - // call the hook functions - $ok = Hooks::run( $event, $args, $deprecatedVersion ); - - // see if the hook changed the text - foreach ( $contentTexts as $k => $orig ) { - /* @var Content $content */ - - $modified = $args[$k]; - $content = $contentObjects[$k]; - - if ( $modified !== $orig ) { - // text was changed, create updated Content object - $content = $content->getContentHandler()->unserializeContent( $modified ); - } - - $args[$k] = $content; - } - - return $ok; } /** diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 0f1efe7..920ba87 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -1663,9 +1663,7 @@ $hook_args = [ &$wikiPage, &$user, &$content, &$summary, $flags & EDIT_MINOR, null, null, &$flags, &$hookStatus ]; // Check if the hook rejected the attempted save - if ( !Hooks::run( 'PageContentSave', $hook_args ) - || !ContentHandler::runLegacyHooks( 'ArticleSave', $hook_args, '1.21' ) - ) { + if ( !Hooks::run( 'PageContentSave', $hook_args ) ) { if ( $hookStatus->isOK() ) { // Hook returned false but didn't call fatal(); use generic message $hookStatus->fatal( 'edit-hook-aborted' ); @@ -1893,7 +1891,6 @@ $params = [ &$wikiPage, &$user, $content, $summary, $flags & EDIT_MINOR, null, null, &$flags, $revision, &$status, $meta['baseRevId'], $meta['undidRevId'] ]; - ContentHandler::runLegacyHooks( 'ArticleSaveComplete', $params ); Hooks::run( 'PageContentSaveComplete', $params ); } ), @@ -2015,13 +2012,10 @@ // Trigger post-create hook $params = [ &$wikiPage, &$user, $content, $summary, $flags & EDIT_MINOR, null, null, &$flags, $revision ]; - ContentHandler::runLegacyHooks( 'ArticleInsertComplete', $params, '1.21' ); Hooks::run( 'PageContentInsertComplete', $params ); // Trigger post-save hook $params = array_merge( $params, [ &$status, $meta['baseRevId'] ] ); - ContentHandler::runLegacyHooks( 'ArticleSaveComplete', $params, '1.21' ); Hooks::run( 'PageContentSaveComplete', $params ); - } ), DeferredUpdates::PRESEND diff --git a/maintenance/findHooks.php b/maintenance/findHooks.php index f6e65f9..81e18c9 100644 --- a/maintenance/findHooks.php +++ b/maintenance/findHooks.php @@ -48,7 +48,7 @@ /* * Hooks that are ignored */ - protected static $ignore = [ 'testRunLegacyHooks', 'Test' ]; + protected static $ignore = [ 'Test' ]; public function __construct() { parent::__construct(); @@ -238,7 +238,7 @@ $m = []; preg_match_all( // All functions which runs hooks - '/(?:wfRunHooks|Hooks\:\:run|ContentHandler\:\:runLegacyHooks)\s*\(\s*' . + '/(?:wfRunHooks|Hooks\:\:run)\s*\(\s*' . // First argument is the hook name as string '([\'"])(.*?)\1' . // Comma for second argument diff --git a/tests/phpunit/includes/content/ContentHandlerTest.php b/tests/phpunit/includes/content/ContentHandlerTest.php index 39948ca..91d2297 100644 --- a/tests/phpunit/includes/content/ContentHandlerTest.php +++ b/tests/phpunit/includes/content/ContentHandlerTest.php @@ -367,22 +367,6 @@ $this->assertFalse( $handler->supportsDirectEditing(), 'direct editing is not supported' ); } - /** - * @covers ContentHandler::runLegacyHooks - */ - public function testRunLegacyHooks() { - Hooks::register( 'testRunLegacyHooks', __CLASS__ . '::dummyHookHandler' ); - - $content = new WikitextContent( 'test text' ); - $ok = ContentHandler::runLegacyHooks( - 'testRunLegacyHooks', - [ 'foo', &$content, 'bar' ] - ); - - $this->assertTrue( $ok, "runLegacyHooks should have returned true" ); - $this->assertEquals( "TEST TEXT", $content->getNativeData() ); - } - public static function dummyHookHandler( $foo, &$text, $bar ) { if ( $text === null || $text === false ) { return false; -- To view, visit https://gerrit.wikimedia.org/r/332150 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ie398fd4e06d3e286fe8e24112d0c8b4ac7d883dc Gerrit-PatchSet: 8 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Filip <r...@protonmail.com> Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de> Gerrit-Reviewer: Filip <r...@protonmail.com> Gerrit-Reviewer: Jackmcbarn <jackmcb...@gmail.com> Gerrit-Reviewer: Reedy <re...@wikimedia.org> Gerrit-Reviewer: TTO <at.li...@live.com.au> Gerrit-Reviewer: Tpt <thoma...@hotmail.fr> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits