MediaWiki REL1_28
ParserOutput.php
Go to the documentation of this file.
1<?php
2
24class ParserOutput extends CacheTime {
28 public $mText;
29
35
40
44 public $mIndicators = [];
45
50
55 public $mLinks = [];
56
61 public $mTemplates = [];
62
67 public $mTemplateIds = [];
68
72 public $mImages = [];
73
78
82 public $mExternalLinks = [];
83
88 public $mInterwikiLinks = [];
89
93 public $mNewSection = false;
94
98 public $mHideNewSection = false;
99
103 public $mNoGallery = false;
104
108 public $mHeadItems = [];
109
113 public $mModules = [];
114
118 public $mModuleScripts = [];
119
123 public $mModuleStyles = [];
124
128 public $mJsConfigVars = [];
129
133 public $mOutputHooks = [];
134
139 public $mWarnings = [];
140
144 public $mSections = [];
145
149 public $mEditSectionTokens = false;
150
154 public $mProperties = [];
155
159 public $mTOCHTML = '';
160
165
169 public $mTOCEnabled = true;
170
174 public $mEnableOOUI = false;
175
179 private $mIndexPolicy = '';
180
184 private $mAccessedOptions = [];
185
189 private $mExtensionData = [];
190
194 private $mLimitReportData = [];
195
199 private $mParseStartTime = [];
200
204 private $mPreventClickjacking = false;
205
209 private $mFlags = [];
210
213
215 private $mMaxAdaptiveExpiry = INF;
216
218 '#<(?:mw:)?editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)(</(?:mw:)?editsection>))#';
219
220 // finalizeAdaptiveCacheExpiry() uses TTL = MAX( m * PARSE_TIME + b, MIN_AR_TTL)
221 // Current values imply that m=3933.333333 and b=-333.333333
222 // See https://www.nngroup.com/articles/website-response-times/
223 const PARSE_FAST_SEC = .100; // perceived "fast" page parse
224 const PARSE_SLOW_SEC = 1.0; // perceived "slow" page parse
225 const FAST_AR_TTL = 60; // adaptive TTL for "fast" pages
226 const SLOW_AR_TTL = 3600; // adaptive TTL for "slow" pages
227 const MIN_AR_TTL = 15; // min adaptive TTL (for sanity, pool counter, and edit stashing)
228
229 public function __construct( $text = '', $languageLinks = [], $categoryLinks = [],
230 $unused = false, $titletext = ''
231 ) {
232 $this->mText = $text;
233 $this->mLanguageLinks = $languageLinks;
234 $this->mCategories = $categoryLinks;
235 $this->mTitleText = $titletext;
236 }
237
245 public function getRawText() {
246 return $this->mText;
247 }
248
249 public function getText() {
250 $text = $this->mText;
251 if ( $this->mEditSectionTokens ) {
252 $text = preg_replace_callback(
254 function ( $m ) {
256 $editsectionPage = Title::newFromText( htmlspecialchars_decode( $m[1] ) );
257 $editsectionSection = htmlspecialchars_decode( $m[2] );
258 $editsectionContent = isset( $m[4] ) ? $m[3] : null;
259
260 if ( !is_object( $editsectionPage ) ) {
261 throw new MWException( "Bad parser output text." );
262 }
263
264 $skin = $wgOut->getSkin();
265 return call_user_func_array(
266 [ $skin, 'doEditSectionLink' ],
267 [ $editsectionPage, $editsectionSection,
268 $editsectionContent, $wgLang->getCode() ]
269 );
270 },
271 $text
272 );
273 } else {
274 $text = preg_replace( ParserOutput::EDITSECTION_REGEX, '', $text );
275 }
276
277 // If you have an old cached version of this class - sorry, you can't disable the TOC
278 if ( isset( $this->mTOCEnabled ) && $this->mTOCEnabled ) {
279 $text = str_replace( [ Parser::TOC_START, Parser::TOC_END ], '', $text );
280 } else {
281 $text = preg_replace(
282 '#' . preg_quote( Parser::TOC_START, '#' ) . '.*?' . preg_quote( Parser::TOC_END, '#' ) . '#s',
283 '',
284 $text
285 );
286 }
287 return $text;
288 }
289
294 public function setSpeculativeRevIdUsed( $id ) {
295 $this->mSpeculativeRevId = $id;
296 }
297
299 public function getSpeculativeRevIdUsed() {
300 return $this->mSpeculativeRevId;
301 }
302
303 public function &getLanguageLinks() {
304 return $this->mLanguageLinks;
305 }
306
307 public function getInterwikiLinks() {
308 return $this->mInterwikiLinks;
309 }
310
311 public function getCategoryLinks() {
312 return array_keys( $this->mCategories );
313 }
314
315 public function &getCategories() {
316 return $this->mCategories;
317 }
318
322 public function getIndicators() {
323 return $this->mIndicators;
324 }
325
326 public function getTitleText() {
327 return $this->mTitleText;
328 }
329
330 public function getSections() {
331 return $this->mSections;
332 }
333
334 public function getEditSectionTokens() {
335 return $this->mEditSectionTokens;
336 }
337
338 public function &getLinks() {
339 return $this->mLinks;
340 }
341
342 public function &getTemplates() {
343 return $this->mTemplates;
344 }
345
346 public function &getTemplateIds() {
347 return $this->mTemplateIds;
348 }
349
350 public function &getImages() {
351 return $this->mImages;
352 }
353
354 public function &getFileSearchOptions() {
355 return $this->mFileSearchOptions;
356 }
357
358 public function &getExternalLinks() {
359 return $this->mExternalLinks;
360 }
361
362 public function getNoGallery() {
363 return $this->mNoGallery;
364 }
365
366 public function getHeadItems() {
367 return $this->mHeadItems;
368 }
369
370 public function getModules() {
371 return $this->mModules;
372 }
373
374 public function getModuleScripts() {
375 return $this->mModuleScripts;
376 }
377
378 public function getModuleStyles() {
379 return $this->mModuleStyles;
380 }
381
383 public function getJsConfigVars() {
384 return $this->mJsConfigVars;
385 }
386
387 public function getOutputHooks() {
388 return (array)$this->mOutputHooks;
389 }
390
391 public function getWarnings() {
392 return array_keys( $this->mWarnings );
393 }
394
395 public function getIndexPolicy() {
396 return $this->mIndexPolicy;
397 }
398
399 public function getTOCHTML() {
400 return $this->mTOCHTML;
401 }
402
406 public function getTimestamp() {
407 return $this->mTimestamp;
408 }
409
410 public function getLimitReportData() {
411 return $this->mLimitReportData;
412 }
413
414 public function getTOCEnabled() {
415 return $this->mTOCEnabled;
416 }
417
418 public function getEnableOOUI() {
419 return $this->mEnableOOUI;
420 }
421
422 public function setText( $text ) {
423 return wfSetVar( $this->mText, $text );
424 }
425
426 public function setLanguageLinks( $ll ) {
427 return wfSetVar( $this->mLanguageLinks, $ll );
428 }
429
430 public function setCategoryLinks( $cl ) {
431 return wfSetVar( $this->mCategories, $cl );
432 }
433
434 public function setTitleText( $t ) {
435 return wfSetVar( $this->mTitleText, $t );
436 }
437
438 public function setSections( $toc ) {
439 return wfSetVar( $this->mSections, $toc );
440 }
441
442 public function setEditSectionTokens( $t ) {
443 return wfSetVar( $this->mEditSectionTokens, $t );
444 }
445
446 public function setIndexPolicy( $policy ) {
447 return wfSetVar( $this->mIndexPolicy, $policy );
448 }
449
450 public function setTOCHTML( $tochtml ) {
451 return wfSetVar( $this->mTOCHTML, $tochtml );
452 }
453
454 public function setTimestamp( $timestamp ) {
455 return wfSetVar( $this->mTimestamp, $timestamp );
456 }
457
458 public function setTOCEnabled( $flag ) {
459 return wfSetVar( $this->mTOCEnabled, $flag );
460 }
461
462 public function addCategory( $c, $sort ) {
463 $this->mCategories[$c] = $sort;
464 }
465
469 public function setIndicator( $id, $content ) {
470 $this->mIndicators[$id] = $content;
471 }
472
480 public function setEnableOOUI( $enable = false ) {
481 $this->mEnableOOUI = $enable;
482 }
483
484 public function addLanguageLink( $t ) {
485 $this->mLanguageLinks[] = $t;
486 }
487
488 public function addWarning( $s ) {
489 $this->mWarnings[$s] = 1;
490 }
491
492 public function addOutputHook( $hook, $data = false ) {
493 $this->mOutputHooks[] = [ $hook, $data ];
494 }
495
496 public function setNewSection( $value ) {
497 $this->mNewSection = (bool)$value;
498 }
499 public function hideNewSection( $value ) {
500 $this->mHideNewSection = (bool)$value;
501 }
502 public function getHideNewSection() {
503 return (bool)$this->mHideNewSection;
504 }
505 public function getNewSection() {
506 return (bool)$this->mNewSection;
507 }
508
516 public static function isLinkInternal( $internal, $url ) {
517 return (bool)preg_match( '/^' .
518 # If server is proto relative, check also for http/https links
519 ( substr( $internal, 0, 2 ) === '//' ? '(?:https?:)?' : '' ) .
520 preg_quote( $internal, '/' ) .
521 # check for query/path/anchor or end of link in each case
522 '(?:[\?\/\#]|$)/i',
523 $url
524 );
525 }
526
527 public function addExternalLink( $url ) {
528 # We don't register links pointing to our own server, unless... :-)
530
531 # Replace unnecessary URL escape codes with the referenced character
532 # This prevents spammers from hiding links from the filters
533 $url = parser::normalizeLinkUrl( $url );
534
535 $registerExternalLink = true;
537 $registerExternalLink = !self::isLinkInternal( $wgServer, $url );
538 }
539 if ( $registerExternalLink ) {
540 $this->mExternalLinks[$url] = 1;
541 }
542 }
543
550 public function addLink( Title $title, $id = null ) {
551 if ( $title->isExternal() ) {
552 // Don't record interwikis in pagelinks
553 $this->addInterwikiLink( $title );
554 return;
555 }
556 $ns = $title->getNamespace();
557 $dbk = $title->getDBkey();
558 if ( $ns == NS_MEDIA ) {
559 // Normalize this pseudo-alias if it makes it down here...
560 $ns = NS_FILE;
561 } elseif ( $ns == NS_SPECIAL ) {
562 // We don't record Special: links currently
563 // It might actually be wise to, but we'd need to do some normalization.
564 return;
565 } elseif ( $dbk === '' ) {
566 // Don't record self links - [[#Foo]]
567 return;
568 }
569 if ( !isset( $this->mLinks[$ns] ) ) {
570 $this->mLinks[$ns] = [];
571 }
572 if ( is_null( $id ) ) {
573 $id = $title->getArticleID();
574 }
575 $this->mLinks[$ns][$dbk] = $id;
576 }
577
585 public function addImage( $name, $timestamp = null, $sha1 = null ) {
586 $this->mImages[$name] = 1;
587 if ( $timestamp !== null && $sha1 !== null ) {
588 $this->mFileSearchOptions[$name] = [ 'time' => $timestamp, 'sha1' => $sha1 ];
589 }
590 }
591
599 public function addTemplate( $title, $page_id, $rev_id ) {
600 $ns = $title->getNamespace();
601 $dbk = $title->getDBkey();
602 if ( !isset( $this->mTemplates[$ns] ) ) {
603 $this->mTemplates[$ns] = [];
604 }
605 $this->mTemplates[$ns][$dbk] = $page_id;
606 if ( !isset( $this->mTemplateIds[$ns] ) ) {
607 $this->mTemplateIds[$ns] = [];
608 }
609 $this->mTemplateIds[$ns][$dbk] = $rev_id; // For versioning
610 }
611
616 public function addInterwikiLink( $title ) {
617 if ( !$title->isExternal() ) {
618 throw new MWException( 'Non-interwiki link passed, internal parser error.' );
619 }
620 $prefix = $title->getInterwiki();
621 if ( !isset( $this->mInterwikiLinks[$prefix] ) ) {
622 $this->mInterwikiLinks[$prefix] = [];
623 }
624 $this->mInterwikiLinks[$prefix][$title->getDBkey()] = 1;
625 }
626
634 public function addHeadItem( $section, $tag = false ) {
635 if ( $tag !== false ) {
636 $this->mHeadItems[$tag] = $section;
637 } else {
638 $this->mHeadItems[] = $section;
639 }
640 }
641
642 public function addModules( $modules ) {
643 $this->mModules = array_merge( $this->mModules, (array)$modules );
644 }
645
646 public function addModuleScripts( $modules ) {
647 $this->mModuleScripts = array_merge( $this->mModuleScripts, (array)$modules );
648 }
649
650 public function addModuleStyles( $modules ) {
651 $this->mModuleStyles = array_merge( $this->mModuleStyles, (array)$modules );
652 }
653
661 public function addJsConfigVars( $keys, $value = null ) {
662 if ( is_array( $keys ) ) {
663 foreach ( $keys as $key => $value ) {
664 $this->mJsConfigVars[$key] = $value;
665 }
666 return;
667 }
668
669 $this->mJsConfigVars[$keys] = $value;
670 }
671
678 $this->addModules( $out->getModules() );
679 $this->addModuleScripts( $out->getModuleScripts() );
680 $this->addModuleStyles( $out->getModuleStyles() );
681 $this->addJsConfigVars( $out->getJsConfigVars() );
682
683 $this->mHeadItems = array_merge( $this->mHeadItems, $out->getHeadItemsArray() );
684 $this->mPreventClickjacking = $this->mPreventClickjacking || $out->getPreventClickjacking();
685 }
686
701 public function addTrackingCategory( $msg, $title ) {
702 if ( $title->getNamespace() === NS_SPECIAL ) {
703 wfDebug( __METHOD__ . ": Not adding tracking category $msg to special page!\n" );
704 return false;
705 }
706
707 // Important to parse with correct title (bug 31469)
708 $cat = wfMessage( $msg )
709 ->title( $title )
710 ->inContentLanguage()
711 ->text();
712
713 # Allow tracking categories to be disabled by setting them to "-"
714 if ( $cat === '-' ) {
715 return false;
716 }
717
718 $containerCategory = Title::makeTitleSafe( NS_CATEGORY, $cat );
719 if ( $containerCategory ) {
720 $this->addCategory( $containerCategory->getDBkey(), $this->getProperty( 'defaultsort' ) ?: '' );
721 return true;
722 } else {
723 wfDebug( __METHOD__ . ": [[MediaWiki:$msg]] is not a valid title!\n" );
724 return false;
725 }
726 }
727
739 public function setDisplayTitle( $text ) {
740 $this->setTitleText( $text );
741 $this->setProperty( 'displaytitle', $text );
742 }
743
752 public function getDisplayTitle() {
753 $t = $this->getTitleText();
754 if ( $t === '' ) {
755 return false;
756 }
757 return $t;
758 }
759
764 public function setFlag( $flag ) {
765 $this->mFlags[$flag] = true;
766 }
767
768 public function getFlag( $flag ) {
769 return isset( $this->mFlags[$flag] );
770 }
771
832 public function setProperty( $name, $value ) {
833 $this->mProperties[$name] = $value;
834 }
835
844 public function getProperty( $name ) {
845 return isset( $this->mProperties[$name] ) ? $this->mProperties[$name] : false;
846 }
847
848 public function unsetProperty( $name ) {
849 unset( $this->mProperties[$name] );
850 }
851
852 public function getProperties() {
853 if ( !isset( $this->mProperties ) ) {
854 $this->mProperties = [];
855 }
856 return $this->mProperties;
857 }
858
864 public function getUsedOptions() {
865 if ( !isset( $this->mAccessedOptions ) ) {
866 return [];
867 }
868 return array_keys( $this->mAccessedOptions );
869 }
870
883 public function recordOption( $option ) {
884 $this->mAccessedOptions[$option] = true;
885 }
886
927 public function setExtensionData( $key, $value ) {
928 if ( $value === null ) {
929 unset( $this->mExtensionData[$key] );
930 } else {
931 $this->mExtensionData[$key] = $value;
932 }
933 }
934
946 public function getExtensionData( $key ) {
947 if ( isset( $this->mExtensionData[$key] ) ) {
948 return $this->mExtensionData[$key];
949 }
950
951 return null;
952 }
953
954 private static function getTimes( $clock = null ) {
955 $ret = [];
956 if ( !$clock || $clock === 'wall' ) {
957 $ret['wall'] = microtime( true );
958 }
959 if ( !$clock || $clock === 'cpu' ) {
960 $ru = wfGetRusage();
961 if ( $ru ) {
962 $ret['cpu'] = $ru['ru_utime.tv_sec'] + $ru['ru_utime.tv_usec'] / 1e6;
963 $ret['cpu'] += $ru['ru_stime.tv_sec'] + $ru['ru_stime.tv_usec'] / 1e6;
964 }
965 }
966 return $ret;
967 }
968
973 public function resetParseStartTime() {
974 $this->mParseStartTime = self::getTimes();
975 }
976
988 public function getTimeSinceStart( $clock ) {
989 if ( !isset( $this->mParseStartTime[$clock] ) ) {
990 return null;
991 }
992
993 $end = self::getTimes( $clock );
994 return $end[$clock] - $this->mParseStartTime[$clock];
995 }
996
1016 public function setLimitReportData( $key, $value ) {
1017 $this->mLimitReportData[$key] = $value;
1018 }
1019
1030 public function hasDynamicContent() {
1032
1033 return $this->getCacheExpiry() < $wgParserCacheExpireTime;
1034 }
1035
1043 public function preventClickjacking( $flag = null ) {
1044 return wfSetVar( $this->mPreventClickjacking, $flag );
1045 }
1046
1053 public function updateRuntimeAdaptiveExpiry( $ttl ) {
1054 $this->mMaxAdaptiveExpiry = min( $ttl, $this->mMaxAdaptiveExpiry );
1055 $this->updateCacheExpiry( $ttl );
1056 }
1057
1064 if ( is_infinite( $this->mMaxAdaptiveExpiry ) ) {
1065 return; // not set
1066 }
1067
1068 $runtime = $this->getTimeSinceStart( 'wall' );
1069 if ( is_float( $runtime ) ) {
1070 $slope = ( self::SLOW_AR_TTL - self::FAST_AR_TTL )
1071 / ( self::PARSE_SLOW_SEC - self::PARSE_FAST_SEC );
1072 // SLOW_AR_TTL = PARSE_SLOW_SEC * $slope + $point
1073 $point = self::SLOW_AR_TTL - self::PARSE_SLOW_SEC * $slope;
1074
1075 $adaptiveTTL = min(
1076 max( $slope * $runtime + $point, self::MIN_AR_TTL ),
1077 $this->mMaxAdaptiveExpiry
1078 );
1079 $this->updateCacheExpiry( $adaptiveTTL );
1080 }
1081 }
1082
1083 public function __sleep() {
1084 return array_diff(
1085 array_keys( get_object_vars( $this ) ),
1086 [ 'mParseStartTime' ]
1087 );
1088 }
1089}
Apache License January http
$wgRegisterInternalExternals
By default MediaWiki does not register links pointing to same server in externallinks dataset,...
$wgParserCacheExpireTime
The expiry time for the parser cache, in seconds.
$wgServer
URL of the server.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
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...
wfGetRusage()
Get system resource usage of current request context.
$wgOut
Definition Setup.php:816
Parser cache specific expiry check.
Definition CacheTime.php:29
updateCacheExpiry( $seconds)
Sets the number of seconds after which this object should expire.
Definition CacheTime.php:93
getCacheExpiry()
Returns the number of seconds after which this object should expire.
MediaWiki exception.
This class should be covered by a general architecture document which does not exist as of January 20...
addOutputPageMetadata(OutputPage $out)
Copy items from the OutputPage object into this one.
getProperty( $name)
unsetProperty( $name)
static getTimes( $clock=null)
hideNewSection( $value)
setNewSection( $value)
addOutputHook( $hook, $data=false)
setDisplayTitle( $text)
Override the title to be used for display.
addJsConfigVars( $keys, $value=null)
Add one or more variables to be set in mw.config in JavaScript.
integer null $mSpeculativeRevId
Assumed rev ID for {{REVISIONID}} if no revision is set.
setIndicator( $id, $content)
addExternalLink( $url)
addModuleScripts( $modules)
setLanguageLinks( $ll)
integer $mMaxAdaptiveExpiry
Upper bound of expiry based on parse duration.
setCategoryLinks( $cl)
addInterwikiLink( $title)
setEditSectionTokens( $t)
setEnableOOUI( $enable=false)
Enables OOUI, if true, in any OutputPage instance this ParserOutput object is added to.
getDisplayTitle()
Get the title to be used for display.
addTrackingCategory( $msg, $title)
Add a tracking category, getting the title from a system message, or print a debug message if the tit...
finalizeAdaptiveCacheExpiry()
Call this when parsing is done to lower the TTL based on low parse times.
addTemplate( $title, $page_id, $rev_id)
Register a template dependency for this output.
addLink(Title $title, $id=null)
Record a local or interwiki inline link for saving in future link tables.
addModules( $modules)
resetParseStartTime()
Resets the parse start timestamps for future calls to getTimeSinceStart()
preventClickjacking( $flag=null)
Get or set the prevent-clickjacking flag.
setProperty( $name, $value)
Set a property to be stored in the page_props database table.
recordOption( $option)
Tags a parser option for use in the cache key for this parser output.
addHeadItem( $section, $tag=false)
Add some text to the "<head>".
hasDynamicContent()
Check whether the cache TTL was lowered due to dynamic content.
getExtensionData( $key)
Gets extensions data previously attached to this ParserOutput using setExtensionData().
getTimeSinceStart( $clock)
Returns the time since resetParseStartTime() was last called.
getRawText()
Get the cacheable text with <mw:editsection> markers still in it.
addImage( $name, $timestamp=null, $sha1=null)
Register a file dependency for this output.
updateRuntimeAdaptiveExpiry( $ttl)
Lower the runtime adaptive TTL to at most this value.
setTOCHTML( $tochtml)
getUsedOptions()
Returns the options from its ParserOptions which have been taken into account to produce this output ...
setLimitReportData( $key, $value)
Sets parser limit report data for a key.
setExtensionData( $key, $value)
Attaches arbitrary data to this ParserObject.
setTimestamp( $timestamp)
setSpeculativeRevIdUsed( $id)
__construct( $text='', $languageLinks=[], $categoryLinks=[], $unused=false, $titletext='')
static isLinkInternal( $internal, $url)
Checks, if a url is pointing to the own server.
setTOCEnabled( $flag)
addModuleStyles( $modules)
setFlag( $flag)
Fairly generic flag setter thingy.
const EDITSECTION_REGEX
addCategory( $c, $sort)
setIndexPolicy( $policy)
Represents a title within MediaWiki.
Definition Title.php:36
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
For a write query
Definition database.txt:26
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
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
Definition design.txt:12
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
Definition design.txt:56
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
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
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
database rows
Definition globals.txt:10
const NS_FILE
Definition Defines.php:62
const NS_SPECIAL
Definition Defines.php:45
const NS_MEDIA
Definition Defines.php:44
const NS_CATEGORY
Definition Defines.php:70
the array() calling protocol came about after MediaWiki 1.4rc1.
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 overridable Default is either copyrightwarning or copyrightwarning2 overridable Default is editpage tos summary such as anonymity and the real check
Definition hooks.txt:1444
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:986
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content $content
Definition hooks.txt:1094
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
Definition hooks.txt:2902
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 "&lt;div ...>$1&lt;/div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
null for the local wiki Added in
Definition hooks.txt:1558
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
Definition hooks.txt:1949
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
Definition hooks.txt:886
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books $tag
Definition hooks.txt:1033
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
Definition hooks.txt:1955
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:304
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
Definition hooks.txt:2901
if( $limit) $timestamp
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
Definition injection.txt:37
$sort
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
in the order they appear.
Definition sitelist.txt:3