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
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
703 * -- this is assumed to have been validated
704 * (check equal normalisation, etc.)
706 * @param string $text Desired title text
708 public function setDisplayTitle( $text ) {
709 $this->setTitleText( $text );
710 $this->setProperty( 'displaytitle', $text );
714 * Get the title to be used for display
718 public function getDisplayTitle() {
719 $t = $this->getTitleText();
727 * Fairly generic flag setter thingy.
728 * @param string $flag
730 public function setFlag( $flag ) {
731 $this->mFlags
[$flag] = true;
734 public function getFlag( $flag ) {
735 return isset( $this->mFlags
[$flag] );
739 * Set a property to be stored in the page_props database table.
741 * page_props is a key value store indexed by the page ID. This allows
742 * the parser to set a property on a page which can then be quickly
743 * retrieved given the page ID or via a DB join when given the page
746 * Since 1.23, page_props are also indexed by numeric value, to allow
747 * for efficient "top k" queries of pages wrt a given property.
749 * setProperty() is thus used to propagate properties from the parsed
750 * page to request contexts other than a page view of the currently parsed
753 * Some applications examples:
755 * * To implement hidden categories, hiding pages from category listings
756 * by storing a property.
758 * * Overriding the displayed article title.
759 * @see ParserOutput::setDisplayTitle()
761 * * To implement image tagging, for example displaying an icon on an
762 * image thumbnail to indicate that it is listed for deletion on
764 * This is not actually implemented, yet but would be pretty cool.
766 * @note Do not use setProperty() to set a property which is only used
767 * in a context where the ParserOutput object itself is already available,
768 * for example a normal page view. There is no need to save such a property
769 * in the database since the text is already parsed. You can just hook
770 * OutputPageParserOutput and get your data out of the ParserOutput object.
772 * If you are writing an extension where you want to set a property in the
773 * parser which is used by an OutputPageParserOutput hook, you have to
774 * associate the extension data directly with the ParserOutput object.
775 * Since MediaWiki 1.21, you can use setExtensionData() to do this:
779 * $parser->getOutput()->setExtensionData( 'my_ext_foo', '...' );
782 * And then later, in OutputPageParserOutput or similar:
786 * $output->getExtensionData( 'my_ext_foo' );
789 * In MediaWiki 1.20 and older, you have to use a custom member variable
790 * within the ParserOutput object:
794 * $parser->getOutput()->my_ext_foo = '...';
798 public function setProperty( $name, $value ) {
799 $this->mProperties
[$name] = $value;
803 * @param string $name The property name to look up.
805 * @return mixed|bool The value previously set using setProperty(). False if null or no value
806 * was set for the given property name.
808 * @note You need to use getProperties() to check for boolean and null properties.
810 public function getProperty( $name ) {
811 return isset( $this->mProperties
[$name] ) ?
$this->mProperties
[$name] : false;
814 public function unsetProperty( $name ) {
815 unset( $this->mProperties
[$name] );
818 public function getProperties() {
819 if ( !isset( $this->mProperties
) ) {
820 $this->mProperties
= array();
822 return $this->mProperties
;
826 * Returns the options from its ParserOptions which have been taken
827 * into account to produce this output or false if not available.
830 public function getUsedOptions() {
831 if ( !isset( $this->mAccessedOptions
) ) {
834 return array_keys( $this->mAccessedOptions
);
838 * Tags a parser option for use in the cache key for this parser output.
839 * Registered as a watcher at ParserOptions::registerWatcher() by Parser::clearState().
840 * The information gathered here is available via getUsedOptions(),
841 * and is used by ParserCache::save().
843 * @see ParserCache::getKey
844 * @see ParserCache::save
845 * @see ParserOptions::addExtraKey
846 * @see ParserOptions::optionsHash
847 * @param string $option
849 public function recordOption( $option ) {
850 $this->mAccessedOptions
[$option] = true;
854 * @deprecated since 1.25. Instead, store any relevant data using setExtensionData,
855 * and implement Content::getSecondaryDataUpdates() if possible, or use the
856 * 'SecondaryDataUpdates' hook to construct the necessary update objects.
858 * @note Hard deprecation and removal without long deprecation period, since there are no
859 * known users, but known conceptual issues.
861 * @todo remove in 1.26
863 * @param DataUpdate $update
865 * @throws MWException
867 public function addSecondaryDataUpdate( DataUpdate
$update ) {
868 wfDeprecated( __METHOD__
, '1.25' );
869 throw new MWException(
870 'ParserOutput::addSecondaryDataUpdate() is no longer supported. ' .
871 'Override Content::getSecondaryDataUpdates() ' .
872 'or use the SecondaryDataUpdates hook instead.'
877 * @deprecated since 1.25.
879 * @note Hard deprecation and removal without long deprecation period, since there are no
880 * known users, but known conceptual issues.
882 * @todo remove in 1.26
884 * @return bool false (since 1.25)
886 public function hasCustomDataUpdates() {
887 wfDeprecated( __METHOD__
, '1.25' );
892 * @deprecated since 1.25. Instead, store any relevant data using setExtensionData,
893 * and implement Content::getSecondaryDataUpdates() if possible, or use the
894 * 'SecondaryDataUpdates' hook to construct the necessary update objects.
896 * @note Hard deprecation and removal without long deprecation period, since there are no
897 * known users, but known conceptual issues.
899 * @todo remove in 1.26
901 * @param Title $title
902 * @param bool $recursive
904 * @return array An array of instances of DataUpdate
906 public function getSecondaryDataUpdates( Title
$title = null, $recursive = true ) {
907 wfDeprecated( __METHOD__
, '1.25' );
912 * Attaches arbitrary data to this ParserObject. This can be used to store some information in
913 * the ParserOutput object for later use during page output. The data will be cached along with
914 * the ParserOutput object, but unlike data set using setProperty(), it is not recorded in the
917 * This method is provided to overcome the unsafe practice of attaching extra information to a
918 * ParserObject by directly assigning member variables.
920 * To use setExtensionData() to pass extension information from a hook inside the parser to a
921 * hook in the page output, use this in the parser hook:
925 * $parser->getOutput()->setExtensionData( 'my_ext_foo', '...' );
928 * And then later, in OutputPageParserOutput or similar:
932 * $output->getExtensionData( 'my_ext_foo' );
935 * In MediaWiki 1.20 and older, you have to use a custom member variable
936 * within the ParserOutput object:
940 * $parser->getOutput()->my_ext_foo = '...';
945 * @param string $key The key for accessing the data. Extensions should take care to avoid
946 * conflicts in naming keys. It is suggested to use the extension's name as a prefix.
948 * @param mixed $value The value to set. Setting a value to null is equivalent to removing
951 public function setExtensionData( $key, $value ) {
952 if ( $value === null ) {
953 unset( $this->mExtensionData
[$key] );
955 $this->mExtensionData
[$key] = $value;
960 * Gets extensions data previously attached to this ParserOutput using setExtensionData().
961 * Typically, such data would be set while parsing the page, e.g. by a parser function.
965 * @param string $key The key to look up.
967 * @return mixed|null The value previously set for the given key using setExtensionData()
968 * or null if no value was set for this key.
970 public function getExtensionData( $key ) {
971 if ( isset( $this->mExtensionData
[$key] ) ) {
972 return $this->mExtensionData
[$key];
978 private static function getTimes( $clock = null ) {
980 if ( !$clock ||
$clock === 'wall' ) {
981 $ret['wall'] = microtime( true );
983 if ( !$clock ||
$clock === 'cpu' ) {
986 $ret['cpu'] = $ru['ru_utime.tv_sec'] +
$ru['ru_utime.tv_usec'] / 1e6
;
987 $ret['cpu'] +
= $ru['ru_stime.tv_sec'] +
$ru['ru_stime.tv_usec'] / 1e6
;
994 * Resets the parse start timestamps for future calls to getTimeSinceStart()
997 public function resetParseStartTime() {
998 $this->mParseStartTime
= self
::getTimes();
1002 * Returns the time since resetParseStartTime() was last called
1004 * Clocks available are:
1005 * - wall: Wall clock time
1006 * - cpu: CPU time (requires getrusage)
1009 * @param string $clock
1010 * @return float|null
1012 public function getTimeSinceStart( $clock ) {
1013 if ( !isset( $this->mParseStartTime
[$clock] ) ) {
1017 $end = self
::getTimes( $clock );
1018 return $end[$clock] - $this->mParseStartTime
[$clock];
1022 * Sets parser limit report data for a key
1024 * The key is used as the prefix for various messages used for formatting:
1025 * - $key: The label for the field in the limit report
1026 * - $key-value-text: Message used to format the value in the "NewPP limit
1027 * report" HTML comment. If missing, uses $key-format.
1028 * - $key-value-html: Message used to format the value in the preview
1029 * limit report table. If missing, uses $key-format.
1030 * - $key-value: Message used to format the value. If missing, uses "$1".
1032 * Note that all values are interpreted as wikitext, and so should be
1033 * encoded with htmlspecialchars() as necessary, but should avoid complex
1034 * HTML for sanity of display in the "NewPP limit report" comment.
1037 * @param string $key Message key
1038 * @param mixed $value Appropriate for Message::params()
1040 public function setLimitReportData( $key, $value ) {
1041 $this->mLimitReportData
[$key] = $value;
1045 * Check whether the cache TTL was lowered due to dynamic content
1047 * When content is determined by more than hard state (e.g. page edits),
1048 * such as template/file transclusions based on the current timestamp or
1049 * extension tags that generate lists based on queries, this return true.
1054 public function hasDynamicContent() {
1055 global $wgParserCacheExpireTime;
1057 return $this->getCacheExpiry() < $wgParserCacheExpireTime;
1061 * Get or set the prevent-clickjacking flag
1064 * @param bool|null $flag New flag value, or null to leave it unchanged
1065 * @return bool Old flag value
1067 public function preventClickjacking( $flag = null ) {
1068 return wfSetVar( $this->mPreventClickjacking
, $flag );
1072 * Save space for serialization by removing useless values
1075 public function __sleep() {
1077 array_keys( get_object_vars( $this ) ),
1078 array( 'mParseStartTime' )