Go to the documentation of this file.
221 '#<(?:mw:)?editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)(</(?:mw:)?editsection>))#s';
232 public function __construct( $text =
'', $languageLinks = [], $categoryLinks = [],
233 $unused =
false, $titletext =
''
235 $this->mText = $text;
236 $this->mLanguageLinks = $languageLinks;
237 $this->mCategories = $categoryLinks;
238 $this->mTitleText = $titletext;
255 if ( $this->mEditSectionTokens ) {
256 $text = preg_replace_callback(
257 self::EDITSECTION_REGEX,
261 $editsectionSection = htmlspecialchars_decode( $m[2] );
262 $editsectionContent = isset( $m[4] ) ? Sanitizer::decodeCharReferences( $m[3] ) :
null;
264 if ( !is_object( $editsectionPage ) ) {
265 throw new MWException(
"Bad parser output text." );
269 return call_user_func_array(
270 [
$skin,
'doEditSectionLink' ],
271 [ $editsectionPage, $editsectionSection,
272 $editsectionContent,
$wgLang->getCode() ]
278 $text = preg_replace( self::EDITSECTION_REGEX,
'', $text );
282 if ( isset( $this->mTOCEnabled ) && $this->mTOCEnabled ) {
283 $text = str_replace( [ Parser::TOC_START, Parser::TOC_END ],
'', $text );
285 $text = preg_replace(
286 '#' . preg_quote( Parser::TOC_START,
'#' ) .
'.*?' . preg_quote( Parser::TOC_END,
'#' ) .
'#s',
299 $this->mSpeculativeRevId = $id;
319 return array_keys( $this->mCategories );
403 return array_keys( $this->mWarnings );
438 return wfSetVar( $this->mText, $text );
442 return wfSetVar( $this->mLanguageLinks, $ll );
446 return wfSetVar( $this->mCategories, $cl );
454 return wfSetVar( $this->mSections, $toc );
458 return wfSetVar( $this->mEditSectionTokens,
$t );
462 return wfSetVar( $this->mIndexPolicy, $policy );
466 return wfSetVar( $this->mTOCHTML, $tochtml );
470 return wfSetVar( $this->mTimestamp, $timestamp );
474 return wfSetVar( $this->mTOCEnabled, $flag );
478 $this->mCategories[$c] =
$sort;
487 $this->mIndicators[$id] = $content;
498 $this->mEnableOOUI = $enable;
502 $this->mLanguageLinks[] =
$t;
506 $this->mWarnings[
$s] = 1;
510 $this->mOutputHooks[] = [ $hook, $data ];
514 $this->mNewSection = (bool)
$value;
517 $this->mHideNewSection = (bool)
$value;
534 return (
bool)preg_match(
'/^' .
536 ( substr( $internal, 0, 2 ) ===
'//' ?
'(?:https?:)?' :
'' ) .
537 preg_quote( $internal,
'/' ) .
545 # We don't register links pointing to our own server, unless... :-)
548 # Replace unnecessary URL escape codes with the referenced character
549 # This prevents spammers from hiding links from the filters
550 $url = parser::normalizeLinkUrl( $url );
552 $registerExternalLink =
true;
556 if ( $registerExternalLink ) {
557 $this->mExternalLinks[$url] = 1;
568 if (
$title->isExternal() ) {
573 $ns =
$title->getNamespace();
574 $dbk =
$title->getDBkey();
582 } elseif ( $dbk ===
'' ) {
586 if ( !isset( $this->mLinks[$ns] ) ) {
587 $this->mLinks[$ns] = [];
589 if ( is_null( $id ) ) {
590 $id =
$title->getArticleID();
592 $this->mLinks[$ns][$dbk] = $id;
603 $this->mImages[
$name] = 1;
604 if ( $timestamp !==
null && $sha1 !==
null ) {
605 $this->mFileSearchOptions[
$name] = [
'time' => $timestamp,
'sha1' => $sha1 ];
617 $ns =
$title->getNamespace();
618 $dbk =
$title->getDBkey();
619 if ( !isset( $this->mTemplates[$ns] ) ) {
620 $this->mTemplates[$ns] = [];
622 $this->mTemplates[$ns][$dbk] = $page_id;
623 if ( !isset( $this->mTemplateIds[$ns] ) ) {
624 $this->mTemplateIds[$ns] = [];
626 $this->mTemplateIds[$ns][$dbk] = $rev_id;
634 if ( !
$title->isExternal() ) {
635 throw new MWException(
'Non-interwiki link passed, internal parser error.' );
637 $prefix =
$title->getInterwiki();
638 if ( !isset( $this->mInterwikiLinks[$prefix] ) ) {
639 $this->mInterwikiLinks[$prefix] = [];
641 $this->mInterwikiLinks[$prefix][
$title->getDBkey()] = 1;
652 if ( $tag !==
false ) {
660 $this->mModules = array_merge( $this->mModules, (
array)
$modules );
664 $this->mModuleScripts = array_merge( $this->mModuleScripts, (
array)
$modules );
668 $this->mModuleStyles = array_merge( $this->mModuleStyles, (
array)
$modules );
679 if ( is_array(
$keys ) ) {
681 $this->mJsConfigVars[$key] =
$value;
700 $this->mHeadItems = array_merge( $this->mHeadItems,
$out->getHeadItemsArray() );
701 $this->mPreventClickjacking = $this->mPreventClickjacking ||
$out->getPreventClickjacking();
721 if (
$title->isSpecialPage() ) {
722 wfDebug( __METHOD__ .
": Not adding tracking category $msg to special page!\n" );
729 ->inContentLanguage()
732 # Allow tracking categories to be disabled by setting them to "-"
733 if ( $cat ===
'-' ) {
738 if ( $containerCategory ) {
742 wfDebug( __METHOD__ .
": [[MediaWiki:$msg]] is not a valid title!\n" );
784 $this->mFlags[$flag] =
true;
788 return isset( $this->mFlags[$flag] );
865 return isset( $this->mProperties[
$name] ) ? $this->mProperties[
$name] :
false;
869 unset( $this->mProperties[
$name] );
873 if ( !isset( $this->mProperties ) ) {
874 $this->mProperties = [];
885 if ( !isset( $this->mAccessedOptions ) ) {
888 return array_keys( $this->mAccessedOptions );
904 $this->mAccessedOptions[$option] =
true;
949 unset( $this->mExtensionData[$key] );
951 $this->mExtensionData[$key] =
$value;
967 if ( isset( $this->mExtensionData[$key] ) ) {
968 return $this->mExtensionData[$key];
974 private static function getTimes( $clock =
null ) {
976 if ( !$clock || $clock ===
'wall' ) {
977 $ret[
'wall'] = microtime(
true );
979 if ( !$clock || $clock ===
'cpu' ) {
982 $ret[
'cpu'] = $ru[
'ru_utime.tv_sec'] + $ru[
'ru_utime.tv_usec'] / 1e6;
983 $ret[
'cpu'] += $ru[
'ru_stime.tv_sec'] + $ru[
'ru_stime.tv_usec'] / 1e6;
1009 if ( !isset( $this->mParseStartTime[$clock] ) ) {
1014 return $end[$clock] - $this->mParseStartTime[$clock];
1037 $this->mLimitReportData[$key] =
$value;
1039 if ( is_array(
$value ) ) {
1040 if ( array_keys(
$value ) === [ 0, 1 ]
1041 && is_numeric(
$value[0] )
1042 && is_numeric(
$value[1] )
1044 $data = [
'value' =>
$value[0],
'limit' =>
$value[1] ];
1052 if ( strpos( $key,
'-' ) ) {
1053 list( $ns,
$name ) = explode(
'-', $key, 2 );
1054 $this->mLimitReportJSData[$ns][
$name] = $data;
1056 $this->mLimitReportJSData[$key] = $data;
1084 return wfSetVar( $this->mPreventClickjacking, $flag );
1094 $this->mMaxAdaptiveExpiry = min( $ttl, $this->mMaxAdaptiveExpiry );
1104 if ( is_infinite( $this->mMaxAdaptiveExpiry ) ) {
1109 if ( is_float( $runtime ) ) {
1111 / ( self::PARSE_SLOW_SEC - self::PARSE_FAST_SEC );
1113 $point = self::SLOW_AR_TTL - self::PARSE_SLOW_SEC * $slope;
1116 max( $slope * $runtime + $point, self::MIN_AR_TTL ),
1117 $this->mMaxAdaptiveExpiry
1125 array_keys( get_object_vars( $this ) ),
1126 [
'mParseStartTime' ]
addOutputPageMetadata(OutputPage $out)
Copy items from the OutputPage object into this one.
getCacheExpiry()
Returns the number of seconds after which this object should expire.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
setSpeculativeRevIdUsed( $id)
Parser cache specific expiry check.
addModuleScripts( $modules)
resetParseStartTime()
Resets the parse start timestamps for future calls to getTimeSinceStart()
setDisplayTitle( $text)
Override the title to be used for display.
setTimestamp( $timestamp)
getUsedOptions()
Returns the options from its ParserOptions which have been taken into account to produce this output ...
We use the convention $dbr for read and $dbw for write to help you keep track of whether the database object is a the world will explode Or to be a subsequent write query which succeeded on the master may fail when replicated to the slave due to a unique key collision Replication on the slave will stop and it may take hours to repair the database and get it back online Setting read_only in my cnf on the slave will avoid this but given the dire we prefer to have as many checks as possible We provide a but the wrapper functions like please read the documentation for except in special pages derived from QueryPage It s a common pitfall for new developers to submit code containing SQL queries which examine huge numbers of rows Remember that COUNT * is(N), counting rows in atable is like counting beans in a bucket.------------------------------------------------------------------------ Replication------------------------------------------------------------------------The largest installation of MediaWiki, Wikimedia, uses a large set ofslave MySQL servers replicating writes made to a master MySQL server. Itis important to understand the issues associated with this setup if youwant to write code destined for Wikipedia.It 's often the case that the best algorithm to use for a given taskdepends on whether or not replication is in use. Due to our unabashedWikipedia-centrism, we often just use the replication-friendly version, but if you like, you can use wfGetLB() ->getServerCount() > 1 tocheck to see if replication is in use.===Lag===Lag primarily occurs when large write queries are sent to the master.Writes on the master are executed in parallel, but they are executed inserial when they are replicated to the slaves. The master writes thequery to the binlog when the transaction is committed. The slaves pollthe binlog and start executing the query as soon as it appears. They canservice reads while they are performing a write query, but will not readanything more from the binlog and thus will perform no more writes. Thismeans that if the write query runs for a long time, the slaves will lagbehind the master for the time it takes for the write query to complete.Lag can be exacerbated by high read load. MediaWiki 's load balancer willstop sending reads to a slave when it is lagged by more than 30 seconds.If the load ratios are set incorrectly, or if there is too much loadgenerally, this may lead to a slave permanently hovering around 30seconds lag.If all slaves are lagged by more than 30 seconds, MediaWiki will stopwriting to the database. All edits and other write operations will berefused, with an error returned to the user. This gives the slaves achance to catch up. Before we had this mechanism, the slaves wouldregularly lag by several minutes, making review of recent editsdifficult.In addition to this, MediaWiki attempts to ensure that the user seesevents occurring on the wiki in chronological order. A few seconds of lagcan be tolerated, as long as the user sees a consistent picture fromsubsequent requests. This is done by saving the master binlog positionin the session, and then at the start of each request, waiting for theslave to catch up to that position before doing any reads from it. Ifthis wait times out, reads are allowed anyway, but the request isconsidered to be in "lagged slave mode". Lagged slave mode can bechecked by calling wfGetLB() ->getLaggedSlaveMode(). The onlypractical consequence at present is a warning displayed in the pagefooter.===Lag avoidance===To avoid excessive lag, queries which write large numbers of rows shouldbe split up, generally to write one row at a time. Multi-row INSERT ...SELECT queries are the worst offenders should be avoided altogether.Instead do the select first and then the insert.===Working with lag===Despite our best efforts, it 's not practical to guarantee a low-lagenvironment. Lag will usually be less than one second, but mayoccasionally be up to 30 seconds. For scalability, it 's very importantto keep load on the master low, so simply sending all your queries tothe master is not the answer. So when you have a genuine need forup-to-date data, the following approach is advised:1) Do a quick query to the master for a sequence number or timestamp 2) Run the full query on the slave and check if it matches the data you gotfrom the master 3) If it doesn 't, run the full query on the masterTo avoid swamping the master every time the slaves lag, use of thisapproach should be kept to a minimum. In most cases you should just readfrom the slave and let the user deal with the delay.------------------------------------------------------------------------ Lock contention------------------------------------------------------------------------Due to the high write rate on Wikipedia(and some other wikis), MediaWiki developers need to be very careful to structure their writesto avoid long-lasting locks. By default, MediaWiki opens a transactionat the first query, and commits it before the output is sent. Locks willbe held from the time when the query is done until the commit. So youcan reduce lock time by doing as much processing as possible before youdo your write queries.Often this approach is not good enough, and it becomes necessary toenclose small groups of queries in their own transaction. Use thefollowing syntax:$dbw=wfGetDB(DB_MASTER
setLimitReportData( $key, $value)
Sets parser limit report data for a key.
wfSetVar(&$dest, $source, $force=false)
Sets dest to source and returns the original value of dest If source is NULL, it just returns the val...
array $mLimitReportJSData
Parser limit report data for JSON.
setIndicator( $id, $content)
addTemplate( $title, $page_id, $rev_id)
Register a template dependency for this output.
getModuleStyles( $filter=false, $position=null)
Get the list of module CSS to include on this page.
setFlag( $flag)
Fairly generic flag setter thingy.
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template to be included in the link
addLink(Title $title, $id=null)
Record a local or interwiki inline link for saving in future link tables.
int $mMaxAdaptiveExpiry
Upper bound of expiry based on parse duration.
__construct( $text='', $languageLinks=[], $categoryLinks=[], $unused=false, $titletext='')
Allows to change the fields on the form that will be generated $name
Apache License January http
getModuleScripts( $filter=false, $position=null)
Get the list of module JS to include on this page.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
getModules( $filter=false, $position=null, $param='mModules', $type=ResourceLoaderModule::TYPE_COMBINED)
Get the list of modules to include on this page.
namespace and then decline to actually register it file or subcat img or subcat $title
static isLinkInternal( $internal, $url)
Checks, if a url is pointing to the own server.
updateRuntimeAdaptiveExpiry( $ttl)
Lower the runtime adaptive TTL to at most this value.
null for the wiki Added in
addImage( $name, $timestamp=null, $sha1=null)
Register a file dependency for this output.
$wgParserCacheExpireTime
The expiry time for the parser cache, in seconds.
static getTimes( $clock=null)
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as $wgLang
addModuleStyles( $modules)
when a variable name is used in a it is silently declared as a new masking the global
getDisplayTitle()
Get the title to be used for display.
in this case you re responsible for computing and outputting the entire conflict i the difference between revisions and your text headers and sections and Diff or overridable Default is either copyrightwarning or copyrightwarning2 overridable Default is editpage tos summary such as anonymity and the real check
setEditSectionTokens( $t)
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
This class should be covered by a general architecture document which does not exist as of January 20...
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
recordOption( $option)
Tags a parser option for use in the cache key for this parser output.
addOutputHook( $hook, $data=false)
This document describes the XML format used to represent information about external sites known to a MediaWiki installation This information about external sites is used to allow inter wiki links
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
setProperty( $name, $value)
Set a property to be stored in the page_props database table.
setExtensionData( $key, $value)
Attaches arbitrary data to this ParserObject.
$wgServer
URL of the server.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Represents a title within MediaWiki.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at https
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
addJsConfigVars( $keys, $value=null)
Add one or more variables to be set in mw.config in JavaScript.
getRawText()
Get the cacheable text with <mw:editsection> markers still in it.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned $skin
updateCacheExpiry( $seconds)
Sets the number of seconds after which this object should expire.
addTrackingCategory( $msg, $title)
Add a tracking category, getting the title from a system message, or print a debug message if the tit...
getExtensionData( $key)
Gets extensions data previously attached to this ParserOutput using setExtensionData().
globals txt Globals are evil The original MediaWiki code relied on globals for processing context far too often MediaWiki development since then has been a story of slowly moving context out of global variables and into objects Storing processing context in object member variables allows those objects to be reused in a much more flexible way Consider the elegance of
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "<
addInterwikiLink( $title)
getJsConfigVars()
Get the javascript config vars to include on this page.
$wgRegisterInternalExternals
By default MediaWiki does not register links pointing to same server in externallinks dataset,...
int null $mSpeculativeRevId
Assumed rev ID for {{REVISIONID}} if no revision is set.
hasDynamicContent()
Check whether the cache TTL was lowered due to dynamic content.
addHeadItem( $section, $tag=false)
Add some text to the "<head>".
setEnableOOUI( $enable=false)
Enables OOUI, if true, in any OutputPage instance this ParserOutput object is added to.
wfGetRusage()
Get system resource usage of current request context.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same so they can t rely on Unix and must forbid reads to even standard directories like tmp lest users read each others files We cannot assume that the user has the ability to install or run any programs not written as web accessible PHP scripts Since anything that works on cheap shared hosting will work if you have shell or root access MediaWiki s design is based around catering to the lowest common denominator Although we support higher end setups as the way many things work by default is tailored toward shared hosting These defaults are unconventional from the point of view of and they certainly aren t ideal for someone who s installing MediaWiki as MediaWiki does not conform to normal Unix filesystem layout Hopefully we ll offer direct support for standard layouts in the but for now *any change to the location of files is unsupported *Moving things and leaving symlinks will *probably *not break but it is *strongly *advised not to try any more intrusive changes to get MediaWiki to conform more closely to your filesystem hierarchy Any such attempt will almost certainly result in unnecessary bugs The standard recommended location to install relative to the web is it should be possible to enable the appropriate rewrite rules by if you can reconfigure the web server
finalizeAdaptiveCacheExpiry()
Call this when parsing is done to lower the TTL based on low parse times.
getSpeculativeRevIdUsed()
getTimeSinceStart( $clock)
Returns the time since resetParseStartTime() was last called.
the array() calling protocol came about after MediaWiki 1.4rc1.
preventClickjacking( $flag=null)
Get or set the prevent-clickjacking flag.
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is and will automatically terminate your rights under this License parties who have received or from you under this License will not have their licenses terminated so long as such parties remain in full compliance You are not required to accept this since you have not signed it nothing else grants you permission to modify or distribute the Program or its derivative works These actions are prohibited by law if you do not accept this License by modifying or distributing the you indicate your acceptance of this License to do and all its terms and conditions for distributing or modifying the Program or works based on it Each time you redistribute the the recipient automatically receives a license from the original licensor to distribute or modify the Program subject to these terms and conditions You may not impose any further restrictions on the recipients exercise of the rights granted herein You are not responsible for enforcing compliance by third parties to this License If
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out