introducing Content::getSecondaryDataUpdates()
authordaniel <daniel.kinzler@wikimedia.de>
Wed, 16 May 2012 18:14:14 +0000 (20:14 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Wed, 16 May 2012 18:14:14 +0000 (20:14 +0200)
includes/Content.php
includes/WikiPage.php
maintenance/refreshLinks.php

index 4fc6e1b..5402499 100644 (file)
@@ -302,7 +302,32 @@ abstract class Content {
         *
         * @return ParserOutput
         */
-       public abstract function getParserOutput( IContextSource $context, $revId = null, ParserOptions $options = NULL, $generateHtml = true );
+       public abstract function getParserOutput( IContextSource $context, $revId = null, ParserOptions $options = null, $generateHtml = true );
+
+       /**
+        * Returns a list of DataUpdate objects for recording information about this Content in some secondary
+        * data store. If the optional second argument, $old, is given, the updates may model only the changes that
+        * need to be made to replace information about the old content with infomration about the new content.
+        *
+        * This default implementation calls $this->getParserOutput( $context, null, null, false ), and then
+        * calls getSecondaryDataUpdates( $context->getTitle(), $recursive ) on the resulting ParserOutput object.
+        *
+        * Subclasses may implement this to determine the necessary updates more efficiently, or make use of information
+        * about the old content.
+        *
+        * @param IContextSource $context the content for determining the necessary updates
+        * @param Content|null $old a Content object representing the previous content, i.e. the content being
+        *                     replaced by this Content object.
+        * @param bool $recursive whether to include recursive updates (default: false).
+        *
+        * @return Array. A list of DataUpdate objects for putting information about this content object somewhere.
+        *
+        * @since WD.1
+        */
+       public function getSecondaryDataUpdates( IContextSource $context, Content $old = null, $recursive = false ) {
+               $po = $this->getParserOutput( $context, null, null, false );
+               return $po->getSecondaryDataUpdates( $context->getTitle(), $recursive );
+       }
 
        /**
         * Construct the redirect destination from this content and return an
index eaf32fe..8f73eec 100644 (file)
@@ -1938,6 +1938,7 @@ class WikiPage extends Page {
                $context = RequestContext::getMain();
                $context->setTitle( $this->mTitle );
                $edit->output = $edit->pstContent->getParserOutput( $context, $revid, $edit->popts );
+               $edit->updates = $edit->pstContent->getSecondaryDataUpdate( $context );
 
                $edit->newContent = $content;
                $edit->oldContent = $this->getContent( Revision::RAW );
@@ -1991,7 +1992,7 @@ class WikiPage extends Page {
                }
 
                # Update the links tables and other secondary data
-               $updates = $editInfo->output->getSecondaryDataUpdates( $this->mTitle );
+               $updates = $editInfo->updates;
                DataUpdate::runUpdates( $updates );
 
                wfRunHooks( 'ArticleEditUpdates', array( &$this, &$editInfo, $options['changed'] ) );
index 7ff3be6..f954b9e 100644 (file)
@@ -218,12 +218,9 @@ class RefreshLinks extends Maintenance {
                $dbw = wfGetDB( DB_MASTER );
                $dbw->begin( __METHOD__ );
 
-               $options = ParserOptions::newFromUserAndLang( new User, $wgContLang );
                $context = RequestContext::getMain();
 
-               $parserOutput = $content->getParserOutput( $context, $page->getLatest(), $options, false );
-
-               $updates = $parserOutput->getSecondaryDataUpdates( $page->getTitle(), false );
+               $updates = $content->getSecondaryDataUpdates( $context );
                DataUpdate::runUpdates( $updates );
 
                $dbw->commit( __METHOD__ );