added unit tests for WikitextContent
[lhc/web/wiklou.git] / includes / LinksUpdate.php
1 <?php
2 /**
3 * See docs/deferred.txt
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 * @todo document (e.g. one-sentence top-level class description).
21 */
22 class LinksUpdate extends SecondaryDBDataUpdate {
23
24 /**@{{
25 * @private
26 */
27 var $mId, //!< Page ID of the article linked from
28 $mTitle, //!< Title object of the article linked from
29 $mParserOutput, //!< Whether to queue jobs for recursive update
30 $mLinks, //!< Map of title strings to IDs for the links in the document
31 $mImages, //!< DB keys of the images used, in the array key only
32 $mTemplates, //!< Map of title strings to IDs for the template references, including broken ones
33 $mExternals, //!< URLs of external links, array key only
34 $mCategories, //!< Map of category names to sort keys
35 $mInterlangs, //!< Map of language codes to titles
36 $mProperties, //!< Map of arbitrary name to value
37 $mRecursive; //!< Whether to queue jobs for recursive updates
38 /**@}}*/
39
40 /**
41 * Constructor
42 *
43 * @param $title Title of the page we're updating
44 * @param $parserOutput ParserOutput: output from a full parse of this page
45 * @param $recursive Boolean: queue jobs for recursive updates?
46 */
47 function __construct( $title, $parserOutput, $recursive = true ) {
48 parent::__construct( );
49
50 if ( !is_object( $title ) ) {
51 throw new MWException( "The calling convention to LinksUpdate::LinksUpdate() has changed. " .
52 "Please see Article::editUpdates() for an invocation example.\n" );
53 }
54
55 if ( !is_object( $title ) ) {
56 throw new MWException( "The calling convention to LinksUpdate::__construct() has changed. " .
57 "Please see WikiPage::doEditUpdates() for an invocation example.\n" );
58 }
59 $this->mTitle = $title;
60 $this->mId = $title->getArticleID();
61
62 $this->mParserOutput = $parserOutput;
63
64 $this->mLinks = $parserOutput->getLinks();
65 $this->mImages = $parserOutput->getImages();
66 $this->mTemplates = $parserOutput->getTemplates();
67 $this->mExternals = $parserOutput->getExternalLinks();
68 $this->mCategories = $parserOutput->getCategories();
69 $this->mProperties = $parserOutput->getProperties();
70 $this->mInterwikis = $parserOutput->getInterwikiLinks();
71
72 # Convert the format of the interlanguage links
73 # I didn't want to change it in the ParserOutput, because that array is passed all
74 # the way back to the skin, so either a skin API break would be required, or an
75 # inefficient back-conversion.
76 $ill = $parserOutput->getLanguageLinks();
77 $this->mInterlangs = array();
78 foreach ( $ill as $link ) {
79 list( $key, $title ) = explode( ':', $link, 2 );
80 $this->mInterlangs[$key] = $title;
81 }
82
83 foreach ( $this->mCategories as &$sortkey ) {
84 # If the sortkey is longer then 255 bytes,
85 # it truncated by DB, and then doesn't get
86 # matched when comparing existing vs current
87 # categories, causing bug 25254.
88 # Also. substr behaves weird when given "".
89 if ( $sortkey !== '' ) {
90 $sortkey = substr( $sortkey, 0, 255 );
91 }
92 }
93
94 $this->mRecursive = $recursive;
95
96 wfRunHooks( 'LinksUpdateConstructed', array( &$this ) );
97 }
98
99 /**
100 * Update link tables with outgoing links from an updated article
101 */
102 public function doUpdate() {
103 global $wgUseDumbLinkUpdate;
104
105 wfRunHooks( 'LinksUpdate', array( &$this ) );
106 if ( $wgUseDumbLinkUpdate ) {
107 $this->doDumbUpdate();
108 } else {
109 $this->doIncrementalUpdate();
110 }
111 wfRunHooks( 'LinksUpdateComplete', array( &$this ) );
112 }
113
114 protected function doIncrementalUpdate() {
115 wfProfileIn( __METHOD__ );
116
117 # Page links
118 $existing = $this->getExistingLinks();
119 $this->incrTableUpdate( 'pagelinks', 'pl', $this->getLinkDeletions( $existing ),
120 $this->getLinkInsertions( $existing ) );
121
122 # Image links
123 $existing = $this->getExistingImages();
124
125 $imageDeletes = $this->getImageDeletions( $existing );
126 $this->incrTableUpdate( 'imagelinks', 'il', $imageDeletes,
127 $this->getImageInsertions( $existing ) );
128
129 # Invalidate all image description pages which had links added or removed
130 $imageUpdates = $imageDeletes + array_diff_key( $this->mImages, $existing );
131 $this->invalidateImageDescriptions( $imageUpdates );
132
133 # External links
134 $existing = $this->getExistingExternals();
135 $this->incrTableUpdate( 'externallinks', 'el', $this->getExternalDeletions( $existing ),
136 $this->getExternalInsertions( $existing ) );
137
138 # Language links
139 $existing = $this->getExistingInterlangs();
140 $this->incrTableUpdate( 'langlinks', 'll', $this->getInterlangDeletions( $existing ),
141 $this->getInterlangInsertions( $existing ) );
142
143 # Inline interwiki links
144 $existing = $this->getExistingInterwikis();
145 $this->incrTableUpdate( 'iwlinks', 'iwl', $this->getInterwikiDeletions( $existing ),
146 $this->getInterwikiInsertions( $existing ) );
147
148 # Template links
149 $existing = $this->getExistingTemplates();
150 $this->incrTableUpdate( 'templatelinks', 'tl', $this->getTemplateDeletions( $existing ),
151 $this->getTemplateInsertions( $existing ) );
152
153 # Category links
154 $existing = $this->getExistingCategories();
155
156 $categoryDeletes = $this->getCategoryDeletions( $existing );
157
158 $this->incrTableUpdate( 'categorylinks', 'cl', $categoryDeletes,
159 $this->getCategoryInsertions( $existing ) );
160
161 # Invalidate all categories which were added, deleted or changed (set symmetric difference)
162 $categoryInserts = array_diff_assoc( $this->mCategories, $existing );
163 $categoryUpdates = $categoryInserts + $categoryDeletes;
164 $this->invalidateCategories( $categoryUpdates );
165 $this->updateCategoryCounts( $categoryInserts, $categoryDeletes );
166
167 # Page properties
168 $existing = $this->getExistingProperties();
169
170 $propertiesDeletes = $this->getPropertyDeletions( $existing );
171
172 $this->incrTableUpdate( 'page_props', 'pp', $propertiesDeletes,
173 $this->getPropertyInsertions( $existing ) );
174
175 # Invalidate the necessary pages
176 $changed = $propertiesDeletes + array_diff_assoc( $this->mProperties, $existing );
177 $this->invalidateProperties( $changed );
178
179 # Refresh links of all pages including this page
180 # This will be in a separate transaction
181 if ( $this->mRecursive ) {
182 $this->queueRecursiveJobs();
183 }
184
185 wfProfileOut( __METHOD__ );
186 }
187
188 /**
189 * Link update which clears the previous entries and inserts new ones
190 * May be slower or faster depending on level of lock contention and write speed of DB
191 * Also useful where link table corruption needs to be repaired, e.g. in refreshLinks.php
192 */
193 protected function doDumbUpdate() {
194 wfProfileIn( __METHOD__ );
195
196 # Refresh category pages and image description pages
197 $existing = $this->getExistingCategories();
198 $categoryInserts = array_diff_assoc( $this->mCategories, $existing );
199 $categoryDeletes = array_diff_assoc( $existing, $this->mCategories );
200 $categoryUpdates = $categoryInserts + $categoryDeletes;
201 $existing = $this->getExistingImages();
202 $imageUpdates = array_diff_key( $existing, $this->mImages ) + array_diff_key( $this->mImages, $existing );
203
204 $this->dumbTableUpdate( 'pagelinks', $this->getLinkInsertions(), 'pl_from' );
205 $this->dumbTableUpdate( 'imagelinks', $this->getImageInsertions(), 'il_from' );
206 $this->dumbTableUpdate( 'categorylinks', $this->getCategoryInsertions(), 'cl_from' );
207 $this->dumbTableUpdate( 'templatelinks', $this->getTemplateInsertions(), 'tl_from' );
208 $this->dumbTableUpdate( 'externallinks', $this->getExternalInsertions(), 'el_from' );
209 $this->dumbTableUpdate( 'langlinks', $this->getInterlangInsertions(),'ll_from' );
210 $this->dumbTableUpdate( 'iwlinks', $this->getInterwikiInsertions(),'iwl_from' );
211 $this->dumbTableUpdate( 'page_props', $this->getPropertyInsertions(), 'pp_page' );
212
213 # Update the cache of all the category pages and image description
214 # pages which were changed, and fix the category table count
215 $this->invalidateCategories( $categoryUpdates );
216 $this->updateCategoryCounts( $categoryInserts, $categoryDeletes );
217 $this->invalidateImageDescriptions( $imageUpdates );
218
219 # Refresh links of all pages including this page
220 # This will be in a separate transaction
221 if ( $this->mRecursive ) {
222 $this->queueRecursiveJobs();
223 }
224
225 wfProfileOut( __METHOD__ );
226 }
227
228 function queueRecursiveJobs() {
229 global $wgUpdateRowsPerJob;
230 wfProfileIn( __METHOD__ );
231
232 $cache = $this->mTitle->getBacklinkCache();
233 $batches = $cache->partition( 'templatelinks', $wgUpdateRowsPerJob );
234 if ( !$batches ) {
235 wfProfileOut( __METHOD__ );
236 return;
237 }
238 $jobs = array();
239 foreach ( $batches as $batch ) {
240 list( $start, $end ) = $batch;
241 $params = array(
242 'table' => 'templatelinks',
243 'start' => $start,
244 'end' => $end,
245 );
246 $jobs[] = new RefreshLinksJob2( $this->mTitle, $params );
247 }
248 Job::batchInsert( $jobs );
249
250 wfProfileOut( __METHOD__ );
251 }
252
253 /**
254 * @param $cats
255 */
256 function invalidateCategories( $cats ) {
257 $this->invalidatePages( NS_CATEGORY, array_keys( $cats ) );
258 }
259
260 /**
261 * Update all the appropriate counts in the category table.
262 * @param $added array associative array of category name => sort key
263 * @param $deleted array associative array of category name => sort key
264 */
265 function updateCategoryCounts( $added, $deleted ) {
266 $a = WikiPage::factory( $this->mTitle );
267 $a->updateCategoryCounts(
268 array_keys( $added ), array_keys( $deleted )
269 );
270 }
271
272 /**
273 * @param $images
274 */
275 function invalidateImageDescriptions( $images ) {
276 $this->invalidatePages( NS_FILE, array_keys( $images ) );
277 }
278
279 /**
280 * @param $table
281 * @param $insertions
282 * @param $fromField
283 */
284 private function dumbTableUpdate( $table, $insertions, $fromField ) {
285 $this->mDb->delete( $table, array( $fromField => $this->mId ), __METHOD__ );
286 if ( count( $insertions ) ) {
287 # The link array was constructed without FOR UPDATE, so there may
288 # be collisions. This may cause minor link table inconsistencies,
289 # which is better than crippling the site with lock contention.
290 $this->mDb->insert( $table, $insertions, __METHOD__, array( 'IGNORE' ) );
291 }
292 }
293
294 /**
295 * Update a table by doing a delete query then an insert query
296 * @param $table
297 * @param $prefix
298 * @param $deletions
299 * @param $insertions
300 */
301 function incrTableUpdate( $table, $prefix, $deletions, $insertions ) {
302 if ( $table == 'page_props' ) {
303 $fromField = 'pp_page';
304 } else {
305 $fromField = "{$prefix}_from";
306 }
307 $where = array( $fromField => $this->mId );
308 if ( $table == 'pagelinks' || $table == 'templatelinks' || $table == 'iwlinks' ) {
309 if ( $table == 'iwlinks' ) {
310 $baseKey = 'iwl_prefix';
311 } else {
312 $baseKey = "{$prefix}_namespace";
313 }
314 $clause = $this->mDb->makeWhereFrom2d( $deletions, $baseKey, "{$prefix}_title" );
315 if ( $clause ) {
316 $where[] = $clause;
317 } else {
318 $where = false;
319 }
320 } else {
321 if ( $table == 'langlinks' ) {
322 $toField = 'll_lang';
323 } elseif ( $table == 'page_props' ) {
324 $toField = 'pp_propname';
325 } else {
326 $toField = $prefix . '_to';
327 }
328 if ( count( $deletions ) ) {
329 $where[] = "$toField IN (" . $this->mDb->makeList( array_keys( $deletions ) ) . ')';
330 } else {
331 $where = false;
332 }
333 }
334 if ( $where ) {
335 $this->mDb->delete( $table, $where, __METHOD__ );
336 }
337 if ( count( $insertions ) ) {
338 $this->mDb->insert( $table, $insertions, __METHOD__, 'IGNORE' );
339 }
340 }
341
342 /**
343 * Get an array of pagelinks insertions for passing to the DB
344 * Skips the titles specified by the 2-D array $existing
345 * @param $existing array
346 * @return array
347 */
348 private function getLinkInsertions( $existing = array() ) {
349 $arr = array();
350 foreach( $this->mLinks as $ns => $dbkeys ) {
351 $diffs = isset( $existing[$ns] )
352 ? array_diff_key( $dbkeys, $existing[$ns] )
353 : $dbkeys;
354 foreach ( $diffs as $dbk => $id ) {
355 $arr[] = array(
356 'pl_from' => $this->mId,
357 'pl_namespace' => $ns,
358 'pl_title' => $dbk
359 );
360 }
361 }
362 return $arr;
363 }
364
365 /**
366 * Get an array of template insertions. Like getLinkInsertions()
367 * @param $existing array
368 * @return array
369 */
370 private function getTemplateInsertions( $existing = array() ) {
371 $arr = array();
372 foreach( $this->mTemplates as $ns => $dbkeys ) {
373 $diffs = isset( $existing[$ns] ) ? array_diff_key( $dbkeys, $existing[$ns] ) : $dbkeys;
374 foreach ( $diffs as $dbk => $id ) {
375 $arr[] = array(
376 'tl_from' => $this->mId,
377 'tl_namespace' => $ns,
378 'tl_title' => $dbk
379 );
380 }
381 }
382 return $arr;
383 }
384
385 /**
386 * Get an array of image insertions
387 * Skips the names specified in $existing
388 * @param $existing array
389 * @return array
390 */
391 private function getImageInsertions( $existing = array() ) {
392 $arr = array();
393 $diffs = array_diff_key( $this->mImages, $existing );
394 foreach( $diffs as $iname => $dummy ) {
395 $arr[] = array(
396 'il_from' => $this->mId,
397 'il_to' => $iname
398 );
399 }
400 return $arr;
401 }
402
403 /**
404 * Get an array of externallinks insertions. Skips the names specified in $existing
405 * @param $existing array
406 * @return array
407 */
408 private function getExternalInsertions( $existing = array() ) {
409 $arr = array();
410 $diffs = array_diff_key( $this->mExternals, $existing );
411 foreach( $diffs as $url => $dummy ) {
412 foreach( wfMakeUrlIndexes( $url ) as $index ) {
413 $arr[] = array(
414 'el_from' => $this->mId,
415 'el_to' => $url,
416 'el_index' => $index,
417 );
418 }
419 }
420 return $arr;
421 }
422
423 /**
424 * Get an array of category insertions
425 *
426 * @param $existing array mapping existing category names to sort keys. If both
427 * match a link in $this, the link will be omitted from the output
428 *
429 * @return array
430 */
431 private function getCategoryInsertions( $existing = array() ) {
432 global $wgContLang, $wgCategoryCollation;
433 $diffs = array_diff_assoc( $this->mCategories, $existing );
434 $arr = array();
435 foreach ( $diffs as $name => $prefix ) {
436 $nt = Title::makeTitleSafe( NS_CATEGORY, $name );
437 $wgContLang->findVariantLink( $name, $nt, true );
438
439 if ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
440 $type = 'subcat';
441 } elseif ( $this->mTitle->getNamespace() == NS_FILE ) {
442 $type = 'file';
443 } else {
444 $type = 'page';
445 }
446
447 # Treat custom sortkeys as a prefix, so that if multiple
448 # things are forced to sort as '*' or something, they'll
449 # sort properly in the category rather than in page_id
450 # order or such.
451 $sortkey = Collation::singleton()->getSortKey(
452 $this->mTitle->getCategorySortkey( $prefix ) );
453
454 $arr[] = array(
455 'cl_from' => $this->mId,
456 'cl_to' => $name,
457 'cl_sortkey' => $sortkey,
458 'cl_timestamp' => $this->mDb->timestamp(),
459 'cl_sortkey_prefix' => $prefix,
460 'cl_collation' => $wgCategoryCollation,
461 'cl_type' => $type,
462 );
463 }
464 return $arr;
465 }
466
467 /**
468 * Get an array of interlanguage link insertions
469 *
470 * @param $existing Array mapping existing language codes to titles
471 *
472 * @return array
473 */
474 private function getInterlangInsertions( $existing = array() ) {
475 $diffs = array_diff_assoc( $this->mInterlangs, $existing );
476 $arr = array();
477 foreach( $diffs as $lang => $title ) {
478 $arr[] = array(
479 'll_from' => $this->mId,
480 'll_lang' => $lang,
481 'll_title' => $title
482 );
483 }
484 return $arr;
485 }
486
487 /**
488 * Get an array of page property insertions
489 * @param $existing array
490 * @return array
491 */
492 function getPropertyInsertions( $existing = array() ) {
493 $diffs = array_diff_assoc( $this->mProperties, $existing );
494 $arr = array();
495 foreach ( $diffs as $name => $value ) {
496 $arr[] = array(
497 'pp_page' => $this->mId,
498 'pp_propname' => $name,
499 'pp_value' => $value,
500 );
501 }
502 return $arr;
503 }
504
505 /**
506 * Get an array of interwiki insertions for passing to the DB
507 * Skips the titles specified by the 2-D array $existing
508 * @param $existing array
509 * @return array
510 */
511 private function getInterwikiInsertions( $existing = array() ) {
512 $arr = array();
513 foreach( $this->mInterwikis as $prefix => $dbkeys ) {
514 $diffs = isset( $existing[$prefix] ) ? array_diff_key( $dbkeys, $existing[$prefix] ) : $dbkeys;
515 foreach ( $diffs as $dbk => $id ) {
516 $arr[] = array(
517 'iwl_from' => $this->mId,
518 'iwl_prefix' => $prefix,
519 'iwl_title' => $dbk
520 );
521 }
522 }
523 return $arr;
524 }
525
526 /**
527 * Given an array of existing links, returns those links which are not in $this
528 * and thus should be deleted.
529 * @param $existing array
530 * @return array
531 */
532 private function getLinkDeletions( $existing ) {
533 $del = array();
534 foreach ( $existing as $ns => $dbkeys ) {
535 if ( isset( $this->mLinks[$ns] ) ) {
536 $del[$ns] = array_diff_key( $existing[$ns], $this->mLinks[$ns] );
537 } else {
538 $del[$ns] = $existing[$ns];
539 }
540 }
541 return $del;
542 }
543
544 /**
545 * Given an array of existing templates, returns those templates which are not in $this
546 * and thus should be deleted.
547 * @param $existing array
548 * @return array
549 */
550 private function getTemplateDeletions( $existing ) {
551 $del = array();
552 foreach ( $existing as $ns => $dbkeys ) {
553 if ( isset( $this->mTemplates[$ns] ) ) {
554 $del[$ns] = array_diff_key( $existing[$ns], $this->mTemplates[$ns] );
555 } else {
556 $del[$ns] = $existing[$ns];
557 }
558 }
559 return $del;
560 }
561
562 /**
563 * Given an array of existing images, returns those images which are not in $this
564 * and thus should be deleted.
565 * @param $existing array
566 * @return array
567 */
568 private function getImageDeletions( $existing ) {
569 return array_diff_key( $existing, $this->mImages );
570 }
571
572 /**
573 * Given an array of existing external links, returns those links which are not
574 * in $this and thus should be deleted.
575 * @param $existing array
576 * @return array
577 */
578 private function getExternalDeletions( $existing ) {
579 return array_diff_key( $existing, $this->mExternals );
580 }
581
582 /**
583 * Given an array of existing categories, returns those categories which are not in $this
584 * and thus should be deleted.
585 * @param $existing array
586 * @return array
587 */
588 private function getCategoryDeletions( $existing ) {
589 return array_diff_assoc( $existing, $this->mCategories );
590 }
591
592 /**
593 * Given an array of existing interlanguage links, returns those links which are not
594 * in $this and thus should be deleted.
595 * @param $existing array
596 * @return array
597 */
598 private function getInterlangDeletions( $existing ) {
599 return array_diff_assoc( $existing, $this->mInterlangs );
600 }
601
602 /**
603 * Get array of properties which should be deleted.
604 * @param $existing array
605 * @return array
606 */
607 function getPropertyDeletions( $existing ) {
608 return array_diff_assoc( $existing, $this->mProperties );
609 }
610
611 /**
612 * Given an array of existing interwiki links, returns those links which are not in $this
613 * and thus should be deleted.
614 * @param $existing array
615 * @return array
616 */
617 private function getInterwikiDeletions( $existing ) {
618 $del = array();
619 foreach ( $existing as $prefix => $dbkeys ) {
620 if ( isset( $this->mInterwikis[$prefix] ) ) {
621 $del[$prefix] = array_diff_key( $existing[$prefix], $this->mInterwikis[$prefix] );
622 } else {
623 $del[$prefix] = $existing[$prefix];
624 }
625 }
626 return $del;
627 }
628
629 /**
630 * Get an array of existing links, as a 2-D array
631 *
632 * @return array
633 */
634 private function getExistingLinks() {
635 $res = $this->mDb->select( 'pagelinks', array( 'pl_namespace', 'pl_title' ),
636 array( 'pl_from' => $this->mId ), __METHOD__, $this->mOptions );
637 $arr = array();
638 foreach ( $res as $row ) {
639 if ( !isset( $arr[$row->pl_namespace] ) ) {
640 $arr[$row->pl_namespace] = array();
641 }
642 $arr[$row->pl_namespace][$row->pl_title] = 1;
643 }
644 return $arr;
645 }
646
647 /**
648 * Get an array of existing templates, as a 2-D array
649 *
650 * @return array
651 */
652 private function getExistingTemplates() {
653 $res = $this->mDb->select( 'templatelinks', array( 'tl_namespace', 'tl_title' ),
654 array( 'tl_from' => $this->mId ), __METHOD__, $this->mOptions );
655 $arr = array();
656 foreach ( $res as $row ) {
657 if ( !isset( $arr[$row->tl_namespace] ) ) {
658 $arr[$row->tl_namespace] = array();
659 }
660 $arr[$row->tl_namespace][$row->tl_title] = 1;
661 }
662 return $arr;
663 }
664
665 /**
666 * Get an array of existing images, image names in the keys
667 *
668 * @return array
669 */
670 private function getExistingImages() {
671 $res = $this->mDb->select( 'imagelinks', array( 'il_to' ),
672 array( 'il_from' => $this->mId ), __METHOD__, $this->mOptions );
673 $arr = array();
674 foreach ( $res as $row ) {
675 $arr[$row->il_to] = 1;
676 }
677 return $arr;
678 }
679
680 /**
681 * Get an array of existing external links, URLs in the keys
682 *
683 * @return array
684 */
685 private function getExistingExternals() {
686 $res = $this->mDb->select( 'externallinks', array( 'el_to' ),
687 array( 'el_from' => $this->mId ), __METHOD__, $this->mOptions );
688 $arr = array();
689 foreach ( $res as $row ) {
690 $arr[$row->el_to] = 1;
691 }
692 return $arr;
693 }
694
695 /**
696 * Get an array of existing categories, with the name in the key and sort key in the value.
697 *
698 * @return array
699 */
700 private function getExistingCategories() {
701 $res = $this->mDb->select( 'categorylinks', array( 'cl_to', 'cl_sortkey_prefix' ),
702 array( 'cl_from' => $this->mId ), __METHOD__, $this->mOptions );
703 $arr = array();
704 foreach ( $res as $row ) {
705 $arr[$row->cl_to] = $row->cl_sortkey_prefix;
706 }
707 return $arr;
708 }
709
710 /**
711 * Get an array of existing interlanguage links, with the language code in the key and the
712 * title in the value.
713 *
714 * @return array
715 */
716 private function getExistingInterlangs() {
717 $res = $this->mDb->select( 'langlinks', array( 'll_lang', 'll_title' ),
718 array( 'll_from' => $this->mId ), __METHOD__, $this->mOptions );
719 $arr = array();
720 foreach ( $res as $row ) {
721 $arr[$row->ll_lang] = $row->ll_title;
722 }
723 return $arr;
724 }
725
726 /**
727 * Get an array of existing inline interwiki links, as a 2-D array
728 * @return array (prefix => array(dbkey => 1))
729 */
730 protected function getExistingInterwikis() {
731 $res = $this->mDb->select( 'iwlinks', array( 'iwl_prefix', 'iwl_title' ),
732 array( 'iwl_from' => $this->mId ), __METHOD__, $this->mOptions );
733 $arr = array();
734 foreach ( $res as $row ) {
735 if ( !isset( $arr[$row->iwl_prefix] ) ) {
736 $arr[$row->iwl_prefix] = array();
737 }
738 $arr[$row->iwl_prefix][$row->iwl_title] = 1;
739 }
740 return $arr;
741 }
742
743 /**
744 * Get an array of existing categories, with the name in the key and sort key in the value.
745 *
746 * @return array
747 */
748 private function getExistingProperties() {
749 $res = $this->mDb->select( 'page_props', array( 'pp_propname', 'pp_value' ),
750 array( 'pp_page' => $this->mId ), __METHOD__, $this->mOptions );
751 $arr = array();
752 foreach ( $res as $row ) {
753 $arr[$row->pp_propname] = $row->pp_value;
754 }
755 return $arr;
756 }
757
758 /**
759 * Return the title object of the page being updated
760 * @return Title
761 */
762 public function getTitle() {
763 return $this->mTitle;
764 }
765
766 /**
767 * Returns parser output
768 * @since 1.19
769 * @return ParserOutput
770 */
771 public function getParserOutput() {
772 return $this->mParserOutput;
773 }
774
775 /**
776 * Return the list of images used as generated by the parser
777 * @return array
778 */
779 public function getImages() {
780 return $this->mImages;
781 }
782
783 /**
784 * Invalidate any necessary link lists related to page property changes
785 * @param $changed
786 */
787 private function invalidateProperties( $changed ) {
788 global $wgPagePropLinkInvalidations;
789
790 foreach ( $changed as $name => $value ) {
791 if ( isset( $wgPagePropLinkInvalidations[$name] ) ) {
792 $inv = $wgPagePropLinkInvalidations[$name];
793 if ( !is_array( $inv ) ) {
794 $inv = array( $inv );
795 }
796 foreach ( $inv as $table ) {
797 $update = new HTMLCacheUpdate( $this->mTitle, $table );
798 $update->doUpdate();
799 }
800 }
801 }
802 }
803 }