LinkHolderArray.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. <?php
  2. /**
  3. * Holder of replacement pairs for wiki links
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. * http://www.gnu.org/copyleft/gpl.html
  19. *
  20. * @file
  21. * @ingroup Parser
  22. */
  23. use MediaWiki\MediaWikiServices;
  24. /**
  25. * @ingroup Parser
  26. */
  27. class LinkHolderArray {
  28. public $internals = [];
  29. public $interwikis = [];
  30. public $size = 0;
  31. /**
  32. * @var Parser
  33. */
  34. public $parent;
  35. protected $tempIdOffset;
  36. /**
  37. * @param Parser $parent
  38. */
  39. public function __construct( $parent ) {
  40. $this->parent = $parent;
  41. }
  42. /**
  43. * Reduce memory usage to reduce the impact of circular references
  44. */
  45. public function __destruct() {
  46. // @phan-suppress-next-line PhanTypeSuspiciousNonTraversableForeach
  47. foreach ( $this as $name => $value ) {
  48. unset( $this->$name );
  49. }
  50. }
  51. /**
  52. * Don't serialize the parent object, it is big, and not needed when it is
  53. * a parameter to mergeForeign(), which is the only application of
  54. * serializing at present.
  55. *
  56. * Compact the titles, only serialize the text form.
  57. * @return array
  58. */
  59. public function __sleep() {
  60. foreach ( $this->internals as &$nsLinks ) {
  61. foreach ( $nsLinks as &$entry ) {
  62. unset( $entry['title'] );
  63. }
  64. }
  65. unset( $nsLinks );
  66. unset( $entry );
  67. foreach ( $this->interwikis as &$entry ) {
  68. unset( $entry['title'] );
  69. }
  70. unset( $entry );
  71. return [ 'internals', 'interwikis', 'size' ];
  72. }
  73. /**
  74. * Recreate the Title objects
  75. */
  76. public function __wakeup() {
  77. foreach ( $this->internals as &$nsLinks ) {
  78. foreach ( $nsLinks as &$entry ) {
  79. $entry['title'] = Title::newFromText( $entry['pdbk'] );
  80. }
  81. }
  82. unset( $nsLinks );
  83. unset( $entry );
  84. foreach ( $this->interwikis as &$entry ) {
  85. $entry['title'] = Title::newFromText( $entry['pdbk'] );
  86. }
  87. unset( $entry );
  88. }
  89. /**
  90. * Merge another LinkHolderArray into this one
  91. * @param LinkHolderArray $other
  92. */
  93. public function merge( $other ) {
  94. foreach ( $other->internals as $ns => $entries ) {
  95. $this->size += count( $entries );
  96. if ( !isset( $this->internals[$ns] ) ) {
  97. $this->internals[$ns] = $entries;
  98. } else {
  99. $this->internals[$ns] += $entries;
  100. }
  101. }
  102. $this->interwikis += $other->interwikis;
  103. }
  104. /**
  105. * Merge a LinkHolderArray from another parser instance into this one. The
  106. * keys will not be preserved. Any text which went with the old
  107. * LinkHolderArray and needs to work with the new one should be passed in
  108. * the $texts array. The strings in this array will have their link holders
  109. * converted for use in the destination link holder. The resulting array of
  110. * strings will be returned.
  111. *
  112. * @param LinkHolderArray $other
  113. * @param array $texts Array of strings
  114. * @return array
  115. */
  116. public function mergeForeign( $other, $texts ) {
  117. $this->tempIdOffset = $idOffset = $this->parent->nextLinkID();
  118. $maxId = 0;
  119. # Renumber internal links
  120. foreach ( $other->internals as $ns => $nsLinks ) {
  121. foreach ( $nsLinks as $key => $entry ) {
  122. $newKey = $idOffset + $key;
  123. $this->internals[$ns][$newKey] = $entry;
  124. $maxId = $newKey > $maxId ? $newKey : $maxId;
  125. }
  126. }
  127. $texts = preg_replace_callback( '/(<!--LINK\'" \d+:)(\d+)(-->)/',
  128. [ $this, 'mergeForeignCallback' ], $texts );
  129. # Renumber interwiki links
  130. foreach ( $other->interwikis as $key => $entry ) {
  131. $newKey = $idOffset + $key;
  132. $this->interwikis[$newKey] = $entry;
  133. $maxId = $newKey > $maxId ? $newKey : $maxId;
  134. }
  135. $texts = preg_replace_callback( '/(<!--IWLINK\'" )(\d+)(-->)/',
  136. [ $this, 'mergeForeignCallback' ], $texts );
  137. # Set the parent link ID to be beyond the highest used ID
  138. $this->parent->setLinkID( $maxId + 1 );
  139. $this->tempIdOffset = null;
  140. return $texts;
  141. }
  142. /**
  143. * @param array $m
  144. * @return string
  145. */
  146. protected function mergeForeignCallback( $m ) {
  147. return $m[1] . ( $m[2] + $this->tempIdOffset ) . $m[3];
  148. }
  149. /**
  150. * Get a subset of the current LinkHolderArray which is sufficient to
  151. * interpret the given text.
  152. * @param string $text
  153. * @return LinkHolderArray
  154. */
  155. public function getSubArray( $text ) {
  156. $sub = new LinkHolderArray( $this->parent );
  157. # Internal links
  158. $pos = 0;
  159. while ( $pos < strlen( $text ) ) {
  160. if ( !preg_match( '/<!--LINK\'" (\d+):(\d+)-->/',
  161. $text, $m, PREG_OFFSET_CAPTURE, $pos )
  162. ) {
  163. break;
  164. }
  165. $ns = $m[1][0];
  166. $key = $m[2][0];
  167. $sub->internals[$ns][$key] = $this->internals[$ns][$key];
  168. $pos = $m[0][1] + strlen( $m[0][0] );
  169. }
  170. # Interwiki links
  171. $pos = 0;
  172. while ( $pos < strlen( $text ) ) {
  173. if ( !preg_match( '/<!--IWLINK\'" (\d+)-->/', $text, $m, PREG_OFFSET_CAPTURE, $pos ) ) {
  174. break;
  175. }
  176. $key = $m[1][0];
  177. $sub->interwikis[$key] = $this->interwikis[$key];
  178. $pos = $m[0][1] + strlen( $m[0][0] );
  179. }
  180. return $sub;
  181. }
  182. /**
  183. * Returns true if the memory requirements of this object are getting large
  184. * @return bool
  185. */
  186. public function isBig() {
  187. global $wgLinkHolderBatchSize;
  188. return $this->size > $wgLinkHolderBatchSize;
  189. }
  190. /**
  191. * Clear all stored link holders.
  192. * Make sure you don't have any text left using these link holders, before you call this
  193. */
  194. public function clear() {
  195. $this->internals = [];
  196. $this->interwikis = [];
  197. $this->size = 0;
  198. }
  199. /**
  200. * Make a link placeholder. The text returned can be later resolved to a real link with
  201. * replaceLinkHolders(). This is done for two reasons: firstly to avoid further
  202. * parsing of interwiki links, and secondly to allow all existence checks and
  203. * article length checks (for stub links) to be bundled into a single query.
  204. *
  205. * @param Title $nt
  206. * @param string $text
  207. * @param array $query [optional]
  208. * @param string $trail [optional]
  209. * @param string $prefix [optional]
  210. * @return string
  211. */
  212. public function makeHolder( $nt, $text = '', $query = [], $trail = '', $prefix = '' ) {
  213. if ( !is_object( $nt ) ) {
  214. # Fail gracefully
  215. $retVal = "<!-- ERROR -->{$prefix}{$text}{$trail}";
  216. } else {
  217. # Separate the link trail from the rest of the link
  218. list( $inside, $trail ) = Linker::splitTrail( $trail );
  219. $entry = [
  220. 'title' => $nt,
  221. 'text' => $prefix . $text . $inside,
  222. 'pdbk' => $nt->getPrefixedDBkey(),
  223. ];
  224. if ( $query !== [] ) {
  225. $entry['query'] = $query;
  226. }
  227. if ( $nt->isExternal() ) {
  228. // Use a globally unique ID to keep the objects mergable
  229. $key = $this->parent->nextLinkID();
  230. $this->interwikis[$key] = $entry;
  231. $retVal = "<!--IWLINK'\" $key-->{$trail}";
  232. } else {
  233. $key = $this->parent->nextLinkID();
  234. $ns = $nt->getNamespace();
  235. $this->internals[$ns][$key] = $entry;
  236. $retVal = "<!--LINK'\" $ns:$key-->{$trail}";
  237. }
  238. $this->size++;
  239. }
  240. return $retVal;
  241. }
  242. /**
  243. * Replace <!--LINK--> link placeholders with actual links, in the buffer
  244. *
  245. * @param string &$text
  246. */
  247. public function replace( &$text ) {
  248. $this->replaceInternal( $text );
  249. $this->replaceInterwiki( $text );
  250. }
  251. /**
  252. * Replace internal links
  253. * @suppress SecurityCheck-XSS Gets confused with $entry['pdbk']
  254. * @param string &$text
  255. */
  256. protected function replaceInternal( &$text ) {
  257. if ( !$this->internals ) {
  258. return;
  259. }
  260. $colours = [];
  261. $linkCache = MediaWikiServices::getInstance()->getLinkCache();
  262. $output = $this->parent->getOutput();
  263. $linkRenderer = $this->parent->getLinkRenderer();
  264. $dbr = wfGetDB( DB_REPLICA );
  265. # Sort by namespace
  266. ksort( $this->internals );
  267. $linkcolour_ids = [];
  268. # Generate query
  269. $lb = new LinkBatch();
  270. $lb->setCaller( __METHOD__ );
  271. foreach ( $this->internals as $ns => $entries ) {
  272. foreach ( $entries as $entry ) {
  273. /** @var Title $title */
  274. $title = $entry['title'];
  275. $pdbk = $entry['pdbk'];
  276. # Skip invalid entries.
  277. # Result will be ugly, but prevents crash.
  278. if ( is_null( $title ) ) {
  279. continue;
  280. }
  281. # Check if it's a static known link, e.g. interwiki
  282. if ( $title->isAlwaysKnown() ) {
  283. $colours[$pdbk] = '';
  284. } elseif ( $ns == NS_SPECIAL ) {
  285. $colours[$pdbk] = 'new';
  286. } else {
  287. $id = $linkCache->getGoodLinkID( $pdbk );
  288. if ( $id != 0 ) {
  289. $colours[$pdbk] = $linkRenderer->getLinkClasses( $title );
  290. $output->addLink( $title, $id );
  291. $linkcolour_ids[$id] = $pdbk;
  292. } elseif ( $linkCache->isBadLink( $pdbk ) ) {
  293. $colours[$pdbk] = 'new';
  294. } else {
  295. # Not in the link cache, add it to the query
  296. $lb->addObj( $title );
  297. }
  298. }
  299. }
  300. }
  301. if ( !$lb->isEmpty() ) {
  302. $fields = array_merge(
  303. LinkCache::getSelectFields(),
  304. [ 'page_namespace', 'page_title' ]
  305. );
  306. $res = $dbr->select(
  307. 'page',
  308. $fields,
  309. $lb->constructSet( 'page', $dbr ),
  310. __METHOD__
  311. );
  312. # Fetch data and form into an associative array
  313. # non-existent = broken
  314. foreach ( $res as $s ) {
  315. $title = Title::makeTitle( $s->page_namespace, $s->page_title );
  316. $pdbk = $title->getPrefixedDBkey();
  317. $linkCache->addGoodLinkObjFromRow( $title, $s );
  318. $output->addLink( $title, $s->page_id );
  319. $colours[$pdbk] = $linkRenderer->getLinkClasses( $title );
  320. // add id to the extension todolist
  321. $linkcolour_ids[$s->page_id] = $pdbk;
  322. }
  323. unset( $res );
  324. }
  325. if ( count( $linkcolour_ids ) ) {
  326. // pass an array of page_ids to an extension
  327. Hooks::run( 'GetLinkColours', [ $linkcolour_ids, &$colours, $this->parent->getTitle() ] );
  328. }
  329. # Do a second query for different language variants of links and categories
  330. if ( $this->parent->getContentLanguage()->hasVariants() ) {
  331. $this->doVariants( $colours );
  332. }
  333. # Construct search and replace arrays
  334. $replacePairs = [];
  335. foreach ( $this->internals as $ns => $entries ) {
  336. foreach ( $entries as $index => $entry ) {
  337. $pdbk = $entry['pdbk'];
  338. $title = $entry['title'];
  339. $query = $entry['query'] ?? [];
  340. $key = "$ns:$index";
  341. $searchkey = "<!--LINK'\" $key-->";
  342. $displayText = $entry['text'];
  343. if ( isset( $entry['selflink'] ) ) {
  344. $replacePairs[$searchkey] = Linker::makeSelfLinkObj( $title, $displayText, $query );
  345. continue;
  346. }
  347. if ( $displayText === '' ) {
  348. $displayText = null;
  349. } else {
  350. $displayText = new HtmlArmor( $displayText );
  351. }
  352. if ( !isset( $colours[$pdbk] ) ) {
  353. $colours[$pdbk] = 'new';
  354. }
  355. $attribs = [];
  356. if ( $colours[$pdbk] == 'new' ) {
  357. $linkCache->addBadLinkObj( $title );
  358. $output->addLink( $title, 0 );
  359. $link = $linkRenderer->makeBrokenLink(
  360. $title, $displayText, $attribs, $query
  361. );
  362. } else {
  363. $link = $linkRenderer->makePreloadedLink(
  364. $title, $displayText, $colours[$pdbk], $attribs, $query
  365. );
  366. }
  367. $replacePairs[$searchkey] = $link;
  368. }
  369. }
  370. # Do the thing
  371. $text = preg_replace_callback(
  372. '/(<!--LINK\'" .*?-->)/',
  373. function ( array $matches ) use ( $replacePairs ) {
  374. return $replacePairs[$matches[1]];
  375. },
  376. $text
  377. );
  378. }
  379. /**
  380. * Replace interwiki links
  381. * @param string &$text
  382. * @suppress SecurityCheck-XSS Gets confused with $this->interwikis['pdbk']
  383. */
  384. protected function replaceInterwiki( &$text ) {
  385. if ( empty( $this->interwikis ) ) {
  386. return;
  387. }
  388. # Make interwiki link HTML
  389. $output = $this->parent->getOutput();
  390. $replacePairs = [];
  391. $linkRenderer = $this->parent->getLinkRenderer();
  392. foreach ( $this->interwikis as $key => $link ) {
  393. $replacePairs[$key] = $linkRenderer->makeLink(
  394. $link['title'],
  395. new HtmlArmor( $link['text'] )
  396. );
  397. $output->addInterwikiLink( $link['title'] );
  398. }
  399. $text = preg_replace_callback(
  400. '/<!--IWLINK\'" (.*?)-->/',
  401. function ( array $matches ) use ( $replacePairs ) {
  402. return $replacePairs[$matches[1]];
  403. },
  404. $text
  405. );
  406. }
  407. /**
  408. * Modify $this->internals and $colours according to language variant linking rules
  409. * @param array &$colours
  410. */
  411. protected function doVariants( &$colours ) {
  412. $linkBatch = new LinkBatch();
  413. $variantMap = []; // maps $pdbkey_Variant => $keys (of link holders)
  414. $output = $this->parent->getOutput();
  415. $linkCache = MediaWikiServices::getInstance()->getLinkCache();
  416. $titlesToBeConverted = '';
  417. $titlesAttrs = [];
  418. // Concatenate titles to a single string, thus we only need auto convert the
  419. // single string to all variants. This would improve parser's performance
  420. // significantly.
  421. foreach ( $this->internals as $ns => $entries ) {
  422. if ( $ns == NS_SPECIAL ) {
  423. continue;
  424. }
  425. foreach ( $entries as $index => $entry ) {
  426. $pdbk = $entry['pdbk'];
  427. // we only deal with new links (in its first query)
  428. if ( !isset( $colours[$pdbk] ) || $colours[$pdbk] === 'new' ) {
  429. $titlesAttrs[] = [ $index, $entry['title'] ];
  430. // separate titles with \0 because it would never appears
  431. // in a valid title
  432. $titlesToBeConverted .= $entry['title']->getText() . "\0";
  433. }
  434. }
  435. }
  436. // Now do the conversion and explode string to text of titles
  437. $titlesAllVariants = $this->parent->getContentLanguage()->
  438. autoConvertToAllVariants( rtrim( $titlesToBeConverted, "\0" ) );
  439. $allVariantsName = array_keys( $titlesAllVariants );
  440. foreach ( $titlesAllVariants as &$titlesVariant ) {
  441. $titlesVariant = explode( "\0", $titlesVariant );
  442. }
  443. // Then add variants of links to link batch
  444. $parentTitle = $this->parent->getTitle();
  445. foreach ( $titlesAttrs as $i => $attrs ) {
  446. /** @var Title $title */
  447. list( $index, $title ) = $attrs;
  448. $ns = $title->getNamespace();
  449. $text = $title->getText();
  450. foreach ( $allVariantsName as $variantName ) {
  451. $textVariant = $titlesAllVariants[$variantName][$i];
  452. if ( $textVariant === $text ) {
  453. continue;
  454. }
  455. $variantTitle = Title::makeTitle( $ns, $textVariant );
  456. // Self-link checking for mixed/different variant titles. At this point, we
  457. // already know the exact title does not exist, so the link cannot be to a
  458. // variant of the current title that exists as a separate page.
  459. if ( $variantTitle->equals( $parentTitle ) && !$title->hasFragment() ) {
  460. $this->internals[$ns][$index]['selflink'] = true;
  461. continue 2;
  462. }
  463. $linkBatch->addObj( $variantTitle );
  464. $variantMap[$variantTitle->getPrefixedDBkey()][] = "$ns:$index";
  465. }
  466. }
  467. // process categories, check if a category exists in some variant
  468. $categoryMap = []; // maps $category_variant => $category (dbkeys)
  469. $varCategories = []; // category replacements oldDBkey => newDBkey
  470. foreach ( $output->getCategoryLinks() as $category ) {
  471. $categoryTitle = Title::makeTitleSafe( NS_CATEGORY, $category );
  472. $linkBatch->addObj( $categoryTitle );
  473. $variants = $this->parent->getContentLanguage()->autoConvertToAllVariants( $category );
  474. foreach ( $variants as $variant ) {
  475. if ( $variant !== $category ) {
  476. $variantTitle = Title::makeTitleSafe( NS_CATEGORY, $variant );
  477. if ( is_null( $variantTitle ) ) {
  478. continue;
  479. }
  480. $linkBatch->addObj( $variantTitle );
  481. $categoryMap[$variant] = [ $category, $categoryTitle ];
  482. }
  483. }
  484. }
  485. if ( !$linkBatch->isEmpty() ) {
  486. // construct query
  487. $dbr = wfGetDB( DB_REPLICA );
  488. $fields = array_merge(
  489. LinkCache::getSelectFields(),
  490. [ 'page_namespace', 'page_title' ]
  491. );
  492. $varRes = $dbr->select( 'page',
  493. $fields,
  494. $linkBatch->constructSet( 'page', $dbr ),
  495. __METHOD__
  496. );
  497. $linkcolour_ids = [];
  498. $linkRenderer = $this->parent->getLinkRenderer();
  499. // for each found variants, figure out link holders and replace
  500. foreach ( $varRes as $s ) {
  501. $variantTitle = Title::makeTitle( $s->page_namespace, $s->page_title );
  502. $varPdbk = $variantTitle->getPrefixedDBkey();
  503. $vardbk = $variantTitle->getDBkey();
  504. $holderKeys = [];
  505. if ( isset( $variantMap[$varPdbk] ) ) {
  506. $holderKeys = $variantMap[$varPdbk];
  507. $linkCache->addGoodLinkObjFromRow( $variantTitle, $s );
  508. $output->addLink( $variantTitle, $s->page_id );
  509. }
  510. // loop over link holders
  511. foreach ( $holderKeys as $key ) {
  512. list( $ns, $index ) = explode( ':', $key, 2 );
  513. $entry =& $this->internals[$ns][$index];
  514. $pdbk = $entry['pdbk'];
  515. if ( !isset( $colours[$pdbk] ) || $colours[$pdbk] === 'new' ) {
  516. // found link in some of the variants, replace the link holder data
  517. $entry['title'] = $variantTitle;
  518. $entry['pdbk'] = $varPdbk;
  519. // set pdbk and colour
  520. $colours[$varPdbk] = $linkRenderer->getLinkClasses( $variantTitle );
  521. $linkcolour_ids[$s->page_id] = $pdbk;
  522. }
  523. }
  524. // check if the object is a variant of a category
  525. if ( isset( $categoryMap[$vardbk] ) ) {
  526. list( $oldkey, $oldtitle ) = $categoryMap[$vardbk];
  527. if ( !isset( $varCategories[$oldkey] ) && !$oldtitle->exists() ) {
  528. $varCategories[$oldkey] = $vardbk;
  529. }
  530. }
  531. }
  532. Hooks::run( 'GetLinkColours', [ $linkcolour_ids, &$colours, $this->parent->getTitle() ] );
  533. // rebuild the categories in original order (if there are replacements)
  534. if ( count( $varCategories ) > 0 ) {
  535. $newCats = [];
  536. $originalCats = $output->getCategories();
  537. foreach ( $originalCats as $cat => $sortkey ) {
  538. // make the replacement
  539. if ( array_key_exists( $cat, $varCategories ) ) {
  540. $newCats[$varCategories[$cat]] = $sortkey;
  541. } else {
  542. $newCats[$cat] = $sortkey;
  543. }
  544. }
  545. $output->setCategoryLinks( $newCats );
  546. }
  547. }
  548. }
  549. /**
  550. * Replace <!--LINK--> link placeholders with plain text of links
  551. * (not HTML-formatted).
  552. *
  553. * @param string $text
  554. * @return string
  555. */
  556. public function replaceText( $text ) {
  557. $text = preg_replace_callback(
  558. '/<!--(LINK|IWLINK)\'" (.*?)-->/',
  559. [ $this, 'replaceTextCallback' ],
  560. $text );
  561. return $text;
  562. }
  563. /**
  564. * Callback for replaceText()
  565. *
  566. * @param array $matches
  567. * @return string
  568. * @private
  569. */
  570. public function replaceTextCallback( $matches ) {
  571. list( , $type, $key ) = $matches;
  572. if ( $type == 'LINK' ) {
  573. list( $ns, $index ) = explode( ':', $key, 2 );
  574. if ( isset( $this->internals[$ns][$index]['text'] ) ) {
  575. return $this->internals[$ns][$index]['text'];
  576. }
  577. } elseif ( $type == 'IWLINK' ) {
  578. if ( isset( $this->interwikis[$key]['text'] ) ) {
  579. return $this->interwikis[$key]['text'];
  580. }
  581. }
  582. return $matches[0];
  583. }
  584. }