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 * Class the manages updates of *_link tables as well as similar extension-managed tables
26 * @note: LinksUpdate is managed by DeferredUpdates::execute(). Do not run this in a transaction.
28 * See docs/deferred.txt
30 class LinksUpdate
extends SqlDataUpdate
implements EnqueueableDataUpdate
{
31 // @todo make members protected, but make sure extensions don't break
33 /** @var int Page ID of the article linked from */
36 /** @var Title Title object of the article linked from */
39 /** @var ParserOutput */
40 public $mParserOutput;
42 /** @var array Map of title strings to IDs for the links in the document */
45 /** @var array DB keys of the images used, in the array key only */
48 /** @var array Map of title strings to IDs for the template references, including broken ones */
51 /** @var array URLs of external links, array key only */
54 /** @var array Map of category names to sort keys */
57 /** @var array Map of language codes to titles */
60 /** @var array 2-D map of (prefix => DBK => 1) */
63 /** @var array Map of arbitrary name to value */
66 /** @var bool Whether to queue jobs for recursive updates */
69 /** @var Revision Revision for which this update has been triggered */
73 * @var null|array Added links if calculated.
75 private $linkInsertions = null;
78 * @var null|array Deleted links if calculated.
80 private $linkDeletions = null;
90 * @param Title $title Title of the page we're updating
91 * @param ParserOutput $parserOutput Output from a full parse of this page
92 * @param bool $recursive Queue jobs for recursive updates?
95 function __construct( Title
$title, ParserOutput
$parserOutput, $recursive = true ) {
96 // Implicit transactions are disabled as they interfere with batching
97 parent
::__construct( false );
99 $this->mTitle
= $title;
100 $this->mId
= $title->getArticleID( Title
::GAID_FOR_UPDATE
);
103 throw new InvalidArgumentException(
104 "The Title object yields no ID. Perhaps the page doesn't exist?"
108 $this->mParserOutput
= $parserOutput;
110 $this->mLinks
= $parserOutput->getLinks();
111 $this->mImages
= $parserOutput->getImages();
112 $this->mTemplates
= $parserOutput->getTemplates();
113 $this->mExternals
= $parserOutput->getExternalLinks();
114 $this->mCategories
= $parserOutput->getCategories();
115 $this->mProperties
= $parserOutput->getProperties();
116 $this->mInterwikis
= $parserOutput->getInterwikiLinks();
118 # Convert the format of the interlanguage links
119 # I didn't want to change it in the ParserOutput, because that array is passed all
120 # the way back to the skin, so either a skin API break would be required, or an
121 # inefficient back-conversion.
122 $ill = $parserOutput->getLanguageLinks();
123 $this->mInterlangs
= [];
124 foreach ( $ill as $link ) {
125 list( $key, $title ) = explode( ':', $link, 2 );
126 $this->mInterlangs
[$key] = $title;
129 foreach ( $this->mCategories
as &$sortkey ) {
130 # If the sortkey is longer then 255 bytes,
131 # it truncated by DB, and then doesn't get
132 # matched when comparing existing vs current
133 # categories, causing bug 25254.
134 # Also. substr behaves weird when given "".
135 if ( $sortkey !== '' ) {
136 $sortkey = substr( $sortkey, 0, 255 );
140 $this->mRecursive
= $recursive;
142 Hooks
::run( 'LinksUpdateConstructed', [ &$this ] );
146 * Update link tables with outgoing links from an updated article
148 * @note: this is managed by DeferredUpdates::execute(). Do not run this in a transaction.
150 public function doUpdate() {
151 // Make sure all links update threads see the changes of each other.
152 // This handles the case when updates have to batched into several COMMITs.
153 $scopedLock = self
::acquirePageLock( $this->mDb
, $this->mId
);
155 Hooks
::run( 'LinksUpdate', [ &$this ] );
156 $this->doIncrementalUpdate();
158 // Commit and release the lock
159 ScopedCallback
::consume( $scopedLock );
160 // Run post-commit hooks without DBO_TRX
161 $this->mDb
->onTransactionIdle( function() {
162 Hooks
::run( 'LinksUpdateComplete', [ &$this ] );
167 * Acquire a lock for performing link table updates for a page on a DB
169 * @param IDatabase $dbw
170 * @param integer $pageId
171 * @return ScopedCallback|null Returns null on failure
172 * @throws RuntimeException
175 public static function acquirePageLock( IDatabase
$dbw, $pageId ) {
176 $scopedLock = $dbw->getScopedLockAndFlush(
177 "LinksUpdate:pageid:$pageId",
181 if ( !$scopedLock ) {
182 throw new RuntimeException( "Could not acquire lock on page #$pageId." );
188 protected function doIncrementalUpdate() {
190 $existing = $this->getExistingLinks();
191 $this->linkDeletions
= $this->getLinkDeletions( $existing );
192 $this->linkInsertions
= $this->getLinkInsertions( $existing );
193 $this->incrTableUpdate( 'pagelinks', 'pl', $this->linkDeletions
, $this->linkInsertions
);
196 $existing = $this->getExistingImages();
197 $imageDeletes = $this->getImageDeletions( $existing );
198 $this->incrTableUpdate( 'imagelinks', 'il', $imageDeletes,
199 $this->getImageInsertions( $existing ) );
201 # Invalidate all image description pages which had links added or removed
202 $imageUpdates = $imageDeletes +
array_diff_key( $this->mImages
, $existing );
203 $this->invalidateImageDescriptions( $imageUpdates );
206 $existing = $this->getExistingExternals();
207 $this->incrTableUpdate( 'externallinks', 'el', $this->getExternalDeletions( $existing ),
208 $this->getExternalInsertions( $existing ) );
211 $existing = $this->getExistingInterlangs();
212 $this->incrTableUpdate( 'langlinks', 'll', $this->getInterlangDeletions( $existing ),
213 $this->getInterlangInsertions( $existing ) );
215 # Inline interwiki links
216 $existing = $this->getExistingInterwikis();
217 $this->incrTableUpdate( 'iwlinks', 'iwl', $this->getInterwikiDeletions( $existing ),
218 $this->getInterwikiInsertions( $existing ) );
221 $existing = $this->getExistingTemplates();
222 $this->incrTableUpdate( 'templatelinks', 'tl', $this->getTemplateDeletions( $existing ),
223 $this->getTemplateInsertions( $existing ) );
226 $existing = $this->getExistingCategories();
227 $categoryDeletes = $this->getCategoryDeletions( $existing );
228 $this->incrTableUpdate( 'categorylinks', 'cl', $categoryDeletes,
229 $this->getCategoryInsertions( $existing ) );
231 # Invalidate all categories which were added, deleted or changed (set symmetric difference)
232 $categoryInserts = array_diff_assoc( $this->mCategories
, $existing );
233 $categoryUpdates = $categoryInserts +
$categoryDeletes;
234 $this->invalidateCategories( $categoryUpdates );
235 $this->updateCategoryCounts( $categoryInserts, $categoryDeletes );
238 $existing = $this->getExistingProperties();
239 $propertiesDeletes = $this->getPropertyDeletions( $existing );
240 $this->incrTableUpdate( 'page_props', 'pp', $propertiesDeletes,
241 $this->getPropertyInsertions( $existing ) );
243 # Invalidate the necessary pages
244 $changed = $propertiesDeletes +
array_diff_assoc( $this->mProperties
, $existing );
245 $this->invalidateProperties( $changed );
247 # Refresh links of all pages including this page
248 # This will be in a separate transaction
249 if ( $this->mRecursive
) {
250 $this->queueRecursiveJobs();
253 # Update the links table freshness for this title
254 $this->updateLinksTimestamp();
258 * Queue recursive jobs for this page
260 * Which means do LinksUpdate on all pages that include the current page,
261 * using the job queue.
263 protected function queueRecursiveJobs() {
264 self
::queueRecursiveJobsForTable( $this->mTitle
, 'templatelinks' );
265 if ( $this->mTitle
->getNamespace() == NS_FILE
) {
266 // Process imagelinks in case the title is or was a redirect
267 self
::queueRecursiveJobsForTable( $this->mTitle
, 'imagelinks' );
270 $bc = $this->mTitle
->getBacklinkCache();
271 // Get jobs for cascade-protected backlinks for a high priority queue.
272 // If meta-templates change to using a new template, the new template
273 // should be implicitly protected as soon as possible, if applicable.
274 // These jobs duplicate a subset of the above ones, but can run sooner.
275 // Which ever runs first generally no-ops the other one.
277 foreach ( $bc->getCascadeProtectedLinks() as $title ) {
278 $jobs[] = RefreshLinksJob
::newPrioritized( $title, [] );
280 JobQueueGroup
::singleton()->push( $jobs );
284 * Queue a RefreshLinks job for any table.
286 * @param Title $title Title to do job for
287 * @param string $table Table to use (e.g. 'templatelinks')
289 public static function queueRecursiveJobsForTable( Title
$title, $table ) {
290 if ( $title->getBacklinkCache()->hasLinks( $table ) ) {
291 $job = new RefreshLinksJob(
296 ] + Job
::newRootJobParams( // "overall" refresh links job info
297 "refreshlinks:{$table}:{$title->getPrefixedText()}"
301 JobQueueGroup
::singleton()->push( $job );
308 function invalidateCategories( $cats ) {
309 $this->invalidatePages( NS_CATEGORY
, array_keys( $cats ) );
313 * Update all the appropriate counts in the category table.
314 * @param array $added Associative array of category name => sort key
315 * @param array $deleted Associative array of category name => sort key
317 function updateCategoryCounts( $added, $deleted ) {
318 $a = WikiPage
::factory( $this->mTitle
);
319 $a->updateCategoryCounts(
320 array_keys( $added ), array_keys( $deleted )
325 * @param array $images
327 function invalidateImageDescriptions( $images ) {
328 $this->invalidatePages( NS_FILE
, array_keys( $images ) );
332 * Update a table by doing a delete query then an insert query
333 * @param string $table Table name
334 * @param string $prefix Field name prefix
335 * @param array $deletions
336 * @param array $insertions Rows to insert
338 private function incrTableUpdate( $table, $prefix, $deletions, $insertions ) {
339 $bSize = RequestContext
::getMain()->getConfig()->get( 'UpdateRowsPerQuery' );
341 if ( $table === 'page_props' ) {
342 $fromField = 'pp_page';
344 $fromField = "{$prefix}_from";
347 $deleteWheres = []; // list of WHERE clause arrays for each DB delete() call
348 if ( $table === 'pagelinks' ||
$table === 'templatelinks' ||
$table === 'iwlinks' ) {
349 $baseKey = ( $table === 'iwlinks' ) ?
'iwl_prefix' : "{$prefix}_namespace";
352 $curDeletionBatch = [];
353 $deletionBatches = [];
354 foreach ( $deletions as $ns => $dbKeys ) {
355 foreach ( $dbKeys as $dbKey => $unused ) {
356 $curDeletionBatch[$ns][$dbKey] = 1;
357 if ( ++
$curBatchSize >= $bSize ) {
358 $deletionBatches[] = $curDeletionBatch;
359 $curDeletionBatch = [];
364 if ( $curDeletionBatch ) {
365 $deletionBatches[] = $curDeletionBatch;
368 foreach ( $deletionBatches as $deletionBatch ) {
370 $fromField => $this->mId
,
371 $this->mDb
->makeWhereFrom2d( $deletionBatch, $baseKey, "{$prefix}_title" )
375 if ( $table === 'langlinks' ) {
376 $toField = 'll_lang';
377 } elseif ( $table === 'page_props' ) {
378 $toField = 'pp_propname';
380 $toField = $prefix . '_to';
383 $deletionBatches = array_chunk( array_keys( $deletions ), $bSize );
384 foreach ( $deletionBatches as $deletionBatch ) {
385 $deleteWheres[] = [ $fromField => $this->mId
, $toField => $deletionBatch ];
389 foreach ( $deleteWheres as $deleteWhere ) {
390 $this->mDb
->delete( $table, $deleteWhere, __METHOD__
);
391 $this->mDb
->commit( __METHOD__
, 'flush' );
392 wfGetLBFactory()->waitForReplication( [ 'wiki' => $this->mDb
->getWikiID() ] );
395 $insertBatches = array_chunk( $insertions, $bSize );
396 foreach ( $insertBatches as $insertBatch ) {
397 $this->mDb
->insert( $table, $insertBatch, __METHOD__
, 'IGNORE' );
398 $this->mDb
->commit( __METHOD__
, 'flush' );
399 wfGetLBFactory()->waitForReplication( [ 'wiki' => $this->mDb
->getWikiID() ] );
402 if ( count( $insertions ) ) {
403 Hooks
::run( 'LinksUpdateAfterInsert', [ $this, $table, $insertions ] );
408 * Get an array of pagelinks insertions for passing to the DB
409 * Skips the titles specified by the 2-D array $existing
410 * @param array $existing
413 private function getLinkInsertions( $existing = [] ) {
415 foreach ( $this->mLinks
as $ns => $dbkeys ) {
416 $diffs = isset( $existing[$ns] )
417 ?
array_diff_key( $dbkeys, $existing[$ns] )
419 foreach ( $diffs as $dbk => $id ) {
421 'pl_from' => $this->mId
,
422 'pl_from_namespace' => $this->mTitle
->getNamespace(),
423 'pl_namespace' => $ns,
433 * Get an array of template insertions. Like getLinkInsertions()
434 * @param array $existing
437 private function getTemplateInsertions( $existing = [] ) {
439 foreach ( $this->mTemplates
as $ns => $dbkeys ) {
440 $diffs = isset( $existing[$ns] ) ?
array_diff_key( $dbkeys, $existing[$ns] ) : $dbkeys;
441 foreach ( $diffs as $dbk => $id ) {
443 'tl_from' => $this->mId
,
444 'tl_from_namespace' => $this->mTitle
->getNamespace(),
445 'tl_namespace' => $ns,
455 * Get an array of image insertions
456 * Skips the names specified in $existing
457 * @param array $existing
460 private function getImageInsertions( $existing = [] ) {
462 $diffs = array_diff_key( $this->mImages
, $existing );
463 foreach ( $diffs as $iname => $dummy ) {
465 'il_from' => $this->mId
,
466 'il_from_namespace' => $this->mTitle
->getNamespace(),
475 * Get an array of externallinks insertions. Skips the names specified in $existing
476 * @param array $existing
479 private function getExternalInsertions( $existing = [] ) {
481 $diffs = array_diff_key( $this->mExternals
, $existing );
482 foreach ( $diffs as $url => $dummy ) {
483 foreach ( wfMakeUrlIndexes( $url ) as $index ) {
485 'el_id' => $this->mDb
->nextSequenceValue( 'externallinks_el_id_seq' ),
486 'el_from' => $this->mId
,
488 'el_index' => $index,
497 * Get an array of category insertions
499 * @param array $existing Mapping existing category names to sort keys. If both
500 * match a link in $this, the link will be omitted from the output
504 private function getCategoryInsertions( $existing = [] ) {
505 global $wgContLang, $wgCategoryCollation;
506 $diffs = array_diff_assoc( $this->mCategories
, $existing );
508 foreach ( $diffs as $name => $prefix ) {
509 $nt = Title
::makeTitleSafe( NS_CATEGORY
, $name );
510 $wgContLang->findVariantLink( $name, $nt, true );
512 if ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
514 } elseif ( $this->mTitle
->getNamespace() == NS_FILE
) {
520 # Treat custom sortkeys as a prefix, so that if multiple
521 # things are forced to sort as '*' or something, they'll
522 # sort properly in the category rather than in page_id
524 $sortkey = Collation
::singleton()->getSortKey(
525 $this->mTitle
->getCategorySortkey( $prefix ) );
528 'cl_from' => $this->mId
,
530 'cl_sortkey' => $sortkey,
531 'cl_timestamp' => $this->mDb
->timestamp(),
532 'cl_sortkey_prefix' => $prefix,
533 'cl_collation' => $wgCategoryCollation,
542 * Get an array of interlanguage link insertions
544 * @param array $existing Mapping existing language codes to titles
548 private function getInterlangInsertions( $existing = [] ) {
549 $diffs = array_diff_assoc( $this->mInterlangs
, $existing );
551 foreach ( $diffs as $lang => $title ) {
553 'll_from' => $this->mId
,
563 * Get an array of page property insertions
564 * @param array $existing
567 function getPropertyInsertions( $existing = [] ) {
568 $diffs = array_diff_assoc( $this->mProperties
, $existing );
571 foreach ( array_keys( $diffs ) as $name ) {
572 $arr[] = $this->getPagePropRowData( $name );
579 * Returns an associative array to be used for inserting a row into
580 * the page_props table. Besides the given property name, this will
581 * include the page id from $this->mId and any property value from
582 * $this->mProperties.
584 * The array returned will include the pp_sortkey field if this
585 * is present in the database (as indicated by $wgPagePropsHaveSortkey).
586 * The sortkey value is currently determined by getPropertySortKeyValue().
588 * @note this assumes that $this->mProperties[$prop] is defined.
590 * @param string $prop The name of the property.
594 private function getPagePropRowData( $prop ) {
595 global $wgPagePropsHaveSortkey;
597 $value = $this->mProperties
[$prop];
600 'pp_page' => $this->mId
,
601 'pp_propname' => $prop,
602 'pp_value' => $value,
605 if ( $wgPagePropsHaveSortkey ) {
606 $row['pp_sortkey'] = $this->getPropertySortKeyValue( $value );
613 * Determines the sort key for the given property value.
614 * This will return $value if it is a float or int,
615 * 1 or resp. 0 if it is a bool, and null otherwise.
617 * @note In the future, we may allow the sortkey to be specified explicitly
618 * in ParserOutput::setProperty.
620 * @param mixed $value
624 private function getPropertySortKeyValue( $value ) {
625 if ( is_int( $value ) ||
is_float( $value ) ||
is_bool( $value ) ) {
626 return floatval( $value );
633 * Get an array of interwiki insertions for passing to the DB
634 * Skips the titles specified by the 2-D array $existing
635 * @param array $existing
638 private function getInterwikiInsertions( $existing = [] ) {
640 foreach ( $this->mInterwikis
as $prefix => $dbkeys ) {
641 $diffs = isset( $existing[$prefix] )
642 ?
array_diff_key( $dbkeys, $existing[$prefix] )
645 foreach ( $diffs as $dbk => $id ) {
647 'iwl_from' => $this->mId
,
648 'iwl_prefix' => $prefix,
658 * Given an array of existing links, returns those links which are not in $this
659 * and thus should be deleted.
660 * @param array $existing
663 private function getLinkDeletions( $existing ) {
665 foreach ( $existing as $ns => $dbkeys ) {
666 if ( isset( $this->mLinks
[$ns] ) ) {
667 $del[$ns] = array_diff_key( $existing[$ns], $this->mLinks
[$ns] );
669 $del[$ns] = $existing[$ns];
677 * Given an array of existing templates, returns those templates which are not in $this
678 * and thus should be deleted.
679 * @param array $existing
682 private function getTemplateDeletions( $existing ) {
684 foreach ( $existing as $ns => $dbkeys ) {
685 if ( isset( $this->mTemplates
[$ns] ) ) {
686 $del[$ns] = array_diff_key( $existing[$ns], $this->mTemplates
[$ns] );
688 $del[$ns] = $existing[$ns];
696 * Given an array of existing images, returns those images which are not in $this
697 * and thus should be deleted.
698 * @param array $existing
701 private function getImageDeletions( $existing ) {
702 return array_diff_key( $existing, $this->mImages
);
706 * Given an array of existing external links, returns those links which are not
707 * in $this and thus should be deleted.
708 * @param array $existing
711 private function getExternalDeletions( $existing ) {
712 return array_diff_key( $existing, $this->mExternals
);
716 * Given an array of existing categories, returns those categories which are not in $this
717 * and thus should be deleted.
718 * @param array $existing
721 private function getCategoryDeletions( $existing ) {
722 return array_diff_assoc( $existing, $this->mCategories
);
726 * Given an array of existing interlanguage links, returns those links which are not
727 * in $this and thus should be deleted.
728 * @param array $existing
731 private function getInterlangDeletions( $existing ) {
732 return array_diff_assoc( $existing, $this->mInterlangs
);
736 * Get array of properties which should be deleted.
737 * @param array $existing
740 function getPropertyDeletions( $existing ) {
741 return array_diff_assoc( $existing, $this->mProperties
);
745 * Given an array of existing interwiki links, returns those links which are not in $this
746 * and thus should be deleted.
747 * @param array $existing
750 private function getInterwikiDeletions( $existing ) {
752 foreach ( $existing as $prefix => $dbkeys ) {
753 if ( isset( $this->mInterwikis
[$prefix] ) ) {
754 $del[$prefix] = array_diff_key( $existing[$prefix], $this->mInterwikis
[$prefix] );
756 $del[$prefix] = $existing[$prefix];
764 * Get an array of existing links, as a 2-D array
768 private function getExistingLinks() {
769 $res = $this->mDb
->select( 'pagelinks', [ 'pl_namespace', 'pl_title' ],
770 [ 'pl_from' => $this->mId
], __METHOD__
, $this->mOptions
);
772 foreach ( $res as $row ) {
773 if ( !isset( $arr[$row->pl_namespace
] ) ) {
774 $arr[$row->pl_namespace
] = [];
776 $arr[$row->pl_namespace
][$row->pl_title
] = 1;
783 * Get an array of existing templates, as a 2-D array
787 private function getExistingTemplates() {
788 $res = $this->mDb
->select( 'templatelinks', [ 'tl_namespace', 'tl_title' ],
789 [ 'tl_from' => $this->mId
], __METHOD__
, $this->mOptions
);
791 foreach ( $res as $row ) {
792 if ( !isset( $arr[$row->tl_namespace
] ) ) {
793 $arr[$row->tl_namespace
] = [];
795 $arr[$row->tl_namespace
][$row->tl_title
] = 1;
802 * Get an array of existing images, image names in the keys
806 private function getExistingImages() {
807 $res = $this->mDb
->select( 'imagelinks', [ 'il_to' ],
808 [ 'il_from' => $this->mId
], __METHOD__
, $this->mOptions
);
810 foreach ( $res as $row ) {
811 $arr[$row->il_to
] = 1;
818 * Get an array of existing external links, URLs in the keys
822 private function getExistingExternals() {
823 $res = $this->mDb
->select( 'externallinks', [ 'el_to' ],
824 [ 'el_from' => $this->mId
], __METHOD__
, $this->mOptions
);
826 foreach ( $res as $row ) {
827 $arr[$row->el_to
] = 1;
834 * Get an array of existing categories, with the name in the key and sort key in the value.
838 private function getExistingCategories() {
839 $res = $this->mDb
->select( 'categorylinks', [ 'cl_to', 'cl_sortkey_prefix' ],
840 [ 'cl_from' => $this->mId
], __METHOD__
, $this->mOptions
);
842 foreach ( $res as $row ) {
843 $arr[$row->cl_to
] = $row->cl_sortkey_prefix
;
850 * Get an array of existing interlanguage links, with the language code in the key and the
851 * title in the value.
855 private function getExistingInterlangs() {
856 $res = $this->mDb
->select( 'langlinks', [ 'll_lang', 'll_title' ],
857 [ 'll_from' => $this->mId
], __METHOD__
, $this->mOptions
);
859 foreach ( $res as $row ) {
860 $arr[$row->ll_lang
] = $row->ll_title
;
867 * Get an array of existing inline interwiki links, as a 2-D array
868 * @return array (prefix => array(dbkey => 1))
870 protected function getExistingInterwikis() {
871 $res = $this->mDb
->select( 'iwlinks', [ 'iwl_prefix', 'iwl_title' ],
872 [ 'iwl_from' => $this->mId
], __METHOD__
, $this->mOptions
);
874 foreach ( $res as $row ) {
875 if ( !isset( $arr[$row->iwl_prefix
] ) ) {
876 $arr[$row->iwl_prefix
] = [];
878 $arr[$row->iwl_prefix
][$row->iwl_title
] = 1;
885 * Get an array of existing categories, with the name in the key and sort key in the value.
887 * @return array Array of property names and values
889 private function getExistingProperties() {
890 $res = $this->mDb
->select( 'page_props', [ 'pp_propname', 'pp_value' ],
891 [ 'pp_page' => $this->mId
], __METHOD__
, $this->mOptions
);
893 foreach ( $res as $row ) {
894 $arr[$row->pp_propname
] = $row->pp_value
;
901 * Return the title object of the page being updated
904 public function getTitle() {
905 return $this->mTitle
;
909 * Returns parser output
911 * @return ParserOutput
913 public function getParserOutput() {
914 return $this->mParserOutput
;
918 * Return the list of images used as generated by the parser
921 public function getImages() {
922 return $this->mImages
;
926 * Set the revision corresponding to this LinksUpdate
930 * @param Revision $revision
932 public function setRevision( Revision
$revision ) {
933 $this->mRevision
= $revision;
938 * @return null|Revision
940 public function getRevision() {
941 return $this->mRevision
;
945 * Set the User who triggered this LinksUpdate
950 public function setTriggeringUser( User
$user ) {
958 public function getTriggeringUser() {
963 * Invalidate any necessary link lists related to page property changes
964 * @param array $changed
966 private function invalidateProperties( $changed ) {
967 global $wgPagePropLinkInvalidations;
969 foreach ( $changed as $name => $value ) {
970 if ( isset( $wgPagePropLinkInvalidations[$name] ) ) {
971 $inv = $wgPagePropLinkInvalidations[$name];
972 if ( !is_array( $inv ) ) {
975 foreach ( $inv as $table ) {
976 DeferredUpdates
::addUpdate( new HTMLCacheUpdate( $this->mTitle
, $table ) );
983 * Fetch page links added by this LinksUpdate. Only available after the update is complete.
985 * @return null|array Array of Titles
987 public function getAddedLinks() {
988 if ( $this->linkInsertions
=== null ) {
992 foreach ( $this->linkInsertions
as $insertion ) {
993 $result[] = Title
::makeTitle( $insertion['pl_namespace'], $insertion['pl_title'] );
1000 * Fetch page links removed by this LinksUpdate. Only available after the update is complete.
1002 * @return null|array Array of Titles
1004 public function getRemovedLinks() {
1005 if ( $this->linkDeletions
=== null ) {
1009 foreach ( $this->linkDeletions
as $ns => $titles ) {
1010 foreach ( $titles as $title => $unused ) {
1011 $result[] = Title
::makeTitle( $ns, $title );
1019 * Update links table freshness
1021 protected function updateLinksTimestamp() {
1023 // The link updates made here only reflect the freshness of the parser output
1024 $timestamp = $this->mParserOutput
->getCacheTime();
1025 $this->mDb
->update( 'page',
1026 [ 'page_links_updated' => $this->mDb
->timestamp( $timestamp ) ],
1027 [ 'page_id' => $this->mId
],
1033 public function getAsJobSpecification() {
1034 if ( $this->user
) {
1036 'userId' => $this->user
->getId(),
1037 'userName' => $this->user
->getName(),
1043 if ( $this->mRevision
) {
1044 $triggeringRevisionId = $this->mRevision
->getId();
1046 $triggeringRevisionId = false;
1050 'wiki' => $this->mDb
->getWikiID(),
1051 'job' => new JobSpecification(
1052 'refreshLinksPrioritized',
1054 // Reuse the parser cache if it was saved
1055 'rootJobTimestamp' => $this->mParserOutput
->getCacheTime(),
1056 'useRecursiveLinksUpdate' => $this->mRecursive
,
1057 'triggeringUser' => $userInfo,
1058 'triggeringRevisionId' => $triggeringRevisionId,
1060 [ 'removeDuplicates' => true ],