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 * @param string $why One of (job, atomicity)
172 * @return ScopedCallback
173 * @throws RuntimeException
176 public static function acquirePageLock( IDatabase
$dbw, $pageId, $why = 'atomicity' ) {
177 $key = "LinksUpdate:$why:pageid:$pageId";
178 $scopedLock = $dbw->getScopedLockAndFlush( $key, __METHOD__
, 15 );
179 if ( !$scopedLock ) {
180 throw new RuntimeException( "Could not acquire lock '$key'." );
186 protected function doIncrementalUpdate() {
188 $existing = $this->getExistingLinks();
189 $this->linkDeletions
= $this->getLinkDeletions( $existing );
190 $this->linkInsertions
= $this->getLinkInsertions( $existing );
191 $this->incrTableUpdate( 'pagelinks', 'pl', $this->linkDeletions
, $this->linkInsertions
);
194 $existing = $this->getExistingImages();
195 $imageDeletes = $this->getImageDeletions( $existing );
196 $this->incrTableUpdate( 'imagelinks', 'il', $imageDeletes,
197 $this->getImageInsertions( $existing ) );
199 # Invalidate all image description pages which had links added or removed
200 $imageUpdates = $imageDeletes +
array_diff_key( $this->mImages
, $existing );
201 $this->invalidateImageDescriptions( $imageUpdates );
204 $existing = $this->getExistingExternals();
205 $this->incrTableUpdate( 'externallinks', 'el', $this->getExternalDeletions( $existing ),
206 $this->getExternalInsertions( $existing ) );
209 $existing = $this->getExistingInterlangs();
210 $this->incrTableUpdate( 'langlinks', 'll', $this->getInterlangDeletions( $existing ),
211 $this->getInterlangInsertions( $existing ) );
213 # Inline interwiki links
214 $existing = $this->getExistingInterwikis();
215 $this->incrTableUpdate( 'iwlinks', 'iwl', $this->getInterwikiDeletions( $existing ),
216 $this->getInterwikiInsertions( $existing ) );
219 $existing = $this->getExistingTemplates();
220 $this->incrTableUpdate( 'templatelinks', 'tl', $this->getTemplateDeletions( $existing ),
221 $this->getTemplateInsertions( $existing ) );
224 $existing = $this->getExistingCategories();
225 $categoryDeletes = $this->getCategoryDeletions( $existing );
226 $this->incrTableUpdate( 'categorylinks', 'cl', $categoryDeletes,
227 $this->getCategoryInsertions( $existing ) );
229 # Invalidate all categories which were added, deleted or changed (set symmetric difference)
230 $categoryInserts = array_diff_assoc( $this->mCategories
, $existing );
231 $categoryUpdates = $categoryInserts +
$categoryDeletes;
232 $this->invalidateCategories( $categoryUpdates );
233 $this->updateCategoryCounts( $categoryInserts, $categoryDeletes );
236 $existing = $this->getExistingProperties();
237 $propertiesDeletes = $this->getPropertyDeletions( $existing );
238 $this->incrTableUpdate( 'page_props', 'pp', $propertiesDeletes,
239 $this->getPropertyInsertions( $existing ) );
241 # Invalidate the necessary pages
242 $changed = $propertiesDeletes +
array_diff_assoc( $this->mProperties
, $existing );
243 $this->invalidateProperties( $changed );
245 # Refresh links of all pages including this page
246 # This will be in a separate transaction
247 if ( $this->mRecursive
) {
248 $this->queueRecursiveJobs();
251 # Update the links table freshness for this title
252 $this->updateLinksTimestamp();
256 * Queue recursive jobs for this page
258 * Which means do LinksUpdate on all pages that include the current page,
259 * using the job queue.
261 protected function queueRecursiveJobs() {
262 self
::queueRecursiveJobsForTable( $this->mTitle
, 'templatelinks' );
263 if ( $this->mTitle
->getNamespace() == NS_FILE
) {
264 // Process imagelinks in case the title is or was a redirect
265 self
::queueRecursiveJobsForTable( $this->mTitle
, 'imagelinks' );
268 $bc = $this->mTitle
->getBacklinkCache();
269 // Get jobs for cascade-protected backlinks for a high priority queue.
270 // If meta-templates change to using a new template, the new template
271 // should be implicitly protected as soon as possible, if applicable.
272 // These jobs duplicate a subset of the above ones, but can run sooner.
273 // Which ever runs first generally no-ops the other one.
275 foreach ( $bc->getCascadeProtectedLinks() as $title ) {
276 $jobs[] = RefreshLinksJob
::newPrioritized( $title, [] );
278 JobQueueGroup
::singleton()->push( $jobs );
282 * Queue a RefreshLinks job for any table.
284 * @param Title $title Title to do job for
285 * @param string $table Table to use (e.g. 'templatelinks')
287 public static function queueRecursiveJobsForTable( Title
$title, $table ) {
288 if ( $title->getBacklinkCache()->hasLinks( $table ) ) {
289 $job = new RefreshLinksJob(
294 ] + Job
::newRootJobParams( // "overall" refresh links job info
295 "refreshlinks:{$table}:{$title->getPrefixedText()}"
299 JobQueueGroup
::singleton()->push( $job );
306 function invalidateCategories( $cats ) {
307 $this->invalidatePages( NS_CATEGORY
, array_keys( $cats ) );
311 * Update all the appropriate counts in the category table.
312 * @param array $added Associative array of category name => sort key
313 * @param array $deleted Associative array of category name => sort key
315 function updateCategoryCounts( $added, $deleted ) {
316 $a = WikiPage
::factory( $this->mTitle
);
317 $a->updateCategoryCounts(
318 array_keys( $added ), array_keys( $deleted )
323 * @param array $images
325 function invalidateImageDescriptions( $images ) {
326 $this->invalidatePages( NS_FILE
, array_keys( $images ) );
330 * Update a table by doing a delete query then an insert query
331 * @param string $table Table name
332 * @param string $prefix Field name prefix
333 * @param array $deletions
334 * @param array $insertions Rows to insert
336 private function incrTableUpdate( $table, $prefix, $deletions, $insertions ) {
337 $bSize = RequestContext
::getMain()->getConfig()->get( 'UpdateRowsPerQuery' );
339 if ( $table === 'page_props' ) {
340 $fromField = 'pp_page';
342 $fromField = "{$prefix}_from";
345 $deleteWheres = []; // list of WHERE clause arrays for each DB delete() call
346 if ( $table === 'pagelinks' ||
$table === 'templatelinks' ||
$table === 'iwlinks' ) {
347 $baseKey = ( $table === 'iwlinks' ) ?
'iwl_prefix' : "{$prefix}_namespace";
350 $curDeletionBatch = [];
351 $deletionBatches = [];
352 foreach ( $deletions as $ns => $dbKeys ) {
353 foreach ( $dbKeys as $dbKey => $unused ) {
354 $curDeletionBatch[$ns][$dbKey] = 1;
355 if ( ++
$curBatchSize >= $bSize ) {
356 $deletionBatches[] = $curDeletionBatch;
357 $curDeletionBatch = [];
362 if ( $curDeletionBatch ) {
363 $deletionBatches[] = $curDeletionBatch;
366 foreach ( $deletionBatches as $deletionBatch ) {
368 $fromField => $this->mId
,
369 $this->mDb
->makeWhereFrom2d( $deletionBatch, $baseKey, "{$prefix}_title" )
373 if ( $table === 'langlinks' ) {
374 $toField = 'll_lang';
375 } elseif ( $table === 'page_props' ) {
376 $toField = 'pp_propname';
378 $toField = $prefix . '_to';
381 $deletionBatches = array_chunk( array_keys( $deletions ), $bSize );
382 foreach ( $deletionBatches as $deletionBatch ) {
383 $deleteWheres[] = [ $fromField => $this->mId
, $toField => $deletionBatch ];
387 foreach ( $deleteWheres as $deleteWhere ) {
388 $this->mDb
->delete( $table, $deleteWhere, __METHOD__
);
389 $this->mDb
->commit( __METHOD__
, 'flush' );
390 wfGetLBFactory()->waitForReplication( [ 'wiki' => $this->mDb
->getWikiID() ] );
393 $insertBatches = array_chunk( $insertions, $bSize );
394 foreach ( $insertBatches as $insertBatch ) {
395 $this->mDb
->insert( $table, $insertBatch, __METHOD__
, 'IGNORE' );
396 $this->mDb
->commit( __METHOD__
, 'flush' );
397 wfGetLBFactory()->waitForReplication( [ 'wiki' => $this->mDb
->getWikiID() ] );
400 if ( count( $insertions ) ) {
401 Hooks
::run( 'LinksUpdateAfterInsert', [ $this, $table, $insertions ] );
406 * Get an array of pagelinks insertions for passing to the DB
407 * Skips the titles specified by the 2-D array $existing
408 * @param array $existing
411 private function getLinkInsertions( $existing = [] ) {
413 foreach ( $this->mLinks
as $ns => $dbkeys ) {
414 $diffs = isset( $existing[$ns] )
415 ?
array_diff_key( $dbkeys, $existing[$ns] )
417 foreach ( $diffs as $dbk => $id ) {
419 'pl_from' => $this->mId
,
420 'pl_from_namespace' => $this->mTitle
->getNamespace(),
421 'pl_namespace' => $ns,
431 * Get an array of template insertions. Like getLinkInsertions()
432 * @param array $existing
435 private function getTemplateInsertions( $existing = [] ) {
437 foreach ( $this->mTemplates
as $ns => $dbkeys ) {
438 $diffs = isset( $existing[$ns] ) ?
array_diff_key( $dbkeys, $existing[$ns] ) : $dbkeys;
439 foreach ( $diffs as $dbk => $id ) {
441 'tl_from' => $this->mId
,
442 'tl_from_namespace' => $this->mTitle
->getNamespace(),
443 'tl_namespace' => $ns,
453 * Get an array of image insertions
454 * Skips the names specified in $existing
455 * @param array $existing
458 private function getImageInsertions( $existing = [] ) {
460 $diffs = array_diff_key( $this->mImages
, $existing );
461 foreach ( $diffs as $iname => $dummy ) {
463 'il_from' => $this->mId
,
464 'il_from_namespace' => $this->mTitle
->getNamespace(),
473 * Get an array of externallinks insertions. Skips the names specified in $existing
474 * @param array $existing
477 private function getExternalInsertions( $existing = [] ) {
479 $diffs = array_diff_key( $this->mExternals
, $existing );
480 foreach ( $diffs as $url => $dummy ) {
481 foreach ( wfMakeUrlIndexes( $url ) as $index ) {
483 'el_id' => $this->mDb
->nextSequenceValue( 'externallinks_el_id_seq' ),
484 'el_from' => $this->mId
,
486 'el_index' => $index,
495 * Get an array of category insertions
497 * @param array $existing Mapping existing category names to sort keys. If both
498 * match a link in $this, the link will be omitted from the output
502 private function getCategoryInsertions( $existing = [] ) {
503 global $wgContLang, $wgCategoryCollation;
504 $diffs = array_diff_assoc( $this->mCategories
, $existing );
506 foreach ( $diffs as $name => $prefix ) {
507 $nt = Title
::makeTitleSafe( NS_CATEGORY
, $name );
508 $wgContLang->findVariantLink( $name, $nt, true );
510 if ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
512 } elseif ( $this->mTitle
->getNamespace() == NS_FILE
) {
518 # Treat custom sortkeys as a prefix, so that if multiple
519 # things are forced to sort as '*' or something, they'll
520 # sort properly in the category rather than in page_id
522 $sortkey = Collation
::singleton()->getSortKey(
523 $this->mTitle
->getCategorySortkey( $prefix ) );
526 'cl_from' => $this->mId
,
528 'cl_sortkey' => $sortkey,
529 'cl_timestamp' => $this->mDb
->timestamp(),
530 'cl_sortkey_prefix' => $prefix,
531 'cl_collation' => $wgCategoryCollation,
540 * Get an array of interlanguage link insertions
542 * @param array $existing Mapping existing language codes to titles
546 private function getInterlangInsertions( $existing = [] ) {
547 $diffs = array_diff_assoc( $this->mInterlangs
, $existing );
549 foreach ( $diffs as $lang => $title ) {
551 'll_from' => $this->mId
,
561 * Get an array of page property insertions
562 * @param array $existing
565 function getPropertyInsertions( $existing = [] ) {
566 $diffs = array_diff_assoc( $this->mProperties
, $existing );
569 foreach ( array_keys( $diffs ) as $name ) {
570 $arr[] = $this->getPagePropRowData( $name );
577 * Returns an associative array to be used for inserting a row into
578 * the page_props table. Besides the given property name, this will
579 * include the page id from $this->mId and any property value from
580 * $this->mProperties.
582 * The array returned will include the pp_sortkey field if this
583 * is present in the database (as indicated by $wgPagePropsHaveSortkey).
584 * The sortkey value is currently determined by getPropertySortKeyValue().
586 * @note this assumes that $this->mProperties[$prop] is defined.
588 * @param string $prop The name of the property.
592 private function getPagePropRowData( $prop ) {
593 global $wgPagePropsHaveSortkey;
595 $value = $this->mProperties
[$prop];
598 'pp_page' => $this->mId
,
599 'pp_propname' => $prop,
600 'pp_value' => $value,
603 if ( $wgPagePropsHaveSortkey ) {
604 $row['pp_sortkey'] = $this->getPropertySortKeyValue( $value );
611 * Determines the sort key for the given property value.
612 * This will return $value if it is a float or int,
613 * 1 or resp. 0 if it is a bool, and null otherwise.
615 * @note In the future, we may allow the sortkey to be specified explicitly
616 * in ParserOutput::setProperty.
618 * @param mixed $value
622 private function getPropertySortKeyValue( $value ) {
623 if ( is_int( $value ) ||
is_float( $value ) ||
is_bool( $value ) ) {
624 return floatval( $value );
631 * Get an array of interwiki insertions for passing to the DB
632 * Skips the titles specified by the 2-D array $existing
633 * @param array $existing
636 private function getInterwikiInsertions( $existing = [] ) {
638 foreach ( $this->mInterwikis
as $prefix => $dbkeys ) {
639 $diffs = isset( $existing[$prefix] )
640 ?
array_diff_key( $dbkeys, $existing[$prefix] )
643 foreach ( $diffs as $dbk => $id ) {
645 'iwl_from' => $this->mId
,
646 'iwl_prefix' => $prefix,
656 * Given an array of existing links, returns those links which are not in $this
657 * and thus should be deleted.
658 * @param array $existing
661 private function getLinkDeletions( $existing ) {
663 foreach ( $existing as $ns => $dbkeys ) {
664 if ( isset( $this->mLinks
[$ns] ) ) {
665 $del[$ns] = array_diff_key( $existing[$ns], $this->mLinks
[$ns] );
667 $del[$ns] = $existing[$ns];
675 * Given an array of existing templates, returns those templates which are not in $this
676 * and thus should be deleted.
677 * @param array $existing
680 private function getTemplateDeletions( $existing ) {
682 foreach ( $existing as $ns => $dbkeys ) {
683 if ( isset( $this->mTemplates
[$ns] ) ) {
684 $del[$ns] = array_diff_key( $existing[$ns], $this->mTemplates
[$ns] );
686 $del[$ns] = $existing[$ns];
694 * Given an array of existing images, returns those images which are not in $this
695 * and thus should be deleted.
696 * @param array $existing
699 private function getImageDeletions( $existing ) {
700 return array_diff_key( $existing, $this->mImages
);
704 * Given an array of existing external links, returns those links which are not
705 * in $this and thus should be deleted.
706 * @param array $existing
709 private function getExternalDeletions( $existing ) {
710 return array_diff_key( $existing, $this->mExternals
);
714 * Given an array of existing categories, returns those categories which are not in $this
715 * and thus should be deleted.
716 * @param array $existing
719 private function getCategoryDeletions( $existing ) {
720 return array_diff_assoc( $existing, $this->mCategories
);
724 * Given an array of existing interlanguage links, returns those links which are not
725 * in $this and thus should be deleted.
726 * @param array $existing
729 private function getInterlangDeletions( $existing ) {
730 return array_diff_assoc( $existing, $this->mInterlangs
);
734 * Get array of properties which should be deleted.
735 * @param array $existing
738 function getPropertyDeletions( $existing ) {
739 return array_diff_assoc( $existing, $this->mProperties
);
743 * Given an array of existing interwiki links, returns those links which are not in $this
744 * and thus should be deleted.
745 * @param array $existing
748 private function getInterwikiDeletions( $existing ) {
750 foreach ( $existing as $prefix => $dbkeys ) {
751 if ( isset( $this->mInterwikis
[$prefix] ) ) {
752 $del[$prefix] = array_diff_key( $existing[$prefix], $this->mInterwikis
[$prefix] );
754 $del[$prefix] = $existing[$prefix];
762 * Get an array of existing links, as a 2-D array
766 private function getExistingLinks() {
767 $res = $this->mDb
->select( 'pagelinks', [ 'pl_namespace', 'pl_title' ],
768 [ 'pl_from' => $this->mId
], __METHOD__
, $this->mOptions
);
770 foreach ( $res as $row ) {
771 if ( !isset( $arr[$row->pl_namespace
] ) ) {
772 $arr[$row->pl_namespace
] = [];
774 $arr[$row->pl_namespace
][$row->pl_title
] = 1;
781 * Get an array of existing templates, as a 2-D array
785 private function getExistingTemplates() {
786 $res = $this->mDb
->select( 'templatelinks', [ 'tl_namespace', 'tl_title' ],
787 [ 'tl_from' => $this->mId
], __METHOD__
, $this->mOptions
);
789 foreach ( $res as $row ) {
790 if ( !isset( $arr[$row->tl_namespace
] ) ) {
791 $arr[$row->tl_namespace
] = [];
793 $arr[$row->tl_namespace
][$row->tl_title
] = 1;
800 * Get an array of existing images, image names in the keys
804 private function getExistingImages() {
805 $res = $this->mDb
->select( 'imagelinks', [ 'il_to' ],
806 [ 'il_from' => $this->mId
], __METHOD__
, $this->mOptions
);
808 foreach ( $res as $row ) {
809 $arr[$row->il_to
] = 1;
816 * Get an array of existing external links, URLs in the keys
820 private function getExistingExternals() {
821 $res = $this->mDb
->select( 'externallinks', [ 'el_to' ],
822 [ 'el_from' => $this->mId
], __METHOD__
, $this->mOptions
);
824 foreach ( $res as $row ) {
825 $arr[$row->el_to
] = 1;
832 * Get an array of existing categories, with the name in the key and sort key in the value.
836 private function getExistingCategories() {
837 $res = $this->mDb
->select( 'categorylinks', [ 'cl_to', 'cl_sortkey_prefix' ],
838 [ 'cl_from' => $this->mId
], __METHOD__
, $this->mOptions
);
840 foreach ( $res as $row ) {
841 $arr[$row->cl_to
] = $row->cl_sortkey_prefix
;
848 * Get an array of existing interlanguage links, with the language code in the key and the
849 * title in the value.
853 private function getExistingInterlangs() {
854 $res = $this->mDb
->select( 'langlinks', [ 'll_lang', 'll_title' ],
855 [ 'll_from' => $this->mId
], __METHOD__
, $this->mOptions
);
857 foreach ( $res as $row ) {
858 $arr[$row->ll_lang
] = $row->ll_title
;
865 * Get an array of existing inline interwiki links, as a 2-D array
866 * @return array (prefix => array(dbkey => 1))
868 protected function getExistingInterwikis() {
869 $res = $this->mDb
->select( 'iwlinks', [ 'iwl_prefix', 'iwl_title' ],
870 [ 'iwl_from' => $this->mId
], __METHOD__
, $this->mOptions
);
872 foreach ( $res as $row ) {
873 if ( !isset( $arr[$row->iwl_prefix
] ) ) {
874 $arr[$row->iwl_prefix
] = [];
876 $arr[$row->iwl_prefix
][$row->iwl_title
] = 1;
883 * Get an array of existing categories, with the name in the key and sort key in the value.
885 * @return array Array of property names and values
887 private function getExistingProperties() {
888 $res = $this->mDb
->select( 'page_props', [ 'pp_propname', 'pp_value' ],
889 [ 'pp_page' => $this->mId
], __METHOD__
, $this->mOptions
);
891 foreach ( $res as $row ) {
892 $arr[$row->pp_propname
] = $row->pp_value
;
899 * Return the title object of the page being updated
902 public function getTitle() {
903 return $this->mTitle
;
907 * Returns parser output
909 * @return ParserOutput
911 public function getParserOutput() {
912 return $this->mParserOutput
;
916 * Return the list of images used as generated by the parser
919 public function getImages() {
920 return $this->mImages
;
924 * Set the revision corresponding to this LinksUpdate
928 * @param Revision $revision
930 public function setRevision( Revision
$revision ) {
931 $this->mRevision
= $revision;
936 * @return null|Revision
938 public function getRevision() {
939 return $this->mRevision
;
943 * Set the User who triggered this LinksUpdate
948 public function setTriggeringUser( User
$user ) {
956 public function getTriggeringUser() {
961 * Invalidate any necessary link lists related to page property changes
962 * @param array $changed
964 private function invalidateProperties( $changed ) {
965 global $wgPagePropLinkInvalidations;
967 foreach ( $changed as $name => $value ) {
968 if ( isset( $wgPagePropLinkInvalidations[$name] ) ) {
969 $inv = $wgPagePropLinkInvalidations[$name];
970 if ( !is_array( $inv ) ) {
973 foreach ( $inv as $table ) {
974 DeferredUpdates
::addUpdate( new HTMLCacheUpdate( $this->mTitle
, $table ) );
981 * Fetch page links added by this LinksUpdate. Only available after the update is complete.
983 * @return null|array Array of Titles
985 public function getAddedLinks() {
986 if ( $this->linkInsertions
=== null ) {
990 foreach ( $this->linkInsertions
as $insertion ) {
991 $result[] = Title
::makeTitle( $insertion['pl_namespace'], $insertion['pl_title'] );
998 * Fetch page links removed by this LinksUpdate. Only available after the update is complete.
1000 * @return null|array Array of Titles
1002 public function getRemovedLinks() {
1003 if ( $this->linkDeletions
=== null ) {
1007 foreach ( $this->linkDeletions
as $ns => $titles ) {
1008 foreach ( $titles as $title => $unused ) {
1009 $result[] = Title
::makeTitle( $ns, $title );
1017 * Update links table freshness
1019 protected function updateLinksTimestamp() {
1021 // The link updates made here only reflect the freshness of the parser output
1022 $timestamp = $this->mParserOutput
->getCacheTime();
1023 $this->mDb
->update( 'page',
1024 [ 'page_links_updated' => $this->mDb
->timestamp( $timestamp ) ],
1025 [ 'page_id' => $this->mId
],
1031 public function getAsJobSpecification() {
1032 if ( $this->user
) {
1034 'userId' => $this->user
->getId(),
1035 'userName' => $this->user
->getName(),
1041 if ( $this->mRevision
) {
1042 $triggeringRevisionId = $this->mRevision
->getId();
1044 $triggeringRevisionId = false;
1048 'wiki' => $this->mDb
->getWikiID(),
1049 'job' => new JobSpecification(
1050 'refreshLinksPrioritized',
1052 // Reuse the parser cache if it was saved
1053 'rootJobTimestamp' => $this->mParserOutput
->getCacheTime(),
1054 'useRecursiveLinksUpdate' => $this->mRecursive
,
1055 'triggeringUser' => $userInfo,
1056 'triggeringRevisionId' => $triggeringRevisionId,
1058 [ 'removeDuplicates' => true ],