c0bf5431105286dc80b74000fa0fc19a0cbb4eb4
[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, $this->getImageInsertions( $existing ) );
114
115 # Invalidate all image description pages which had links added or removed
116 $imageUpdates = $imageDeletes + array_diff_key( $this->mImages, $existing );
117 $this->invalidateImageDescriptions( $imageUpdates );
118
119 # External links
120 $existing = $this->getExistingExternals();
121 $this->incrTableUpdate( 'externallinks', 'el', $this->getExternalDeletions( $existing ),
122 $this->getExternalInsertions( $existing ) );
123
124 # Language links
125 $existing = $this->getExistingInterlangs();
126 $this->incrTableUpdate( 'langlinks', 'll', $this->getInterlangDeletions( $existing ),
127 $this->getInterlangInsertions( $existing ) );
128
129 # Inline interwiki links
130 $existing = $this->getExistingInterwikis();
131 $this->incrTableUpdate( 'iwlinks', 'iwl', $this->getInterwikiDeletions( $existing ),
132 $this->getInterwikiInsertions( $existing ) );
133
134 # Template links
135 $existing = $this->getExistingTemplates();
136 $this->incrTableUpdate( 'templatelinks', 'tl', $this->getTemplateDeletions( $existing ),
137 $this->getTemplateInsertions( $existing ) );
138
139 # Category links
140 $existing = $this->getExistingCategories();
141
142 $categoryDeletes = $this->getCategoryDeletions( $existing );
143
144 $this->incrTableUpdate( 'categorylinks', 'cl', $categoryDeletes, $this->getCategoryInsertions( $existing ) );
145
146 # Invalidate all categories which were added, deleted or changed (set symmetric difference)
147 $categoryInserts = array_diff_assoc( $this->mCategories, $existing );
148 $categoryUpdates = $categoryInserts + $categoryDeletes;
149 $this->invalidateCategories( $categoryUpdates );
150 $this->updateCategoryCounts( $categoryInserts, $categoryDeletes );
151
152 # Page properties
153 $existing = $this->getExistingProperties();
154
155 $propertiesDeletes = $this->getPropertyDeletions( $existing );
156
157 $this->incrTableUpdate( 'page_props', 'pp', $propertiesDeletes, $this->getPropertyInsertions( $existing ) );
158
159 # Invalidate the necessary pages
160 $changed = $propertiesDeletes + array_diff_assoc( $this->mProperties, $existing );
161 $this->invalidateProperties( $changed );
162
163 # Refresh links of all pages including this page
164 # This will be in a separate transaction
165 if ( $this->mRecursive ) {
166 $this->queueRecursiveJobs();
167 }
168
169 wfProfileOut( __METHOD__ );
170 }
171
172 /**
173 * Link update which clears the previous entries and inserts new ones
174 * May be slower or faster depending on level of lock contention and write speed of DB
175 * Also useful where link table corruption needs to be repaired, e.g. in refreshLinks.php
176 */
177 protected function doDumbUpdate() {
178 wfProfileIn( __METHOD__ );
179
180 # Refresh category pages and image description pages
181 $existing = $this->getExistingCategories();
182 $categoryInserts = array_diff_assoc( $this->mCategories, $existing );
183 $categoryDeletes = array_diff_assoc( $existing, $this->mCategories );
184 $categoryUpdates = $categoryInserts + $categoryDeletes;
185 $existing = $this->getExistingImages();
186 $imageUpdates = array_diff_key( $existing, $this->mImages ) + array_diff_key( $this->mImages, $existing );
187
188 $this->dumbTableUpdate( 'pagelinks', $this->getLinkInsertions(), 'pl_from' );
189 $this->dumbTableUpdate( 'imagelinks', $this->getImageInsertions(), 'il_from' );
190 $this->dumbTableUpdate( 'categorylinks', $this->getCategoryInsertions(), 'cl_from' );
191 $this->dumbTableUpdate( 'templatelinks', $this->getTemplateInsertions(), 'tl_from' );
192 $this->dumbTableUpdate( 'externallinks', $this->getExternalInsertions(), 'el_from' );
193 $this->dumbTableUpdate( 'langlinks', $this->getInterlangInsertions(),'ll_from' );
194 $this->dumbTableUpdate( 'iwlinks', $this->getInterwikiInsertions(),'iwl_from' );
195 $this->dumbTableUpdate( 'page_props', $this->getPropertyInsertions(), 'pp_page' );
196
197 # Update the cache of all the category pages and image description
198 # pages which were changed, and fix the category table count
199 $this->invalidateCategories( $categoryUpdates );
200 $this->updateCategoryCounts( $categoryInserts, $categoryDeletes );
201 $this->invalidateImageDescriptions( $imageUpdates );
202
203 # Refresh links of all pages including this page
204 # This will be in a separate transaction
205 if ( $this->mRecursive ) {
206 $this->queueRecursiveJobs();
207 }
208
209 wfProfileOut( __METHOD__ );
210 }
211
212 function queueRecursiveJobs() {
213 global $wgUpdateRowsPerJob;
214 wfProfileIn( __METHOD__ );
215
216 $cache = $this->mTitle->getBacklinkCache();
217 $batches = $cache->partition( 'templatelinks', $wgUpdateRowsPerJob );
218 if ( !$batches ) {
219 wfProfileOut( __METHOD__ );
220 return;
221 }
222 $jobs = array();
223 foreach ( $batches as $batch ) {
224 list( $start, $end ) = $batch;
225 $params = array(
226 'start' => $start,
227 'end' => $end,
228 );
229 $jobs[] = new RefreshLinksJob2( $this->mTitle, $params );
230 }
231 Job::batchInsert( $jobs );
232
233 wfProfileOut( __METHOD__ );
234 }
235
236 /**
237 * Invalidate the cache of a list of pages from a single namespace
238 *
239 * @param $namespace Integer
240 * @param $dbkeys Array
241 */
242 function invalidatePages( $namespace, $dbkeys ) {
243 if ( !count( $dbkeys ) ) {
244 return;
245 }
246
247 /**
248 * Determine which pages need to be updated
249 * This is necessary to prevent the job queue from smashing the DB with
250 * large numbers of concurrent invalidations of the same page
251 */
252 $now = $this->mDb->timestamp();
253 $ids = array();
254 $res = $this->mDb->select( 'page', array( 'page_id' ),
255 array(
256 'page_namespace' => $namespace,
257 'page_title IN (' . $this->mDb->makeList( $dbkeys ) . ')',
258 'page_touched < ' . $this->mDb->addQuotes( $now )
259 ), __METHOD__
260 );
261 foreach ( $res as $row ) {
262 $ids[] = $row->page_id;
263 }
264 if ( !count( $ids ) ) {
265 return;
266 }
267
268 /**
269 * Do the update
270 * We still need the page_touched condition, in case the row has changed since
271 * the non-locking select above.
272 */
273 $this->mDb->update( 'page', array( 'page_touched' => $now ),
274 array(
275 'page_id IN (' . $this->mDb->makeList( $ids ) . ')',
276 'page_touched < ' . $this->mDb->addQuotes( $now )
277 ), __METHOD__
278 );
279 }
280
281 function invalidateCategories( $cats ) {
282 $this->invalidatePages( NS_CATEGORY, array_keys( $cats ) );
283 }
284
285 /**
286 * Update all the appropriate counts in the category table.
287 * @param $added associative array of category name => sort key
288 * @param $deleted associative array of category name => sort key
289 */
290 function updateCategoryCounts( $added, $deleted ) {
291 $a = new Article($this->mTitle);
292 $a->updateCategoryCounts(
293 array_keys( $added ), array_keys( $deleted )
294 );
295 }
296
297 function invalidateImageDescriptions( $images ) {
298 $this->invalidatePages( NS_FILE, array_keys( $images ) );
299 }
300
301 function dumbTableUpdate( $table, $insertions, $fromField ) {
302 $this->mDb->delete( $table, array( $fromField => $this->mId ), __METHOD__ );
303 if ( count( $insertions ) ) {
304 # The link array was constructed without FOR UPDATE, so there may
305 # be collisions. This may cause minor link table inconsistencies,
306 # which is better than crippling the site with lock contention.
307 $this->mDb->insert( $table, $insertions, __METHOD__, array( 'IGNORE' ) );
308 }
309 }
310
311 /**
312 * Update a table by doing a delete query then an insert query
313 * @private
314 */
315 function incrTableUpdate( $table, $prefix, $deletions, $insertions ) {
316 if ( $table == 'page_props' ) {
317 $fromField = 'pp_page';
318 } else {
319 $fromField = "{$prefix}_from";
320 }
321 $where = array( $fromField => $this->mId );
322 if ( $table == 'pagelinks' || $table == 'templatelinks' || $table == 'iwlinks' ) {
323 if ( $table == 'iwlinks' ) {
324 $baseKey = 'iwl_prefix';
325 } else {
326 $baseKey = "{$prefix}_namespace";
327 }
328 $clause = $this->mDb->makeWhereFrom2d( $deletions, $baseKey, "{$prefix}_title" );
329 if ( $clause ) {
330 $where[] = $clause;
331 } else {
332 $where = false;
333 }
334 } else {
335 if ( $table == 'langlinks' ) {
336 $toField = 'll_lang';
337 } elseif ( $table == 'page_props' ) {
338 $toField = 'pp_propname';
339 } else {
340 $toField = $prefix . '_to';
341 }
342 if ( count( $deletions ) ) {
343 $where[] = "$toField IN (" . $this->mDb->makeList( array_keys( $deletions ) ) . ')';
344 } else {
345 $where = false;
346 }
347 }
348
349 // Create and use a new loadBalancer object, to prevent "1205: Lock wait timeout exceeded;"
350 $lb = wfGetLBFactory()->newMainLB();
351 $dbw = $lb->getConnection( DB_MASTER );
352
353 if ( $where ) {
354 $dbw->delete( $table, $where, __METHOD__ );
355 }
356 if ( count( $insertions ) ) {
357 $dbw->insert( $table, $insertions, __METHOD__, 'IGNORE' );
358 }
359
360 $lb->commitMasterChanges();
361 $lb->closeAll();
362 }
363
364 /**
365 * Get an array of pagelinks insertions for passing to the DB
366 * Skips the titles specified by the 2-D array $existing
367 * @private
368 */
369 function getLinkInsertions( $existing = array() ) {
370 $arr = array();
371 foreach( $this->mLinks as $ns => $dbkeys ) {
372 $diffs = isset( $existing[$ns] ) ? array_diff_key( $dbkeys, $existing[$ns] ) : $dbkeys;
373 foreach ( $diffs as $dbk => $id ) {
374 $arr[] = array(
375 'pl_from' => $this->mId,
376 'pl_namespace' => $ns,
377 'pl_title' => $dbk
378 );
379 }
380 }
381 return $arr;
382 }
383
384 /**
385 * Get an array of template insertions. Like getLinkInsertions()
386 * @private
387 */
388 function getTemplateInsertions( $existing = array() ) {
389 $arr = array();
390 foreach( $this->mTemplates as $ns => $dbkeys ) {
391 $diffs = isset( $existing[$ns] ) ? array_diff_key( $dbkeys, $existing[$ns] ) : $dbkeys;
392 foreach ( $diffs as $dbk => $id ) {
393 $arr[] = array(
394 'tl_from' => $this->mId,
395 'tl_namespace' => $ns,
396 'tl_title' => $dbk
397 );
398 }
399 }
400 return $arr;
401 }
402
403 /**
404 * Get an array of image insertions
405 * Skips the names specified in $existing
406 * @private
407 */
408 function getImageInsertions( $existing = array() ) {
409 $arr = array();
410 $diffs = array_diff_key( $this->mImages, $existing );
411 foreach( $diffs as $iname => $dummy ) {
412 $arr[] = array(
413 'il_from' => $this->mId,
414 'il_to' => $iname
415 );
416 }
417 return $arr;
418 }
419
420 /**
421 * Get an array of externallinks insertions. Skips the names specified in $existing
422 * @private
423 */
424 function getExternalInsertions( $existing = array() ) {
425 $arr = array();
426 $diffs = array_diff_key( $this->mExternals, $existing );
427 foreach( $diffs as $url => $dummy ) {
428 $arr[] = array(
429 'el_from' => $this->mId,
430 'el_to' => $url,
431 'el_index' => wfMakeUrlIndex( $url ),
432 );
433 }
434 return $arr;
435 }
436
437 /**
438 * Get an array of category insertions
439 *
440 * @param $existing Array mapping existing category names to sort keys. If both
441 * match a link in $this, the link will be omitted from the output
442 * @private
443 */
444 function getCategoryInsertions( $existing = array() ) {
445 global $wgContLang, $wgCategoryCollation;
446 $diffs = array_diff_assoc( $this->mCategories, $existing );
447 $arr = array();
448 foreach ( $diffs as $name => $prefix ) {
449 $nt = Title::makeTitleSafe( NS_CATEGORY, $name );
450 $wgContLang->findVariantLink( $name, $nt, true );
451
452 if ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
453 $type = 'subcat';
454 } elseif ( $this->mTitle->getNamespace() == NS_FILE ) {
455 $type = 'file';
456 } else {
457 $type = 'page';
458 }
459
460 # Treat custom sortkeys as a prefix, so that if multiple
461 # things are forced to sort as '*' or something, they'll
462 # sort properly in the category rather than in page_id
463 # order or such.
464 $sortkey = Collation::singleton()->getSortKey(
465 $this->mTitle->getCategorySortkey( $prefix ) );
466
467 $arr[] = array(
468 'cl_from' => $this->mId,
469 'cl_to' => $name,
470 'cl_sortkey' => $sortkey,
471 'cl_timestamp' => $this->mDb->timestamp(),
472 'cl_sortkey_prefix' => $prefix,
473 'cl_collation' => $wgCategoryCollation,
474 'cl_type' => $type,
475 );
476 }
477 return $arr;
478 }
479
480 /**
481 * Get an array of interlanguage link insertions
482 *
483 * @param $existing Array mapping existing language codes to titles
484 * @private
485 */
486 function getInterlangInsertions( $existing = array() ) {
487 $diffs = array_diff_assoc( $this->mInterlangs, $existing );
488 $arr = array();
489 foreach( $diffs as $lang => $title ) {
490 $arr[] = array(
491 'll_from' => $this->mId,
492 'll_lang' => $lang,
493 'll_title' => $title
494 );
495 }
496 return $arr;
497 }
498
499 /**
500 * Get an array of page property insertions
501 */
502 function getPropertyInsertions( $existing = array() ) {
503 $diffs = array_diff_assoc( $this->mProperties, $existing );
504 $arr = array();
505 foreach ( $diffs as $name => $value ) {
506 $arr[] = array(
507 'pp_page' => $this->mId,
508 'pp_propname' => $name,
509 'pp_value' => $value,
510 );
511 }
512 return $arr;
513 }
514
515 /**
516 * Get an array of interwiki insertions for passing to the DB
517 * Skips the titles specified by the 2-D array $existing
518 * @private
519 */
520 function getInterwikiInsertions( $existing = array() ) {
521 $arr = array();
522 foreach( $this->mInterwikis as $prefix => $dbkeys ) {
523 $diffs = isset( $existing[$prefix] ) ? array_diff_key( $dbkeys, $existing[$prefix] ) : $dbkeys;
524 foreach ( $diffs as $dbk => $id ) {
525 $arr[] = array(
526 'iwl_from' => $this->mId,
527 'iwl_prefix' => $prefix,
528 'iwl_title' => $dbk
529 );
530 }
531 }
532 return $arr;
533 }
534
535 /**
536 * Given an array of existing links, returns those links which are not in $this
537 * and thus should be deleted.
538 * @private
539 */
540 function getLinkDeletions( $existing ) {
541 $del = array();
542 foreach ( $existing as $ns => $dbkeys ) {
543 if ( isset( $this->mLinks[$ns] ) ) {
544 $del[$ns] = array_diff_key( $existing[$ns], $this->mLinks[$ns] );
545 } else {
546 $del[$ns] = $existing[$ns];
547 }
548 }
549 return $del;
550 }
551
552 /**
553 * Given an array of existing templates, returns those templates which are not in $this
554 * and thus should be deleted.
555 * @private
556 */
557 function getTemplateDeletions( $existing ) {
558 $del = array();
559 foreach ( $existing as $ns => $dbkeys ) {
560 if ( isset( $this->mTemplates[$ns] ) ) {
561 $del[$ns] = array_diff_key( $existing[$ns], $this->mTemplates[$ns] );
562 } else {
563 $del[$ns] = $existing[$ns];
564 }
565 }
566 return $del;
567 }
568
569 /**
570 * Given an array of existing images, returns those images which are not in $this
571 * and thus should be deleted.
572 * @private
573 */
574 function getImageDeletions( $existing ) {
575 return array_diff_key( $existing, $this->mImages );
576 }
577
578 /**
579 * Given an array of existing external links, returns those links which are not
580 * in $this and thus should be deleted.
581 * @private
582 */
583 function getExternalDeletions( $existing ) {
584 return array_diff_key( $existing, $this->mExternals );
585 }
586
587 /**
588 * Given an array of existing categories, returns those categories which are not in $this
589 * and thus should be deleted.
590 * @private
591 */
592 function getCategoryDeletions( $existing ) {
593 return array_diff_assoc( $existing, $this->mCategories );
594 }
595
596 /**
597 * Given an array of existing interlanguage links, returns those links which are not
598 * in $this and thus should be deleted.
599 * @private
600 */
601 function getInterlangDeletions( $existing ) {
602 return array_diff_assoc( $existing, $this->mInterlangs );
603 }
604
605 /**
606 * Get array of properties which should be deleted.
607 * @private
608 */
609 function getPropertyDeletions( $existing ) {
610 return array_diff_assoc( $existing, $this->mProperties );
611 }
612
613 /**
614 * Given an array of existing interwiki links, returns those links which are not in $this
615 * and thus should be deleted.
616 * @private
617 */
618 function getInterwikiDeletions( $existing ) {
619 $del = array();
620 foreach ( $existing as $prefix => $dbkeys ) {
621 if ( isset( $this->mInterwikis[$prefix] ) ) {
622 $del[$prefix] = array_diff_key( $existing[$prefix], $this->mInterwikis[$prefix] );
623 } else {
624 $del[$prefix] = $existing[$prefix];
625 }
626 }
627 return $del;
628 }
629
630 /**
631 * Get an array of existing links, as a 2-D array
632 * @private
633 */
634 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 * @private
650 */
651 function getExistingTemplates() {
652 $res = $this->mDb->select( 'templatelinks', array( 'tl_namespace', 'tl_title' ),
653 array( 'tl_from' => $this->mId ), __METHOD__, $this->mOptions );
654 $arr = array();
655 foreach ( $res as $row ) {
656 if ( !isset( $arr[$row->tl_namespace] ) ) {
657 $arr[$row->tl_namespace] = array();
658 }
659 $arr[$row->tl_namespace][$row->tl_title] = 1;
660 }
661 return $arr;
662 }
663
664 /**
665 * Get an array of existing images, image names in the keys
666 * @private
667 */
668 function getExistingImages() {
669 $res = $this->mDb->select( 'imagelinks', array( 'il_to' ),
670 array( 'il_from' => $this->mId ), __METHOD__, $this->mOptions );
671 $arr = array();
672 foreach ( $res as $row ) {
673 $arr[$row->il_to] = 1;
674 }
675 return $arr;
676 }
677
678 /**
679 * Get an array of existing external links, URLs in the keys
680 * @private
681 */
682 function getExistingExternals() {
683 $res = $this->mDb->select( 'externallinks', array( 'el_to' ),
684 array( 'el_from' => $this->mId ), __METHOD__, $this->mOptions );
685 $arr = array();
686 foreach ( $res as $row ) {
687 $arr[$row->el_to] = 1;
688 }
689 return $arr;
690 }
691
692 /**
693 * Get an array of existing categories, with the name in the key and sort key in the value.
694 * @private
695 */
696 function getExistingCategories() {
697 $res = $this->mDb->select( 'categorylinks', array( 'cl_to', 'cl_sortkey_prefix' ),
698 array( 'cl_from' => $this->mId ), __METHOD__, $this->mOptions );
699 $arr = array();
700 foreach ( $res as $row ) {
701 $arr[$row->cl_to] = $row->cl_sortkey_prefix;
702 }
703 return $arr;
704 }
705
706 /**
707 * Get an array of existing interlanguage links, with the language code in the key and the
708 * title in the value.
709 * @private
710 */
711 function getExistingInterlangs() {
712 $res = $this->mDb->select( 'langlinks', array( 'll_lang', 'll_title' ),
713 array( 'll_from' => $this->mId ), __METHOD__, $this->mOptions );
714 $arr = array();
715 foreach ( $res as $row ) {
716 $arr[$row->ll_lang] = $row->ll_title;
717 }
718 return $arr;
719 }
720
721 /**
722 * Get an array of existing inline interwiki links, as a 2-D array
723 * @return array (prefix => array(dbkey => 1))
724 */
725 protected function getExistingInterwikis() {
726 $res = $this->mDb->select( 'iwlinks', array( 'iwl_prefix', 'iwl_title' ),
727 array( 'iwl_from' => $this->mId ), __METHOD__, $this->mOptions );
728 $arr = array();
729 foreach ( $res as $row ) {
730 if ( !isset( $arr[$row->iwl_prefix] ) ) {
731 $arr[$row->iwl_prefix] = array();
732 }
733 $arr[$row->iwl_prefix][$row->iwl_title] = 1;
734 }
735 return $arr;
736 }
737
738 /**
739 * Get an array of existing categories, with the name in the key and sort key in the value.
740 * @private
741 */
742 function getExistingProperties() {
743 $res = $this->mDb->select( 'page_props', array( 'pp_propname', 'pp_value' ),
744 array( 'pp_page' => $this->mId ), __METHOD__, $this->mOptions );
745 $arr = array();
746 foreach ( $res as $row ) {
747 $arr[$row->pp_propname] = $row->pp_value;
748 }
749 return $arr;
750 }
751
752
753 /**
754 * Return the title object of the page being updated
755 */
756 function getTitle() {
757 return $this->mTitle;
758 }
759
760 /**
761 * Return the list of images used as generated by the parser
762 */
763 public function getImages() {
764 return $this->mImages;
765 }
766
767 /**
768 * Invalidate any necessary link lists related to page property changes
769 */
770 function invalidateProperties( $changed ) {
771 global $wgPagePropLinkInvalidations;
772
773 foreach ( $changed as $name => $value ) {
774 if ( isset( $wgPagePropLinkInvalidations[$name] ) ) {
775 $inv = $wgPagePropLinkInvalidations[$name];
776 if ( !is_array( $inv ) ) {
777 $inv = array( $inv );
778 }
779 foreach ( $inv as $table ) {
780 $update = new HTMLCacheUpdate( $this->mTitle, $table );
781 $update->doUpdate();
782 }
783 }
784 }
785 }
786 }