Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like ParserOutput often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ParserOutput, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 24 | class ParserOutput extends CacheTime { |
||
| 25 | /** |
||
| 26 | * @var string $mText The output text |
||
| 27 | */ |
||
| 28 | public $mText; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var array $mLanguageLinks List of the full text of language links, |
||
| 32 | * in the order they appear. |
||
| 33 | */ |
||
| 34 | public $mLanguageLinks; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var array $mCategoriesMap of category names to sort keys |
||
| 38 | */ |
||
| 39 | public $mCategories; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var array $mIndicators Page status indicators, usually displayed in top-right corner. |
||
| 43 | */ |
||
| 44 | public $mIndicators = []; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var string $mTitleText Title text of the chosen language variant, as HTML. |
||
| 48 | */ |
||
| 49 | public $mTitleText; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var array $mLinks 2-D map of NS/DBK to ID for the links in the document. |
||
| 53 | * ID=zero for broken. |
||
| 54 | */ |
||
| 55 | public $mLinks = []; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @var array $mTemplates 2-D map of NS/DBK to ID for the template references. |
||
| 59 | * ID=zero for broken. |
||
| 60 | */ |
||
| 61 | public $mTemplates = []; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var array $mTemplateIds 2-D map of NS/DBK to rev ID for the template references. |
||
| 65 | * ID=zero for broken. |
||
| 66 | */ |
||
| 67 | public $mTemplateIds = []; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var array $mImages DB keys of the images used, in the array key only |
||
| 71 | */ |
||
| 72 | public $mImages = []; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var array $mFileSearchOptions DB keys of the images used mapped to sha1 and MW timestamp. |
||
| 76 | */ |
||
| 77 | public $mFileSearchOptions = []; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var array $mExternalLinks External link URLs, in the key only. |
||
| 81 | */ |
||
| 82 | public $mExternalLinks = []; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var array $mInterwikiLinks 2-D map of prefix/DBK (in keys only) |
||
| 86 | * for the inline interwiki links in the document. |
||
| 87 | */ |
||
| 88 | public $mInterwikiLinks = []; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @var bool $mNewSection Show a new section link? |
||
| 92 | */ |
||
| 93 | public $mNewSection = false; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @var bool $mHideNewSection Hide the new section link? |
||
| 97 | */ |
||
| 98 | public $mHideNewSection = false; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @var bool $mNoGallery No gallery on category page? (__NOGALLERY__). |
||
| 102 | */ |
||
| 103 | public $mNoGallery = false; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @var array $mHeadItems Items to put in the <head> section |
||
| 107 | */ |
||
| 108 | public $mHeadItems = []; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @var array $mModules Modules to be loaded by ResourceLoader |
||
| 112 | */ |
||
| 113 | public $mModules = []; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @var array $mModuleScripts Modules of which only the JS will be loaded by ResourceLoader. |
||
| 117 | */ |
||
| 118 | public $mModuleScripts = []; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @var array $mModuleStyles Modules of which only the CSSS will be loaded by ResourceLoader. |
||
| 122 | */ |
||
| 123 | public $mModuleStyles = []; |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @var array $mJsConfigVars JavaScript config variable for mw.config combined with this page. |
||
| 127 | */ |
||
| 128 | public $mJsConfigVars = []; |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @var array $mOutputHooks Hook tags as per $wgParserOutputHooks. |
||
| 132 | */ |
||
| 133 | public $mOutputHooks = []; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @var array $mWarnings Warning text to be returned to the user. |
||
| 137 | * Wikitext formatted, in the key only. |
||
| 138 | */ |
||
| 139 | public $mWarnings = []; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @var array $mSections Table of contents |
||
| 143 | */ |
||
| 144 | public $mSections = []; |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @var bool $mEditSectionTokens prefix/suffix markers if edit sections were output as tokens. |
||
| 148 | */ |
||
| 149 | public $mEditSectionTokens = false; |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @var array $mProperties Name/value pairs to be cached in the DB. |
||
| 153 | */ |
||
| 154 | public $mProperties = []; |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @var string $mTOCHTML HTML of the TOC. |
||
| 158 | */ |
||
| 159 | public $mTOCHTML = ''; |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @var string $mTimestamp Timestamp of the revision. |
||
| 163 | */ |
||
| 164 | public $mTimestamp; |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @var bool $mTOCEnabled Whether TOC should be shown, can't override __NOTOC__. |
||
| 168 | */ |
||
| 169 | public $mTOCEnabled = true; |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @var bool $mEnableOOUI Whether OOUI should be enabled. |
||
| 173 | */ |
||
| 174 | public $mEnableOOUI = false; |
||
| 175 | |||
| 176 | /** |
||
| 177 | * @var string $mIndexPolicy 'index' or 'noindex'? Any other value will result in no change. |
||
| 178 | */ |
||
| 179 | private $mIndexPolicy = ''; |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @var array $mAccessedOptions List of ParserOptions (stored in the keys). |
||
| 183 | */ |
||
| 184 | private $mAccessedOptions = []; |
||
| 185 | |||
| 186 | /** |
||
| 187 | * @var array $mExtensionData extra data used by extensions. |
||
| 188 | */ |
||
| 189 | private $mExtensionData = []; |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @var array $mLimitReportData Parser limit report data. |
||
| 193 | */ |
||
| 194 | private $mLimitReportData = []; |
||
| 195 | |||
| 196 | /** |
||
| 197 | * @var array $mParseStartTime Timestamps for getTimeSinceStart(). |
||
| 198 | */ |
||
| 199 | private $mParseStartTime = []; |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @var bool $mPreventClickjacking Whether to emit X-Frame-Options: DENY. |
||
| 203 | */ |
||
| 204 | private $mPreventClickjacking = false; |
||
| 205 | |||
| 206 | /** |
||
| 207 | * @var array $mFlags Generic flags. |
||
| 208 | */ |
||
| 209 | private $mFlags = []; |
||
| 210 | |||
| 211 | const EDITSECTION_REGEX = |
||
| 212 | '#<(?:mw:)?editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)(</(?:mw:)?editsection>))#'; |
||
| 213 | |||
| 214 | public function __construct( $text = '', $languageLinks = [], $categoryLinks = [], |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Get the cacheable text with <mw:editsection> markers still in it. The |
||
| 225 | * return value is suitable for writing back via setText() but is not valid |
||
| 226 | * for display to the user. |
||
| 227 | * |
||
| 228 | * @since 1.27 |
||
| 229 | */ |
||
| 230 | public function getRawText() { |
||
| 233 | |||
| 234 | public function getText() { |
||
| 274 | |||
| 275 | public function &getLanguageLinks() { |
||
| 278 | |||
| 279 | public function getInterwikiLinks() { |
||
| 282 | |||
| 283 | public function getCategoryLinks() { |
||
| 286 | |||
| 287 | public function &getCategories() { |
||
| 290 | |||
| 291 | /** |
||
| 292 | * @since 1.25 |
||
| 293 | */ |
||
| 294 | public function getIndicators() { |
||
| 297 | |||
| 298 | public function getTitleText() { |
||
| 301 | |||
| 302 | public function getSections() { |
||
| 305 | |||
| 306 | public function getEditSectionTokens() { |
||
| 309 | |||
| 310 | public function &getLinks() { |
||
| 313 | |||
| 314 | public function &getTemplates() { |
||
| 317 | |||
| 318 | public function &getTemplateIds() { |
||
| 321 | |||
| 322 | public function &getImages() { |
||
| 325 | |||
| 326 | public function &getFileSearchOptions() { |
||
| 329 | |||
| 330 | public function &getExternalLinks() { |
||
| 333 | |||
| 334 | public function getNoGallery() { |
||
| 337 | |||
| 338 | public function getHeadItems() { |
||
| 341 | |||
| 342 | public function getModules() { |
||
| 345 | |||
| 346 | public function getModuleScripts() { |
||
| 349 | |||
| 350 | public function getModuleStyles() { |
||
| 353 | |||
| 354 | /** |
||
| 355 | * @deprecated since 1.26 Obsolete |
||
| 356 | * @return array |
||
| 357 | */ |
||
| 358 | public function getModuleMessages() { |
||
| 362 | |||
| 363 | /** @since 1.23 */ |
||
| 364 | public function getJsConfigVars() { |
||
| 367 | |||
| 368 | public function getOutputHooks() { |
||
| 371 | |||
| 372 | public function getWarnings() { |
||
| 375 | |||
| 376 | public function getIndexPolicy() { |
||
| 379 | |||
| 380 | public function getTOCHTML() { |
||
| 383 | |||
| 384 | /** |
||
| 385 | * @return string|null TS_MW timestamp of the revision content |
||
| 386 | */ |
||
| 387 | public function getTimestamp() { |
||
| 390 | |||
| 391 | public function getLimitReportData() { |
||
| 394 | |||
| 395 | public function getTOCEnabled() { |
||
| 398 | |||
| 399 | public function getEnableOOUI() { |
||
| 402 | |||
| 403 | public function setText( $text ) { |
||
| 406 | |||
| 407 | public function setLanguageLinks( $ll ) { |
||
| 410 | |||
| 411 | public function setCategoryLinks( $cl ) { |
||
| 414 | |||
| 415 | public function setTitleText( $t ) { |
||
| 418 | |||
| 419 | public function setSections( $toc ) { |
||
| 422 | |||
| 423 | public function setEditSectionTokens( $t ) { |
||
| 426 | |||
| 427 | public function setIndexPolicy( $policy ) { |
||
| 430 | |||
| 431 | public function setTOCHTML( $tochtml ) { |
||
| 434 | |||
| 435 | public function setTimestamp( $timestamp ) { |
||
| 438 | |||
| 439 | public function setTOCEnabled( $flag ) { |
||
| 442 | |||
| 443 | public function addCategory( $c, $sort ) { |
||
| 446 | |||
| 447 | /** |
||
| 448 | * @since 1.25 |
||
| 449 | */ |
||
| 450 | public function setIndicator( $id, $content ) { |
||
| 453 | |||
| 454 | /** |
||
| 455 | * Enables OOUI, if true, in any OutputPage instance this ParserOutput |
||
| 456 | * object is added to. |
||
| 457 | * |
||
| 458 | * @since 1.26 |
||
| 459 | * @param bool $enable If OOUI should be enabled or not |
||
| 460 | */ |
||
| 461 | public function setEnableOOUI( $enable = false ) { |
||
| 464 | |||
| 465 | public function addLanguageLink( $t ) { |
||
| 468 | |||
| 469 | public function addWarning( $s ) { |
||
| 472 | |||
| 473 | public function addOutputHook( $hook, $data = false ) { |
||
| 476 | |||
| 477 | public function setNewSection( $value ) { |
||
| 489 | |||
| 490 | /** |
||
| 491 | * Checks, if a url is pointing to the own server |
||
| 492 | * |
||
| 493 | * @param string $internal The server to check against |
||
| 494 | * @param string $url The url to check |
||
| 495 | * @return bool |
||
| 496 | */ |
||
| 497 | public static function isLinkInternal( $internal, $url ) { |
||
| 507 | |||
| 508 | public function addExternalLink( $url ) { |
||
| 520 | |||
| 521 | /** |
||
| 522 | * Record a local or interwiki inline link for saving in future link tables. |
||
| 523 | * |
||
| 524 | * @param Title $title |
||
| 525 | * @param int|null $id Optional known page_id so we can skip the lookup |
||
| 526 | */ |
||
| 527 | public function addLink( Title $title, $id = null ) { |
||
| 554 | |||
| 555 | /** |
||
| 556 | * Register a file dependency for this output |
||
| 557 | * @param string $name Title dbKey |
||
| 558 | * @param string $timestamp MW timestamp of file creation (or false if non-existing) |
||
| 559 | * @param string $sha1 Base 36 SHA-1 of file (or false if non-existing) |
||
| 560 | * @return void |
||
| 561 | */ |
||
| 562 | public function addImage( $name, $timestamp = null, $sha1 = null ) { |
||
| 568 | |||
| 569 | /** |
||
| 570 | * Register a template dependency for this output |
||
| 571 | * @param Title $title |
||
| 572 | * @param int $page_id |
||
| 573 | * @param int $rev_id |
||
| 574 | * @return void |
||
| 575 | */ |
||
| 576 | public function addTemplate( $title, $page_id, $rev_id ) { |
||
| 588 | |||
| 589 | /** |
||
| 590 | * @param Title $title Title object, must be an interwiki link |
||
| 591 | * @throws MWException If given invalid input |
||
| 592 | */ |
||
| 593 | public function addInterwikiLink( $title ) { |
||
| 603 | |||
| 604 | /** |
||
| 605 | * Add some text to the "<head>". |
||
| 606 | * If $tag is set, the section with that tag will only be included once |
||
| 607 | * in a given page. |
||
| 608 | * @param string $section |
||
| 609 | * @param string|bool $tag |
||
| 610 | */ |
||
| 611 | public function addHeadItem( $section, $tag = false ) { |
||
| 618 | |||
| 619 | public function addModules( $modules ) { |
||
| 622 | |||
| 623 | public function addModuleScripts( $modules ) { |
||
| 626 | |||
| 627 | public function addModuleStyles( $modules ) { |
||
| 630 | |||
| 631 | /** |
||
| 632 | * @deprecated since 1.26 Use addModules() instead |
||
| 633 | * @param string|array $modules |
||
| 634 | */ |
||
| 635 | public function addModuleMessages( $modules ) { |
||
| 638 | |||
| 639 | /** |
||
| 640 | * Add one or more variables to be set in mw.config in JavaScript. |
||
| 641 | * |
||
| 642 | * @param string|array $keys Key or array of key/value pairs. |
||
| 643 | * @param mixed $value [optional] Value of the configuration variable. |
||
| 644 | * @since 1.23 |
||
| 645 | */ |
||
| 646 | View Code Duplication | public function addJsConfigVars( $keys, $value = null ) { |
|
| 656 | |||
| 657 | /** |
||
| 658 | * Copy items from the OutputPage object into this one |
||
| 659 | * |
||
| 660 | * @param OutputPage $out |
||
| 661 | */ |
||
| 662 | public function addOutputPageMetadata( OutputPage $out ) { |
||
| 671 | |||
| 672 | /** |
||
| 673 | * Add a tracking category, getting the title from a system message, |
||
| 674 | * or print a debug message if the title is invalid. |
||
| 675 | * |
||
| 676 | * Any message used with this function should be registered so it will |
||
| 677 | * show up on Special:TrackingCategories. Core messages should be added |
||
| 678 | * to SpecialTrackingCategories::$coreTrackingCategories, and extensions |
||
| 679 | * should add to "TrackingCategories" in their extension.json. |
||
| 680 | * |
||
| 681 | * @param string $msg Message key |
||
| 682 | * @param Title $title title of the page which is being tracked |
||
| 683 | * @return bool Whether the addition was successful |
||
| 684 | * @since 1.25 |
||
| 685 | */ |
||
| 686 | public function addTrackingCategory( $msg, $title ) { |
||
| 712 | |||
| 713 | /** |
||
| 714 | * Override the title to be used for display |
||
| 715 | * |
||
| 716 | * @note this is assumed to have been validated |
||
| 717 | * (check equal normalisation, etc.) |
||
| 718 | * |
||
| 719 | * @note this is expected to be safe HTML, |
||
| 720 | * ready to be served to the client. |
||
| 721 | * |
||
| 722 | * @param string $text Desired title text |
||
| 723 | */ |
||
| 724 | public function setDisplayTitle( $text ) { |
||
| 728 | |||
| 729 | /** |
||
| 730 | * Get the title to be used for display. |
||
| 731 | * |
||
| 732 | * As per the contract of setDisplayTitle(), this is safe HTML, |
||
| 733 | * ready to be served to the client. |
||
| 734 | * |
||
| 735 | * @return string HTML |
||
| 736 | */ |
||
| 737 | public function getDisplayTitle() { |
||
| 744 | |||
| 745 | /** |
||
| 746 | * Fairly generic flag setter thingy. |
||
| 747 | * @param string $flag |
||
| 748 | */ |
||
| 749 | public function setFlag( $flag ) { |
||
| 752 | |||
| 753 | public function getFlag( $flag ) { |
||
| 756 | |||
| 757 | /** |
||
| 758 | * Set a property to be stored in the page_props database table. |
||
| 759 | * |
||
| 760 | * page_props is a key value store indexed by the page ID. This allows |
||
| 761 | * the parser to set a property on a page which can then be quickly |
||
| 762 | * retrieved given the page ID or via a DB join when given the page |
||
| 763 | * title. |
||
| 764 | * |
||
| 765 | * Since 1.23, page_props are also indexed by numeric value, to allow |
||
| 766 | * for efficient "top k" queries of pages wrt a given property. |
||
| 767 | * |
||
| 768 | * setProperty() is thus used to propagate properties from the parsed |
||
| 769 | * page to request contexts other than a page view of the currently parsed |
||
| 770 | * article. |
||
| 771 | * |
||
| 772 | * Some applications examples: |
||
| 773 | * |
||
| 774 | * * To implement hidden categories, hiding pages from category listings |
||
| 775 | * by storing a property. |
||
| 776 | * |
||
| 777 | * * Overriding the displayed article title. |
||
| 778 | * @see ParserOutput::setDisplayTitle() |
||
| 779 | * |
||
| 780 | * * To implement image tagging, for example displaying an icon on an |
||
| 781 | * image thumbnail to indicate that it is listed for deletion on |
||
| 782 | * Wikimedia Commons. |
||
| 783 | * This is not actually implemented, yet but would be pretty cool. |
||
| 784 | * |
||
| 785 | * @note Do not use setProperty() to set a property which is only used |
||
| 786 | * in a context where the ParserOutput object itself is already available, |
||
| 787 | * for example a normal page view. There is no need to save such a property |
||
| 788 | * in the database since the text is already parsed. You can just hook |
||
| 789 | * OutputPageParserOutput and get your data out of the ParserOutput object. |
||
| 790 | * |
||
| 791 | * If you are writing an extension where you want to set a property in the |
||
| 792 | * parser which is used by an OutputPageParserOutput hook, you have to |
||
| 793 | * associate the extension data directly with the ParserOutput object. |
||
| 794 | * Since MediaWiki 1.21, you can use setExtensionData() to do this: |
||
| 795 | * |
||
| 796 | * @par Example: |
||
| 797 | * @code |
||
| 798 | * $parser->getOutput()->setExtensionData( 'my_ext_foo', '...' ); |
||
| 799 | * @endcode |
||
| 800 | * |
||
| 801 | * And then later, in OutputPageParserOutput or similar: |
||
| 802 | * |
||
| 803 | * @par Example: |
||
| 804 | * @code |
||
| 805 | * $output->getExtensionData( 'my_ext_foo' ); |
||
| 806 | * @endcode |
||
| 807 | * |
||
| 808 | * In MediaWiki 1.20 and older, you have to use a custom member variable |
||
| 809 | * within the ParserOutput object: |
||
| 810 | * |
||
| 811 | * @par Example: |
||
| 812 | * @code |
||
| 813 | * $parser->getOutput()->my_ext_foo = '...'; |
||
| 814 | * @endcode |
||
| 815 | * |
||
| 816 | */ |
||
| 817 | public function setProperty( $name, $value ) { |
||
| 820 | |||
| 821 | /** |
||
| 822 | * @param string $name The property name to look up. |
||
| 823 | * |
||
| 824 | * @return mixed|bool The value previously set using setProperty(). False if null or no value |
||
| 825 | * was set for the given property name. |
||
| 826 | * |
||
| 827 | * @note You need to use getProperties() to check for boolean and null properties. |
||
| 828 | */ |
||
| 829 | public function getProperty( $name ) { |
||
| 832 | |||
| 833 | public function unsetProperty( $name ) { |
||
| 836 | |||
| 837 | public function getProperties() { |
||
| 843 | |||
| 844 | /** |
||
| 845 | * Returns the options from its ParserOptions which have been taken |
||
| 846 | * into account to produce this output or false if not available. |
||
| 847 | * @return array |
||
| 848 | */ |
||
| 849 | public function getUsedOptions() { |
||
| 855 | |||
| 856 | /** |
||
| 857 | * Tags a parser option for use in the cache key for this parser output. |
||
| 858 | * Registered as a watcher at ParserOptions::registerWatcher() by Parser::clearState(). |
||
| 859 | * The information gathered here is available via getUsedOptions(), |
||
| 860 | * and is used by ParserCache::save(). |
||
| 861 | * |
||
| 862 | * @see ParserCache::getKey |
||
| 863 | * @see ParserCache::save |
||
| 864 | * @see ParserOptions::addExtraKey |
||
| 865 | * @see ParserOptions::optionsHash |
||
| 866 | * @param string $option |
||
| 867 | */ |
||
| 868 | public function recordOption( $option ) { |
||
| 871 | |||
| 872 | /** |
||
| 873 | * Attaches arbitrary data to this ParserObject. This can be used to store some information in |
||
| 874 | * the ParserOutput object for later use during page output. The data will be cached along with |
||
| 875 | * the ParserOutput object, but unlike data set using setProperty(), it is not recorded in the |
||
| 876 | * database. |
||
| 877 | * |
||
| 878 | * This method is provided to overcome the unsafe practice of attaching extra information to a |
||
| 879 | * ParserObject by directly assigning member variables. |
||
| 880 | * |
||
| 881 | * To use setExtensionData() to pass extension information from a hook inside the parser to a |
||
| 882 | * hook in the page output, use this in the parser hook: |
||
| 883 | * |
||
| 884 | * @par Example: |
||
| 885 | * @code |
||
| 886 | * $parser->getOutput()->setExtensionData( 'my_ext_foo', '...' ); |
||
| 887 | * @endcode |
||
| 888 | * |
||
| 889 | * And then later, in OutputPageParserOutput or similar: |
||
| 890 | * |
||
| 891 | * @par Example: |
||
| 892 | * @code |
||
| 893 | * $output->getExtensionData( 'my_ext_foo' ); |
||
| 894 | * @endcode |
||
| 895 | * |
||
| 896 | * In MediaWiki 1.20 and older, you have to use a custom member variable |
||
| 897 | * within the ParserOutput object: |
||
| 898 | * |
||
| 899 | * @par Example: |
||
| 900 | * @code |
||
| 901 | * $parser->getOutput()->my_ext_foo = '...'; |
||
| 902 | * @endcode |
||
| 903 | * |
||
| 904 | * @since 1.21 |
||
| 905 | * |
||
| 906 | * @param string $key The key for accessing the data. Extensions should take care to avoid |
||
| 907 | * conflicts in naming keys. It is suggested to use the extension's name as a prefix. |
||
| 908 | * |
||
| 909 | * @param mixed $value The value to set. Setting a value to null is equivalent to removing |
||
| 910 | * the value. |
||
| 911 | */ |
||
| 912 | public function setExtensionData( $key, $value ) { |
||
| 919 | |||
| 920 | /** |
||
| 921 | * Gets extensions data previously attached to this ParserOutput using setExtensionData(). |
||
| 922 | * Typically, such data would be set while parsing the page, e.g. by a parser function. |
||
| 923 | * |
||
| 924 | * @since 1.21 |
||
| 925 | * |
||
| 926 | * @param string $key The key to look up. |
||
| 927 | * |
||
| 928 | * @return mixed|null The value previously set for the given key using setExtensionData() |
||
| 929 | * or null if no value was set for this key. |
||
| 930 | */ |
||
| 931 | public function getExtensionData( $key ) { |
||
| 938 | |||
| 939 | private static function getTimes( $clock = null ) { |
||
| 953 | |||
| 954 | /** |
||
| 955 | * Resets the parse start timestamps for future calls to getTimeSinceStart() |
||
| 956 | * @since 1.22 |
||
| 957 | */ |
||
| 958 | public function resetParseStartTime() { |
||
| 961 | |||
| 962 | /** |
||
| 963 | * Returns the time since resetParseStartTime() was last called |
||
| 964 | * |
||
| 965 | * Clocks available are: |
||
| 966 | * - wall: Wall clock time |
||
| 967 | * - cpu: CPU time (requires getrusage) |
||
| 968 | * |
||
| 969 | * @since 1.22 |
||
| 970 | * @param string $clock |
||
| 971 | * @return float|null |
||
| 972 | */ |
||
| 973 | public function getTimeSinceStart( $clock ) { |
||
| 981 | |||
| 982 | /** |
||
| 983 | * Sets parser limit report data for a key |
||
| 984 | * |
||
| 985 | * The key is used as the prefix for various messages used for formatting: |
||
| 986 | * - $key: The label for the field in the limit report |
||
| 987 | * - $key-value-text: Message used to format the value in the "NewPP limit |
||
| 988 | * report" HTML comment. If missing, uses $key-format. |
||
| 989 | * - $key-value-html: Message used to format the value in the preview |
||
| 990 | * limit report table. If missing, uses $key-format. |
||
| 991 | * - $key-value: Message used to format the value. If missing, uses "$1". |
||
| 992 | * |
||
| 993 | * Note that all values are interpreted as wikitext, and so should be |
||
| 994 | * encoded with htmlspecialchars() as necessary, but should avoid complex |
||
| 995 | * HTML for sanity of display in the "NewPP limit report" comment. |
||
| 996 | * |
||
| 997 | * @since 1.22 |
||
| 998 | * @param string $key Message key |
||
| 999 | * @param mixed $value Appropriate for Message::params() |
||
| 1000 | */ |
||
| 1001 | public function setLimitReportData( $key, $value ) { |
||
| 1004 | |||
| 1005 | /** |
||
| 1006 | * Check whether the cache TTL was lowered due to dynamic content |
||
| 1007 | * |
||
| 1008 | * When content is determined by more than hard state (e.g. page edits), |
||
| 1009 | * such as template/file transclusions based on the current timestamp or |
||
| 1010 | * extension tags that generate lists based on queries, this return true. |
||
| 1011 | * |
||
| 1012 | * @return bool |
||
| 1013 | * @since 1.25 |
||
| 1014 | */ |
||
| 1015 | public function hasDynamicContent() { |
||
| 1020 | |||
| 1021 | /** |
||
| 1022 | * Get or set the prevent-clickjacking flag |
||
| 1023 | * |
||
| 1024 | * @since 1.24 |
||
| 1025 | * @param bool|null $flag New flag value, or null to leave it unchanged |
||
| 1026 | * @return bool Old flag value |
||
| 1027 | */ |
||
| 1028 | public function preventClickjacking( $flag = null ) { |
||
| 1031 | |||
| 1032 | /** |
||
| 1033 | * Save space for serialization by removing useless values |
||
| 1034 | * @return array |
||
| 1035 | */ |
||
| 1036 | public function __sleep() { |
||
| 1042 | } |
||
| 1043 |