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