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