(bug 35565) Special:Log/patrol doesn't indicate whether patrolling was automatic
[mediawiki.git] / includes / LinksUpdate.php
blob716e7d80722747599edbb83a0ed54b6af1e7e40d
1 <?php
2 /**
3 * See docs/deferred.txt
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.
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.
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
20 * @todo document (e.g. one-sentence top-level class description).
22 class LinksUpdate {
24 /**@{{
25 * @private
27 var $mId, //!< Page ID of the article linked from
28 $mTitle, //!< Title object of the article linked from
29 $mParserOutput, //!< Parser output
30 $mLinks, //!< Map of title strings to IDs for the links in the document
31 $mImages, //!< DB keys of the images used, in the array key only
32 $mTemplates, //!< Map of title strings to IDs for the template references, including broken ones
33 $mExternals, //!< URLs of external links, array key only
34 $mCategories, //!< Map of category names to sort keys
35 $mInterlangs, //!< Map of language codes to titles
36 $mProperties, //!< Map of arbitrary name to value
37 $mDb, //!< Database connection reference
38 $mOptions, //!< SELECT options to be used (array)
39 $mRecursive; //!< Whether to queue jobs for recursive updates
40 /**@}}*/
42 /**
43 * Constructor
45 * @param $title Title of the page we're updating
46 * @param $parserOutput ParserOutput: output from a full parse of this page
47 * @param $recursive Boolean: queue jobs for recursive updates?
49 function __construct( $title, $parserOutput, $recursive = true ) {
50 global $wgAntiLockFlags;
52 if ( $wgAntiLockFlags & ALF_NO_LINK_LOCK ) {
53 $this->mOptions = array();
54 } else {
55 $this->mOptions = array( 'FOR UPDATE' );
57 $this->mDb = wfGetDB( DB_MASTER );
59 if ( !is_object( $title ) ) {
60 throw new MWException( "The calling convention to LinksUpdate::__construct() has changed. " .
61 "Please see WikiPage::doEditUpdates() for an invocation example.\n" );
63 $this->mTitle = $title;
64 $this->mId = $title->getArticleID();
66 $this->mParserOutput = $parserOutput;
67 $this->mLinks = $parserOutput->getLinks();
68 $this->mImages = $parserOutput->getImages();
69 $this->mTemplates = $parserOutput->getTemplates();
70 $this->mExternals = $parserOutput->getExternalLinks();
71 $this->mCategories = $parserOutput->getCategories();
72 $this->mProperties = $parserOutput->getProperties();
73 $this->mInterwikis = $parserOutput->getInterwikiLinks();
75 # Convert the format of the interlanguage links
76 # I didn't want to change it in the ParserOutput, because that array is passed all
77 # the way back to the skin, so either a skin API break would be required, or an
78 # inefficient back-conversion.
79 $ill = $parserOutput->getLanguageLinks();
80 $this->mInterlangs = array();
81 foreach ( $ill as $link ) {
82 list( $key, $title ) = explode( ':', $link, 2 );
83 $this->mInterlangs[$key] = $title;
86 foreach ( $this->mCategories as &$sortkey ) {
87 # If the sortkey is longer then 255 bytes,
88 # it truncated by DB, and then doesn't get
89 # matched when comparing existing vs current
90 # categories, causing bug 25254.
91 # Also. substr behaves weird when given "".
92 if ( $sortkey !== '' ) {
93 $sortkey = substr( $sortkey, 0, 255 );
97 $this->mRecursive = $recursive;
99 wfRunHooks( 'LinksUpdateConstructed', array( &$this ) );
103 * Update link tables with outgoing links from an updated article
105 public function doUpdate() {
106 global $wgUseDumbLinkUpdate;
108 wfRunHooks( 'LinksUpdate', array( &$this ) );
109 if ( $wgUseDumbLinkUpdate ) {
110 $this->doDumbUpdate();
111 } else {
112 $this->doIncrementalUpdate();
114 wfRunHooks( 'LinksUpdateComplete', array( &$this ) );
117 protected function doIncrementalUpdate() {
118 wfProfileIn( __METHOD__ );
120 # Page links
121 $existing = $this->getExistingLinks();
122 $this->incrTableUpdate( 'pagelinks', 'pl', $this->getLinkDeletions( $existing ),
123 $this->getLinkInsertions( $existing ) );
125 # Image links
126 $existing = $this->getExistingImages();
128 $imageDeletes = $this->getImageDeletions( $existing );
129 $this->incrTableUpdate( 'imagelinks', 'il', $imageDeletes,
130 $this->getImageInsertions( $existing ) );
132 # Invalidate all image description pages which had links added or removed
133 $imageUpdates = $imageDeletes + array_diff_key( $this->mImages, $existing );
134 $this->invalidateImageDescriptions( $imageUpdates );
136 # External links
137 $existing = $this->getExistingExternals();
138 $this->incrTableUpdate( 'externallinks', 'el', $this->getExternalDeletions( $existing ),
139 $this->getExternalInsertions( $existing ) );
141 # Language links
142 $existing = $this->getExistingInterlangs();
143 $this->incrTableUpdate( 'langlinks', 'll', $this->getInterlangDeletions( $existing ),
144 $this->getInterlangInsertions( $existing ) );
146 # Inline interwiki links
147 $existing = $this->getExistingInterwikis();
148 $this->incrTableUpdate( 'iwlinks', 'iwl', $this->getInterwikiDeletions( $existing ),
149 $this->getInterwikiInsertions( $existing ) );
151 # Template links
152 $existing = $this->getExistingTemplates();
153 $this->incrTableUpdate( 'templatelinks', 'tl', $this->getTemplateDeletions( $existing ),
154 $this->getTemplateInsertions( $existing ) );
156 # Category links
157 $existing = $this->getExistingCategories();
159 $categoryDeletes = $this->getCategoryDeletions( $existing );
161 $this->incrTableUpdate( 'categorylinks', 'cl', $categoryDeletes,
162 $this->getCategoryInsertions( $existing ) );
164 # Invalidate all categories which were added, deleted or changed (set symmetric difference)
165 $categoryInserts = array_diff_assoc( $this->mCategories, $existing );
166 $categoryUpdates = $categoryInserts + $categoryDeletes;
167 $this->invalidateCategories( $categoryUpdates );
168 $this->updateCategoryCounts( $categoryInserts, $categoryDeletes );
170 # Page properties
171 $existing = $this->getExistingProperties();
173 $propertiesDeletes = $this->getPropertyDeletions( $existing );
175 $this->incrTableUpdate( 'page_props', 'pp', $propertiesDeletes,
176 $this->getPropertyInsertions( $existing ) );
178 # Invalidate the necessary pages
179 $changed = $propertiesDeletes + array_diff_assoc( $this->mProperties, $existing );
180 $this->invalidateProperties( $changed );
182 # Refresh links of all pages including this page
183 # This will be in a separate transaction
184 if ( $this->mRecursive ) {
185 $this->queueRecursiveJobs();
188 wfProfileOut( __METHOD__ );
192 * Link update which clears the previous entries and inserts new ones
193 * May be slower or faster depending on level of lock contention and write speed of DB
194 * Also useful where link table corruption needs to be repaired, e.g. in refreshLinks.php
196 protected function doDumbUpdate() {
197 wfProfileIn( __METHOD__ );
199 # Refresh category pages and image description pages
200 $existing = $this->getExistingCategories();
201 $categoryInserts = array_diff_assoc( $this->mCategories, $existing );
202 $categoryDeletes = array_diff_assoc( $existing, $this->mCategories );
203 $categoryUpdates = $categoryInserts + $categoryDeletes;
204 $existing = $this->getExistingImages();
205 $imageUpdates = array_diff_key( $existing, $this->mImages ) + array_diff_key( $this->mImages, $existing );
207 $this->dumbTableUpdate( 'pagelinks', $this->getLinkInsertions(), 'pl_from' );
208 $this->dumbTableUpdate( 'imagelinks', $this->getImageInsertions(), 'il_from' );
209 $this->dumbTableUpdate( 'categorylinks', $this->getCategoryInsertions(), 'cl_from' );
210 $this->dumbTableUpdate( 'templatelinks', $this->getTemplateInsertions(), 'tl_from' );
211 $this->dumbTableUpdate( 'externallinks', $this->getExternalInsertions(), 'el_from' );
212 $this->dumbTableUpdate( 'langlinks', $this->getInterlangInsertions(),'ll_from' );
213 $this->dumbTableUpdate( 'iwlinks', $this->getInterwikiInsertions(),'iwl_from' );
214 $this->dumbTableUpdate( 'page_props', $this->getPropertyInsertions(), 'pp_page' );
216 # Update the cache of all the category pages and image description
217 # pages which were changed, and fix the category table count
218 $this->invalidateCategories( $categoryUpdates );
219 $this->updateCategoryCounts( $categoryInserts, $categoryDeletes );
220 $this->invalidateImageDescriptions( $imageUpdates );
222 # Refresh links of all pages including this page
223 # This will be in a separate transaction
224 if ( $this->mRecursive ) {
225 $this->queueRecursiveJobs();
228 wfProfileOut( __METHOD__ );
231 function queueRecursiveJobs() {
232 global $wgUpdateRowsPerJob;
233 wfProfileIn( __METHOD__ );
235 $cache = $this->mTitle->getBacklinkCache();
236 $batches = $cache->partition( 'templatelinks', $wgUpdateRowsPerJob );
237 if ( !$batches ) {
238 wfProfileOut( __METHOD__ );
239 return;
241 $jobs = array();
242 foreach ( $batches as $batch ) {
243 list( $start, $end ) = $batch;
244 $params = array(
245 'table' => 'templatelinks',
246 'start' => $start,
247 'end' => $end,
249 $jobs[] = new RefreshLinksJob2( $this->mTitle, $params );
251 Job::batchInsert( $jobs );
253 wfProfileOut( __METHOD__ );
257 * Invalidate the cache of a list of pages from a single namespace
259 * @param $namespace Integer
260 * @param $dbkeys Array
262 function invalidatePages( $namespace, $dbkeys ) {
263 if ( !count( $dbkeys ) ) {
264 return;
268 * Determine which pages need to be updated
269 * This is necessary to prevent the job queue from smashing the DB with
270 * large numbers of concurrent invalidations of the same page
272 $now = $this->mDb->timestamp();
273 $ids = array();
274 $res = $this->mDb->select( 'page', array( 'page_id' ),
275 array(
276 'page_namespace' => $namespace,
277 'page_title IN (' . $this->mDb->makeList( $dbkeys ) . ')',
278 'page_touched < ' . $this->mDb->addQuotes( $now )
279 ), __METHOD__
281 foreach ( $res as $row ) {
282 $ids[] = $row->page_id;
284 if ( !count( $ids ) ) {
285 return;
289 * Do the update
290 * We still need the page_touched condition, in case the row has changed since
291 * the non-locking select above.
293 $this->mDb->update( 'page', array( 'page_touched' => $now ),
294 array(
295 'page_id IN (' . $this->mDb->makeList( $ids ) . ')',
296 'page_touched < ' . $this->mDb->addQuotes( $now )
297 ), __METHOD__
302 * @param $cats
304 function invalidateCategories( $cats ) {
305 $this->invalidatePages( NS_CATEGORY, array_keys( $cats ) );
309 * Update all the appropriate counts in the category table.
310 * @param $added array associative array of category name => sort key
311 * @param $deleted array associative array of category name => sort key
313 function updateCategoryCounts( $added, $deleted ) {
314 $a = WikiPage::factory( $this->mTitle );
315 $a->updateCategoryCounts(
316 array_keys( $added ), array_keys( $deleted )
321 * @param $images
323 function invalidateImageDescriptions( $images ) {
324 $this->invalidatePages( NS_FILE, array_keys( $images ) );
328 * @param $table
329 * @param $insertions
330 * @param $fromField
332 private function dumbTableUpdate( $table, $insertions, $fromField ) {
333 $this->mDb->delete( $table, array( $fromField => $this->mId ), __METHOD__ );
334 if ( count( $insertions ) ) {
335 # The link array was constructed without FOR UPDATE, so there may
336 # be collisions. This may cause minor link table inconsistencies,
337 # which is better than crippling the site with lock contention.
338 $this->mDb->insert( $table, $insertions, __METHOD__, array( 'IGNORE' ) );
343 * Update a table by doing a delete query then an insert query
344 * @param $table
345 * @param $prefix
346 * @param $deletions
347 * @param $insertions
349 function incrTableUpdate( $table, $prefix, $deletions, $insertions ) {
350 if ( $table == 'page_props' ) {
351 $fromField = 'pp_page';
352 } else {
353 $fromField = "{$prefix}_from";
355 $where = array( $fromField => $this->mId );
356 if ( $table == 'pagelinks' || $table == 'templatelinks' || $table == 'iwlinks' ) {
357 if ( $table == 'iwlinks' ) {
358 $baseKey = 'iwl_prefix';
359 } else {
360 $baseKey = "{$prefix}_namespace";
362 $clause = $this->mDb->makeWhereFrom2d( $deletions, $baseKey, "{$prefix}_title" );
363 if ( $clause ) {
364 $where[] = $clause;
365 } else {
366 $where = false;
368 } else {
369 if ( $table == 'langlinks' ) {
370 $toField = 'll_lang';
371 } elseif ( $table == 'page_props' ) {
372 $toField = 'pp_propname';
373 } else {
374 $toField = $prefix . '_to';
376 if ( count( $deletions ) ) {
377 $where[] = "$toField IN (" . $this->mDb->makeList( array_keys( $deletions ) ) . ')';
378 } else {
379 $where = false;
382 if ( $where ) {
383 $this->mDb->delete( $table, $where, __METHOD__ );
385 if ( count( $insertions ) ) {
386 $this->mDb->insert( $table, $insertions, __METHOD__, 'IGNORE' );
391 * Get an array of pagelinks insertions for passing to the DB
392 * Skips the titles specified by the 2-D array $existing
393 * @param $existing array
394 * @return array
396 private function getLinkInsertions( $existing = array() ) {
397 $arr = array();
398 foreach( $this->mLinks as $ns => $dbkeys ) {
399 $diffs = isset( $existing[$ns] )
400 ? array_diff_key( $dbkeys, $existing[$ns] )
401 : $dbkeys;
402 foreach ( $diffs as $dbk => $id ) {
403 $arr[] = array(
404 'pl_from' => $this->mId,
405 'pl_namespace' => $ns,
406 'pl_title' => $dbk
410 return $arr;
414 * Get an array of template insertions. Like getLinkInsertions()
415 * @param $existing array
416 * @return array
418 private function getTemplateInsertions( $existing = array() ) {
419 $arr = array();
420 foreach( $this->mTemplates as $ns => $dbkeys ) {
421 $diffs = isset( $existing[$ns] ) ? array_diff_key( $dbkeys, $existing[$ns] ) : $dbkeys;
422 foreach ( $diffs as $dbk => $id ) {
423 $arr[] = array(
424 'tl_from' => $this->mId,
425 'tl_namespace' => $ns,
426 'tl_title' => $dbk
430 return $arr;
434 * Get an array of image insertions
435 * Skips the names specified in $existing
436 * @param $existing array
437 * @return array
439 private function getImageInsertions( $existing = array() ) {
440 $arr = array();
441 $diffs = array_diff_key( $this->mImages, $existing );
442 foreach( $diffs as $iname => $dummy ) {
443 $arr[] = array(
444 'il_from' => $this->mId,
445 'il_to' => $iname
448 return $arr;
452 * Get an array of externallinks insertions. Skips the names specified in $existing
453 * @param $existing array
454 * @return array
456 private function getExternalInsertions( $existing = array() ) {
457 $arr = array();
458 $diffs = array_diff_key( $this->mExternals, $existing );
459 foreach( $diffs as $url => $dummy ) {
460 foreach( wfMakeUrlIndexes( $url ) as $index ) {
461 $arr[] = array(
462 'el_from' => $this->mId,
463 'el_to' => $url,
464 'el_index' => $index,
468 return $arr;
472 * Get an array of category insertions
474 * @param $existing array mapping existing category names to sort keys. If both
475 * match a link in $this, the link will be omitted from the output
477 * @return array
479 private function getCategoryInsertions( $existing = array() ) {
480 global $wgContLang, $wgCategoryCollation;
481 $diffs = array_diff_assoc( $this->mCategories, $existing );
482 $arr = array();
483 foreach ( $diffs as $name => $prefix ) {
484 $nt = Title::makeTitleSafe( NS_CATEGORY, $name );
485 $wgContLang->findVariantLink( $name, $nt, true );
487 if ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
488 $type = 'subcat';
489 } elseif ( $this->mTitle->getNamespace() == NS_FILE ) {
490 $type = 'file';
491 } else {
492 $type = 'page';
495 # Treat custom sortkeys as a prefix, so that if multiple
496 # things are forced to sort as '*' or something, they'll
497 # sort properly in the category rather than in page_id
498 # order or such.
499 $sortkey = Collation::singleton()->getSortKey(
500 $this->mTitle->getCategorySortkey( $prefix ) );
502 $arr[] = array(
503 'cl_from' => $this->mId,
504 'cl_to' => $name,
505 'cl_sortkey' => $sortkey,
506 'cl_timestamp' => $this->mDb->timestamp(),
507 'cl_sortkey_prefix' => $prefix,
508 'cl_collation' => $wgCategoryCollation,
509 'cl_type' => $type,
512 return $arr;
516 * Get an array of interlanguage link insertions
518 * @param $existing Array mapping existing language codes to titles
520 * @return array
522 private function getInterlangInsertions( $existing = array() ) {
523 $diffs = array_diff_assoc( $this->mInterlangs, $existing );
524 $arr = array();
525 foreach( $diffs as $lang => $title ) {
526 $arr[] = array(
527 'll_from' => $this->mId,
528 'll_lang' => $lang,
529 'll_title' => $title
532 return $arr;
536 * Get an array of page property insertions
537 * @param $existing array
538 * @return array
540 function getPropertyInsertions( $existing = array() ) {
541 $diffs = array_diff_assoc( $this->mProperties, $existing );
542 $arr = array();
543 foreach ( $diffs as $name => $value ) {
544 $arr[] = array(
545 'pp_page' => $this->mId,
546 'pp_propname' => $name,
547 'pp_value' => $value,
550 return $arr;
554 * Get an array of interwiki insertions for passing to the DB
555 * Skips the titles specified by the 2-D array $existing
556 * @param $existing array
557 * @return array
559 private function getInterwikiInsertions( $existing = array() ) {
560 $arr = array();
561 foreach( $this->mInterwikis as $prefix => $dbkeys ) {
562 $diffs = isset( $existing[$prefix] ) ? array_diff_key( $dbkeys, $existing[$prefix] ) : $dbkeys;
563 foreach ( $diffs as $dbk => $id ) {
564 $arr[] = array(
565 'iwl_from' => $this->mId,
566 'iwl_prefix' => $prefix,
567 'iwl_title' => $dbk
571 return $arr;
575 * Given an array of existing links, returns those links which are not in $this
576 * and thus should be deleted.
577 * @param $existing array
578 * @return array
580 private function getLinkDeletions( $existing ) {
581 $del = array();
582 foreach ( $existing as $ns => $dbkeys ) {
583 if ( isset( $this->mLinks[$ns] ) ) {
584 $del[$ns] = array_diff_key( $existing[$ns], $this->mLinks[$ns] );
585 } else {
586 $del[$ns] = $existing[$ns];
589 return $del;
593 * Given an array of existing templates, returns those templates which are not in $this
594 * and thus should be deleted.
595 * @param $existing array
596 * @return array
598 private function getTemplateDeletions( $existing ) {
599 $del = array();
600 foreach ( $existing as $ns => $dbkeys ) {
601 if ( isset( $this->mTemplates[$ns] ) ) {
602 $del[$ns] = array_diff_key( $existing[$ns], $this->mTemplates[$ns] );
603 } else {
604 $del[$ns] = $existing[$ns];
607 return $del;
611 * Given an array of existing images, returns those images which are not in $this
612 * and thus should be deleted.
613 * @param $existing array
614 * @return array
616 private function getImageDeletions( $existing ) {
617 return array_diff_key( $existing, $this->mImages );
621 * Given an array of existing external links, returns those links which are not
622 * in $this and thus should be deleted.
623 * @param $existing array
624 * @return array
626 private function getExternalDeletions( $existing ) {
627 return array_diff_key( $existing, $this->mExternals );
631 * Given an array of existing categories, returns those categories which are not in $this
632 * and thus should be deleted.
633 * @param $existing array
634 * @return array
636 private function getCategoryDeletions( $existing ) {
637 return array_diff_assoc( $existing, $this->mCategories );
641 * Given an array of existing interlanguage links, returns those links which are not
642 * in $this and thus should be deleted.
643 * @param $existing array
644 * @return array
646 private function getInterlangDeletions( $existing ) {
647 return array_diff_assoc( $existing, $this->mInterlangs );
651 * Get array of properties which should be deleted.
652 * @param $existing array
653 * @return array
655 function getPropertyDeletions( $existing ) {
656 return array_diff_assoc( $existing, $this->mProperties );
660 * Given an array of existing interwiki links, returns those links which are not in $this
661 * and thus should be deleted.
662 * @param $existing array
663 * @return array
665 private function getInterwikiDeletions( $existing ) {
666 $del = array();
667 foreach ( $existing as $prefix => $dbkeys ) {
668 if ( isset( $this->mInterwikis[$prefix] ) ) {
669 $del[$prefix] = array_diff_key( $existing[$prefix], $this->mInterwikis[$prefix] );
670 } else {
671 $del[$prefix] = $existing[$prefix];
674 return $del;
678 * Get an array of existing links, as a 2-D array
680 * @return array
682 private function getExistingLinks() {
683 $res = $this->mDb->select( 'pagelinks', array( 'pl_namespace', 'pl_title' ),
684 array( 'pl_from' => $this->mId ), __METHOD__, $this->mOptions );
685 $arr = array();
686 foreach ( $res as $row ) {
687 if ( !isset( $arr[$row->pl_namespace] ) ) {
688 $arr[$row->pl_namespace] = array();
690 $arr[$row->pl_namespace][$row->pl_title] = 1;
692 return $arr;
696 * Get an array of existing templates, as a 2-D array
698 * @return array
700 private function getExistingTemplates() {
701 $res = $this->mDb->select( 'templatelinks', array( 'tl_namespace', 'tl_title' ),
702 array( 'tl_from' => $this->mId ), __METHOD__, $this->mOptions );
703 $arr = array();
704 foreach ( $res as $row ) {
705 if ( !isset( $arr[$row->tl_namespace] ) ) {
706 $arr[$row->tl_namespace] = array();
708 $arr[$row->tl_namespace][$row->tl_title] = 1;
710 return $arr;
714 * Get an array of existing images, image names in the keys
716 * @return array
718 private function getExistingImages() {
719 $res = $this->mDb->select( 'imagelinks', array( 'il_to' ),
720 array( 'il_from' => $this->mId ), __METHOD__, $this->mOptions );
721 $arr = array();
722 foreach ( $res as $row ) {
723 $arr[$row->il_to] = 1;
725 return $arr;
729 * Get an array of existing external links, URLs in the keys
731 * @return array
733 private function getExistingExternals() {
734 $res = $this->mDb->select( 'externallinks', array( 'el_to' ),
735 array( 'el_from' => $this->mId ), __METHOD__, $this->mOptions );
736 $arr = array();
737 foreach ( $res as $row ) {
738 $arr[$row->el_to] = 1;
740 return $arr;
744 * Get an array of existing categories, with the name in the key and sort key in the value.
746 * @return array
748 private function getExistingCategories() {
749 $res = $this->mDb->select( 'categorylinks', array( 'cl_to', 'cl_sortkey_prefix' ),
750 array( 'cl_from' => $this->mId ), __METHOD__, $this->mOptions );
751 $arr = array();
752 foreach ( $res as $row ) {
753 $arr[$row->cl_to] = $row->cl_sortkey_prefix;
755 return $arr;
759 * Get an array of existing interlanguage links, with the language code in the key and the
760 * title in the value.
762 * @return array
764 private function getExistingInterlangs() {
765 $res = $this->mDb->select( 'langlinks', array( 'll_lang', 'll_title' ),
766 array( 'll_from' => $this->mId ), __METHOD__, $this->mOptions );
767 $arr = array();
768 foreach ( $res as $row ) {
769 $arr[$row->ll_lang] = $row->ll_title;
771 return $arr;
775 * Get an array of existing inline interwiki links, as a 2-D array
776 * @return array (prefix => array(dbkey => 1))
778 protected function getExistingInterwikis() {
779 $res = $this->mDb->select( 'iwlinks', array( 'iwl_prefix', 'iwl_title' ),
780 array( 'iwl_from' => $this->mId ), __METHOD__, $this->mOptions );
781 $arr = array();
782 foreach ( $res as $row ) {
783 if ( !isset( $arr[$row->iwl_prefix] ) ) {
784 $arr[$row->iwl_prefix] = array();
786 $arr[$row->iwl_prefix][$row->iwl_title] = 1;
788 return $arr;
792 * Get an array of existing categories, with the name in the key and sort key in the value.
794 * @return array
796 private function getExistingProperties() {
797 $res = $this->mDb->select( 'page_props', array( 'pp_propname', 'pp_value' ),
798 array( 'pp_page' => $this->mId ), __METHOD__, $this->mOptions );
799 $arr = array();
800 foreach ( $res as $row ) {
801 $arr[$row->pp_propname] = $row->pp_value;
803 return $arr;
807 * Return the title object of the page being updated
808 * @return Title
810 public function getTitle() {
811 return $this->mTitle;
815 * Returns parser output
816 * @since 1.19
817 * @return ParserOutput
819 public function getParserOutput() {
820 return $this->mParserOutput;
824 * Return the list of images used as generated by the parser
825 * @return array
827 public function getImages() {
828 return $this->mImages;
832 * Invalidate any necessary link lists related to page property changes
833 * @param $changed
835 private function invalidateProperties( $changed ) {
836 global $wgPagePropLinkInvalidations;
838 foreach ( $changed as $name => $value ) {
839 if ( isset( $wgPagePropLinkInvalidations[$name] ) ) {
840 $inv = $wgPagePropLinkInvalidations[$name];
841 if ( !is_array( $inv ) ) {
842 $inv = array( $inv );
844 foreach ( $inv as $table ) {
845 $update = new HTMLCacheUpdate( $this->mTitle, $table );
846 $update->doUpdate();