From: daniel Date: Mon, 23 Jul 2012 20:54:25 +0000 (+0200) Subject: moved getDeletionUpdates to Content interface X-Git-Tag: 1.31.0-rc.0~22097^2^2~71 X-Git-Url: http://git.cyclocoop.org//%22%22._DIR_PLUGIN_FULLCALENDAR.%22prive/themes/spip/images/event_edit.png/%22?a=commitdiff_plain;h=c8e633f1e38d8fee671fc5453536adccaee616be;p=lhc%2Fweb%2Fwiklou.git moved getDeletionUpdates to Content interface Change-Id: I1b46b1d663f8efd609aeb1b63cb07ee1a0a00c33 --- diff --git a/docs/hooks.txt b/docs/hooks.txt index 950cb5f0b6..c42315e351 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -2407,7 +2407,7 @@ One, and only one hook should set this, and return false. 'WikiPageDeletionUpdates': manipulate the list of DataUpdates to be applied when a page is deleted. Called in WikiPage::getDeletionUpdates(). Note that updates specific to a content model should be provided by the - respective ContentHandler's getDeletionUpdates() method. + respective Content's getDeletionUpdates() method. $page: the WikiPage &$updates: the array of DataUpdate objects. Hook function may want to add to it. diff --git a/includes/Content.php b/includes/Content.php index f7f03460fb..0f2fa0b0ec 100644 --- a/includes/Content.php +++ b/includes/Content.php @@ -378,6 +378,24 @@ interface Content { */ public function prepareSave( WikiPage $page, $flags, $baseRevId, User $user ); + /** + * Returns a list of updates to perform when this content is deleted. + * The necessary updates may be taken from the Content object, or depend on + * the current state of the database. + * + * @since WD.1 + * + * @param $title \Title the title of the deleted page + * @param $parserOutput null|\ParserOutput optional parser output object + * for efficient access to meta-information about the content object. + * Provide if you have one handy. + * + * @return array A list of DataUpdate instances that will clean up the + * database after deletion. + */ + public function getDeletionUpdates( Title $title, + ParserOutput $parserOutput = null ); + # TODO: handle ImagePage and CategoryPage # TODO: make sure we cover lucene search / wikisearch. # TODO: make sure ReplaceTemplates still works @@ -643,6 +661,29 @@ abstract class AbstractContent implements Content { return Status::newFatal( "invalid-content-data" ); } } + + /** + * Returns a list of updates to perform when this content is deleted. + * The necessary updates may be taken from the Content object, or depend on + * the current state of the database. + * + * @since WD.1 + * + * @param $title \Title the title of the deleted page + * @param $parserOutput null|\ParserOutput optional parser output object + * for efficient access to meta-information about the content object. + * Provide if you have one handy. + * + * @return array A list of DataUpdate instances that will clean up the + * database after deletion. + */ + public function getDeletionUpdates( Title $title, + ParserOutput $parserOutput = null ) + { + return array( + new LinksDeletionUpdate( $title ), + ); + } } /** @@ -769,7 +810,6 @@ abstract class TextContent extends AbstractContent { return $diff; } - } /** diff --git a/includes/ContentHandler.php b/includes/ContentHandler.php index c90e140bed..f8bc256a5c 100644 --- a/includes/ContentHandler.php +++ b/includes/ContentHandler.php @@ -50,6 +50,7 @@ abstract class ContentHandler { * - otherwise, the behaviour is undefined. * * @since WD.1 + * @deprecated since WD.1. Always try to use the content object. * * @static * @param $content Content|null @@ -879,30 +880,6 @@ abstract class ContentHandler { return true; } - /** - * Returns a list of updates to perform when the given content is deleted. - * The necessary updates may be taken from the Content object, or depend on - * the current state of the database. - * - * @since WD.1 - * - * @param $content \Content the Content object for deletion - * @param $title \Title the title of the deleted page - * @param $parserOutput null|\ParserOutput optional parser output object - * for efficient access to meta-information about the content object. - * Provide if you have one handy. - * - * @return array A list of DataUpdate instances that will clean up the - * database after deletion. - */ - public function getDeletionUpdates( Content $content, Title $title, - ParserOutput $parserOutput = null ) - { - return array( - new LinksDeletionUpdate( $title ), - ); - } - /** * Returns true if this content model supports sections. * diff --git a/includes/WikiPage.php b/includes/WikiPage.php index 657fcf3d06..276fe0ef26 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -3202,7 +3202,7 @@ class WikiPage extends Page { $content = $this->getContent( Revision::RAW ); } - $updates = $this->getContentHandler()->getDeletionUpdates( $content, $this->mTitle ); + $updates = $this->getContent()->getDeletionUpdates( $this->mTitle ); wfRunHooks( 'WikiPageDeletionUpdates', array( $this, &$updates ) ); return $updates; diff --git a/tests/phpunit/includes/ContentHandlerTest.php b/tests/phpunit/includes/ContentHandlerTest.php index 2eaa285c4a..77950c39f9 100644 --- a/tests/phpunit/includes/ContentHandlerTest.php +++ b/tests/phpunit/includes/ContentHandlerTest.php @@ -296,48 +296,6 @@ class ContentHandlerTest extends MediaWikiTestCase { } } - public function dataGetDeletionUpdates() { - return array( - array("ContentHandlerTest_testGetSecondaryDataUpdates_1", "hello ''world''\n", - array( 'LinksDeletionUpdate' => array( ) ) - ), - array("ContentHandlerTest_testGetSecondaryDataUpdates_2", "hello [[world test 21344]]\n", - array( 'LinksDeletionUpdate' => array( ) ) - ), - // @todo: more...? - ); - } - - /** - * @dataProvider dataGetDeletionUpdates - */ - public function testDeletionUpdates( $title, $text, $expectedStuff ) { - $title = Title::newFromText( $title ); - $title->resetArticleID( 2342 ); //dummy id. fine as long as we don't try to execute the updates! - - $handler = ContentHandler::getForModelID( $title->getContentModel() ); - $content = ContentHandler::makeContent( $text, $title ); - - $updates = $handler->getDeletionUpdates( $content, $title ); - - // make updates accessible by class name - foreach ( $updates as $update ) { - $class = get_class( $update ); - $updates[ $class ] = $update; - } - - foreach ( $expectedStuff as $class => $fieldValues ) { - $this->assertArrayHasKey( $class, $updates, "missing an update of type $class" ); - - $update = $updates[ $class ]; - - foreach ( $fieldValues as $field => $value ) { - $v = $update->$field; #if the field doesn't exist, just crash and burn - $this->assertEquals( $value, $v, "unexpected value for field $field in instance of $class" ); - } - } - } - public function testSupportsSections() { $this->markTestIncomplete( "not yet implemented" ); } diff --git a/tests/phpunit/includes/WikitextContentTest.php b/tests/phpunit/includes/WikitextContentTest.php index 5feec832e7..7e86c7fd77 100644 --- a/tests/phpunit/includes/WikitextContentTest.php +++ b/tests/phpunit/includes/WikitextContentTest.php @@ -418,4 +418,46 @@ just a test" $this->assertEquals( $equal, $a->equals( $b ) ); } + public function dataGetDeletionUpdates() { + return array( + array("WikitextContentTest_testGetSecondaryDataUpdates_1", "hello ''world''\n", + array( 'LinksDeletionUpdate' => array( ) ) + ), + array("WikitextContentTest_testGetSecondaryDataUpdates_2", "hello [[world test 21344]]\n", + array( 'LinksDeletionUpdate' => array( ) ) + ), + // @todo: more...? + ); + } + + /** + * @dataProvider dataGetDeletionUpdates + */ + public function testDeletionUpdates( $title, $text, $expectedStuff ) { + $title = Title::newFromText( $title ); + $title->resetArticleID( 2342 ); //dummy id. fine as long as we don't try to execute the updates! + + $handler = ContentHandler::getForModelID( $title->getContentModel() ); + $content = ContentHandler::makeContent( $text, $title ); + + $updates = $content->getDeletionUpdates( $title ); + + // make updates accessible by class name + foreach ( $updates as $update ) { + $class = get_class( $update ); + $updates[ $class ] = $update; + } + + foreach ( $expectedStuff as $class => $fieldValues ) { + $this->assertArrayHasKey( $class, $updates, "missing an update of type $class" ); + + $update = $updates[ $class ]; + + foreach ( $fieldValues as $field => $value ) { + $v = $update->$field; #if the field doesn't exist, just crash and burn + $this->assertEquals( $value, $v, "unexpected value for field $field in instance of $class" ); + } + } + } + }