4 * Output of the PHP parser.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
24 class ParserOutput
extends CacheTime
{
26 * @var string $mText The output text
31 * @var array $mLanguageLinks List of the full text of language links,
32 * in the order they appear.
34 public $mLanguageLinks;
37 * @var array $mCategoriesMap of category names to sort keys
42 * @var array $mIndicators Page status indicators, usually displayed in top-right corner.
44 public $mIndicators = array();
47 * @var string $mTitleText Title text of the chosen language variant, as HTML.
52 * @var array $mLinks 2-D map of NS/DBK to ID for the links in the document.
55 public $mLinks = array();
58 * @var array $mTemplates 2-D map of NS/DBK to ID for the template references.
61 public $mTemplates = array();
64 * @var array $mTemplateIds 2-D map of NS/DBK to rev ID for the template references.
67 public $mTemplateIds = array();
70 * @var array $mImages DB keys of the images used, in the array key only
72 public $mImages = array();
75 * @var array $mFileSearchOptions DB keys of the images used mapped to sha1 and MW timestamp.
77 public $mFileSearchOptions = array();
80 * @var array $mExternalLinks External link URLs, in the key only.
82 public $mExternalLinks = array();
85 * @var array $mInterwikiLinks 2-D map of prefix/DBK (in keys only)
86 * for the inline interwiki links in the document.
88 public $mInterwikiLinks = array();
91 * @var bool $mNewSection Show a new section link?
93 public $mNewSection = false;
96 * @var bool $mHideNewSection Hide the new section link?
98 public $mHideNewSection = false;
101 * @var bool $mNoGallery No gallery on category page? (__NOGALLERY__).
103 public $mNoGallery = false;
106 * @var array $mHeadItems Items to put in the <head> section
108 public $mHeadItems = array();
111 * @var array $mModules Modules to be loaded by the resource loader
113 public $mModules = array();
116 * @var array $mModuleScripts Modules of which only the JS will be loaded by
117 * the resource loader.
119 public $mModuleScripts = array();
122 * @var array $mModuleStyles Modules of which only the CSSS will be loaded by
123 * the resource loader.
125 public $mModuleStyles = array();
128 * @var array $mJsConfigVars JavaScript config variable for mw.config combined with this page.
130 public $mJsConfigVars = array();
133 * @var array $mOutputHooks Hook tags as per $wgParserOutputHooks.
135 public $mOutputHooks = array();
138 * @var array $mWarnings Warning text to be returned to the user.
139 * Wikitext formatted, in the key only.
141 public $mWarnings = array();
144 * @var array $mSections Table of contents
146 public $mSections = array();
149 * @var bool $mEditSectionTokens prefix/suffix markers if edit sections were output as tokens.
151 public $mEditSectionTokens = false;
154 * @var array $mProperties Name/value pairs to be cached in the DB.
156 public $mProperties = array();
159 * @var string $mTOCHTML HTML of the TOC.
161 public $mTOCHTML = '';
164 * @var string $mTimestamp Timestamp of the revision.
169 * @var bool $mTOCEnabled Whether TOC should be shown, can't override __NOTOC__.
171 public $mTOCEnabled = true;
174 * @var bool $mEnableOOUI Whether OOUI should be enabled.
176 public $mEnableOOUI = false;
179 * @var string $mIndexPolicy 'index' or 'noindex'? Any other value will result in no change.
181 private $mIndexPolicy = '';
184 * @var array $mAccessedOptions List of ParserOptions (stored in the keys).
186 private $mAccessedOptions = array();
189 * @var array $mExtensionData extra data used by extensions.
191 private $mExtensionData = array();
194 * @var array $mLimitReportData Parser limit report data.
196 private $mLimitReportData = array();
199 * @var array $mParseStartTime Timestamps for getTimeSinceStart().
201 private $mParseStartTime = array();
204 * @var bool $mPreventClickjacking Whether to emit X-Frame-Options: DENY.
206 private $mPreventClickjacking = false;
209 * @var array $mFlags Generic flags.
211 private $mFlags = array();
213 const EDITSECTION_REGEX
=
214 '#<(?:mw:)?editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)(</(?:mw:)?editsection>))#';
216 public function __construct( $text = '', $languageLinks = array(), $categoryLinks = array(),
217 $unused = false, $titletext = ''
219 $this->mText
= $text;
220 $this->mLanguageLinks
= $languageLinks;
221 $this->mCategories
= $categoryLinks;
222 $this->mTitleText
= $titletext;
225 public function getText() {
226 $text = $this->mText
;
227 if ( $this->mEditSectionTokens
) {
228 $text = preg_replace_callback(
229 ParserOutput
::EDITSECTION_REGEX
,
231 global $wgOut, $wgLang;
232 $editsectionPage = Title
::newFromText( htmlspecialchars_decode( $m[1] ) );
233 $editsectionSection = htmlspecialchars_decode( $m[2] );
234 $editsectionContent = isset( $m[4] ) ?
$m[3] : null;
236 if ( !is_object( $editsectionPage ) ) {
237 throw new MWException( "Bad parser output text." );
240 $skin = $wgOut->getSkin();
241 return call_user_func_array(
242 array( $skin, 'doEditSectionLink' ),
243 array( $editsectionPage, $editsectionSection,
244 $editsectionContent, $wgLang->getCode() )
250 $text = preg_replace( ParserOutput
::EDITSECTION_REGEX
, '', $text );
253 // If you have an old cached version of this class - sorry, you can't disable the TOC
254 if ( isset( $this->mTOCEnabled
) && $this->mTOCEnabled
) {
255 $text = str_replace( array( Parser
::TOC_START
, Parser
::TOC_END
), '', $text );
257 $text = preg_replace(
258 '#' . preg_quote( Parser
::TOC_START
, '#' ) . '.*?' . preg_quote( Parser
::TOC_END
, '#' ) . '#s',
266 public function &getLanguageLinks() {
267 return $this->mLanguageLinks
;
270 public function getInterwikiLinks() {
271 return $this->mInterwikiLinks
;
274 public function getCategoryLinks() {
275 return array_keys( $this->mCategories
);
278 public function &getCategories() {
279 return $this->mCategories
;
285 public function getIndicators() {
286 return $this->mIndicators
;
289 public function getTitleText() {
290 return $this->mTitleText
;
293 public function getSections() {
294 return $this->mSections
;
297 public function getEditSectionTokens() {
298 return $this->mEditSectionTokens
;
301 public function &getLinks() {
302 return $this->mLinks
;
305 public function &getTemplates() {
306 return $this->mTemplates
;
309 public function &getTemplateIds() {
310 return $this->mTemplateIds
;
313 public function &getImages() {
314 return $this->mImages
;
317 public function &getFileSearchOptions() {
318 return $this->mFileSearchOptions
;
321 public function &getExternalLinks() {
322 return $this->mExternalLinks
;
325 public function getNoGallery() {
326 return $this->mNoGallery
;
329 public function getHeadItems() {
330 return $this->mHeadItems
;
333 public function getModules() {
334 return $this->mModules
;
337 public function getModuleScripts() {
338 return $this->mModuleScripts
;
341 public function getModuleStyles() {
342 return $this->mModuleStyles
;
346 * @deprecated since 1.26 Obsolete
349 public function getModuleMessages() {
350 wfDeprecated( __METHOD__
, '1.26' );
355 public function getJsConfigVars() {
356 return $this->mJsConfigVars
;
359 public function getOutputHooks() {
360 return (array)$this->mOutputHooks
;
363 public function getWarnings() {
364 return array_keys( $this->mWarnings
);
367 public function getIndexPolicy() {
368 return $this->mIndexPolicy
;
371 public function getTOCHTML() {
372 return $this->mTOCHTML
;
375 public function getTimestamp() {
376 return $this->mTimestamp
;
379 public function getLimitReportData() {
380 return $this->mLimitReportData
;
383 public function getTOCEnabled() {
384 return $this->mTOCEnabled
;
387 public function getEnableOOUI() {
388 return $this->mEnableOOUI
;
391 public function setText( $text ) {
392 return wfSetVar( $this->mText
, $text );
395 public function setLanguageLinks( $ll ) {
396 return wfSetVar( $this->mLanguageLinks
, $ll );
399 public function setCategoryLinks( $cl ) {
400 return wfSetVar( $this->mCategories
, $cl );
403 public function setTitleText( $t ) {
404 return wfSetVar( $this->mTitleText
, $t );
407 public function setSections( $toc ) {
408 return wfSetVar( $this->mSections
, $toc );
411 public function setEditSectionTokens( $t ) {
412 return wfSetVar( $this->mEditSectionTokens
, $t );
415 public function setIndexPolicy( $policy ) {
416 return wfSetVar( $this->mIndexPolicy
, $policy );
419 public function setTOCHTML( $tochtml ) {
420 return wfSetVar( $this->mTOCHTML
, $tochtml );
423 public function setTimestamp( $timestamp ) {
424 return wfSetVar( $this->mTimestamp
, $timestamp );
427 public function setTOCEnabled( $flag ) {
428 return wfSetVar( $this->mTOCEnabled
, $flag );
431 public function addCategory( $c, $sort ) {
432 $this->mCategories
[$c] = $sort;
438 public function setIndicator( $id, $content ) {
439 $this->mIndicators
[$id] = $content;
443 * Enables OOUI, if true, in any OutputPage instance this ParserOutput
444 * object is added to.
447 * @param bool $enable If OOUI should be enabled or not
449 public function setEnableOOUI( $enable = false ) {
450 $this->mEnableOOUI
= $enable;
453 public function addLanguageLink( $t ) {
454 $this->mLanguageLinks
[] = $t;
457 public function addWarning( $s ) {
458 $this->mWarnings
[$s] = 1;
461 public function addOutputHook( $hook, $data = false ) {
462 $this->mOutputHooks
[] = array( $hook, $data );
465 public function setNewSection( $value ) {
466 $this->mNewSection
= (bool)$value;
468 public function hideNewSection( $value ) {
469 $this->mHideNewSection
= (bool)$value;
471 public function getHideNewSection() {
472 return (bool)$this->mHideNewSection
;
474 public function getNewSection() {
475 return (bool)$this->mNewSection
;
479 * Checks, if a url is pointing to the own server
481 * @param string $internal The server to check against
482 * @param string $url The url to check
485 public static function isLinkInternal( $internal, $url ) {
486 return (bool)preg_match( '/^' .
487 # If server is proto relative, check also for http/https links
488 ( substr( $internal, 0, 2 ) === '//' ?
'(?:https?:)?' : '' ) .
489 preg_quote( $internal, '/' ) .
490 # check for query/path/anchor or end of link in each case
496 public function addExternalLink( $url ) {
497 # We don't register links pointing to our own server, unless... :-)
498 global $wgServer, $wgRegisterInternalExternals;
500 $registerExternalLink = true;
501 if ( !$wgRegisterInternalExternals ) {
502 $registerExternalLink = !self
::isLinkInternal( $wgServer, $url );
504 if ( $registerExternalLink ) {
505 $this->mExternalLinks
[$url] = 1;
510 * Record a local or interwiki inline link for saving in future link tables.
512 * @param Title $title
513 * @param int|null $id Optional known page_id so we can skip the lookup
515 public function addLink( Title
$title, $id = null ) {
516 if ( $title->isExternal() ) {
517 // Don't record interwikis in pagelinks
518 $this->addInterwikiLink( $title );
521 $ns = $title->getNamespace();
522 $dbk = $title->getDBkey();
523 if ( $ns == NS_MEDIA
) {
524 // Normalize this pseudo-alias if it makes it down here...
526 } elseif ( $ns == NS_SPECIAL
) {
527 // We don't record Special: links currently
528 // It might actually be wise to, but we'd need to do some normalization.
530 } elseif ( $dbk === '' ) {
531 // Don't record self links - [[#Foo]]
534 if ( !isset( $this->mLinks
[$ns] ) ) {
535 $this->mLinks
[$ns] = array();
537 if ( is_null( $id ) ) {
538 $id = $title->getArticleID();
540 $this->mLinks
[$ns][$dbk] = $id;
544 * Register a file dependency for this output
545 * @param string $name Title dbKey
546 * @param string $timestamp MW timestamp of file creation (or false if non-existing)
547 * @param string $sha1 Base 36 SHA-1 of file (or false if non-existing)
550 public function addImage( $name, $timestamp = null, $sha1 = null ) {
551 $this->mImages
[$name] = 1;
552 if ( $timestamp !== null && $sha1 !== null ) {
553 $this->mFileSearchOptions
[$name] = array( 'time' => $timestamp, 'sha1' => $sha1 );
558 * Register a template dependency for this output
559 * @param Title $title
560 * @param int $page_id
564 public function addTemplate( $title, $page_id, $rev_id ) {
565 $ns = $title->getNamespace();
566 $dbk = $title->getDBkey();
567 if ( !isset( $this->mTemplates
[$ns] ) ) {
568 $this->mTemplates
[$ns] = array();
570 $this->mTemplates
[$ns][$dbk] = $page_id;
571 if ( !isset( $this->mTemplateIds
[$ns] ) ) {
572 $this->mTemplateIds
[$ns] = array();
574 $this->mTemplateIds
[$ns][$dbk] = $rev_id; // For versioning
578 * @param Title $title Title object, must be an interwiki link
579 * @throws MWException If given invalid input
581 public function addInterwikiLink( $title ) {
582 if ( !$title->isExternal() ) {
583 throw new MWException( 'Non-interwiki link passed, internal parser error.' );
585 $prefix = $title->getInterwiki();
586 if ( !isset( $this->mInterwikiLinks
[$prefix] ) ) {
587 $this->mInterwikiLinks
[$prefix] = array();
589 $this->mInterwikiLinks
[$prefix][$title->getDBkey()] = 1;
593 * Add some text to the "<head>".
594 * If $tag is set, the section with that tag will only be included once
596 * @param string $section
597 * @param string|bool $tag
599 public function addHeadItem( $section, $tag = false ) {
600 if ( $tag !== false ) {
601 $this->mHeadItems
[$tag] = $section;
603 $this->mHeadItems
[] = $section;
607 public function addModules( $modules ) {
608 $this->mModules
= array_merge( $this->mModules
, (array)$modules );
611 public function addModuleScripts( $modules ) {
612 $this->mModuleScripts
= array_merge( $this->mModuleScripts
, (array)$modules );
615 public function addModuleStyles( $modules ) {
616 $this->mModuleStyles
= array_merge( $this->mModuleStyles
, (array)$modules );
620 * @deprecated since 1.26 Use addModules() instead
621 * @param string|array $modules
623 public function addModuleMessages( $modules ) {
624 wfDeprecated( __METHOD__
, '1.26' );
628 * Add one or more variables to be set in mw.config in JavaScript.
630 * @param string|array $keys Key or array of key/value pairs.
631 * @param mixed $value [optional] Value of the configuration variable.
634 public function addJsConfigVars( $keys, $value = null ) {
635 if ( is_array( $keys ) ) {
636 foreach ( $keys as $key => $value ) {
637 $this->mJsConfigVars
[$key] = $value;
642 $this->mJsConfigVars
[$keys] = $value;
646 * Copy items from the OutputPage object into this one
648 * @param OutputPage $out
650 public function addOutputPageMetadata( OutputPage
$out ) {
651 $this->addModules( $out->getModules() );
652 $this->addModuleScripts( $out->getModuleScripts() );
653 $this->addModuleStyles( $out->getModuleStyles() );
654 $this->addJsConfigVars( $out->getJsConfigVars() );
656 $this->mHeadItems
= array_merge( $this->mHeadItems
, $out->getHeadItemsArray() );
657 $this->mPreventClickjacking
= $this->mPreventClickjacking ||
$out->getPreventClickjacking();
661 * Add a tracking category, getting the title from a system message,
662 * or print a debug message if the title is invalid.
664 * Any message used with this function should be registered so it will
665 * show up on Special:TrackingCategories. Core messages should be added
666 * to SpecialTrackingCategories::$coreTrackingCategories, and extensions
667 * should add to "TrackingCategories" in their extension.json.
669 * @param string $msg Message key
670 * @param Title $title title of the page which is being tracked
671 * @return bool Whether the addition was successful
674 public function addTrackingCategory( $msg, $title ) {
675 if ( $title->getNamespace() === NS_SPECIAL
) {
676 wfDebug( __METHOD__
. ": Not adding tracking category $msg to special page!\n" );
680 // Important to parse with correct title (bug 31469)
681 $cat = wfMessage( $msg )
683 ->inContentLanguage()
686 # Allow tracking categories to be disabled by setting them to "-"
687 if ( $cat === '-' ) {
691 $containerCategory = Title
::makeTitleSafe( NS_CATEGORY
, $cat );
692 if ( $containerCategory ) {
693 $this->addCategory( $containerCategory->getDBkey(), $this->getProperty( 'defaultsort' ) ?
: '' );
696 wfDebug( __METHOD__
. ": [[MediaWiki:$msg]] is not a valid title!\n" );
702 * Override the title to be used for display
704 * @note this is assumed to have been validated
705 * (check equal normalisation, etc.)
707 * @note this is expected to be safe HTML,
708 * ready to be served to the client.
710 * @param string $text Desired title text
712 public function setDisplayTitle( $text ) {
713 $this->setTitleText( $text );
714 $this->setProperty( 'displaytitle', $text );
718 * Get the title to be used for display.
720 * As per the contract of setDisplayTitle(), this is safe HTML,
721 * ready to be served to the client.
723 * @return string HTML
725 public function getDisplayTitle() {
726 $t = $this->getTitleText();
734 * Fairly generic flag setter thingy.
735 * @param string $flag
737 public function setFlag( $flag ) {
738 $this->mFlags
[$flag] = true;
741 public function getFlag( $flag ) {
742 return isset( $this->mFlags
[$flag] );
746 * Set a property to be stored in the page_props database table.
748 * page_props is a key value store indexed by the page ID. This allows
749 * the parser to set a property on a page which can then be quickly
750 * retrieved given the page ID or via a DB join when given the page
753 * Since 1.23, page_props are also indexed by numeric value, to allow
754 * for efficient "top k" queries of pages wrt a given property.
756 * setProperty() is thus used to propagate properties from the parsed
757 * page to request contexts other than a page view of the currently parsed
760 * Some applications examples:
762 * * To implement hidden categories, hiding pages from category listings
763 * by storing a property.
765 * * Overriding the displayed article title.
766 * @see ParserOutput::setDisplayTitle()
768 * * To implement image tagging, for example displaying an icon on an
769 * image thumbnail to indicate that it is listed for deletion on
771 * This is not actually implemented, yet but would be pretty cool.
773 * @note Do not use setProperty() to set a property which is only used
774 * in a context where the ParserOutput object itself is already available,
775 * for example a normal page view. There is no need to save such a property
776 * in the database since the text is already parsed. You can just hook
777 * OutputPageParserOutput and get your data out of the ParserOutput object.
779 * If you are writing an extension where you want to set a property in the
780 * parser which is used by an OutputPageParserOutput hook, you have to
781 * associate the extension data directly with the ParserOutput object.
782 * Since MediaWiki 1.21, you can use setExtensionData() to do this:
786 * $parser->getOutput()->setExtensionData( 'my_ext_foo', '...' );
789 * And then later, in OutputPageParserOutput or similar:
793 * $output->getExtensionData( 'my_ext_foo' );
796 * In MediaWiki 1.20 and older, you have to use a custom member variable
797 * within the ParserOutput object:
801 * $parser->getOutput()->my_ext_foo = '...';
805 public function setProperty( $name, $value ) {
806 $this->mProperties
[$name] = $value;
810 * @param string $name The property name to look up.
812 * @return mixed|bool The value previously set using setProperty(). False if null or no value
813 * was set for the given property name.
815 * @note You need to use getProperties() to check for boolean and null properties.
817 public function getProperty( $name ) {
818 return isset( $this->mProperties
[$name] ) ?
$this->mProperties
[$name] : false;
821 public function unsetProperty( $name ) {
822 unset( $this->mProperties
[$name] );
825 public function getProperties() {
826 if ( !isset( $this->mProperties
) ) {
827 $this->mProperties
= array();
829 return $this->mProperties
;
833 * Returns the options from its ParserOptions which have been taken
834 * into account to produce this output or false if not available.
837 public function getUsedOptions() {
838 if ( !isset( $this->mAccessedOptions
) ) {
841 return array_keys( $this->mAccessedOptions
);
845 * Tags a parser option for use in the cache key for this parser output.
846 * Registered as a watcher at ParserOptions::registerWatcher() by Parser::clearState().
847 * The information gathered here is available via getUsedOptions(),
848 * and is used by ParserCache::save().
850 * @see ParserCache::getKey
851 * @see ParserCache::save
852 * @see ParserOptions::addExtraKey
853 * @see ParserOptions::optionsHash
854 * @param string $option
856 public function recordOption( $option ) {
857 $this->mAccessedOptions
[$option] = true;
861 * @deprecated since 1.25. Instead, store any relevant data using setExtensionData,
862 * and implement Content::getSecondaryDataUpdates() if possible, or use the
863 * 'SecondaryDataUpdates' hook to construct the necessary update objects.
865 * @note Hard deprecation and removal without long deprecation period, since there are no
866 * known users, but known conceptual issues.
868 * @todo remove in 1.26
870 * @param DataUpdate $update
872 * @throws MWException
874 public function addSecondaryDataUpdate( DataUpdate
$update ) {
875 wfDeprecated( __METHOD__
, '1.25' );
876 throw new MWException(
877 'ParserOutput::addSecondaryDataUpdate() is no longer supported. ' .
878 'Override Content::getSecondaryDataUpdates() ' .
879 'or use the SecondaryDataUpdates hook instead.'
884 * @deprecated since 1.25.
886 * @note Hard deprecation and removal without long deprecation period, since there are no
887 * known users, but known conceptual issues.
889 * @todo remove in 1.26
891 * @return bool false (since 1.25)
893 public function hasCustomDataUpdates() {
894 wfDeprecated( __METHOD__
, '1.25' );
899 * @deprecated since 1.25. Instead, store any relevant data using setExtensionData,
900 * and implement Content::getSecondaryDataUpdates() if possible, or use the
901 * 'SecondaryDataUpdates' hook to construct the necessary update objects.
903 * @note Hard deprecation and removal without long deprecation period, since there are no
904 * known users, but known conceptual issues.
906 * @todo remove in 1.26
908 * @param Title $title
909 * @param bool $recursive
911 * @return array An array of instances of DataUpdate
913 public function getSecondaryDataUpdates( Title
$title = null, $recursive = true ) {
914 wfDeprecated( __METHOD__
, '1.25' );
919 * Attaches arbitrary data to this ParserObject. This can be used to store some information in
920 * the ParserOutput object for later use during page output. The data will be cached along with
921 * the ParserOutput object, but unlike data set using setProperty(), it is not recorded in the
924 * This method is provided to overcome the unsafe practice of attaching extra information to a
925 * ParserObject by directly assigning member variables.
927 * To use setExtensionData() to pass extension information from a hook inside the parser to a
928 * hook in the page output, use this in the parser hook:
932 * $parser->getOutput()->setExtensionData( 'my_ext_foo', '...' );
935 * And then later, in OutputPageParserOutput or similar:
939 * $output->getExtensionData( 'my_ext_foo' );
942 * In MediaWiki 1.20 and older, you have to use a custom member variable
943 * within the ParserOutput object:
947 * $parser->getOutput()->my_ext_foo = '...';
952 * @param string $key The key for accessing the data. Extensions should take care to avoid
953 * conflicts in naming keys. It is suggested to use the extension's name as a prefix.
955 * @param mixed $value The value to set. Setting a value to null is equivalent to removing
958 public function setExtensionData( $key, $value ) {
959 if ( $value === null ) {
960 unset( $this->mExtensionData
[$key] );
962 $this->mExtensionData
[$key] = $value;
967 * Gets extensions data previously attached to this ParserOutput using setExtensionData().
968 * Typically, such data would be set while parsing the page, e.g. by a parser function.
972 * @param string $key The key to look up.
974 * @return mixed|null The value previously set for the given key using setExtensionData()
975 * or null if no value was set for this key.
977 public function getExtensionData( $key ) {
978 if ( isset( $this->mExtensionData
[$key] ) ) {
979 return $this->mExtensionData
[$key];
985 private static function getTimes( $clock = null ) {
987 if ( !$clock ||
$clock === 'wall' ) {
988 $ret['wall'] = microtime( true );
990 if ( !$clock ||
$clock === 'cpu' ) {
993 $ret['cpu'] = $ru['ru_utime.tv_sec'] +
$ru['ru_utime.tv_usec'] / 1e6
;
994 $ret['cpu'] +
= $ru['ru_stime.tv_sec'] +
$ru['ru_stime.tv_usec'] / 1e6
;
1001 * Resets the parse start timestamps for future calls to getTimeSinceStart()
1004 public function resetParseStartTime() {
1005 $this->mParseStartTime
= self
::getTimes();
1009 * Returns the time since resetParseStartTime() was last called
1011 * Clocks available are:
1012 * - wall: Wall clock time
1013 * - cpu: CPU time (requires getrusage)
1016 * @param string $clock
1017 * @return float|null
1019 public function getTimeSinceStart( $clock ) {
1020 if ( !isset( $this->mParseStartTime
[$clock] ) ) {
1024 $end = self
::getTimes( $clock );
1025 return $end[$clock] - $this->mParseStartTime
[$clock];
1029 * Sets parser limit report data for a key
1031 * The key is used as the prefix for various messages used for formatting:
1032 * - $key: The label for the field in the limit report
1033 * - $key-value-text: Message used to format the value in the "NewPP limit
1034 * report" HTML comment. If missing, uses $key-format.
1035 * - $key-value-html: Message used to format the value in the preview
1036 * limit report table. If missing, uses $key-format.
1037 * - $key-value: Message used to format the value. If missing, uses "$1".
1039 * Note that all values are interpreted as wikitext, and so should be
1040 * encoded with htmlspecialchars() as necessary, but should avoid complex
1041 * HTML for sanity of display in the "NewPP limit report" comment.
1044 * @param string $key Message key
1045 * @param mixed $value Appropriate for Message::params()
1047 public function setLimitReportData( $key, $value ) {
1048 $this->mLimitReportData
[$key] = $value;
1052 * Check whether the cache TTL was lowered due to dynamic content
1054 * When content is determined by more than hard state (e.g. page edits),
1055 * such as template/file transclusions based on the current timestamp or
1056 * extension tags that generate lists based on queries, this return true.
1061 public function hasDynamicContent() {
1062 global $wgParserCacheExpireTime;
1064 return $this->getCacheExpiry() < $wgParserCacheExpireTime;
1068 * Get or set the prevent-clickjacking flag
1071 * @param bool|null $flag New flag value, or null to leave it unchanged
1072 * @return bool Old flag value
1074 public function preventClickjacking( $flag = null ) {
1075 return wfSetVar( $this->mPreventClickjacking
, $flag );
1079 * Save space for serialization by removing useless values
1082 public function __sleep() {
1084 array_keys( get_object_vars( $this ) ),
1085 array( 'mParseStartTime' )