X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fparser%2FParserOutput.php;h=d1e3e580fc594018b42da54b2edc5658d105de3f;hb=a8304d4c73fd04c338ae23f3028fc475921cc0fa;hp=8cd978b14da0a31c9ba6682e92be148763febb70;hpb=b6d6d778182f60376f69463d9426894173304c97;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php index 8cd978b14d..d1e3e580fc 100644 --- a/includes/parser/ParserOutput.php +++ b/includes/parser/ParserOutput.php @@ -41,6 +41,7 @@ class ParserOutput extends CacheTime { $mModuleScripts = array(), # Modules of which only the JS will be loaded by the resource loader $mModuleStyles = array(), # Modules of which only the CSSS will be loaded by the resource loader $mModuleMessages = array(), # Modules of which only the messages will be loaded by the resource loader + $mJsConfigVars = array(), # JavaScript config variable for mw.config combined with this page $mOutputHooks = array(), # Hook tags as per $wgParserOutputHooks $mWarnings = array(), # Warning text to be returned to the user. Wikitext formatted, in the key only $mSections = array(), # Table of contents @@ -134,6 +135,8 @@ class ParserOutput extends CacheTime { function getModuleScripts() { return $this->mModuleScripts; } function getModuleStyles() { return $this->mModuleStyles; } function getModuleMessages() { return $this->mModuleMessages; } + /** @since 1.23 */ + function getJsConfigVars() { return $this->mJsConfigVars; } function getOutputHooks() { return (array)$this->mOutputHooks; } function getWarnings() { return array_keys( $this->mWarnings ); } function getIndexPolicy() { return $this->mIndexPolicy; } @@ -318,6 +321,24 @@ class ParserOutput extends CacheTime { $this->mModuleMessages = array_merge( $this->mModuleMessages, (array)$modules ); } + /** + * Add one or more variables to be set in mw.config in JavaScript. + * + * @param $keys {String|Array} Key or array of key/value pairs. + * @param $value {Mixed} [optional] Value of the configuration variable. + * @since 1.23 + */ + public function addJsConfigVars( $keys, $value = null ) { + if ( is_array( $keys ) ) { + foreach ( $keys as $key => $value ) { + $this->mJsConfigVars[$key] = $value; + } + return; + } + + $this->mJsConfigVars[$keys] = $value; + } + /** * Copy items from the OutputPage object into this one * @@ -328,6 +349,7 @@ class ParserOutput extends CacheTime { $this->addModuleScripts( $out->getModuleScripts() ); $this->addModuleStyles( $out->getModuleStyles() ); $this->addModuleMessages( $out->getModuleMessages() ); + $this->addJsConfigVars( $out->getJsConfigVars() ); $this->mHeadItems = array_merge( $this->mHeadItems, $out->getHeadItemsArray() ); } @@ -396,7 +418,7 @@ class ParserOutput extends CacheTime { * @note: Do not use setProperty() to set a property which is only used * in a context where the ParserOutput object itself is already available, * for example a normal page view. There is no need to save such a property - * in the database since it the text is already parsed. You can just hook + * in the database since the text is already parsed. You can just hook * OutputPageParserOutput and get your data out of the ParserOutput object. * * If you are writing an extension where you want to set a property in the @@ -453,16 +475,23 @@ class ParserOutput extends CacheTime { } /** - * Callback passed by the Parser to the ParserOptions to keep track of which options are used. - * @access private + * Tags a parser option for use in the cache key for this parser output. + * Registered as a watcher at ParserOptions::registerWatcher() by Parser::clearState(). + * + * @see ParserCache::getKey + * @see ParserCache::save + * @see ParserOptions::addExtraKey + * @see ParserOptions::optionsHash */ - function recordOption( $option ) { + public 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. + * Adds an update job to the output. Any update jobs added to the output will + * eventually be executed in order to store any secondary information extracted + * from the page's content. This is triggered by calling getSecondaryDataUpdates() + * and is used for forward links updates on edit and backlink updates by jobs. * * @since 1.20 * @@ -629,4 +658,14 @@ class ParserOutput extends CacheTime { function setLimitReportData( $key, $value ) { $this->mLimitReportData[$key] = $value; } + + /** + * Save space for for serialization by removing useless values + */ + function __sleep() { + return array_diff( + array_keys( get_object_vars( $this ) ), + array( 'mSecondaryDataUpdates', 'mParseStartTime' ) + ); + } }