50 unset( $this->
$name );
63 foreach ( $this->internals
as &$nsLinks ) {
64 foreach ( $nsLinks
as &$entry ) {
65 unset( $entry[
'title'] );
71 foreach ( $this->interwikis
as &$entry ) {
72 unset( $entry[
'title'] );
76 return [
'internals',
'interwikis',
'size' ];
83 foreach ( $this->internals
as &$nsLinks ) {
84 foreach ( $nsLinks
as &$entry ) {
85 $entry[
'title'] = Title::newFromText( $entry[
'pdbk'] );
91 foreach ( $this->interwikis
as &$entry ) {
92 $entry[
'title'] = Title::newFromText( $entry[
'pdbk'] );
102 foreach ( $other->internals
as $ns => $entries ) {
103 $this->size += count( $entries );
104 if ( !isset( $this->internals[$ns] ) ) {
105 $this->internals[$ns] = $entries;
107 $this->internals[$ns] += $entries;
110 $this->interwikis += $other->interwikis;
126 $this->tempIdOffset = $idOffset = $this->parent->nextLinkID();
129 # Renumber internal links
130 foreach ( $other->internals
as $ns => $nsLinks ) {
131 foreach ( $nsLinks
as $key => $entry ) {
132 $newKey = $idOffset + $key;
133 $this->internals[$ns][$newKey] = $entry;
134 $maxId = $newKey > $maxId ? $newKey : $maxId;
137 $texts = preg_replace_callback(
'/(<!--LINK \d+:)(\d+)(-->)/',
138 [ $this,
'mergeForeignCallback' ], $texts );
140 # Renumber interwiki links
141 foreach ( $other->interwikis
as $key => $entry ) {
142 $newKey = $idOffset + $key;
143 $this->interwikis[$newKey] = $entry;
144 $maxId = $newKey > $maxId ? $newKey : $maxId;
146 $texts = preg_replace_callback(
'/(<!--IWLINK )(\d+)(-->)/',
147 [ $this,
'mergeForeignCallback' ], $texts );
149 # Set the parent link ID to be beyond the highest used ID
150 $this->parent->setLinkID( $maxId + 1 );
151 $this->tempIdOffset =
null;
174 while ( $pos < strlen( $text ) ) {
175 if ( !preg_match(
'/<!--LINK (\d+):(\d+)-->/',
176 $text, $m, PREG_OFFSET_CAPTURE, $pos )
182 $sub->internals[$ns][$key] = $this->internals[$ns][$key];
183 $pos = $m[0][1] + strlen( $m[0][0] );
188 while ( $pos < strlen( $text ) ) {
189 if ( !preg_match(
'/<!--IWLINK (\d+)-->/', $text, $m, PREG_OFFSET_CAPTURE, $pos ) ) {
193 $sub->interwikis[$key] = $this->interwikis[$key];
194 $pos = $m[0][1] + strlen( $m[0][0] );
213 $this->internals = [];
214 $this->interwikis = [];
232 if ( !is_object( $nt ) ) {
234 $retVal =
"<!-- ERROR -->{$prefix}{$text}{$trail}";
236 # Separate the link trail from the rest of the link
241 'text' => $prefix . $text . $inside,
242 'pdbk' => $nt->getPrefixedDBkey(),
248 if ( $nt->isExternal() ) {
250 $key = $this->parent->nextLinkID();
251 $this->interwikis[$key] = $entry;
252 $retVal =
"<!--IWLINK $key-->{$trail}";
254 $key = $this->parent->nextLinkID();
255 $ns = $nt->getNamespace();
256 $this->internals[$ns][$key] = $entry;
257 $retVal =
"<!--LINK $ns:$key-->{$trail}";
279 if ( !$this->internals ) {
286 $linkCache = LinkCache::singleton();
287 $output = $this->parent->getOutput();
293 ksort( $this->internals );
295 $linkcolour_ids = [];
299 $lb->setCaller( __METHOD__ );
301 foreach ( $this->internals
as $ns => $entries ) {
302 foreach ( $entries
as $entry ) {
305 $pdbk = $entry[
'pdbk'];
307 # Skip invalid entries.
308 # Result will be ugly, but prevents crash.
309 if ( is_null(
$title ) ) {
313 # Check if it's a static known link, e.g. interwiki
314 if (
$title->isAlwaysKnown() ) {
319 $id = $linkCache->getGoodLinkID( $pdbk );
323 $linkcolour_ids[$id] = $pdbk;
324 } elseif ( $linkCache->isBadLink( $pdbk ) ) {
327 # Not in the link cache, add it to the query
333 if ( !$lb->isEmpty() ) {
334 $fields = array_merge(
335 LinkCache::getSelectFields(),
336 [
'page_namespace',
'page_title' ]
342 $lb->constructSet(
'page',
$dbr ),
346 # Fetch data and form into an associative array
347 # non-existent = broken
349 $title = Title::makeTitle(
$s->page_namespace,
$s->page_title );
350 $pdbk =
$title->getPrefixedDBkey();
351 $linkCache->addGoodLinkObjFromRow(
$title,
$s );
355 $linkcolour_ids[
$s->page_id] = $pdbk;
359 if ( count( $linkcolour_ids ) ) {
361 Hooks::run(
'GetLinkColours', [ $linkcolour_ids, &
$colours ] );
364 # Do a second query for different language variants of links and categories
369 # Construct search and replace arrays
371 foreach ( $this->internals
as $ns => $entries ) {
372 foreach ( $entries
as $index => $entry ) {
373 $pdbk = $entry[
'pdbk'];
375 $query = isset( $entry[
'query'] ) ? $entry[
'query'] : [];
377 $searchkey =
"<!--LINK $key-->";
378 $displayText = $entry[
'text'];
379 if ( isset( $entry[
'selflink'] ) ) {
383 if ( $displayText ===
'' ) {
386 $displayText =
new HtmlArmor( $displayText );
393 $linkCache->addBadLinkObj(
$title );
404 $replacePairs[$searchkey] =
$link;
410 $text = preg_replace_callback(
411 '/(<!--LINK .*?-->)/',
422 if ( empty( $this->interwikis ) ) {
426 # Make interwiki link HTML
427 $output = $this->parent->getOutput();
430 foreach ( $this->interwikis
as $key =>
$link ) {
439 $text = preg_replace_callback(
440 '/<!--IWLINK (.*?)-->/',
453 $output = $this->parent->getOutput();
454 $linkCache = LinkCache::singleton();
455 $titlesToBeConverted =
'';
461 foreach ( $this->internals
as $ns => $entries ) {
465 foreach ( $entries
as $index => $entry ) {
466 $pdbk = $entry[
'pdbk'];
469 $titlesAttrs[] = [ $index, $entry[
'title'] ];
472 $titlesToBeConverted .= $entry[
'title']->getText() .
"\0";
478 $titlesAllVariants =
$wgContLang->autoConvertToAllVariants( rtrim( $titlesToBeConverted,
"\0" ) );
479 $allVariantsName = array_keys( $titlesAllVariants );
480 foreach ( $titlesAllVariants
as &$titlesVariant ) {
481 $titlesVariant = explode(
"\0", $titlesVariant );
485 $parentTitle = $this->parent->getTitle();
486 foreach ( $titlesAttrs
as $i => $attrs ) {
489 $ns =
$title->getNamespace();
490 $text =
$title->getText();
492 foreach ( $allVariantsName
as $variantName ) {
493 $textVariant = $titlesAllVariants[$variantName][$i];
494 if ( $textVariant === $text ) {
498 $variantTitle = Title::makeTitle( $ns, $textVariant );
503 if ( $variantTitle->equals( $parentTitle ) && !
$title->hasFragment() ) {
504 $this->internals[$ns][$index][
'selflink'] =
true;
508 $linkBatch->addObj( $variantTitle );
509 $variantMap[$variantTitle->getPrefixedDBkey()][] =
"$ns:$index";
516 foreach (
$output->getCategoryLinks()
as $category ) {
517 $categoryTitle = Title::makeTitleSafe(
NS_CATEGORY, $category );
518 $linkBatch->addObj( $categoryTitle );
519 $variants =
$wgContLang->autoConvertToAllVariants( $category );
520 foreach ( $variants
as $variant ) {
521 if ( $variant !== $category ) {
522 $variantTitle = Title::makeTitleSafe(
NS_CATEGORY, $variant );
523 if ( is_null( $variantTitle ) ) {
526 $linkBatch->addObj( $variantTitle );
527 $categoryMap[$variant] = [ $category, $categoryTitle ];
532 if ( !$linkBatch->isEmpty() ) {
535 $fields = array_merge(
536 LinkCache::getSelectFields(),
537 [
'page_namespace',
'page_title' ]
540 $varRes =
$dbr->select(
'page',
542 $linkBatch->constructSet(
'page',
$dbr ),
546 $linkcolour_ids = [];
550 foreach ( $varRes
as $s ) {
551 $variantTitle = Title::makeTitle(
$s->page_namespace,
$s->page_title );
552 $varPdbk = $variantTitle->getPrefixedDBkey();
553 $vardbk = $variantTitle->getDBkey();
556 if ( isset( $variantMap[$varPdbk] ) ) {
557 $holderKeys = $variantMap[$varPdbk];
558 $linkCache->addGoodLinkObjFromRow( $variantTitle,
$s );
559 $output->addLink( $variantTitle,
$s->page_id );
563 foreach ( $holderKeys
as $key ) {
564 list( $ns, $index ) = explode(
':', $key, 2 );
565 $entry =& $this->internals[$ns][$index];
566 $pdbk = $entry[
'pdbk'];
570 $entry[
'title'] = $variantTitle;
571 $entry[
'pdbk'] = $varPdbk;
575 $linkcolour_ids[
$s->page_id] = $pdbk;
580 if ( isset( $categoryMap[$vardbk] ) ) {
581 list( $oldkey, $oldtitle ) = $categoryMap[$vardbk];
582 if ( !isset( $varCategories[$oldkey] ) && !$oldtitle->exists() ) {
583 $varCategories[$oldkey] = $vardbk;
587 Hooks::run(
'GetLinkColours', [ $linkcolour_ids, &
$colours ] );
590 if ( count( $varCategories ) > 0 ) {
592 $originalCats =
$output->getCategories();
593 foreach ( $originalCats
as $cat => $sortkey ) {
595 if ( array_key_exists( $cat, $varCategories ) ) {
596 $newCats[$varCategories[$cat]] = $sortkey;
598 $newCats[$cat] = $sortkey;
601 $output->setCategoryLinks( $newCats );
614 $text = preg_replace_callback(
615 '/<!--(LINK|IWLINK) (.*?)-->/',
616 [ $this,
'replaceTextCallback' ],
632 if (
$type ==
'LINK' ) {
633 list( $ns, $index ) = explode(
':', $key, 2 );
634 if ( isset( $this->internals[$ns][$index][
'text'] ) ) {
635 return $this->internals[$ns][$index][
'text'];
637 } elseif (
$type ==
'IWLINK' ) {
638 if ( isset( $this->interwikis[$key][
'text'] ) ) {
639 return $this->interwikis[$key][
'text'];
$wgLinkHolderBatchSize
LinkHolderArray batch size For debugging.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Class to perform replacement based on a simple hashtable lookup.
Marks HTML that shouldn't be escaped.
Class representing a list of titles The execute() method checks them all for existence and adds them ...
__wakeup()
Recreate the Title objects.
getSubArray( $text)
Get a subset of the current LinkHolderArray which is sufficient to interpret the given text.
replaceInterwiki(&$text)
Replace interwiki links.
merge( $other)
Merge another LinkHolderArray into this one.
replaceText( $text)
Replace link placeholders with plain text of links (not HTML-formatted).
replaceTextCallback( $matches)
Callback for replaceText()
mergeForeign( $other, $texts)
Merge a LinkHolderArray from another parser instance into this one.
replaceInternal(&$text)
Replace internal links.
__destruct()
Reduce memory usage to reduce the impact of circular references.
clear()
Clear all stored link holders.
mergeForeignCallback( $m)
isBig()
Returns true if the memory requirements of this object are getting large.
makeHolder( $nt, $text='', $query=[], $trail='', $prefix='')
Make a link placeholder.
doVariants(&$colours)
Modify $this->internals and $colours according to language variant linking rules.
__sleep()
Don't serialize the parent object, it is big, and not needed when it is a parameter to mergeForeign()...
replace(&$text)
Replace link placeholders with actual links, in the buffer.
static makeSelfLinkObj( $nt, $html='', $query='', $trail='', $prefix='')
Make appropriate markup for a link to the current article.
static splitTrail( $trail)
Split a link trail, return the "inside" portion and the remainder of the trail as a two-element array...
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
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
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 and the local content language as $wgContLang
when a variable name is used in a it is silently declared as a new local masking the global
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
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
namespace and then decline to actually register it file or subcat img or subcat $title
if the prop value should be in the metadata multi language array can modify can modify indexed by page_id & $colours
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Allows to change the fields on the form that will be generated $name
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 and may include noclasses after processing & $attribs
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
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 and may include noclasses after processing after in associative array form before processing starts Return false to skip default processing and return $ret $linkRenderer
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