3 * Updater for link tracking tables after a page edit.
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
24 * See docs/deferred.txt
26 * @todo document (e.g. one-sentence top-level class description).
28 class LinksUpdate
extends SqlDataUpdate
implements EnqueueableDataUpdate
{
29 // @todo make members protected, but make sure extensions don't break
31 /** @var int Page ID of the article linked from */
34 /** @var Title Title object of the article linked from */
37 /** @var ParserOutput */
38 public $mParserOutput;
40 /** @var array Map of title strings to IDs for the links in the document */
43 /** @var array DB keys of the images used, in the array key only */
46 /** @var array Map of title strings to IDs for the template references, including broken ones */
49 /** @var array URLs of external links, array key only */
52 /** @var array Map of category names to sort keys */
55 /** @var array Map of language codes to titles */
58 /** @var array Map of arbitrary name to value */
61 /** @var bool Whether to queue jobs for recursive updates */
64 /** @var bool Whether this job was triggered by a recursive update job */
65 private $mTriggeredRecursive;
67 /** @var Revision Revision for which this update has been triggered */
71 * @var null|array Added links if calculated.
73 private $linkInsertions = null;
76 * @var null|array Deleted links if calculated.
78 private $linkDeletions = null;
83 * @param Title $title Title of the page we're updating
84 * @param ParserOutput $parserOutput Output from a full parse of this page
85 * @param bool $recursive Queue jobs for recursive updates?
88 function __construct( $title, $parserOutput, $recursive = true ) {
89 parent
::__construct( false ); // no implicit transaction
91 if ( !( $title instanceof Title
) ) {
92 throw new MWException( "The calling convention to LinksUpdate::LinksUpdate() has changed. " .
93 "Please see Article::editUpdates() for an invocation example.\n" );
96 if ( !( $parserOutput instanceof ParserOutput
) ) {
97 throw new MWException( "The calling convention to LinksUpdate::__construct() has changed. " .
98 "Please see WikiPage::doEditUpdates() for an invocation example.\n" );
101 $this->mTitle
= $title;
102 $this->mId
= $title->getArticleID();
105 throw new MWException( "The Title object did not provide an article " .
106 "ID. Perhaps the page doesn't exist?" );
109 $this->mParserOutput
= $parserOutput;
111 $this->mLinks
= $parserOutput->getLinks();
112 $this->mImages
= $parserOutput->getImages();
113 $this->mTemplates
= $parserOutput->getTemplates();
114 $this->mExternals
= $parserOutput->getExternalLinks();
115 $this->mCategories
= $parserOutput->getCategories();
116 $this->mProperties
= $parserOutput->getProperties();
117 $this->mInterwikis
= $parserOutput->getInterwikiLinks();
119 # Convert the format of the interlanguage links
120 # I didn't want to change it in the ParserOutput, because that array is passed all
121 # the way back to the skin, so either a skin API break would be required, or an
122 # inefficient back-conversion.
123 $ill = $parserOutput->getLanguageLinks();
124 $this->mInterlangs
= array();
125 foreach ( $ill as $link ) {
126 list( $key, $title ) = explode( ':', $link, 2 );
127 $this->mInterlangs
[$key] = $title;
130 foreach ( $this->mCategories
as &$sortkey ) {
131 # If the sortkey is longer then 255 bytes,
132 # it truncated by DB, and then doesn't get
133 # matched when comparing existing vs current
134 # categories, causing bug 25254.
135 # Also. substr behaves weird when given "".
136 if ( $sortkey !== '' ) {
137 $sortkey = substr( $sortkey, 0, 255 );
141 $this->mRecursive
= $recursive;
143 Hooks
::run( 'LinksUpdateConstructed', array( &$this ) );
147 * Update link tables with outgoing links from an updated article
149 public function doUpdate() {
150 Hooks
::run( 'LinksUpdate', array( &$this ) );
151 $this->doIncrementalUpdate();
152 Hooks
::run( 'LinksUpdateComplete', array( &$this ) );
155 protected function doIncrementalUpdate() {
156 global $wgRCWatchCategoryMembership;
159 $existing = $this->getExistingLinks();
160 $this->linkDeletions
= $this->getLinkDeletions( $existing );
161 $this->linkInsertions
= $this->getLinkInsertions( $existing );
162 $this->incrTableUpdate( 'pagelinks', 'pl', $this->linkDeletions
, $this->linkInsertions
);
165 $existing = $this->getExistingImages();
167 $imageDeletes = $this->getImageDeletions( $existing );
168 $this->incrTableUpdate( 'imagelinks', 'il', $imageDeletes,
169 $this->getImageInsertions( $existing ) );
171 # Invalidate all image description pages which had links added or removed
172 $imageUpdates = $imageDeletes +
array_diff_key( $this->mImages
, $existing );
173 $this->invalidateImageDescriptions( $imageUpdates );
176 $existing = $this->getExistingExternals();
177 $this->incrTableUpdate( 'externallinks', 'el', $this->getExternalDeletions( $existing ),
178 $this->getExternalInsertions( $existing ) );
181 $existing = $this->getExistingInterlangs();
182 $this->incrTableUpdate( 'langlinks', 'll', $this->getInterlangDeletions( $existing ),
183 $this->getInterlangInsertions( $existing ) );
185 # Inline interwiki links
186 $existing = $this->getExistingInterwikis();
187 $this->incrTableUpdate( 'iwlinks', 'iwl', $this->getInterwikiDeletions( $existing ),
188 $this->getInterwikiInsertions( $existing ) );
191 $existing = $this->getExistingTemplates();
192 $this->incrTableUpdate( 'templatelinks', 'tl', $this->getTemplateDeletions( $existing ),
193 $this->getTemplateInsertions( $existing ) );
196 $existing = $this->getExistingCategories();
198 $categoryDeletes = $this->getCategoryDeletions( $existing );
200 $this->incrTableUpdate( 'categorylinks', 'cl', $categoryDeletes,
201 $this->getCategoryInsertions( $existing ) );
203 # Invalidate all categories which were added, deleted or changed (set symmetric difference)
204 $categoryInserts = array_diff_assoc( $this->mCategories
, $existing );
205 $categoryUpdates = $categoryInserts +
$categoryDeletes;
206 $this->invalidateCategories( $categoryUpdates );
207 $this->updateCategoryCounts( $categoryInserts, $categoryDeletes );
209 # Category membership changes
211 $wgRCWatchCategoryMembership &&
212 !$this->mTriggeredRecursive
&& ( $categoryInserts ||
$categoryDeletes )
214 $this->triggerCategoryChanges( $categoryInserts, $categoryDeletes );
218 $existing = $this->getExistingProperties();
220 $propertiesDeletes = $this->getPropertyDeletions( $existing );
222 $this->incrTableUpdate( 'page_props', 'pp', $propertiesDeletes,
223 $this->getPropertyInsertions( $existing ) );
225 # Invalidate the necessary pages
226 $changed = $propertiesDeletes +
array_diff_assoc( $this->mProperties
, $existing );
227 $this->invalidateProperties( $changed );
229 # Update the links table freshness for this title
230 $this->updateLinksTimestamp();
232 # Refresh links of all pages including this page
233 # This will be in a separate transaction
234 if ( $this->mRecursive
) {
235 $this->queueRecursiveJobs();
240 private function triggerCategoryChanges( $categoryInserts, $categoryDeletes ) {
241 $catMembChange = new CategoryMembershipChange( $this->mTitle
, $this->mRevision
);
243 if ( $this->mRecursive
) {
244 $catMembChange->checkTemplateLinks();
247 foreach ( $categoryInserts as $categoryName => $value ) {
248 $categoryTitle = Title
::newFromText( $categoryName, NS_CATEGORY
);
249 $catMembChange->triggerCategoryAddedNotification( $categoryTitle );
252 foreach ( $categoryDeletes as $categoryName => $value ) {
253 $categoryTitle = Title
::newFromText( $categoryName, NS_CATEGORY
);
254 $catMembChange->triggerCategoryRemovedNotification( $categoryTitle );
259 * Queue recursive jobs for this page
261 * Which means do LinksUpdate on all pages that include the current page,
262 * using the job queue.
264 protected function queueRecursiveJobs() {
265 self
::queueRecursiveJobsForTable( $this->mTitle
, 'templatelinks' );
266 if ( $this->mTitle
->getNamespace() == NS_FILE
) {
267 // Process imagelinks in case the title is or was a redirect
268 self
::queueRecursiveJobsForTable( $this->mTitle
, 'imagelinks' );
271 $bc = $this->mTitle
->getBacklinkCache();
272 // Get jobs for cascade-protected backlinks for a high priority queue.
273 // If meta-templates change to using a new template, the new template
274 // should be implicitly protected as soon as possible, if applicable.
275 // These jobs duplicate a subset of the above ones, but can run sooner.
276 // Which ever runs first generally no-ops the other one.
278 foreach ( $bc->getCascadeProtectedLinks() as $title ) {
279 $jobs[] = new RefreshLinksJob( $title, array( 'prioritize' => true ) );
281 JobQueueGroup
::singleton()->push( $jobs );
285 * Queue a RefreshLinks job for any table.
287 * @param Title $title Title to do job for
288 * @param string $table Table to use (e.g. 'templatelinks')
290 public static function queueRecursiveJobsForTable( Title
$title, $table ) {
291 if ( $title->getBacklinkCache()->hasLinks( $table ) ) {
292 $job = new RefreshLinksJob(
297 ) + Job
::newRootJobParams( // "overall" refresh links job info
298 "refreshlinks:{$table}:{$title->getPrefixedText()}"
302 JobQueueGroup
::singleton()->push( $job );
309 function invalidateCategories( $cats ) {
310 $this->invalidatePages( NS_CATEGORY
, array_keys( $cats ) );
314 * Update all the appropriate counts in the category table.
315 * @param array $added Associative array of category name => sort key
316 * @param array $deleted Associative array of category name => sort key
318 function updateCategoryCounts( $added, $deleted ) {
319 $a = WikiPage
::factory( $this->mTitle
);
320 $a->updateCategoryCounts(
321 array_keys( $added ), array_keys( $deleted )
326 * @param array $images
328 function invalidateImageDescriptions( $images ) {
329 $this->invalidatePages( NS_FILE
, array_keys( $images ) );
333 * Update a table by doing a delete query then an insert query
334 * @param string $table Table name
335 * @param string $prefix Field name prefix
336 * @param array $deletions
337 * @param array $insertions Rows to insert
339 function incrTableUpdate( $table, $prefix, $deletions, $insertions ) {
340 if ( $table == 'page_props' ) {
341 $fromField = 'pp_page';
343 $fromField = "{$prefix}_from";
345 $where = array( $fromField => $this->mId
);
346 if ( $table == 'pagelinks' ||
$table == 'templatelinks' ||
$table == 'iwlinks' ) {
347 if ( $table == 'iwlinks' ) {
348 $baseKey = 'iwl_prefix';
350 $baseKey = "{$prefix}_namespace";
352 $clause = $this->mDb
->makeWhereFrom2d( $deletions, $baseKey, "{$prefix}_title" );
359 if ( $table == 'langlinks' ) {
360 $toField = 'll_lang';
361 } elseif ( $table == 'page_props' ) {
362 $toField = 'pp_propname';
364 $toField = $prefix . '_to';
366 if ( count( $deletions ) ) {
367 $where[$toField] = array_keys( $deletions );
373 $this->mDb
->delete( $table, $where, __METHOD__
);
375 if ( count( $insertions ) ) {
376 $this->mDb
->insert( $table, $insertions, __METHOD__
, 'IGNORE' );
377 Hooks
::run( 'LinksUpdateAfterInsert', array( $this, $table, $insertions ) );
382 * Get an array of pagelinks insertions for passing to the DB
383 * Skips the titles specified by the 2-D array $existing
384 * @param array $existing
387 private function getLinkInsertions( $existing = array() ) {
389 foreach ( $this->mLinks
as $ns => $dbkeys ) {
390 $diffs = isset( $existing[$ns] )
391 ?
array_diff_key( $dbkeys, $existing[$ns] )
393 foreach ( $diffs as $dbk => $id ) {
395 'pl_from' => $this->mId
,
396 'pl_from_namespace' => $this->mTitle
->getNamespace(),
397 'pl_namespace' => $ns,
407 * Get an array of template insertions. Like getLinkInsertions()
408 * @param array $existing
411 private function getTemplateInsertions( $existing = array() ) {
413 foreach ( $this->mTemplates
as $ns => $dbkeys ) {
414 $diffs = isset( $existing[$ns] ) ?
array_diff_key( $dbkeys, $existing[$ns] ) : $dbkeys;
415 foreach ( $diffs as $dbk => $id ) {
417 'tl_from' => $this->mId
,
418 'tl_from_namespace' => $this->mTitle
->getNamespace(),
419 'tl_namespace' => $ns,
429 * Get an array of image insertions
430 * Skips the names specified in $existing
431 * @param array $existing
434 private function getImageInsertions( $existing = array() ) {
436 $diffs = array_diff_key( $this->mImages
, $existing );
437 foreach ( $diffs as $iname => $dummy ) {
439 'il_from' => $this->mId
,
440 'il_from_namespace' => $this->mTitle
->getNamespace(),
449 * Get an array of externallinks insertions. Skips the names specified in $existing
450 * @param array $existing
453 private function getExternalInsertions( $existing = array() ) {
455 $diffs = array_diff_key( $this->mExternals
, $existing );
456 foreach ( $diffs as $url => $dummy ) {
457 foreach ( wfMakeUrlIndexes( $url ) as $index ) {
459 'el_id' => $this->mDb
->nextSequenceValue( 'externallinks_el_id_seq' ),
460 'el_from' => $this->mId
,
462 'el_index' => $index,
471 * Get an array of category insertions
473 * @param array $existing Mapping existing category names to sort keys. If both
474 * match a link in $this, the link will be omitted from the output
478 private function getCategoryInsertions( $existing = array() ) {
479 global $wgContLang, $wgCategoryCollation;
480 $diffs = array_diff_assoc( $this->mCategories
, $existing );
482 foreach ( $diffs as $name => $prefix ) {
483 $nt = Title
::makeTitleSafe( NS_CATEGORY
, $name );
484 $wgContLang->findVariantLink( $name, $nt, true );
486 if ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
488 } elseif ( $this->mTitle
->getNamespace() == NS_FILE
) {
494 # Treat custom sortkeys as a prefix, so that if multiple
495 # things are forced to sort as '*' or something, they'll
496 # sort properly in the category rather than in page_id
498 $sortkey = Collation
::singleton()->getSortKey(
499 $this->mTitle
->getCategorySortkey( $prefix ) );
502 'cl_from' => $this->mId
,
504 'cl_sortkey' => $sortkey,
505 'cl_timestamp' => $this->mDb
->timestamp(),
506 'cl_sortkey_prefix' => $prefix,
507 'cl_collation' => $wgCategoryCollation,
516 * Get an array of interlanguage link insertions
518 * @param array $existing Mapping existing language codes to titles
522 private function getInterlangInsertions( $existing = array() ) {
523 $diffs = array_diff_assoc( $this->mInterlangs
, $existing );
525 foreach ( $diffs as $lang => $title ) {
527 'll_from' => $this->mId
,
537 * Get an array of page property insertions
538 * @param array $existing
541 function getPropertyInsertions( $existing = array() ) {
542 $diffs = array_diff_assoc( $this->mProperties
, $existing );
545 foreach ( array_keys( $diffs ) as $name ) {
546 $arr[] = $this->getPagePropRowData( $name );
553 * Returns an associative array to be used for inserting a row into
554 * the page_props table. Besides the given property name, this will
555 * include the page id from $this->mId and any property value from
556 * $this->mProperties.
558 * The array returned will include the pp_sortkey field if this
559 * is present in the database (as indicated by $wgPagePropsHaveSortkey).
560 * The sortkey value is currently determined by getPropertySortKeyValue().
562 * @note this assumes that $this->mProperties[$prop] is defined.
564 * @param string $prop The name of the property.
568 private function getPagePropRowData( $prop ) {
569 global $wgPagePropsHaveSortkey;
571 $value = $this->mProperties
[$prop];
574 'pp_page' => $this->mId
,
575 'pp_propname' => $prop,
576 'pp_value' => $value,
579 if ( $wgPagePropsHaveSortkey ) {
580 $row['pp_sortkey'] = $this->getPropertySortKeyValue( $value );
587 * Determines the sort key for the given property value.
588 * This will return $value if it is a float or int,
589 * 1 or resp. 0 if it is a bool, and null otherwise.
591 * @note In the future, we may allow the sortkey to be specified explicitly
592 * in ParserOutput::setProperty.
594 * @param mixed $value
598 private function getPropertySortKeyValue( $value ) {
599 if ( is_int( $value ) ||
is_float( $value ) ||
is_bool( $value ) ) {
600 return floatval( $value );
607 * Get an array of interwiki insertions for passing to the DB
608 * Skips the titles specified by the 2-D array $existing
609 * @param array $existing
612 private function getInterwikiInsertions( $existing = array() ) {
614 foreach ( $this->mInterwikis
as $prefix => $dbkeys ) {
615 $diffs = isset( $existing[$prefix] )
616 ?
array_diff_key( $dbkeys, $existing[$prefix] )
619 foreach ( $diffs as $dbk => $id ) {
621 'iwl_from' => $this->mId
,
622 'iwl_prefix' => $prefix,
632 * Given an array of existing links, returns those links which are not in $this
633 * and thus should be deleted.
634 * @param array $existing
637 private function getLinkDeletions( $existing ) {
639 foreach ( $existing as $ns => $dbkeys ) {
640 if ( isset( $this->mLinks
[$ns] ) ) {
641 $del[$ns] = array_diff_key( $existing[$ns], $this->mLinks
[$ns] );
643 $del[$ns] = $existing[$ns];
651 * Given an array of existing templates, returns those templates which are not in $this
652 * and thus should be deleted.
653 * @param array $existing
656 private function getTemplateDeletions( $existing ) {
658 foreach ( $existing as $ns => $dbkeys ) {
659 if ( isset( $this->mTemplates
[$ns] ) ) {
660 $del[$ns] = array_diff_key( $existing[$ns], $this->mTemplates
[$ns] );
662 $del[$ns] = $existing[$ns];
670 * Given an array of existing images, returns those images which are not in $this
671 * and thus should be deleted.
672 * @param array $existing
675 private function getImageDeletions( $existing ) {
676 return array_diff_key( $existing, $this->mImages
);
680 * Given an array of existing external links, returns those links which are not
681 * in $this and thus should be deleted.
682 * @param array $existing
685 private function getExternalDeletions( $existing ) {
686 return array_diff_key( $existing, $this->mExternals
);
690 * Given an array of existing categories, returns those categories which are not in $this
691 * and thus should be deleted.
692 * @param array $existing
695 private function getCategoryDeletions( $existing ) {
696 return array_diff_assoc( $existing, $this->mCategories
);
700 * Given an array of existing interlanguage links, returns those links which are not
701 * in $this and thus should be deleted.
702 * @param array $existing
705 private function getInterlangDeletions( $existing ) {
706 return array_diff_assoc( $existing, $this->mInterlangs
);
710 * Get array of properties which should be deleted.
711 * @param array $existing
714 function getPropertyDeletions( $existing ) {
715 return array_diff_assoc( $existing, $this->mProperties
);
719 * Given an array of existing interwiki links, returns those links which are not in $this
720 * and thus should be deleted.
721 * @param array $existing
724 private function getInterwikiDeletions( $existing ) {
726 foreach ( $existing as $prefix => $dbkeys ) {
727 if ( isset( $this->mInterwikis
[$prefix] ) ) {
728 $del[$prefix] = array_diff_key( $existing[$prefix], $this->mInterwikis
[$prefix] );
730 $del[$prefix] = $existing[$prefix];
738 * Get an array of existing links, as a 2-D array
742 private function getExistingLinks() {
743 $res = $this->mDb
->select( 'pagelinks', array( 'pl_namespace', 'pl_title' ),
744 array( 'pl_from' => $this->mId
), __METHOD__
, $this->mOptions
);
746 foreach ( $res as $row ) {
747 if ( !isset( $arr[$row->pl_namespace
] ) ) {
748 $arr[$row->pl_namespace
] = array();
750 $arr[$row->pl_namespace
][$row->pl_title
] = 1;
757 * Get an array of existing templates, as a 2-D array
761 private function getExistingTemplates() {
762 $res = $this->mDb
->select( 'templatelinks', array( 'tl_namespace', 'tl_title' ),
763 array( 'tl_from' => $this->mId
), __METHOD__
, $this->mOptions
);
765 foreach ( $res as $row ) {
766 if ( !isset( $arr[$row->tl_namespace
] ) ) {
767 $arr[$row->tl_namespace
] = array();
769 $arr[$row->tl_namespace
][$row->tl_title
] = 1;
776 * Get an array of existing images, image names in the keys
780 private function getExistingImages() {
781 $res = $this->mDb
->select( 'imagelinks', array( 'il_to' ),
782 array( 'il_from' => $this->mId
), __METHOD__
, $this->mOptions
);
784 foreach ( $res as $row ) {
785 $arr[$row->il_to
] = 1;
792 * Get an array of existing external links, URLs in the keys
796 private function getExistingExternals() {
797 $res = $this->mDb
->select( 'externallinks', array( 'el_to' ),
798 array( 'el_from' => $this->mId
), __METHOD__
, $this->mOptions
);
800 foreach ( $res as $row ) {
801 $arr[$row->el_to
] = 1;
808 * Get an array of existing categories, with the name in the key and sort key in the value.
812 private function getExistingCategories() {
813 $res = $this->mDb
->select( 'categorylinks', array( 'cl_to', 'cl_sortkey_prefix' ),
814 array( 'cl_from' => $this->mId
), __METHOD__
, $this->mOptions
);
816 foreach ( $res as $row ) {
817 $arr[$row->cl_to
] = $row->cl_sortkey_prefix
;
824 * Get an array of existing interlanguage links, with the language code in the key and the
825 * title in the value.
829 private function getExistingInterlangs() {
830 $res = $this->mDb
->select( 'langlinks', array( 'll_lang', 'll_title' ),
831 array( 'll_from' => $this->mId
), __METHOD__
, $this->mOptions
);
833 foreach ( $res as $row ) {
834 $arr[$row->ll_lang
] = $row->ll_title
;
841 * Get an array of existing inline interwiki links, as a 2-D array
842 * @return array (prefix => array(dbkey => 1))
844 protected function getExistingInterwikis() {
845 $res = $this->mDb
->select( 'iwlinks', array( 'iwl_prefix', 'iwl_title' ),
846 array( 'iwl_from' => $this->mId
), __METHOD__
, $this->mOptions
);
848 foreach ( $res as $row ) {
849 if ( !isset( $arr[$row->iwl_prefix
] ) ) {
850 $arr[$row->iwl_prefix
] = array();
852 $arr[$row->iwl_prefix
][$row->iwl_title
] = 1;
859 * Get an array of existing categories, with the name in the key and sort key in the value.
861 * @return array Array of property names and values
863 private function getExistingProperties() {
864 $res = $this->mDb
->select( 'page_props', array( 'pp_propname', 'pp_value' ),
865 array( 'pp_page' => $this->mId
), __METHOD__
, $this->mOptions
);
867 foreach ( $res as $row ) {
868 $arr[$row->pp_propname
] = $row->pp_value
;
875 * Return the title object of the page being updated
878 public function getTitle() {
879 return $this->mTitle
;
883 * Returns parser output
885 * @return ParserOutput
887 public function getParserOutput() {
888 return $this->mParserOutput
;
892 * Return the list of images used as generated by the parser
895 public function getImages() {
896 return $this->mImages
;
900 * Set this object as being triggered by a recursive LinksUpdate
904 public function setTriggeredRecursive() {
905 $this->mTriggeredRecursive
= true;
909 * Set the revision corresponding to this LinksUpdate
913 * @param Revision $revision
915 public function setRevision( Revision
$revision ) {
916 $this->mRevision
= $revision;
920 * Invalidate any necessary link lists related to page property changes
921 * @param array $changed
923 private function invalidateProperties( $changed ) {
924 global $wgPagePropLinkInvalidations;
926 foreach ( $changed as $name => $value ) {
927 if ( isset( $wgPagePropLinkInvalidations[$name] ) ) {
928 $inv = $wgPagePropLinkInvalidations[$name];
929 if ( !is_array( $inv ) ) {
930 $inv = array( $inv );
932 foreach ( $inv as $table ) {
933 $update = new HTMLCacheUpdate( $this->mTitle
, $table );
941 * Fetch page links added by this LinksUpdate. Only available after the update is complete.
943 * @return null|array Array of Titles
945 public function getAddedLinks() {
946 if ( $this->linkInsertions
=== null ) {
950 foreach ( $this->linkInsertions
as $insertion ) {
951 $result[] = Title
::makeTitle( $insertion['pl_namespace'], $insertion['pl_title'] );
958 * Fetch page links removed by this LinksUpdate. Only available after the update is complete.
960 * @return null|array Array of Titles
962 public function getRemovedLinks() {
963 if ( $this->linkDeletions
=== null ) {
967 foreach ( $this->linkDeletions
as $ns => $titles ) {
968 foreach ( $titles as $title => $unused ) {
969 $result[] = Title
::makeTitle( $ns, $title );
977 * Update links table freshness
979 protected function updateLinksTimestamp() {
981 // The link updates made here only reflect the freshness of the parser output
982 $timestamp = $this->mParserOutput
->getCacheTime();
983 $this->mDb
->update( 'page',
984 array( 'page_links_updated' => $this->mDb
->timestamp( $timestamp ) ),
985 array( 'page_id' => $this->mId
),
991 public function getAsJobSpecification() {
993 'wiki' => $this->mDb
->getWikiID(),
994 'job' => new JobSpecification(
995 'refreshLinksPrioritized',
997 'prioritize' => true,
998 // Reuse the parser cache if it was saved
999 'rootJobTimestamp' => $this->mParserOutput
->getCacheTime(),
1000 'useRecursiveLinksUpdate' => $this->mRecursive
1002 array( 'removeDuplicates' => true ),