From 437f60f3589cae2929bb9888bb6eb2dbdfa26a73 Mon Sep 17 00:00:00 2001 From: aude Date: Mon, 15 Feb 2016 16:19:58 +0100 Subject: [PATCH] Add ContentHandler::supportsCategories method and check for this in WikiPage::doEditUpdates before inserting a new CategoryMembershipChangeJob. Some content models like the Wikibase ones do not have categories and it's wasteful to add these jobs for all Wikibase edits. Bug: T126977 Change-Id: I2c54a4ba1546445dc41101e15cb83a2c6cc2b1c9 --- RELEASE-NOTES-1.27 | 3 +++ includes/content/ContentHandler.php | 10 ++++++++++ includes/page/WikiPage.php | 1 + tests/phpunit/includes/content/ContentHandlerTest.php | 5 +++++ 4 files changed, 19 insertions(+) diff --git a/RELEASE-NOTES-1.27 b/RELEASE-NOTES-1.27 index 867abd7a12..b8ec76d657 100644 --- a/RELEASE-NOTES-1.27 +++ b/RELEASE-NOTES-1.27 @@ -319,6 +319,9 @@ changes to languages because of Phabricator reports. a user forgot password/account was stolen. * wfCheckEntropy() was removed (deprecated in 1.27). * Browser support for Internet Explorer 8 lowered from Grade A to Grade C. +* ContentHandler::supportsCategories method added. Default is true. + CategoryMembershipChangeJob updates are skipped for content that + does not support categories. == Compatibility == diff --git a/includes/content/ContentHandler.php b/includes/content/ContentHandler.php index 6bc6abfda7..9ab11f3b68 100644 --- a/includes/content/ContentHandler.php +++ b/includes/content/ContentHandler.php @@ -1082,6 +1082,16 @@ abstract class ContentHandler { return false; } + /** + * Returns true if this content model supports categories. + * The default implementation returns true. + * + * @return bool Always true. + */ + public function supportsCategories() { + return true; + } + /** * Returns true if this content model supports redirects. * This default implementation returns false. diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 330889081d..27412edfcb 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -2261,6 +2261,7 @@ class WikiPage implements Page, IDBAccessObject { DeferredUpdates::addUpdate( $update ); } if ( $wgRCWatchCategoryMembership + && $this->getContentHandler()->supportsCategories() === true && ( $options['changed'] || $options['created'] ) && !$options['restored'] ) { diff --git a/tests/phpunit/includes/content/ContentHandlerTest.php b/tests/phpunit/includes/content/ContentHandlerTest.php index 9c17c3ee81..91f27fbe71 100644 --- a/tests/phpunit/includes/content/ContentHandlerTest.php +++ b/tests/phpunit/includes/content/ContentHandlerTest.php @@ -350,6 +350,11 @@ class ContentHandlerTest extends MediaWikiTestCase { } */ + public function testSupportsCategories() { + $handler = new DummyContentHandlerForTesting( CONTENT_MODEL_WIKITEXT ); + $this->assertTrue( $handler->supportsCategories(), 'content model supports categories' ); + } + public function testSupportsDirectEditing() { $handler = new DummyContentHandlerForTesting( CONTENT_MODEL_JSON ); $this->assertFalse( $handler->supportsDirectEditing(), 'direct editing is not supported' ); -- 2.20.1