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