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;
83 * @var null|array Added properties if calculated.
85 private $propertyInsertions = null;
88 * @var null|array Deleted properties if calculated.
90 private $propertyDeletions = null;
100 * @param Title $title Title of the page we're updating
101 * @param ParserOutput $parserOutput Output from a full parse of this page
102 * @param bool $recursive Queue jobs for recursive updates?
103 * @throws MWException
105 function __construct( Title
$title, ParserOutput
$parserOutput, $recursive = true ) {
106 // Implicit transactions are disabled as they interfere with batching
107 parent
::__construct( false );
109 $this->mTitle
= $title;
110 $this->mId
= $title->getArticleID( Title
::GAID_FOR_UPDATE
);
113 throw new InvalidArgumentException(
114 "The Title object yields no ID. Perhaps the page doesn't exist?"
118 $this->mParserOutput
= $parserOutput;
120 $this->mLinks
= $parserOutput->getLinks();
121 $this->mImages
= $parserOutput->getImages();
122 $this->mTemplates
= $parserOutput->getTemplates();
123 $this->mExternals
= $parserOutput->getExternalLinks();
124 $this->mCategories
= $parserOutput->getCategories();
125 $this->mProperties
= $parserOutput->getProperties();
126 $this->mInterwikis
= $parserOutput->getInterwikiLinks();
128 # Convert the format of the interlanguage links
129 # I didn't want to change it in the ParserOutput, because that array is passed all
130 # the way back to the skin, so either a skin API break would be required, or an
131 # inefficient back-conversion.
132 $ill = $parserOutput->getLanguageLinks();
133 $this->mInterlangs
= [];
134 foreach ( $ill as $link ) {
135 list( $key, $title ) = explode( ':', $link, 2 );
136 $this->mInterlangs
[$key] = $title;
139 foreach ( $this->mCategories
as &$sortkey ) {
140 # If the sortkey is longer then 255 bytes,
141 # it truncated by DB, and then doesn't get
142 # matched when comparing existing vs current
143 # categories, causing bug 25254.
144 # Also. substr behaves weird when given "".
145 if ( $sortkey !== '' ) {
146 $sortkey = substr( $sortkey, 0, 255 );
150 $this->mRecursive
= $recursive;
152 Hooks
::run( 'LinksUpdateConstructed', [ &$this ] );
156 * Update link tables with outgoing links from an updated article
158 * @note: this is managed by DeferredUpdates::execute(). Do not run this in a transaction.
160 public function doUpdate() {
161 // Make sure all links update threads see the changes of each other.
162 // This handles the case when updates have to batched into several COMMITs.
163 $scopedLock = self
::acquirePageLock( $this->mDb
, $this->mId
);
165 Hooks
::run( 'LinksUpdate', [ &$this ] );
166 $this->doIncrementalUpdate();
168 // Commit and release the lock
169 ScopedCallback
::consume( $scopedLock );
170 // Run post-commit hooks without DBO_TRX
171 $this->mDb
->onTransactionIdle( function() {
172 Hooks
::run( 'LinksUpdateComplete', [ &$this ] );
177 * Acquire a lock for performing link table updates for a page on a DB
179 * @param IDatabase $dbw
180 * @param integer $pageId
181 * @param string $why One of (job, atomicity)
182 * @return ScopedCallback
183 * @throws RuntimeException
186 public static function acquirePageLock( IDatabase
$dbw, $pageId, $why = 'atomicity' ) {
187 $key = "LinksUpdate:$why:pageid:$pageId";
188 $scopedLock = $dbw->getScopedLockAndFlush( $key, __METHOD__
, 15 );
189 if ( !$scopedLock ) {
190 throw new RuntimeException( "Could not acquire lock '$key'." );
196 protected function doIncrementalUpdate() {
198 $existing = $this->getExistingLinks();
199 $this->linkDeletions
= $this->getLinkDeletions( $existing );
200 $this->linkInsertions
= $this->getLinkInsertions( $existing );
201 $this->incrTableUpdate( 'pagelinks', 'pl', $this->linkDeletions
, $this->linkInsertions
);
204 $existing = $this->getExistingImages();
205 $imageDeletes = $this->getImageDeletions( $existing );
206 $this->incrTableUpdate( 'imagelinks', 'il', $imageDeletes,
207 $this->getImageInsertions( $existing ) );
209 # Invalidate all image description pages which had links added or removed
210 $imageUpdates = $imageDeletes +
array_diff_key( $this->mImages
, $existing );
211 $this->invalidateImageDescriptions( $imageUpdates );
214 $existing = $this->getExistingExternals();
215 $this->incrTableUpdate( 'externallinks', 'el', $this->getExternalDeletions( $existing ),
216 $this->getExternalInsertions( $existing ) );
219 $existing = $this->getExistingInterlangs();
220 $this->incrTableUpdate( 'langlinks', 'll', $this->getInterlangDeletions( $existing ),
221 $this->getInterlangInsertions( $existing ) );
223 # Inline interwiki links
224 $existing = $this->getExistingInterwikis();
225 $this->incrTableUpdate( 'iwlinks', 'iwl', $this->getInterwikiDeletions( $existing ),
226 $this->getInterwikiInsertions( $existing ) );
229 $existing = $this->getExistingTemplates();
230 $this->incrTableUpdate( 'templatelinks', 'tl', $this->getTemplateDeletions( $existing ),
231 $this->getTemplateInsertions( $existing ) );
234 $existing = $this->getExistingCategories();
235 $categoryDeletes = $this->getCategoryDeletions( $existing );
236 $this->incrTableUpdate( 'categorylinks', 'cl', $categoryDeletes,
237 $this->getCategoryInsertions( $existing ) );
239 # Invalidate all categories which were added, deleted or changed (set symmetric difference)
240 $categoryInserts = array_diff_assoc( $this->mCategories
, $existing );
241 $categoryUpdates = $categoryInserts +
$categoryDeletes;
242 $this->invalidateCategories( $categoryUpdates );
243 $this->updateCategoryCounts( $categoryInserts, $categoryDeletes );
246 $existing = $this->getExistingProperties();
247 $this->propertyDeletions
= $this->getPropertyDeletions( $existing );
248 $this->incrTableUpdate( 'page_props', 'pp', $this->propertyDeletions
,
249 $this->getPropertyInsertions( $existing ) );
251 # Invalidate the necessary pages
252 $this->propertyInsertions
= array_diff_assoc( $this->mProperties
, $existing );
253 $changed = $this->propertyDeletions +
$this->propertyInsertions
;
254 $this->invalidateProperties( $changed );
256 # Refresh links of all pages including this page
257 # This will be in a separate transaction
258 if ( $this->mRecursive
) {
259 $this->queueRecursiveJobs();
262 # Update the links table freshness for this title
263 $this->updateLinksTimestamp();
267 * Queue recursive jobs for this page
269 * Which means do LinksUpdate on all pages that include the current page,
270 * using the job queue.
272 protected function queueRecursiveJobs() {
273 self
::queueRecursiveJobsForTable( $this->mTitle
, 'templatelinks' );
274 if ( $this->mTitle
->getNamespace() == NS_FILE
) {
275 // Process imagelinks in case the title is or was a redirect
276 self
::queueRecursiveJobsForTable( $this->mTitle
, 'imagelinks' );
279 $bc = $this->mTitle
->getBacklinkCache();
280 // Get jobs for cascade-protected backlinks for a high priority queue.
281 // If meta-templates change to using a new template, the new template
282 // should be implicitly protected as soon as possible, if applicable.
283 // These jobs duplicate a subset of the above ones, but can run sooner.
284 // Which ever runs first generally no-ops the other one.
286 foreach ( $bc->getCascadeProtectedLinks() as $title ) {
287 $jobs[] = RefreshLinksJob
::newPrioritized( $title, [] );
289 JobQueueGroup
::singleton()->push( $jobs );
293 * Queue a RefreshLinks job for any table.
295 * @param Title $title Title to do job for
296 * @param string $table Table to use (e.g. 'templatelinks')
298 public static function queueRecursiveJobsForTable( Title
$title, $table ) {
299 if ( $title->getBacklinkCache()->hasLinks( $table ) ) {
300 $job = new RefreshLinksJob(
305 ] + Job
::newRootJobParams( // "overall" refresh links job info
306 "refreshlinks:{$table}:{$title->getPrefixedText()}"
310 JobQueueGroup
::singleton()->push( $job );
317 function invalidateCategories( $cats ) {
318 PurgeJobUtils
::invalidatePages( $this->mDb
, NS_CATEGORY
, array_keys( $cats ) );
322 * Update all the appropriate counts in the category table.
323 * @param array $added Associative array of category name => sort key
324 * @param array $deleted Associative array of category name => sort key
326 function updateCategoryCounts( $added, $deleted ) {
327 $a = WikiPage
::factory( $this->mTitle
);
328 $a->updateCategoryCounts(
329 array_keys( $added ), array_keys( $deleted )
334 * @param array $images
336 function invalidateImageDescriptions( $images ) {
337 PurgeJobUtils
::invalidatePages( $this->mDb
, NS_FILE
, array_keys( $images ) );
341 * Update a table by doing a delete query then an insert query
342 * @param string $table Table name
343 * @param string $prefix Field name prefix
344 * @param array $deletions
345 * @param array $insertions Rows to insert
347 private function incrTableUpdate( $table, $prefix, $deletions, $insertions ) {
348 $bSize = RequestContext
::getMain()->getConfig()->get( 'UpdateRowsPerQuery' );
349 $factory = wfGetLBFactory();
351 if ( $table === 'page_props' ) {
352 $fromField = 'pp_page';
354 $fromField = "{$prefix}_from";
357 $deleteWheres = []; // list of WHERE clause arrays for each DB delete() call
358 if ( $table === 'pagelinks' ||
$table === 'templatelinks' ||
$table === 'iwlinks' ) {
359 $baseKey = ( $table === 'iwlinks' ) ?
'iwl_prefix' : "{$prefix}_namespace";
362 $curDeletionBatch = [];
363 $deletionBatches = [];
364 foreach ( $deletions as $ns => $dbKeys ) {
365 foreach ( $dbKeys as $dbKey => $unused ) {
366 $curDeletionBatch[$ns][$dbKey] = 1;
367 if ( ++
$curBatchSize >= $bSize ) {
368 $deletionBatches[] = $curDeletionBatch;
369 $curDeletionBatch = [];
374 if ( $curDeletionBatch ) {
375 $deletionBatches[] = $curDeletionBatch;
378 foreach ( $deletionBatches as $deletionBatch ) {
380 $fromField => $this->mId
,
381 $this->mDb
->makeWhereFrom2d( $deletionBatch, $baseKey, "{$prefix}_title" )
385 if ( $table === 'langlinks' ) {
386 $toField = 'll_lang';
387 } elseif ( $table === 'page_props' ) {
388 $toField = 'pp_propname';
390 $toField = $prefix . '_to';
393 $deletionBatches = array_chunk( array_keys( $deletions ), $bSize );
394 foreach ( $deletionBatches as $deletionBatch ) {
395 $deleteWheres[] = [ $fromField => $this->mId
, $toField => $deletionBatch ];
399 foreach ( $deleteWheres as $deleteWhere ) {
400 $this->mDb
->delete( $table, $deleteWhere, __METHOD__
);
401 $factory->commitAndWaitForReplication(
402 __METHOD__
, $this->ticket
, [ 'wiki' => $this->mDb
->getWikiID() ]
406 $insertBatches = array_chunk( $insertions, $bSize );
407 foreach ( $insertBatches as $insertBatch ) {
408 $this->mDb
->insert( $table, $insertBatch, __METHOD__
, 'IGNORE' );
409 $factory->commitAndWaitForReplication(
410 __METHOD__
, $this->ticket
, [ 'wiki' => $this->mDb
->getWikiID() ]
414 if ( count( $insertions ) ) {
415 Hooks
::run( 'LinksUpdateAfterInsert', [ $this, $table, $insertions ] );
420 * Get an array of pagelinks insertions for passing to the DB
421 * Skips the titles specified by the 2-D array $existing
422 * @param array $existing
425 private function getLinkInsertions( $existing = [] ) {
427 foreach ( $this->mLinks
as $ns => $dbkeys ) {
428 $diffs = isset( $existing[$ns] )
429 ?
array_diff_key( $dbkeys, $existing[$ns] )
431 foreach ( $diffs as $dbk => $id ) {
433 'pl_from' => $this->mId
,
434 'pl_from_namespace' => $this->mTitle
->getNamespace(),
435 'pl_namespace' => $ns,
445 * Get an array of template insertions. Like getLinkInsertions()
446 * @param array $existing
449 private function getTemplateInsertions( $existing = [] ) {
451 foreach ( $this->mTemplates
as $ns => $dbkeys ) {
452 $diffs = isset( $existing[$ns] ) ?
array_diff_key( $dbkeys, $existing[$ns] ) : $dbkeys;
453 foreach ( $diffs as $dbk => $id ) {
455 'tl_from' => $this->mId
,
456 'tl_from_namespace' => $this->mTitle
->getNamespace(),
457 'tl_namespace' => $ns,
467 * Get an array of image insertions
468 * Skips the names specified in $existing
469 * @param array $existing
472 private function getImageInsertions( $existing = [] ) {
474 $diffs = array_diff_key( $this->mImages
, $existing );
475 foreach ( $diffs as $iname => $dummy ) {
477 'il_from' => $this->mId
,
478 'il_from_namespace' => $this->mTitle
->getNamespace(),
487 * Get an array of externallinks insertions. Skips the names specified in $existing
488 * @param array $existing
491 private function getExternalInsertions( $existing = [] ) {
493 $diffs = array_diff_key( $this->mExternals
, $existing );
494 foreach ( $diffs as $url => $dummy ) {
495 foreach ( wfMakeUrlIndexes( $url ) as $index ) {
497 'el_id' => $this->mDb
->nextSequenceValue( 'externallinks_el_id_seq' ),
498 'el_from' => $this->mId
,
500 'el_index' => $index,
509 * Get an array of category insertions
511 * @param array $existing Mapping existing category names to sort keys. If both
512 * match a link in $this, the link will be omitted from the output
516 private function getCategoryInsertions( $existing = [] ) {
517 global $wgContLang, $wgCategoryCollation;
518 $diffs = array_diff_assoc( $this->mCategories
, $existing );
520 foreach ( $diffs as $name => $prefix ) {
521 $nt = Title
::makeTitleSafe( NS_CATEGORY
, $name );
522 $wgContLang->findVariantLink( $name, $nt, true );
524 if ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
526 } elseif ( $this->mTitle
->getNamespace() == NS_FILE
) {
532 # Treat custom sortkeys as a prefix, so that if multiple
533 # things are forced to sort as '*' or something, they'll
534 # sort properly in the category rather than in page_id
536 $sortkey = Collation
::singleton()->getSortKey(
537 $this->mTitle
->getCategorySortkey( $prefix ) );
540 'cl_from' => $this->mId
,
542 'cl_sortkey' => $sortkey,
543 'cl_timestamp' => $this->mDb
->timestamp(),
544 'cl_sortkey_prefix' => $prefix,
545 'cl_collation' => $wgCategoryCollation,
554 * Get an array of interlanguage link insertions
556 * @param array $existing Mapping existing language codes to titles
560 private function getInterlangInsertions( $existing = [] ) {
561 $diffs = array_diff_assoc( $this->mInterlangs
, $existing );
563 foreach ( $diffs as $lang => $title ) {
565 'll_from' => $this->mId
,
575 * Get an array of page property insertions
576 * @param array $existing
579 function getPropertyInsertions( $existing = [] ) {
580 $diffs = array_diff_assoc( $this->mProperties
, $existing );
583 foreach ( array_keys( $diffs ) as $name ) {
584 $arr[] = $this->getPagePropRowData( $name );
591 * Returns an associative array to be used for inserting a row into
592 * the page_props table. Besides the given property name, this will
593 * include the page id from $this->mId and any property value from
594 * $this->mProperties.
596 * The array returned will include the pp_sortkey field if this
597 * is present in the database (as indicated by $wgPagePropsHaveSortkey).
598 * The sortkey value is currently determined by getPropertySortKeyValue().
600 * @note this assumes that $this->mProperties[$prop] is defined.
602 * @param string $prop The name of the property.
606 private function getPagePropRowData( $prop ) {
607 global $wgPagePropsHaveSortkey;
609 $value = $this->mProperties
[$prop];
612 'pp_page' => $this->mId
,
613 'pp_propname' => $prop,
614 'pp_value' => $value,
617 if ( $wgPagePropsHaveSortkey ) {
618 $row['pp_sortkey'] = $this->getPropertySortKeyValue( $value );
625 * Determines the sort key for the given property value.
626 * This will return $value if it is a float or int,
627 * 1 or resp. 0 if it is a bool, and null otherwise.
629 * @note In the future, we may allow the sortkey to be specified explicitly
630 * in ParserOutput::setProperty.
632 * @param mixed $value
636 private function getPropertySortKeyValue( $value ) {
637 if ( is_int( $value ) ||
is_float( $value ) ||
is_bool( $value ) ) {
638 return floatval( $value );
645 * Get an array of interwiki insertions for passing to the DB
646 * Skips the titles specified by the 2-D array $existing
647 * @param array $existing
650 private function getInterwikiInsertions( $existing = [] ) {
652 foreach ( $this->mInterwikis
as $prefix => $dbkeys ) {
653 $diffs = isset( $existing[$prefix] )
654 ?
array_diff_key( $dbkeys, $existing[$prefix] )
657 foreach ( $diffs as $dbk => $id ) {
659 'iwl_from' => $this->mId
,
660 'iwl_prefix' => $prefix,
670 * Given an array of existing links, returns those links which are not in $this
671 * and thus should be deleted.
672 * @param array $existing
675 private function getLinkDeletions( $existing ) {
677 foreach ( $existing as $ns => $dbkeys ) {
678 if ( isset( $this->mLinks
[$ns] ) ) {
679 $del[$ns] = array_diff_key( $existing[$ns], $this->mLinks
[$ns] );
681 $del[$ns] = $existing[$ns];
689 * Given an array of existing templates, returns those templates which are not in $this
690 * and thus should be deleted.
691 * @param array $existing
694 private function getTemplateDeletions( $existing ) {
696 foreach ( $existing as $ns => $dbkeys ) {
697 if ( isset( $this->mTemplates
[$ns] ) ) {
698 $del[$ns] = array_diff_key( $existing[$ns], $this->mTemplates
[$ns] );
700 $del[$ns] = $existing[$ns];
708 * Given an array of existing images, returns those images which are not in $this
709 * and thus should be deleted.
710 * @param array $existing
713 private function getImageDeletions( $existing ) {
714 return array_diff_key( $existing, $this->mImages
);
718 * Given an array of existing external links, returns those links which are not
719 * in $this and thus should be deleted.
720 * @param array $existing
723 private function getExternalDeletions( $existing ) {
724 return array_diff_key( $existing, $this->mExternals
);
728 * Given an array of existing categories, returns those categories which are not in $this
729 * and thus should be deleted.
730 * @param array $existing
733 private function getCategoryDeletions( $existing ) {
734 return array_diff_assoc( $existing, $this->mCategories
);
738 * Given an array of existing interlanguage links, returns those links which are not
739 * in $this and thus should be deleted.
740 * @param array $existing
743 private function getInterlangDeletions( $existing ) {
744 return array_diff_assoc( $existing, $this->mInterlangs
);
748 * Get array of properties which should be deleted.
749 * @param array $existing
752 function getPropertyDeletions( $existing ) {
753 return array_diff_assoc( $existing, $this->mProperties
);
757 * Given an array of existing interwiki links, returns those links which are not in $this
758 * and thus should be deleted.
759 * @param array $existing
762 private function getInterwikiDeletions( $existing ) {
764 foreach ( $existing as $prefix => $dbkeys ) {
765 if ( isset( $this->mInterwikis
[$prefix] ) ) {
766 $del[$prefix] = array_diff_key( $existing[$prefix], $this->mInterwikis
[$prefix] );
768 $del[$prefix] = $existing[$prefix];
776 * Get an array of existing links, as a 2-D array
780 private function getExistingLinks() {
781 $res = $this->mDb
->select( 'pagelinks', [ 'pl_namespace', 'pl_title' ],
782 [ 'pl_from' => $this->mId
], __METHOD__
, $this->mOptions
);
784 foreach ( $res as $row ) {
785 if ( !isset( $arr[$row->pl_namespace
] ) ) {
786 $arr[$row->pl_namespace
] = [];
788 $arr[$row->pl_namespace
][$row->pl_title
] = 1;
795 * Get an array of existing templates, as a 2-D array
799 private function getExistingTemplates() {
800 $res = $this->mDb
->select( 'templatelinks', [ 'tl_namespace', 'tl_title' ],
801 [ 'tl_from' => $this->mId
], __METHOD__
, $this->mOptions
);
803 foreach ( $res as $row ) {
804 if ( !isset( $arr[$row->tl_namespace
] ) ) {
805 $arr[$row->tl_namespace
] = [];
807 $arr[$row->tl_namespace
][$row->tl_title
] = 1;
814 * Get an array of existing images, image names in the keys
818 private function getExistingImages() {
819 $res = $this->mDb
->select( 'imagelinks', [ 'il_to' ],
820 [ 'il_from' => $this->mId
], __METHOD__
, $this->mOptions
);
822 foreach ( $res as $row ) {
823 $arr[$row->il_to
] = 1;
830 * Get an array of existing external links, URLs in the keys
834 private function getExistingExternals() {
835 $res = $this->mDb
->select( 'externallinks', [ 'el_to' ],
836 [ 'el_from' => $this->mId
], __METHOD__
, $this->mOptions
);
838 foreach ( $res as $row ) {
839 $arr[$row->el_to
] = 1;
846 * Get an array of existing categories, with the name in the key and sort key in the value.
850 private function getExistingCategories() {
851 $res = $this->mDb
->select( 'categorylinks', [ 'cl_to', 'cl_sortkey_prefix' ],
852 [ 'cl_from' => $this->mId
], __METHOD__
, $this->mOptions
);
854 foreach ( $res as $row ) {
855 $arr[$row->cl_to
] = $row->cl_sortkey_prefix
;
862 * Get an array of existing interlanguage links, with the language code in the key and the
863 * title in the value.
867 private function getExistingInterlangs() {
868 $res = $this->mDb
->select( 'langlinks', [ 'll_lang', 'll_title' ],
869 [ 'll_from' => $this->mId
], __METHOD__
, $this->mOptions
);
871 foreach ( $res as $row ) {
872 $arr[$row->ll_lang
] = $row->ll_title
;
879 * Get an array of existing inline interwiki links, as a 2-D array
880 * @return array (prefix => array(dbkey => 1))
882 protected function getExistingInterwikis() {
883 $res = $this->mDb
->select( 'iwlinks', [ 'iwl_prefix', 'iwl_title' ],
884 [ 'iwl_from' => $this->mId
], __METHOD__
, $this->mOptions
);
886 foreach ( $res as $row ) {
887 if ( !isset( $arr[$row->iwl_prefix
] ) ) {
888 $arr[$row->iwl_prefix
] = [];
890 $arr[$row->iwl_prefix
][$row->iwl_title
] = 1;
897 * Get an array of existing categories, with the name in the key and sort key in the value.
899 * @return array Array of property names and values
901 private function getExistingProperties() {
902 $res = $this->mDb
->select( 'page_props', [ 'pp_propname', 'pp_value' ],
903 [ 'pp_page' => $this->mId
], __METHOD__
, $this->mOptions
);
905 foreach ( $res as $row ) {
906 $arr[$row->pp_propname
] = $row->pp_value
;
913 * Return the title object of the page being updated
916 public function getTitle() {
917 return $this->mTitle
;
921 * Returns parser output
923 * @return ParserOutput
925 public function getParserOutput() {
926 return $this->mParserOutput
;
930 * Return the list of images used as generated by the parser
933 public function getImages() {
934 return $this->mImages
;
938 * Set the revision corresponding to this LinksUpdate
942 * @param Revision $revision
944 public function setRevision( Revision
$revision ) {
945 $this->mRevision
= $revision;
950 * @return null|Revision
952 public function getRevision() {
953 return $this->mRevision
;
957 * Set the User who triggered this LinksUpdate
962 public function setTriggeringUser( User
$user ) {
970 public function getTriggeringUser() {
975 * Invalidate any necessary link lists related to page property changes
976 * @param array $changed
978 private function invalidateProperties( $changed ) {
979 global $wgPagePropLinkInvalidations;
981 foreach ( $changed as $name => $value ) {
982 if ( isset( $wgPagePropLinkInvalidations[$name] ) ) {
983 $inv = $wgPagePropLinkInvalidations[$name];
984 if ( !is_array( $inv ) ) {
987 foreach ( $inv as $table ) {
988 DeferredUpdates
::addUpdate( new HTMLCacheUpdate( $this->mTitle
, $table ) );
995 * Fetch page links added by this LinksUpdate. Only available after the update is complete.
997 * @return null|array Array of Titles
999 public function getAddedLinks() {
1000 if ( $this->linkInsertions
=== null ) {
1004 foreach ( $this->linkInsertions
as $insertion ) {
1005 $result[] = Title
::makeTitle( $insertion['pl_namespace'], $insertion['pl_title'] );
1012 * Fetch page links removed by this LinksUpdate. Only available after the update is complete.
1014 * @return null|array Array of Titles
1016 public function getRemovedLinks() {
1017 if ( $this->linkDeletions
=== null ) {
1021 foreach ( $this->linkDeletions
as $ns => $titles ) {
1022 foreach ( $titles as $title => $unused ) {
1023 $result[] = Title
::makeTitle( $ns, $title );
1031 * Fetch page properties added by this LinksUpdate.
1032 * Only available after the update is complete.
1034 * @return null|array
1036 public function getAddedProperties() {
1037 return $this->propertyInsertions
;
1041 * Fetch page properties removed by this LinksUpdate.
1042 * Only available after the update is complete.
1044 * @return null|array
1046 public function getRemovedProperties() {
1047 return $this->propertyDeletions
;
1051 * Update links table freshness
1053 protected function updateLinksTimestamp() {
1055 // The link updates made here only reflect the freshness of the parser output
1056 $timestamp = $this->mParserOutput
->getCacheTime();
1057 $this->mDb
->update( 'page',
1058 [ 'page_links_updated' => $this->mDb
->timestamp( $timestamp ) ],
1059 [ 'page_id' => $this->mId
],
1065 public function getAsJobSpecification() {
1066 if ( $this->user
) {
1068 'userId' => $this->user
->getId(),
1069 'userName' => $this->user
->getName(),
1075 if ( $this->mRevision
) {
1076 $triggeringRevisionId = $this->mRevision
->getId();
1078 $triggeringRevisionId = false;
1082 'wiki' => $this->mDb
->getWikiID(),
1083 'job' => new JobSpecification(
1084 'refreshLinksPrioritized',
1086 // Reuse the parser cache if it was saved
1087 'rootJobTimestamp' => $this->mParserOutput
->getCacheTime(),
1088 'useRecursiveLinksUpdate' => $this->mRecursive
,
1089 'triggeringUser' => $userInfo,
1090 'triggeringRevisionId' => $triggeringRevisionId,
1092 [ 'removeDuplicates' => true ],