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