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