From: rlot Date: Sun, 15 Jan 2017 18:49:28 +0000 (+0100) Subject: Removed deprecated ContentHandler hooks. X-Git-Tag: 1.31.0-rc.0~4293 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=99800a9e0360e1a24c061d908dbe111bf687963f Removed deprecated ContentHandler hooks. Plus removed unused "ContentHandler::runLegacyHooks" Bug: T154498 Change-Id: Ie398fd4e06d3e286fe8e24112d0c8b4ac7d883dc --- diff --git a/RELEASE-NOTES-1.29 b/RELEASE-NOTES-1.29 index fac6f7ea32..e4049403b5 100644 --- a/RELEASE-NOTES-1.29 +++ b/RELEASE-NOTES-1.29 @@ -152,8 +152,9 @@ changes to languages because of Phabricator reports. 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 @@ changes to languages because of Phabricator reports. 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 6209b1426c..5f379e7e33 100644 --- a/docs/contenthandler.txt +++ b/docs/contenthandler.txt @@ -21,10 +21,6 @@ ContentHandler::getDefaultModelFor($title) as follows: * 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 adfb128aea..4057cce20d 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -603,12 +603,6 @@ a chance to hide their (unrelated) log entries. 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 @@ Wiki::articleFromTitle(). &$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) @@ -740,31 +722,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 $create: Whether or not the restoration caused the page to be created (i.e. it @@ -1334,12 +1291,6 @@ $section: Section being edited &$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 @@ -1448,13 +1399,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 &$editpage: The current EditPage object @@ -3315,13 +3259,6 @@ by the isKnown method. $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 @@ $title: Title object that is being checked 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 05fa366eba..de08880de7 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1621,15 +1621,7 @@ class EditPage { */ 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 @@ HTML } $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 65b69a29a6..5cf911f638 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1233,12 +1233,6 @@ class Title implements LinkTarget { && ( $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 db20f514d2..5862bf1156 100644 --- a/includes/content/ContentHandler.php +++ b/includes/content/ContentHandler.php @@ -198,9 +198,6 @@ abstract class ContentHandler { $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 @@ -213,9 +210,6 @@ abstract class ContentHandler { $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 ) { case 'js': @@ -1095,65 +1089,6 @@ abstract class ContentHandler { 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; - } - /** * Get fields definition for search index * diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 0f1efe71da..920ba87806 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -1663,9 +1663,7 @@ class WikiPage implements Page, IDBAccessObject { $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 @@ class WikiPage implements Page, IDBAccessObject { $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 @@ class WikiPage implements Page, IDBAccessObject { // 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 f6e65f9452..81e18c993b 100644 --- a/maintenance/findHooks.php +++ b/maintenance/findHooks.php @@ -48,7 +48,7 @@ class FindHooks extends Maintenance { /* * Hooks that are ignored */ - protected static $ignore = [ 'testRunLegacyHooks', 'Test' ]; + protected static $ignore = [ 'Test' ]; public function __construct() { parent::__construct(); @@ -238,7 +238,7 @@ class FindHooks extends Maintenance { $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 39948ca130..91d2297d8a 100644 --- a/tests/phpunit/includes/content/ContentHandlerTest.php +++ b/tests/phpunit/includes/content/ContentHandlerTest.php @@ -367,22 +367,6 @@ class ContentHandlerTest extends MediaWikiTestCase { $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;