2007-01-20 12:50:56 +00:00
|
|
|
<?php
|
2012-08-20 14:55:28 +00:00
|
|
|
|
2010-08-22 14:31:05 +00:00
|
|
|
/**
|
2012-08-20 14:55:28 +00:00
|
|
|
* Output of the PHP parser.
|
2010-08-22 14:31:05 +00:00
|
|
|
*
|
2012-04-30 09:22:16 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2010-08-22 14:31:05 +00:00
|
|
|
* @file
|
|
|
|
|
* @ingroup Parser
|
|
|
|
|
*/
|
2010-12-28 09:54:25 +00:00
|
|
|
class ParserOutput extends CacheTime {
|
2014-05-10 22:52:21 +00:00
|
|
|
/** @var string The output text */
|
|
|
|
|
public $mText;
|
|
|
|
|
|
|
|
|
|
/** @var array List of the full text of language links; in the order they appear */
|
|
|
|
|
public $mLanguageLinks;
|
|
|
|
|
|
|
|
|
|
/** @var array Map of category names to sort keys */
|
|
|
|
|
public $mCategories;
|
|
|
|
|
|
|
|
|
|
/** @var array DB keys of the images used; in the array key only */
|
|
|
|
|
public $mImages = array();
|
|
|
|
|
|
|
|
|
|
/** @var array Modules to be loaded by the resource loader */
|
|
|
|
|
public $mModules = array();
|
|
|
|
|
|
|
|
|
|
/** @var array Name/value pairs to be cached in the DB */
|
|
|
|
|
public $mProperties = array();
|
|
|
|
|
|
|
|
|
|
/** @var string Title text of the chosen language variant */
|
|
|
|
|
protected $mTitleText;
|
|
|
|
|
|
|
|
|
|
/** @var array 2-D map of NS/DBK to ID for the links in the document. ID=zero for broken. */
|
|
|
|
|
protected $mLinks = array();
|
|
|
|
|
|
|
|
|
|
/** @var array 2-D map of NS/DBK to ID for the template references. ID=zero for broken. */
|
|
|
|
|
protected $mTemplates = array();
|
|
|
|
|
|
|
|
|
|
/** @var array 2-D map of NS/DBK to rev ID for the template references. ID=zero for broken. */
|
|
|
|
|
protected $mTemplateIds = array();
|
|
|
|
|
|
|
|
|
|
/** @var array DB keys of the images used mapped to sha1 and MW timestamp */
|
|
|
|
|
protected $mFileSearchOptions = array();
|
|
|
|
|
|
|
|
|
|
/** @var array External link URLs; in the key only */
|
|
|
|
|
protected $mExternalLinks = array();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var array 2-D map of prefix/DBK (in keys only) for the inline interwiki
|
|
|
|
|
* links in the document.
|
|
|
|
|
*/
|
|
|
|
|
protected $mInterwikiLinks = array();
|
|
|
|
|
|
|
|
|
|
/** @var bool Show a new section link? */
|
|
|
|
|
protected $mNewSection = false;
|
|
|
|
|
|
|
|
|
|
/** @var bool Hide the new section link? */
|
|
|
|
|
protected $mHideNewSection = false;
|
|
|
|
|
|
|
|
|
|
/** @var bool No gallery on category page? (__NOGALLERY__) */
|
|
|
|
|
public $mNoGallery = false;
|
|
|
|
|
|
|
|
|
|
/** @var array Items to put in the <head> section */
|
|
|
|
|
protected $mHeadItems = array();
|
|
|
|
|
|
|
|
|
|
/** @var array Modules of which only the JS will be loaded by the resource loader */
|
|
|
|
|
protected $mModuleScripts = array();
|
|
|
|
|
|
|
|
|
|
/** @var array Modules of which only the CSSS will be loaded by the resource loader */
|
|
|
|
|
protected $mModuleStyles = array();
|
|
|
|
|
|
|
|
|
|
/** @var array Modules of which only the messages will be loaded by the resource loader */
|
|
|
|
|
protected $mModuleMessages = array();
|
|
|
|
|
|
|
|
|
|
/** @var array JavaScript config variable for mw.config combined with this page */
|
|
|
|
|
protected $mJsConfigVars = array();
|
|
|
|
|
|
|
|
|
|
/** @var array Hook tags as per $wgParserOutputHooks */
|
|
|
|
|
protected $mOutputHooks = array();
|
|
|
|
|
|
|
|
|
|
/** @var array Warning text to be returned to the user. Wikitext formatted; in the key only */
|
|
|
|
|
protected $mWarnings = array();
|
|
|
|
|
|
|
|
|
|
/** @var array Table of contents */
|
|
|
|
|
protected $mSections = array();
|
|
|
|
|
|
|
|
|
|
/** @var bool Prefix/suffix markers if edit sections were output as tokens */
|
|
|
|
|
protected $mEditSectionTokens = false;
|
|
|
|
|
|
|
|
|
|
/** @var string HTML of the TOC */
|
|
|
|
|
protected $mTOCHTML = '';
|
|
|
|
|
|
|
|
|
|
/** @var string Timestamp of the revision */
|
|
|
|
|
protected $mTimestamp;
|
|
|
|
|
|
|
|
|
|
/** @var bool Whether TOC should be shown, can't override __NOTOC__ */
|
|
|
|
|
protected $mTOCEnabled = true;
|
|
|
|
|
|
|
|
|
|
/** @var string 'index' or 'noindex'? Any other value will result in no change. */
|
|
|
|
|
private $mIndexPolicy = '';
|
|
|
|
|
|
|
|
|
|
/** @var array List of ParserOptions (stored in the keys) */
|
|
|
|
|
private $mAccessedOptions = array();
|
|
|
|
|
|
|
|
|
|
/** @var array List of DataUpdate, used to save info from the page somewhere else. */
|
|
|
|
|
private $mSecondaryDataUpdates = array();
|
|
|
|
|
|
|
|
|
|
/** @var array Extra data used by extensions */
|
|
|
|
|
private $mExtensionData = array();
|
|
|
|
|
|
|
|
|
|
/** @var array Parser limit report data */
|
|
|
|
|
private $mLimitReportData = array();
|
|
|
|
|
|
|
|
|
|
/** @var array Timestamps for getTimeSinceStart() */
|
|
|
|
|
private $mParseStartTime = array();
|
2008-02-20 08:53:12 +00:00
|
|
|
|
2014-05-10 23:03:45 +00:00
|
|
|
const EDITSECTION_REGEX =
|
|
|
|
|
'#<(?:mw:)?editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)(</(?:mw:)?editsection>))#';
|
2011-02-08 01:31:21 +00:00
|
|
|
|
2010-08-30 16:52:51 +00:00
|
|
|
function __construct( $text = '', $languageLinks = array(), $categoryLinks = array(),
|
2013-12-01 20:39:00 +00:00
|
|
|
$containsOldMagic = false, $titletext = ''
|
|
|
|
|
) {
|
2007-01-20 12:50:56 +00:00
|
|
|
$this->mText = $text;
|
|
|
|
|
$this->mLanguageLinks = $languageLinks;
|
|
|
|
|
$this->mCategories = $categoryLinks;
|
|
|
|
|
$this->mContainsOldMagic = $containsOldMagic;
|
|
|
|
|
$this->mTitleText = $titletext;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-03 20:17:20 +00:00
|
|
|
function getText() {
|
2013-08-22 22:22:03 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
$text = $this->mText;
|
2011-01-03 20:17:20 +00:00
|
|
|
if ( $this->mEditSectionTokens ) {
|
2013-08-22 22:22:03 +00:00
|
|
|
$text = preg_replace_callback( ParserOutput::EDITSECTION_REGEX,
|
|
|
|
|
array( &$this, 'replaceEditSectionLinksCallback' ), $text );
|
|
|
|
|
} else {
|
|
|
|
|
$text = preg_replace( ParserOutput::EDITSECTION_REGEX, '', $text );
|
2011-01-03 20:17:20 +00:00
|
|
|
}
|
2013-08-22 22:22:03 +00:00
|
|
|
|
|
|
|
|
// If you have an old cached version of this class - sorry, you can't disable the TOC
|
|
|
|
|
if ( isset( $this->mTOCEnabled ) && $this->mTOCEnabled ) {
|
|
|
|
|
$text = str_replace( array( Parser::TOC_START, Parser::TOC_END ), '', $text );
|
|
|
|
|
} else {
|
|
|
|
|
$text = preg_replace(
|
2013-11-19 18:03:54 +00:00
|
|
|
'#' . preg_quote( Parser::TOC_START ) . '.*?' . preg_quote( Parser::TOC_END ) . '#s',
|
2013-08-22 22:22:03 +00:00
|
|
|
'',
|
|
|
|
|
$text
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return $text;
|
2011-01-03 20:17:20 +00:00
|
|
|
}
|
2011-08-01 15:40:02 +00:00
|
|
|
|
2011-01-03 20:17:20 +00:00
|
|
|
/**
|
|
|
|
|
* callback used by getText to replace editsection tokens
|
|
|
|
|
* @private
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param array $m
|
2012-10-07 23:35:26 +00:00
|
|
|
* @throws MWException
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return mixed
|
2011-01-03 20:17:20 +00:00
|
|
|
*/
|
|
|
|
|
function replaceEditSectionLinksCallback( $m ) {
|
2011-04-03 11:44:11 +00:00
|
|
|
global $wgOut, $wgLang;
|
2011-01-04 04:20:09 +00:00
|
|
|
$args = array(
|
2013-02-03 19:42:08 +00:00
|
|
|
htmlspecialchars_decode( $m[1] ),
|
|
|
|
|
htmlspecialchars_decode( $m[2] ),
|
|
|
|
|
isset( $m[4] ) ? $m[3] : null,
|
2011-01-04 04:20:09 +00:00
|
|
|
);
|
2011-01-03 20:17:20 +00:00
|
|
|
$args[0] = Title::newFromText( $args[0] );
|
2013-02-03 19:42:08 +00:00
|
|
|
if ( !is_object( $args[0] ) ) {
|
|
|
|
|
throw new MWException( "Bad parser output text." );
|
2011-01-03 21:04:05 +00:00
|
|
|
}
|
2011-01-03 20:17:20 +00:00
|
|
|
$args[] = $wgLang->getCode();
|
2011-04-03 11:44:11 +00:00
|
|
|
$skin = $wgOut->getSkin();
|
2011-01-03 20:17:20 +00:00
|
|
|
return call_user_func_array( array( $skin, 'doEditSectionLink' ), $args );
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-10 23:03:45 +00:00
|
|
|
function &getLanguageLinks() {
|
|
|
|
|
return $this->mLanguageLinks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getInterwikiLinks() {
|
|
|
|
|
return $this->mInterwikiLinks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getCategoryLinks() {
|
|
|
|
|
return array_keys( $this->mCategories );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function &getCategories() {
|
|
|
|
|
return $this->mCategories;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getTitleText() {
|
|
|
|
|
return $this->mTitleText;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getSections() {
|
|
|
|
|
return $this->mSections;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getEditSectionTokens() {
|
|
|
|
|
return $this->mEditSectionTokens;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function &getLinks() {
|
|
|
|
|
return $this->mLinks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function &getTemplates() {
|
|
|
|
|
return $this->mTemplates;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function &getTemplateIds() {
|
|
|
|
|
return $this->mTemplateIds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function &getImages() {
|
|
|
|
|
return $this->mImages;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function &getFileSearchOptions() {
|
|
|
|
|
return $this->mFileSearchOptions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function &getExternalLinks() {
|
|
|
|
|
return $this->mExternalLinks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getNoGallery() {
|
|
|
|
|
return $this->mNoGallery;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getHeadItems() {
|
|
|
|
|
return $this->mHeadItems;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getModules() {
|
|
|
|
|
return $this->mModules;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getModuleScripts() {
|
|
|
|
|
return $this->mModuleScripts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getModuleStyles() {
|
|
|
|
|
return $this->mModuleStyles;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getModuleMessages() {
|
|
|
|
|
return $this->mModuleMessages;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-19 15:39:46 +00:00
|
|
|
/** @since 1.23 */
|
2014-05-10 23:03:45 +00:00
|
|
|
function getJsConfigVars() {
|
|
|
|
|
return $this->mJsConfigVars;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getOutputHooks() {
|
|
|
|
|
return (array)$this->mOutputHooks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getWarnings() {
|
|
|
|
|
return array_keys( $this->mWarnings );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getIndexPolicy() {
|
|
|
|
|
return $this->mIndexPolicy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getTOCHTML() {
|
|
|
|
|
return $this->mTOCHTML;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getTimestamp() {
|
|
|
|
|
return $this->mTimestamp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getLimitReportData() {
|
|
|
|
|
return $this->mLimitReportData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getTOCEnabled() {
|
|
|
|
|
return $this->mTOCEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setText( $text ) {
|
|
|
|
|
return wfSetVar( $this->mText, $text );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setLanguageLinks( $ll ) {
|
|
|
|
|
return wfSetVar( $this->mLanguageLinks, $ll );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setCategoryLinks( $cl ) {
|
|
|
|
|
return wfSetVar( $this->mCategories, $cl );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setTitleText( $t ) {
|
|
|
|
|
return wfSetVar( $this->mTitleText, $t );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setSections( $toc ) {
|
|
|
|
|
return wfSetVar( $this->mSections, $toc );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setEditSectionTokens( $t ) {
|
|
|
|
|
return wfSetVar( $this->mEditSectionTokens, $t );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setIndexPolicy( $policy ) {
|
|
|
|
|
return wfSetVar( $this->mIndexPolicy, $policy );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setTOCHTML( $tochtml ) {
|
|
|
|
|
return wfSetVar( $this->mTOCHTML, $tochtml );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setTimestamp( $timestamp ) {
|
|
|
|
|
return wfSetVar( $this->mTimestamp, $timestamp );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setTOCEnabled( $flag ) {
|
|
|
|
|
return wfSetVar( $this->mTOCEnabled, $flag );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addCategory( $c, $sort ) {
|
|
|
|
|
$this->mCategories[$c] = $sort;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addLanguageLink( $t ) {
|
|
|
|
|
$this->mLanguageLinks[] = $t;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addWarning( $s ) {
|
|
|
|
|
$this->mWarnings[$s] = 1;
|
|
|
|
|
}
|
2007-01-20 12:50:56 +00:00
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
function addOutputHook( $hook, $data = false ) {
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
$this->mOutputHooks[] = array( $hook, $data );
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-20 12:50:56 +00:00
|
|
|
function setNewSection( $value ) {
|
|
|
|
|
$this->mNewSection = (bool)$value;
|
|
|
|
|
}
|
2013-03-18 19:44:43 +00:00
|
|
|
function hideNewSection( $value ) {
|
2009-02-19 22:14:59 +00:00
|
|
|
$this->mHideNewSection = (bool)$value;
|
|
|
|
|
}
|
2013-03-18 19:44:43 +00:00
|
|
|
function getHideNewSection() {
|
2009-02-19 22:14:59 +00:00
|
|
|
return (bool)$this->mHideNewSection;
|
|
|
|
|
}
|
2007-01-20 12:50:56 +00:00
|
|
|
function getNewSection() {
|
|
|
|
|
return (bool)$this->mNewSection;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-29 10:36:33 +00:00
|
|
|
/**
|
|
|
|
|
* Checks, if a url is pointing to the own server
|
|
|
|
|
*
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param string $internal The server to check against
|
|
|
|
|
* @param string $url The url to check
|
2012-09-29 10:36:33 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
static function isLinkInternal( $internal, $url ) {
|
|
|
|
|
return (bool)preg_match( '/^' .
|
|
|
|
|
# If server is proto relative, check also for http/https links
|
|
|
|
|
( substr( $internal, 0, 2 ) === '//' ? '(?:https?:)?' : '' ) .
|
|
|
|
|
preg_quote( $internal, '/' ) .
|
|
|
|
|
# check for query/path/anchor or end of link in each case
|
|
|
|
|
'(?:[\?\/\#]|$)/i',
|
|
|
|
|
$url
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-11 08:04:31 +00:00
|
|
|
function addExternalLink( $url ) {
|
|
|
|
|
# We don't register links pointing to our own server, unless... :-)
|
|
|
|
|
global $wgServer, $wgRegisterInternalExternals;
|
2012-09-29 10:36:33 +00:00
|
|
|
|
|
|
|
|
$registerExternalLink = true;
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( !$wgRegisterInternalExternals ) {
|
2012-09-29 10:36:33 +00:00
|
|
|
$registerExternalLink = !self::isLinkInternal( $wgServer, $url );
|
|
|
|
|
}
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $registerExternalLink ) {
|
2011-08-01 15:40:02 +00:00
|
|
|
$this->mExternalLinks[$url] = 1;
|
2012-09-29 10:36:33 +00:00
|
|
|
}
|
2009-07-11 08:04:31 +00:00
|
|
|
}
|
|
|
|
|
|
2010-04-16 01:40:05 +00:00
|
|
|
/**
|
|
|
|
|
* Record a local or interwiki inline link for saving in future link tables.
|
|
|
|
|
*
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Title $title
|
|
|
|
|
* @param int|null $id Optional known page_id so we can skip the lookup
|
2010-04-16 01:40:05 +00:00
|
|
|
*/
|
2013-01-25 15:58:24 +00:00
|
|
|
function addLink( Title $title, $id = null ) {
|
2009-07-18 22:49:31 +00:00
|
|
|
if ( $title->isExternal() ) {
|
|
|
|
|
// Don't record interwikis in pagelinks
|
2010-04-16 01:40:05 +00:00
|
|
|
$this->addInterwikiLink( $title );
|
2009-07-18 22:49:31 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2007-01-20 12:50:56 +00:00
|
|
|
$ns = $title->getNamespace();
|
|
|
|
|
$dbk = $title->getDBkey();
|
2009-01-01 00:05:08 +00:00
|
|
|
if ( $ns == NS_MEDIA ) {
|
|
|
|
|
// Normalize this pseudo-alias if it makes it down here...
|
|
|
|
|
$ns = NS_FILE;
|
2013-04-20 15:38:24 +00:00
|
|
|
} elseif ( $ns == NS_SPECIAL ) {
|
2009-01-01 00:05:08 +00:00
|
|
|
// We don't record Special: links currently
|
|
|
|
|
// It might actually be wise to, but we'd need to do some normalization.
|
|
|
|
|
return;
|
2013-04-20 15:38:24 +00:00
|
|
|
} elseif ( $dbk === '' ) {
|
2009-01-11 03:42:13 +00:00
|
|
|
// Don't record self links - [[#Foo]]
|
|
|
|
|
return;
|
2009-01-01 00:05:08 +00:00
|
|
|
}
|
2007-01-20 12:50:56 +00:00
|
|
|
if ( !isset( $this->mLinks[$ns] ) ) {
|
|
|
|
|
$this->mLinks[$ns] = array();
|
|
|
|
|
}
|
|
|
|
|
if ( is_null( $id ) ) {
|
|
|
|
|
$id = $title->getArticleID();
|
|
|
|
|
}
|
|
|
|
|
$this->mLinks[$ns][$dbk] = $id;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2011-03-23 17:35:40 +00:00
|
|
|
/**
|
2011-04-04 01:22:08 +00:00
|
|
|
* Register a file dependency for this output
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $name Title dbKey
|
|
|
|
|
* @param string $timestamp MW timestamp of file creation (or false if non-existing)
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param string $sha1 Base 36 SHA-1 of file (or false if non-existing)
|
2012-01-12 19:41:18 +00:00
|
|
|
* @return void
|
2011-03-23 17:35:40 +00:00
|
|
|
*/
|
2011-03-23 21:45:32 +00:00
|
|
|
function addImage( $name, $timestamp = null, $sha1 = null ) {
|
2007-05-31 16:01:26 +00:00
|
|
|
$this->mImages[$name] = 1;
|
2011-04-04 01:22:08 +00:00
|
|
|
if ( $timestamp !== null && $sha1 !== null ) {
|
2011-09-14 19:05:43 +00:00
|
|
|
$this->mFileSearchOptions[$name] = array( 'time' => $timestamp, 'sha1' => $sha1 );
|
2011-04-04 01:22:08 +00:00
|
|
|
}
|
2007-05-31 16:01:26 +00:00
|
|
|
}
|
2007-01-20 12:50:56 +00:00
|
|
|
|
2011-02-19 01:02:56 +00:00
|
|
|
/**
|
2011-04-04 01:22:08 +00:00
|
|
|
* Register a template dependency for this output
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Title $title
|
|
|
|
|
* @param int $page_id
|
|
|
|
|
* @param int $rev_id
|
2012-01-12 19:41:18 +00:00
|
|
|
* @return void
|
2011-02-19 01:02:56 +00:00
|
|
|
*/
|
2007-05-31 16:01:26 +00:00
|
|
|
function addTemplate( $title, $page_id, $rev_id ) {
|
2007-01-20 12:50:56 +00:00
|
|
|
$ns = $title->getNamespace();
|
|
|
|
|
$dbk = $title->getDBkey();
|
|
|
|
|
if ( !isset( $this->mTemplates[$ns] ) ) {
|
|
|
|
|
$this->mTemplates[$ns] = array();
|
|
|
|
|
}
|
2007-05-31 16:01:26 +00:00
|
|
|
$this->mTemplates[$ns][$dbk] = $page_id;
|
|
|
|
|
if ( !isset( $this->mTemplateIds[$ns] ) ) {
|
|
|
|
|
$this->mTemplateIds[$ns] = array();
|
|
|
|
|
}
|
|
|
|
|
$this->mTemplateIds[$ns][$dbk] = $rev_id; // For versioning
|
2007-01-20 12:50:56 +00:00
|
|
|
}
|
2011-08-01 15:40:02 +00:00
|
|
|
|
2010-04-16 01:40:05 +00:00
|
|
|
/**
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Title $title Title object, must be an interwiki link
|
2010-04-16 01:40:05 +00:00
|
|
|
* @throws MWException if given invalid input
|
|
|
|
|
*/
|
|
|
|
|
function addInterwikiLink( $title ) {
|
2014-01-02 10:59:10 +00:00
|
|
|
if ( !$title->isExternal() ) {
|
2010-04-16 01:40:05 +00:00
|
|
|
throw new MWException( 'Non-interwiki link passed, internal parser error.' );
|
|
|
|
|
}
|
2014-01-02 10:59:10 +00:00
|
|
|
$prefix = $title->getInterwiki();
|
2013-02-03 19:42:08 +00:00
|
|
|
if ( !isset( $this->mInterwikiLinks[$prefix] ) ) {
|
2010-04-16 01:40:05 +00:00
|
|
|
$this->mInterwikiLinks[$prefix] = array();
|
|
|
|
|
}
|
|
|
|
|
$this->mInterwikiLinks[$prefix][$title->getDBkey()] = 1;
|
|
|
|
|
}
|
2007-01-20 12:50:56 +00:00
|
|
|
|
2007-04-03 21:58:18 +00:00
|
|
|
/**
|
2012-07-10 12:48:06 +00:00
|
|
|
* Add some text to the "<head>".
|
2008-04-14 07:45:50 +00:00
|
|
|
* If $tag is set, the section with that tag will only be included once
|
2007-04-03 21:58:18 +00:00
|
|
|
* in a given page.
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param string $section
|
|
|
|
|
* @param string|bool $tag
|
2007-04-03 21:58:18 +00:00
|
|
|
*/
|
|
|
|
|
function addHeadItem( $section, $tag = false ) {
|
|
|
|
|
if ( $tag !== false ) {
|
|
|
|
|
$this->mHeadItems[$tag] = $section;
|
|
|
|
|
} else {
|
|
|
|
|
$this->mHeadItems[] = $section;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-08-01 15:40:02 +00:00
|
|
|
|
2011-08-02 15:40:03 +00:00
|
|
|
public function addModules( $modules ) {
|
2013-08-31 16:36:02 +00:00
|
|
|
$this->mModules = array_merge( $this->mModules, (array)$modules );
|
2010-09-04 04:00:09 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2011-08-02 15:40:03 +00:00
|
|
|
public function addModuleScripts( $modules ) {
|
|
|
|
|
$this->mModuleScripts = array_merge( $this->mModuleScripts, (array)$modules );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addModuleStyles( $modules ) {
|
|
|
|
|
$this->mModuleStyles = array_merge( $this->mModuleStyles, (array)$modules );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addModuleMessages( $modules ) {
|
|
|
|
|
$this->mModuleMessages = array_merge( $this->mModuleMessages, (array)$modules );
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-19 15:39:46 +00:00
|
|
|
/**
|
|
|
|
|
* Add one or more variables to be set in mw.config in JavaScript.
|
|
|
|
|
*
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param string|array $keys Key or array of key/value pairs.
|
|
|
|
|
* @param mixed $value [optional] Value of the configuration variable.
|
2014-01-19 15:39:46 +00:00
|
|
|
* @since 1.23
|
|
|
|
|
*/
|
|
|
|
|
public function addJsConfigVars( $keys, $value = null ) {
|
|
|
|
|
if ( is_array( $keys ) ) {
|
|
|
|
|
foreach ( $keys as $key => $value ) {
|
|
|
|
|
$this->mJsConfigVars[$key] = $value;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->mJsConfigVars[$keys] = $value;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-02 15:40:03 +00:00
|
|
|
/**
|
|
|
|
|
* Copy items from the OutputPage object into this one
|
|
|
|
|
*
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param OutputPage $out
|
2011-08-02 15:40:03 +00:00
|
|
|
*/
|
2011-08-02 16:31:22 +00:00
|
|
|
public function addOutputPageMetadata( OutputPage $out ) {
|
2011-08-02 15:40:03 +00:00
|
|
|
$this->addModules( $out->getModules() );
|
|
|
|
|
$this->addModuleScripts( $out->getModuleScripts() );
|
|
|
|
|
$this->addModuleStyles( $out->getModuleStyles() );
|
|
|
|
|
$this->addModuleMessages( $out->getModuleMessages() );
|
2014-01-19 15:39:46 +00:00
|
|
|
$this->addJsConfigVars( $out->getJsConfigVars() );
|
2011-08-02 15:40:03 +00:00
|
|
|
|
|
|
|
|
$this->mHeadItems = array_merge( $this->mHeadItems, $out->getHeadItemsArray() );
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-25 15:51:09 +00:00
|
|
|
/**
|
|
|
|
|
* Override the title to be used for display
|
|
|
|
|
* -- this is assumed to have been validated
|
|
|
|
|
* (check equal normalisation, etc.)
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $text desired title text
|
2007-06-25 15:51:09 +00:00
|
|
|
*/
|
|
|
|
|
public function setDisplayTitle( $text ) {
|
2010-01-15 19:14:23 +00:00
|
|
|
$this->setTitleText( $text );
|
2010-07-10 11:30:11 +00:00
|
|
|
$this->setProperty( 'displaytitle', $text );
|
2007-06-25 15:51:09 +00:00
|
|
|
}
|
2008-12-31 16:49:38 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the title to be used for display
|
|
|
|
|
*
|
2014-04-21 23:38:39 +00:00
|
|
|
* @return string
|
2008-12-31 16:49:38 +00:00
|
|
|
*/
|
|
|
|
|
public function getDisplayTitle() {
|
2010-12-28 09:54:25 +00:00
|
|
|
$t = $this->getTitleText();
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $t === '' ) {
|
2010-01-15 19:14:23 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2010-02-16 03:37:19 +00:00
|
|
|
return $t;
|
2007-06-25 15:51:09 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-11-15 02:54:28 +00:00
|
|
|
/**
|
|
|
|
|
* Fairly generic flag setter thingy.
|
|
|
|
|
*/
|
|
|
|
|
public function setFlag( $flag ) {
|
|
|
|
|
$this->mFlags[$flag] = true;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-11-15 02:54:28 +00:00
|
|
|
public function getFlag( $flag ) {
|
|
|
|
|
return isset( $this->mFlags[$flag] );
|
|
|
|
|
}
|
2008-02-20 08:53:12 +00:00
|
|
|
|
|
|
|
|
/**
|
2012-10-22 00:58:05 +00:00
|
|
|
* Set a property to be stored in the page_props database table.
|
|
|
|
|
*
|
|
|
|
|
* page_props is a key value store indexed by the page ID. This allows
|
|
|
|
|
* the parser to set a property on a page which can then be quickly
|
|
|
|
|
* retrieved given the page ID or via a DB join when given the page
|
|
|
|
|
* title.
|
|
|
|
|
*
|
2014-03-31 11:00:28 +00:00
|
|
|
* Since 1.23, page_props are also indexed by numeric value, to allow
|
|
|
|
|
* for efficient "top k" queries of pages wrt a given property.
|
|
|
|
|
*
|
2012-10-22 00:58:05 +00:00
|
|
|
* setProperty() is thus used to propagate properties from the parsed
|
|
|
|
|
* page to request contexts other than a page view of the currently parsed
|
|
|
|
|
* article.
|
|
|
|
|
*
|
|
|
|
|
* Some applications examples:
|
|
|
|
|
*
|
|
|
|
|
* * To implement hidden categories, hiding pages from category listings
|
|
|
|
|
* by storing a property.
|
|
|
|
|
*
|
|
|
|
|
* * Overriding the displayed article title.
|
|
|
|
|
* @see ParserOutput::setDisplayTitle()
|
|
|
|
|
*
|
|
|
|
|
* * To implement image tagging, for example displaying an icon on an
|
|
|
|
|
* image thumbnail to indicate that it is listed for deletion on
|
|
|
|
|
* Wikimedia Commons.
|
|
|
|
|
* This is not actually implemented, yet but would be pretty cool.
|
|
|
|
|
*
|
2013-01-22 11:59:23 +00:00
|
|
|
* @note: Do not use setProperty() to set a property which is only used
|
|
|
|
|
* in a context where the ParserOutput object itself is already available,
|
|
|
|
|
* for example a normal page view. There is no need to save such a property
|
2014-03-18 20:20:09 +00:00
|
|
|
* in the database since the text is already parsed. You can just hook
|
2012-10-22 00:58:05 +00:00
|
|
|
* OutputPageParserOutput and get your data out of the ParserOutput object.
|
|
|
|
|
*
|
2013-01-22 11:59:23 +00:00
|
|
|
* If you are writing an extension where you want to set a property in the
|
|
|
|
|
* parser which is used by an OutputPageParserOutput hook, you have to
|
|
|
|
|
* associate the extension data directly with the ParserOutput object.
|
|
|
|
|
* Since MediaWiki 1.21, you can use setExtensionData() to do this:
|
|
|
|
|
*
|
|
|
|
|
* @par Example:
|
|
|
|
|
* @code
|
|
|
|
|
* $parser->getOutput()->setExtensionData( 'my_ext_foo', '...' );
|
|
|
|
|
* @endcode
|
|
|
|
|
*
|
|
|
|
|
* And then later, in OutputPageParserOutput or similar:
|
|
|
|
|
*
|
|
|
|
|
* @par Example:
|
|
|
|
|
* @code
|
|
|
|
|
* $output->getExtensionData( 'my_ext_foo' );
|
|
|
|
|
* @endcode
|
|
|
|
|
*
|
|
|
|
|
* In MediaWiki 1.20 and older, you have to use a custom member variable
|
|
|
|
|
* within the ParserOutput object:
|
2012-10-22 00:58:05 +00:00
|
|
|
*
|
|
|
|
|
* @par Example:
|
|
|
|
|
* @code
|
|
|
|
|
* $parser->getOutput()->my_ext_foo = '...';
|
|
|
|
|
* @endcode
|
|
|
|
|
*
|
2008-02-20 08:53:12 +00:00
|
|
|
*/
|
|
|
|
|
public function setProperty( $name, $value ) {
|
|
|
|
|
$this->mProperties[$name] = $value;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-26 21:11:09 +00:00
|
|
|
public function getProperty( $name ) {
|
2008-02-20 08:53:12 +00:00
|
|
|
return isset( $this->mProperties[$name] ) ? $this->mProperties[$name] : false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getProperties() {
|
|
|
|
|
if ( !isset( $this->mProperties ) ) {
|
|
|
|
|
$this->mProperties = array();
|
|
|
|
|
}
|
|
|
|
|
return $this->mProperties;
|
|
|
|
|
}
|
2011-08-01 15:40:02 +00:00
|
|
|
|
2010-12-26 19:21:45 +00:00
|
|
|
/**
|
2011-08-01 15:40:02 +00:00
|
|
|
* Returns the options from its ParserOptions which have been taken
|
2010-12-26 19:21:45 +00:00
|
|
|
* into account to produce this output or false if not available.
|
2014-04-21 23:38:39 +00:00
|
|
|
* @return array
|
2010-12-26 19:21:45 +00:00
|
|
|
*/
|
2013-01-26 21:11:09 +00:00
|
|
|
public function getUsedOptions() {
|
2010-12-26 19:21:45 +00:00
|
|
|
if ( !isset( $this->mAccessedOptions ) ) {
|
2011-08-01 15:50:49 +00:00
|
|
|
return array();
|
2010-12-26 19:21:45 +00:00
|
|
|
}
|
|
|
|
|
return array_keys( $this->mAccessedOptions );
|
2013-01-26 21:11:09 +00:00
|
|
|
}
|
2011-08-01 15:40:02 +00:00
|
|
|
|
2013-01-26 21:11:09 +00:00
|
|
|
/**
|
2013-12-02 13:20:26 +00:00
|
|
|
* Tags a parser option for use in the cache key for this parser output.
|
|
|
|
|
* Registered as a watcher at ParserOptions::registerWatcher() by Parser::clearState().
|
|
|
|
|
*
|
|
|
|
|
* @see ParserCache::getKey
|
|
|
|
|
* @see ParserCache::save
|
|
|
|
|
* @see ParserOptions::addExtraKey
|
|
|
|
|
* @see ParserOptions::optionsHash
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param string $option
|
2013-01-26 21:11:09 +00:00
|
|
|
*/
|
2013-12-02 13:20:26 +00:00
|
|
|
public function recordOption( $option ) {
|
2013-01-26 21:11:09 +00:00
|
|
|
$this->mAccessedOptions[$option] = true;
|
|
|
|
|
}
|
2012-04-05 15:21:07 +00:00
|
|
|
|
2012-05-08 15:09:30 +00:00
|
|
|
/**
|
2014-03-18 20:20:09 +00:00
|
|
|
* Adds an update job to the output. Any update jobs added to the output will
|
|
|
|
|
* eventually be executed in order to store any secondary information extracted
|
|
|
|
|
* from the page's content. This is triggered by calling getSecondaryDataUpdates()
|
|
|
|
|
* and is used for forward links updates on edit and backlink updates by jobs.
|
2012-05-10 19:22:11 +00:00
|
|
|
*
|
2012-08-20 14:55:28 +00:00
|
|
|
* @since 1.20
|
|
|
|
|
*
|
|
|
|
|
* @param DataUpdate $update
|
2012-05-08 15:09:30 +00:00
|
|
|
*/
|
|
|
|
|
public function addSecondaryDataUpdate( DataUpdate $update ) {
|
|
|
|
|
$this->mSecondaryDataUpdates[] = $update;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns any DataUpdate jobs to be executed in order to store secondary information
|
|
|
|
|
* extracted from the page's content, including a LinksUpdate object for all links stored in
|
|
|
|
|
* this ParserOutput object.
|
2012-05-10 19:22:11 +00:00
|
|
|
*
|
2014-05-10 23:03:45 +00:00
|
|
|
* @note Avoid using this method directly, use ContentHandler::getSecondaryDataUpdates()
|
|
|
|
|
* instead! The content handler may provide additional update objects.
|
2012-06-07 12:57:43 +00:00
|
|
|
*
|
2012-08-20 14:55:28 +00:00
|
|
|
* @since 1.20
|
|
|
|
|
*
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Title $title The title of the page we're updating. If not given, a title object will
|
|
|
|
|
* be created based on $this->getTitleText()
|
|
|
|
|
* @param bool $recursive Queue jobs for recursive updates?
|
2012-05-08 15:09:30 +00:00
|
|
|
*
|
2014-04-21 23:38:39 +00:00
|
|
|
* @return array An array of instances of DataUpdate
|
2012-05-08 15:09:30 +00:00
|
|
|
*/
|
|
|
|
|
public function getSecondaryDataUpdates( Title $title = null, $recursive = true ) {
|
2012-08-20 14:55:28 +00:00
|
|
|
if ( is_null( $title ) ) {
|
2012-05-08 15:09:30 +00:00
|
|
|
$title = Title::newFromText( $this->getTitleText() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$linksUpdate = new LinksUpdate( $title, $this, $recursive );
|
|
|
|
|
|
2013-01-25 15:46:24 +00:00
|
|
|
return array_merge( $this->mSecondaryDataUpdates, array( $linksUpdate ) );
|
2013-01-26 21:11:09 +00:00
|
|
|
}
|
2012-08-20 14:55:28 +00:00
|
|
|
|
2013-01-22 11:59:23 +00:00
|
|
|
/**
|
|
|
|
|
* Attaches arbitrary data to this ParserObject. This can be used to store some information in
|
|
|
|
|
* the ParserOutput object for later use during page output. The data will be cached along with
|
|
|
|
|
* the ParserOutput object, but unlike data set using setProperty(), it is not recorded in the
|
|
|
|
|
* database.
|
|
|
|
|
*
|
|
|
|
|
* This method is provided to overcome the unsafe practice of attaching extra information to a
|
|
|
|
|
* ParserObject by directly assigning member variables.
|
|
|
|
|
*
|
|
|
|
|
* To use setExtensionData() to pass extension information from a hook inside the parser to a
|
|
|
|
|
* hook in the page output, use this in the parser hook:
|
|
|
|
|
*
|
|
|
|
|
* @par Example:
|
|
|
|
|
* @code
|
|
|
|
|
* $parser->getOutput()->setExtensionData( 'my_ext_foo', '...' );
|
|
|
|
|
* @endcode
|
|
|
|
|
*
|
|
|
|
|
* And then later, in OutputPageParserOutput or similar:
|
|
|
|
|
*
|
|
|
|
|
* @par Example:
|
|
|
|
|
* @code
|
|
|
|
|
* $output->getExtensionData( 'my_ext_foo' );
|
|
|
|
|
* @endcode
|
|
|
|
|
*
|
|
|
|
|
* In MediaWiki 1.20 and older, you have to use a custom member variable
|
|
|
|
|
* within the ParserOutput object:
|
|
|
|
|
*
|
|
|
|
|
* @par Example:
|
|
|
|
|
* @code
|
|
|
|
|
* $parser->getOutput()->my_ext_foo = '...';
|
|
|
|
|
* @endcode
|
|
|
|
|
*
|
|
|
|
|
* @since 1.21
|
|
|
|
|
*
|
|
|
|
|
* @param string $key The key for accessing the data. Extensions should take care to avoid
|
2014-04-21 23:38:39 +00:00
|
|
|
* conflicts in naming keys. It is suggested to use the extension's name as a prefix.
|
2013-01-22 11:59:23 +00:00
|
|
|
*
|
|
|
|
|
* @param mixed $value The value to set. Setting a value to null is equivalent to removing
|
2014-04-21 23:38:39 +00:00
|
|
|
* the value.
|
2013-01-22 11:59:23 +00:00
|
|
|
*/
|
|
|
|
|
public function setExtensionData( $key, $value ) {
|
|
|
|
|
if ( $value === null ) {
|
|
|
|
|
unset( $this->mExtensionData[$key] );
|
|
|
|
|
} else {
|
|
|
|
|
$this->mExtensionData[$key] = $value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets extensions data previously attached to this ParserOutput using setExtensionData().
|
|
|
|
|
* Typically, such data would be set while parsing the page, e.g. by a parser function.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.21
|
|
|
|
|
*
|
|
|
|
|
* @param string $key The key to look up.
|
|
|
|
|
*
|
|
|
|
|
* @return mixed The value previously set for the given key using setExtensionData( $key ),
|
|
|
|
|
* or null if no value was set for this key.
|
|
|
|
|
*/
|
|
|
|
|
public function getExtensionData( $key ) {
|
|
|
|
|
if ( isset( $this->mExtensionData[$key] ) ) {
|
|
|
|
|
return $this->mExtensionData[$key];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-14 12:43:06 +00:00
|
|
|
private static function getTimes( $clock = null ) {
|
|
|
|
|
$ret = array();
|
|
|
|
|
if ( !$clock || $clock === 'wall' ) {
|
|
|
|
|
$ret['wall'] = microtime( true );
|
|
|
|
|
}
|
|
|
|
|
if ( ( !$clock || $clock === 'cpu' ) && function_exists( 'getrusage' ) ) {
|
|
|
|
|
$ru = getrusage();
|
|
|
|
|
$ret['cpu'] = $ru['ru_utime.tv_sec'] + $ru['ru_utime.tv_usec'] / 1e6;
|
|
|
|
|
$ret['cpu'] += $ru['ru_stime.tv_sec'] + $ru['ru_stime.tv_usec'] / 1e6;
|
|
|
|
|
}
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Resets the parse start timestamps for future calls to getTimeSinceStart()
|
|
|
|
|
* @since 1.22
|
|
|
|
|
*/
|
|
|
|
|
function resetParseStartTime() {
|
|
|
|
|
$this->mParseStartTime = self::getTimes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the time since resetParseStartTime() was last called
|
|
|
|
|
*
|
|
|
|
|
* Clocks available are:
|
|
|
|
|
* - wall: Wall clock time
|
|
|
|
|
* - cpu: CPU time (requires getrusage)
|
|
|
|
|
*
|
|
|
|
|
* @since 1.22
|
|
|
|
|
* @param string $clock
|
|
|
|
|
* @return float|null
|
|
|
|
|
*/
|
|
|
|
|
function getTimeSinceStart( $clock ) {
|
|
|
|
|
if ( !isset( $this->mParseStartTime[$clock] ) ) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$end = self::getTimes( $clock );
|
|
|
|
|
return $end[$clock] - $this->mParseStartTime[$clock];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets parser limit report data for a key
|
|
|
|
|
*
|
|
|
|
|
* The key is used as the prefix for various messages used for formatting:
|
|
|
|
|
* - $key: The label for the field in the limit report
|
|
|
|
|
* - $key-value-text: Message used to format the value in the "NewPP limit
|
|
|
|
|
* report" HTML comment. If missing, uses $key-format.
|
|
|
|
|
* - $key-value-html: Message used to format the value in the preview
|
|
|
|
|
* limit report table. If missing, uses $key-format.
|
|
|
|
|
* - $key-value: Message used to format the value. If missing, uses "$1".
|
|
|
|
|
*
|
|
|
|
|
* Note that all values are interpreted as wikitext, and so should be
|
|
|
|
|
* encoded with htmlspecialchars() as necessary, but should avoid complex
|
|
|
|
|
* HTML for sanity of display in the "NewPP limit report" comment.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.22
|
|
|
|
|
* @param string $key Message key
|
|
|
|
|
* @param mixed $value Appropriate for Message::params()
|
|
|
|
|
*/
|
|
|
|
|
function setLimitReportData( $key, $value ) {
|
|
|
|
|
$this->mLimitReportData[$key] = $value;
|
|
|
|
|
}
|
2014-03-18 20:20:09 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Save space for for serialization by removing useless values
|
|
|
|
|
*/
|
|
|
|
|
function __sleep() {
|
|
|
|
|
return array_diff(
|
|
|
|
|
array_keys( get_object_vars( $this ) ),
|
|
|
|
|
array( 'mSecondaryDataUpdates', 'mParseStartTime' )
|
|
|
|
|
);
|
|
|
|
|
}
|
2007-01-20 12:50:56 +00:00
|
|
|
}
|