moved getDeletionUpdates to Content interface
authordaniel <daniel.kinzler@wikimedia.de>
Mon, 23 Jul 2012 20:54:25 +0000 (22:54 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Mon, 23 Jul 2012 20:54:25 +0000 (22:54 +0200)
Change-Id: I1b46b1d663f8efd609aeb1b63cb07ee1a0a00c33

docs/hooks.txt
includes/Content.php
includes/ContentHandler.php
includes/WikiPage.php
tests/phpunit/includes/ContentHandlerTest.php
tests/phpunit/includes/WikitextContentTest.php

index 950cb5f..c42315e 100644 (file)
@@ -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.
 
index f7f0346..0f2fa0b 100644 (file)
@@ -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;
        }
 
-
 }
 
 /**
index c90e140..f8bc256 100644 (file)
@@ -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.
         *
index 657fcf3..276fe0e 100644 (file)
@@ -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;
index 2eaa285..77950c3 100644 (file)
@@ -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" );
        }
index 5feec83..7e86c7f 100644 (file)
@@ -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" );
+                       }
+               }
+       }
+
 }