Merge "Introducing pp_sortkey."
[lhc/web/wiklou.git] / includes / parser / ParserOutput.php
1 <?php
2
3 /**
4 * Output of the PHP parser.
5 *
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.
10 *
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.
15 *
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
20 *
21 * @file
22 * @ingroup Parser
23 */
24 class ParserOutput extends CacheTime {
25 var $mText, # The output text
26 $mLanguageLinks, # List of the full text of language links, in the order they appear
27 $mCategories, # Map of category names to sort keys
28 $mTitleText, # title text of the chosen language variant
29 $mLinks = array(), # 2-D map of NS/DBK to ID for the links in the document. ID=zero for broken.
30 $mTemplates = array(), # 2-D map of NS/DBK to ID for the template references. ID=zero for broken.
31 $mTemplateIds = array(), # 2-D map of NS/DBK to rev ID for the template references. ID=zero for broken.
32 $mImages = array(), # DB keys of the images used, in the array key only
33 $mFileSearchOptions = array(), # DB keys of the images used mapped to sha1 and MW timestamp
34 $mExternalLinks = array(), # External link URLs, in the key only
35 $mInterwikiLinks = array(), # 2-D map of prefix/DBK (in keys only) for the inline interwiki links in the document.
36 $mNewSection = false, # Show a new section link?
37 $mHideNewSection = false, # Hide the new section link?
38 $mNoGallery = false, # No gallery on category page? (__NOGALLERY__)
39 $mHeadItems = array(), # Items to put in the <head> section
40 $mModules = array(), # Modules to be loaded by the resource loader
41 $mModuleScripts = array(), # Modules of which only the JS will be loaded by the resource loader
42 $mModuleStyles = array(), # Modules of which only the CSSS will be loaded by the resource loader
43 $mModuleMessages = array(), # Modules of which only the messages will be loaded by the resource loader
44 $mJsConfigVars = array(), # JavaScript config variable for mw.config combined with this page
45 $mOutputHooks = array(), # Hook tags as per $wgParserOutputHooks
46 $mWarnings = array(), # Warning text to be returned to the user. Wikitext formatted, in the key only
47 $mSections = array(), # Table of contents
48 $mEditSectionTokens = false, # prefix/suffix markers if edit sections were output as tokens
49 $mProperties = array(), # Name/value pairs to be cached in the DB
50 $mTOCHTML = '', # HTML of the TOC
51 $mTimestamp, # Timestamp of the revision
52 $mTOCEnabled = true; # Whether TOC should be shown, can't override __NOTOC__
53 private $mIndexPolicy = ''; # 'index' or 'noindex'? Any other value will result in no change.
54 private $mAccessedOptions = array(); # List of ParserOptions (stored in the keys)
55 private $mSecondaryDataUpdates = array(); # List of DataUpdate, used to save info from the page somewhere else.
56 private $mExtensionData = array(); # extra data used by extensions
57 private $mLimitReportData = array(); # Parser limit report data
58 private $mParseStartTime = array(); # Timestamps for getTimeSinceStart()
59
60 const EDITSECTION_REGEX = '#<(?:mw:)?editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)(</(?:mw:)?editsection>))#';
61
62 function __construct( $text = '', $languageLinks = array(), $categoryLinks = array(),
63 $containsOldMagic = false, $titletext = ''
64 ) {
65 $this->mText = $text;
66 $this->mLanguageLinks = $languageLinks;
67 $this->mCategories = $categoryLinks;
68 $this->mContainsOldMagic = $containsOldMagic;
69 $this->mTitleText = $titletext;
70 }
71
72 function getText() {
73 wfProfileIn( __METHOD__ );
74 $text = $this->mText;
75 if ( $this->mEditSectionTokens ) {
76 $text = preg_replace_callback( ParserOutput::EDITSECTION_REGEX,
77 array( &$this, 'replaceEditSectionLinksCallback' ), $text );
78 } else {
79 $text = preg_replace( ParserOutput::EDITSECTION_REGEX, '', $text );
80 }
81
82 // If you have an old cached version of this class - sorry, you can't disable the TOC
83 if ( isset( $this->mTOCEnabled ) && $this->mTOCEnabled ) {
84 $text = str_replace( array( Parser::TOC_START, Parser::TOC_END ), '', $text );
85 } else {
86 $text = preg_replace(
87 '#' . preg_quote( Parser::TOC_START ) . '.*?' . preg_quote( Parser::TOC_END ) . '#s',
88 '',
89 $text
90 );
91 }
92 wfProfileOut( __METHOD__ );
93 return $text;
94 }
95
96 /**
97 * callback used by getText to replace editsection tokens
98 * @private
99 * @param array $m
100 * @throws MWException
101 * @return mixed
102 */
103 function replaceEditSectionLinksCallback( $m ) {
104 global $wgOut, $wgLang;
105 $args = array(
106 htmlspecialchars_decode( $m[1] ),
107 htmlspecialchars_decode( $m[2] ),
108 isset( $m[4] ) ? $m[3] : null,
109 );
110 $args[0] = Title::newFromText( $args[0] );
111 if ( !is_object( $args[0] ) ) {
112 throw new MWException( "Bad parser output text." );
113 }
114 $args[] = $wgLang->getCode();
115 $skin = $wgOut->getSkin();
116 return call_user_func_array( array( $skin, 'doEditSectionLink' ), $args );
117 }
118
119 function &getLanguageLinks() { return $this->mLanguageLinks; }
120 function getInterwikiLinks() { return $this->mInterwikiLinks; }
121 function getCategoryLinks() { return array_keys( $this->mCategories ); }
122 function &getCategories() { return $this->mCategories; }
123 function getTitleText() { return $this->mTitleText; }
124 function getSections() { return $this->mSections; }
125 function getEditSectionTokens() { return $this->mEditSectionTokens; }
126 function &getLinks() { return $this->mLinks; }
127 function &getTemplates() { return $this->mTemplates; }
128 function &getTemplateIds() { return $this->mTemplateIds; }
129 function &getImages() { return $this->mImages; }
130 function &getFileSearchOptions() { return $this->mFileSearchOptions; }
131 function &getExternalLinks() { return $this->mExternalLinks; }
132 function getNoGallery() { return $this->mNoGallery; }
133 function getHeadItems() { return $this->mHeadItems; }
134 function getModules() { return $this->mModules; }
135 function getModuleScripts() { return $this->mModuleScripts; }
136 function getModuleStyles() { return $this->mModuleStyles; }
137 function getModuleMessages() { return $this->mModuleMessages; }
138 /** @since 1.23 */
139 function getJsConfigVars() { return $this->mJsConfigVars; }
140 function getOutputHooks() { return (array)$this->mOutputHooks; }
141 function getWarnings() { return array_keys( $this->mWarnings ); }
142 function getIndexPolicy() { return $this->mIndexPolicy; }
143 function getTOCHTML() { return $this->mTOCHTML; }
144 function getTimestamp() { return $this->mTimestamp; }
145 function getLimitReportData() { return $this->mLimitReportData; }
146 function getTOCEnabled() { return $this->mTOCEnabled; }
147
148 function setText( $text ) { return wfSetVar( $this->mText, $text ); }
149 function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks, $ll ); }
150 function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategories, $cl ); }
151
152 function setTitleText( $t ) { return wfSetVar( $this->mTitleText, $t ); }
153 function setSections( $toc ) { return wfSetVar( $this->mSections, $toc ); }
154 function setEditSectionTokens( $t ) { return wfSetVar( $this->mEditSectionTokens, $t ); }
155 function setIndexPolicy( $policy ) { return wfSetVar( $this->mIndexPolicy, $policy ); }
156 function setTOCHTML( $tochtml ) { return wfSetVar( $this->mTOCHTML, $tochtml ); }
157 function setTimestamp( $timestamp ) { return wfSetVar( $this->mTimestamp, $timestamp ); }
158 function setTOCEnabled( $flag ) { return wfSetVar( $this->mTOCEnabled, $flag ); }
159
160 function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; }
161 function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; }
162 function addWarning( $s ) { $this->mWarnings[$s] = 1; }
163
164 function addOutputHook( $hook, $data = false ) {
165 $this->mOutputHooks[] = array( $hook, $data );
166 }
167
168 function setNewSection( $value ) {
169 $this->mNewSection = (bool)$value;
170 }
171 function hideNewSection( $value ) {
172 $this->mHideNewSection = (bool)$value;
173 }
174 function getHideNewSection() {
175 return (bool)$this->mHideNewSection;
176 }
177 function getNewSection() {
178 return (bool)$this->mNewSection;
179 }
180
181 /**
182 * Checks, if a url is pointing to the own server
183 *
184 * @param string $internal The server to check against
185 * @param string $url The url to check
186 * @return bool
187 */
188 static function isLinkInternal( $internal, $url ) {
189 return (bool)preg_match( '/^' .
190 # If server is proto relative, check also for http/https links
191 ( substr( $internal, 0, 2 ) === '//' ? '(?:https?:)?' : '' ) .
192 preg_quote( $internal, '/' ) .
193 # check for query/path/anchor or end of link in each case
194 '(?:[\?\/\#]|$)/i',
195 $url
196 );
197 }
198
199 function addExternalLink( $url ) {
200 # We don't register links pointing to our own server, unless... :-)
201 global $wgServer, $wgRegisterInternalExternals;
202
203 $registerExternalLink = true;
204 if ( !$wgRegisterInternalExternals ) {
205 $registerExternalLink = !self::isLinkInternal( $wgServer, $url );
206 }
207 if ( $registerExternalLink ) {
208 $this->mExternalLinks[$url] = 1;
209 }
210 }
211
212 /**
213 * Record a local or interwiki inline link for saving in future link tables.
214 *
215 * @param Title $title
216 * @param int|null $id Optional known page_id so we can skip the lookup
217 */
218 function addLink( Title $title, $id = null ) {
219 if ( $title->isExternal() ) {
220 // Don't record interwikis in pagelinks
221 $this->addInterwikiLink( $title );
222 return;
223 }
224 $ns = $title->getNamespace();
225 $dbk = $title->getDBkey();
226 if ( $ns == NS_MEDIA ) {
227 // Normalize this pseudo-alias if it makes it down here...
228 $ns = NS_FILE;
229 } elseif ( $ns == NS_SPECIAL ) {
230 // We don't record Special: links currently
231 // It might actually be wise to, but we'd need to do some normalization.
232 return;
233 } elseif ( $dbk === '' ) {
234 // Don't record self links - [[#Foo]]
235 return;
236 }
237 if ( !isset( $this->mLinks[$ns] ) ) {
238 $this->mLinks[$ns] = array();
239 }
240 if ( is_null( $id ) ) {
241 $id = $title->getArticleID();
242 }
243 $this->mLinks[$ns][$dbk] = $id;
244 }
245
246 /**
247 * Register a file dependency for this output
248 * @param string $name Title dbKey
249 * @param string $timestamp MW timestamp of file creation (or false if non-existing)
250 * @param string $sha1 Base 36 SHA-1 of file (or false if non-existing)
251 * @return void
252 */
253 function addImage( $name, $timestamp = null, $sha1 = null ) {
254 $this->mImages[$name] = 1;
255 if ( $timestamp !== null && $sha1 !== null ) {
256 $this->mFileSearchOptions[$name] = array( 'time' => $timestamp, 'sha1' => $sha1 );
257 }
258 }
259
260 /**
261 * Register a template dependency for this output
262 * @param Title $title
263 * @param int $page_id
264 * @param int $rev_id
265 * @return void
266 */
267 function addTemplate( $title, $page_id, $rev_id ) {
268 $ns = $title->getNamespace();
269 $dbk = $title->getDBkey();
270 if ( !isset( $this->mTemplates[$ns] ) ) {
271 $this->mTemplates[$ns] = array();
272 }
273 $this->mTemplates[$ns][$dbk] = $page_id;
274 if ( !isset( $this->mTemplateIds[$ns] ) ) {
275 $this->mTemplateIds[$ns] = array();
276 }
277 $this->mTemplateIds[$ns][$dbk] = $rev_id; // For versioning
278 }
279
280 /**
281 * @param Title $title Title object, must be an interwiki link
282 * @throws MWException if given invalid input
283 */
284 function addInterwikiLink( $title ) {
285 if ( !$title->isExternal() ) {
286 throw new MWException( 'Non-interwiki link passed, internal parser error.' );
287 }
288 $prefix = $title->getInterwiki();
289 if ( !isset( $this->mInterwikiLinks[$prefix] ) ) {
290 $this->mInterwikiLinks[$prefix] = array();
291 }
292 $this->mInterwikiLinks[$prefix][$title->getDBkey()] = 1;
293 }
294
295 /**
296 * Add some text to the "<head>".
297 * If $tag is set, the section with that tag will only be included once
298 * in a given page.
299 * @param string $section
300 * @param string|bool $tag
301 */
302 function addHeadItem( $section, $tag = false ) {
303 if ( $tag !== false ) {
304 $this->mHeadItems[$tag] = $section;
305 } else {
306 $this->mHeadItems[] = $section;
307 }
308 }
309
310 public function addModules( $modules ) {
311 $this->mModules = array_merge( $this->mModules, (array)$modules );
312 }
313
314 public function addModuleScripts( $modules ) {
315 $this->mModuleScripts = array_merge( $this->mModuleScripts, (array)$modules );
316 }
317
318 public function addModuleStyles( $modules ) {
319 $this->mModuleStyles = array_merge( $this->mModuleStyles, (array)$modules );
320 }
321
322 public function addModuleMessages( $modules ) {
323 $this->mModuleMessages = array_merge( $this->mModuleMessages, (array)$modules );
324 }
325
326 /**
327 * Add one or more variables to be set in mw.config in JavaScript.
328 *
329 * @param string|array $keys Key or array of key/value pairs.
330 * @param mixed $value [optional] Value of the configuration variable.
331 * @since 1.23
332 */
333 public function addJsConfigVars( $keys, $value = null ) {
334 if ( is_array( $keys ) ) {
335 foreach ( $keys as $key => $value ) {
336 $this->mJsConfigVars[$key] = $value;
337 }
338 return;
339 }
340
341 $this->mJsConfigVars[$keys] = $value;
342 }
343
344 /**
345 * Copy items from the OutputPage object into this one
346 *
347 * @param OutputPage $out
348 */
349 public function addOutputPageMetadata( OutputPage $out ) {
350 $this->addModules( $out->getModules() );
351 $this->addModuleScripts( $out->getModuleScripts() );
352 $this->addModuleStyles( $out->getModuleStyles() );
353 $this->addModuleMessages( $out->getModuleMessages() );
354 $this->addJsConfigVars( $out->getJsConfigVars() );
355
356 $this->mHeadItems = array_merge( $this->mHeadItems, $out->getHeadItemsArray() );
357 }
358
359 /**
360 * Override the title to be used for display
361 * -- this is assumed to have been validated
362 * (check equal normalisation, etc.)
363 *
364 * @param string $text desired title text
365 */
366 public function setDisplayTitle( $text ) {
367 $this->setTitleText( $text );
368 $this->setProperty( 'displaytitle', $text );
369 }
370
371 /**
372 * Get the title to be used for display
373 *
374 * @return string
375 */
376 public function getDisplayTitle() {
377 $t = $this->getTitleText();
378 if ( $t === '' ) {
379 return false;
380 }
381 return $t;
382 }
383
384 /**
385 * Fairly generic flag setter thingy.
386 */
387 public function setFlag( $flag ) {
388 $this->mFlags[$flag] = true;
389 }
390
391 public function getFlag( $flag ) {
392 return isset( $this->mFlags[$flag] );
393 }
394
395 /**
396 * Set a property to be stored in the page_props database table.
397 *
398 * page_props is a key value store indexed by the page ID. This allows
399 * the parser to set a property on a page which can then be quickly
400 * retrieved given the page ID or via a DB join when given the page
401 * title.
402 *
403 * Since 1.23, page_props are also indexed by numeric value, to allow
404 * for efficient "top k" queries of pages wrt a given property.
405 *
406 * setProperty() is thus used to propagate properties from the parsed
407 * page to request contexts other than a page view of the currently parsed
408 * article.
409 *
410 * Some applications examples:
411 *
412 * * To implement hidden categories, hiding pages from category listings
413 * by storing a property.
414 *
415 * * Overriding the displayed article title.
416 * @see ParserOutput::setDisplayTitle()
417 *
418 * * To implement image tagging, for example displaying an icon on an
419 * image thumbnail to indicate that it is listed for deletion on
420 * Wikimedia Commons.
421 * This is not actually implemented, yet but would be pretty cool.
422 *
423 * @note: Do not use setProperty() to set a property which is only used
424 * in a context where the ParserOutput object itself is already available,
425 * for example a normal page view. There is no need to save such a property
426 * in the database since the text is already parsed. You can just hook
427 * OutputPageParserOutput and get your data out of the ParserOutput object.
428 *
429 * If you are writing an extension where you want to set a property in the
430 * parser which is used by an OutputPageParserOutput hook, you have to
431 * associate the extension data directly with the ParserOutput object.
432 * Since MediaWiki 1.21, you can use setExtensionData() to do this:
433 *
434 * @par Example:
435 * @code
436 * $parser->getOutput()->setExtensionData( 'my_ext_foo', '...' );
437 * @endcode
438 *
439 * And then later, in OutputPageParserOutput or similar:
440 *
441 * @par Example:
442 * @code
443 * $output->getExtensionData( 'my_ext_foo' );
444 * @endcode
445 *
446 * In MediaWiki 1.20 and older, you have to use a custom member variable
447 * within the ParserOutput object:
448 *
449 * @par Example:
450 * @code
451 * $parser->getOutput()->my_ext_foo = '...';
452 * @endcode
453 *
454 */
455 public function setProperty( $name, $value ) {
456 $this->mProperties[$name] = $value;
457 }
458
459 public function getProperty( $name ) {
460 return isset( $this->mProperties[$name] ) ? $this->mProperties[$name] : false;
461 }
462
463 public function getProperties() {
464 if ( !isset( $this->mProperties ) ) {
465 $this->mProperties = array();
466 }
467 return $this->mProperties;
468 }
469
470 /**
471 * Returns the options from its ParserOptions which have been taken
472 * into account to produce this output or false if not available.
473 * @return array
474 */
475 public function getUsedOptions() {
476 if ( !isset( $this->mAccessedOptions ) ) {
477 return array();
478 }
479 return array_keys( $this->mAccessedOptions );
480 }
481
482 /**
483 * Tags a parser option for use in the cache key for this parser output.
484 * Registered as a watcher at ParserOptions::registerWatcher() by Parser::clearState().
485 *
486 * @see ParserCache::getKey
487 * @see ParserCache::save
488 * @see ParserOptions::addExtraKey
489 * @see ParserOptions::optionsHash
490 * @param string $option
491 */
492 public function recordOption( $option ) {
493 $this->mAccessedOptions[$option] = true;
494 }
495
496 /**
497 * Adds an update job to the output. Any update jobs added to the output will
498 * eventually be executed in order to store any secondary information extracted
499 * from the page's content. This is triggered by calling getSecondaryDataUpdates()
500 * and is used for forward links updates on edit and backlink updates by jobs.
501 *
502 * @since 1.20
503 *
504 * @param DataUpdate $update
505 */
506 public function addSecondaryDataUpdate( DataUpdate $update ) {
507 $this->mSecondaryDataUpdates[] = $update;
508 }
509
510 /**
511 * Returns any DataUpdate jobs to be executed in order to store secondary information
512 * extracted from the page's content, including a LinksUpdate object for all links stored in
513 * this ParserOutput object.
514 *
515 * @note: Avoid using this method directly, use ContentHandler::getSecondaryDataUpdates() instead! The content
516 * handler may provide additional update objects.
517 *
518 * @since 1.20
519 *
520 * @param Title $title The title of the page we're updating. If not given, a title object will
521 * be created based on $this->getTitleText()
522 * @param bool $recursive Queue jobs for recursive updates?
523 *
524 * @return array An array of instances of DataUpdate
525 */
526 public function getSecondaryDataUpdates( Title $title = null, $recursive = true ) {
527 if ( is_null( $title ) ) {
528 $title = Title::newFromText( $this->getTitleText() );
529 }
530
531 $linksUpdate = new LinksUpdate( $title, $this, $recursive );
532
533 return array_merge( $this->mSecondaryDataUpdates, array( $linksUpdate ) );
534 }
535
536 /**
537 * Attaches arbitrary data to this ParserObject. This can be used to store some information in
538 * the ParserOutput object for later use during page output. The data will be cached along with
539 * the ParserOutput object, but unlike data set using setProperty(), it is not recorded in the
540 * database.
541 *
542 * This method is provided to overcome the unsafe practice of attaching extra information to a
543 * ParserObject by directly assigning member variables.
544 *
545 * To use setExtensionData() to pass extension information from a hook inside the parser to a
546 * hook in the page output, use this in the parser hook:
547 *
548 * @par Example:
549 * @code
550 * $parser->getOutput()->setExtensionData( 'my_ext_foo', '...' );
551 * @endcode
552 *
553 * And then later, in OutputPageParserOutput or similar:
554 *
555 * @par Example:
556 * @code
557 * $output->getExtensionData( 'my_ext_foo' );
558 * @endcode
559 *
560 * In MediaWiki 1.20 and older, you have to use a custom member variable
561 * within the ParserOutput object:
562 *
563 * @par Example:
564 * @code
565 * $parser->getOutput()->my_ext_foo = '...';
566 * @endcode
567 *
568 * @since 1.21
569 *
570 * @param string $key The key for accessing the data. Extensions should take care to avoid
571 * conflicts in naming keys. It is suggested to use the extension's name as a prefix.
572 *
573 * @param mixed $value The value to set. Setting a value to null is equivalent to removing
574 * the value.
575 */
576 public function setExtensionData( $key, $value ) {
577 if ( $value === null ) {
578 unset( $this->mExtensionData[$key] );
579 } else {
580 $this->mExtensionData[$key] = $value;
581 }
582 }
583
584 /**
585 * Gets extensions data previously attached to this ParserOutput using setExtensionData().
586 * Typically, such data would be set while parsing the page, e.g. by a parser function.
587 *
588 * @since 1.21
589 *
590 * @param string $key The key to look up.
591 *
592 * @return mixed The value previously set for the given key using setExtensionData( $key ),
593 * or null if no value was set for this key.
594 */
595 public function getExtensionData( $key ) {
596 if ( isset( $this->mExtensionData[$key] ) ) {
597 return $this->mExtensionData[$key];
598 }
599
600 return null;
601 }
602
603 private static function getTimes( $clock = null ) {
604 $ret = array();
605 if ( !$clock || $clock === 'wall' ) {
606 $ret['wall'] = microtime( true );
607 }
608 if ( ( !$clock || $clock === 'cpu' ) && function_exists( 'getrusage' ) ) {
609 $ru = getrusage();
610 $ret['cpu'] = $ru['ru_utime.tv_sec'] + $ru['ru_utime.tv_usec'] / 1e6;
611 $ret['cpu'] += $ru['ru_stime.tv_sec'] + $ru['ru_stime.tv_usec'] / 1e6;
612 }
613 return $ret;
614 }
615
616 /**
617 * Resets the parse start timestamps for future calls to getTimeSinceStart()
618 * @since 1.22
619 */
620 function resetParseStartTime() {
621 $this->mParseStartTime = self::getTimes();
622 }
623
624 /**
625 * Returns the time since resetParseStartTime() was last called
626 *
627 * Clocks available are:
628 * - wall: Wall clock time
629 * - cpu: CPU time (requires getrusage)
630 *
631 * @since 1.22
632 * @param string $clock
633 * @return float|null
634 */
635 function getTimeSinceStart( $clock ) {
636 if ( !isset( $this->mParseStartTime[$clock] ) ) {
637 return null;
638 }
639
640 $end = self::getTimes( $clock );
641 return $end[$clock] - $this->mParseStartTime[$clock];
642 }
643
644 /**
645 * Sets parser limit report data for a key
646 *
647 * The key is used as the prefix for various messages used for formatting:
648 * - $key: The label for the field in the limit report
649 * - $key-value-text: Message used to format the value in the "NewPP limit
650 * report" HTML comment. If missing, uses $key-format.
651 * - $key-value-html: Message used to format the value in the preview
652 * limit report table. If missing, uses $key-format.
653 * - $key-value: Message used to format the value. If missing, uses "$1".
654 *
655 * Note that all values are interpreted as wikitext, and so should be
656 * encoded with htmlspecialchars() as necessary, but should avoid complex
657 * HTML for sanity of display in the "NewPP limit report" comment.
658 *
659 * @since 1.22
660 * @param string $key Message key
661 * @param mixed $value Appropriate for Message::params()
662 */
663 function setLimitReportData( $key, $value ) {
664 $this->mLimitReportData[$key] = $value;
665 }
666
667 /**
668 * Save space for for serialization by removing useless values
669 */
670 function __sleep() {
671 return array_diff(
672 array_keys( get_object_vars( $this ) ),
673 array( 'mSecondaryDataUpdates', 'mParseStartTime' )
674 );
675 }
676 }