From cc365c35522b53a24ce6faf23f8526559038ce4c Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 5 Apr 2012 17:21:07 +0200 Subject: [PATCH] Added an array of SecondaryDataUpdate objects to ParserOutput Change-Id: I329be83a0899b3f16c99119f2f802233a157ee42 --- includes/parser/ParserOutput.php | 54 ++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php index beeeb30a62..086b48626d 100644 --- a/includes/parser/ParserOutput.php +++ b/includes/parser/ParserOutput.php @@ -140,8 +140,9 @@ class ParserOutput extends CacheTime { $mProperties = array(), # Name/value pairs to be cached in the DB $mTOCHTML = '', # HTML of the TOC $mTimestamp; # Timestamp of the revision - private $mIndexPolicy = ''; # 'index' or 'noindex'? Any other value will result in no change. - private $mAccessedOptions = array(); # List of ParserOptions (stored in the keys) + private $mIndexPolicy = ''; # 'index' or 'noindex'? Any other value will result in no change. + private $mAccessedOptions = array(); # List of ParserOptions (stored in the keys) + private $mSecondaryDataUpdates = array(); # List of instances of SecondaryDataObject(), used to cause some information extracted from the page in a custom place. const EDITSECTION_REGEX = '#<(?:mw:)?editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)())#'; @@ -447,4 +448,53 @@ class ParserOutput extends CacheTime { function recordOption( $option ) { $this->mAccessedOptions[$option] = true; } + + /** + * Adds an update job to the output. Any update jobs added to the output will eventually bexecuted in order to + * store any secondary information extracted from the page's content. + * + * @param SecondaryDataUpdate $update + */ + public function addSecondaryDataUpdate( SecondaryDataUpdate $update ) { + $this->mSecondaryDataUpdates[] = $update; + } + + /** + * Returns any SecondaryDataUpdate jobs to be executed in order to store secondary information + * extracted from the page's content. + * + * This does not automatically include an LinksUpdate object for the links in this ParserOutput instance. + * Use getLinksUpdateAndOtherUpdates() if you want that. + * + * @return array an array of instances of SecondaryDataUpdate + */ + public function getSecondaryDataUpdates() { + return $this->mSecondaryDataUpdates; + } + + /** + * Conveniance method that returns any SecondaryDataUpdate jobs to be executed in order + * to store secondary information extracted from the page's content, including the LinksUpdate object + * for all links stopred in this ParserOutput object. + * + * @param $title Title of the page we're updating. If not given, a title object will be created based on $this->getTitleText() + * @param $recursive Boolean: queue jobs for recursive updates? + * + * @return array an array of instances of SecondaryDataUpdate + */ + public function getLinksUpdateAndOtherUpdates( Title $title = null, $recursive = true ) { + if ( empty( $title ) ) { + $title = Title::newFromText( $this->getTitleText() ); + } + + $linksUpdate = new LinksUpdate( $title, $this, $recursive ); + + if ( empty( $this->mSecondaryDataUpdates ) ) { + return array( $linksUpdate ); + } else { + $updates = array_merge( $this->mSecondaryDataUpdates, array( $linksUpdate ) ); + } + + return $updates; + } } -- 2.20.1