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 PurgeJobUtils
::invalidatePages( $this->mDb
, 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 PurgeJobUtils
::invalidatePages( $this->mDb
, 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' );
338 $factory = wfGetLBFactory();
340 if ( $table === 'page_props' ) {
341 $fromField = 'pp_page';
343 $fromField = "{$prefix}_from";
346 $deleteWheres = []; // list of WHERE clause arrays for each DB delete() call
347 if ( $table === 'pagelinks' ||
$table === 'templatelinks' ||
$table === 'iwlinks' ) {
348 $baseKey = ( $table === 'iwlinks' ) ?
'iwl_prefix' : "{$prefix}_namespace";
351 $curDeletionBatch = [];
352 $deletionBatches = [];
353 foreach ( $deletions as $ns => $dbKeys ) {
354 foreach ( $dbKeys as $dbKey => $unused ) {
355 $curDeletionBatch[$ns][$dbKey] = 1;
356 if ( ++
$curBatchSize >= $bSize ) {
357 $deletionBatches[] = $curDeletionBatch;
358 $curDeletionBatch = [];
363 if ( $curDeletionBatch ) {
364 $deletionBatches[] = $curDeletionBatch;
367 foreach ( $deletionBatches as $deletionBatch ) {
369 $fromField => $this->mId
,
370 $this->mDb
->makeWhereFrom2d( $deletionBatch, $baseKey, "{$prefix}_title" )
374 if ( $table === 'langlinks' ) {
375 $toField = 'll_lang';
376 } elseif ( $table === 'page_props' ) {
377 $toField = 'pp_propname';
379 $toField = $prefix . '_to';
382 $deletionBatches = array_chunk( array_keys( $deletions ), $bSize );
383 foreach ( $deletionBatches as $deletionBatch ) {
384 $deleteWheres[] = [ $fromField => $this->mId
, $toField => $deletionBatch ];
388 foreach ( $deleteWheres as $deleteWhere ) {
389 $this->mDb
->delete( $table, $deleteWhere, __METHOD__
);
390 $factory->commitAndWaitForReplication(
391 __METHOD__
, $this->ticket
, [ 'wiki' => $this->mDb
->getWikiID() ]
395 $insertBatches = array_chunk( $insertions, $bSize );
396 foreach ( $insertBatches as $insertBatch ) {
397 $this->mDb
->insert( $table, $insertBatch, __METHOD__
, 'IGNORE' );
398 $factory->commitAndWaitForReplication(
399 __METHOD__
, $this->ticket
, [ 'wiki' => $this->mDb
->getWikiID() ]
403 if ( count( $insertions ) ) {
404 Hooks
::run( 'LinksUpdateAfterInsert', [ $this, $table, $insertions ] );
409 * Get an array of pagelinks insertions for passing to the DB
410 * Skips the titles specified by the 2-D array $existing
411 * @param array $existing
414 private function getLinkInsertions( $existing = [] ) {
416 foreach ( $this->mLinks
as $ns => $dbkeys ) {
417 $diffs = isset( $existing[$ns] )
418 ?
array_diff_key( $dbkeys, $existing[$ns] )
420 foreach ( $diffs as $dbk => $id ) {
422 'pl_from' => $this->mId
,
423 'pl_from_namespace' => $this->mTitle
->getNamespace(),
424 'pl_namespace' => $ns,
434 * Get an array of template insertions. Like getLinkInsertions()
435 * @param array $existing
438 private function getTemplateInsertions( $existing = [] ) {
440 foreach ( $this->mTemplates
as $ns => $dbkeys ) {
441 $diffs = isset( $existing[$ns] ) ?
array_diff_key( $dbkeys, $existing[$ns] ) : $dbkeys;
442 foreach ( $diffs as $dbk => $id ) {
444 'tl_from' => $this->mId
,
445 'tl_from_namespace' => $this->mTitle
->getNamespace(),
446 'tl_namespace' => $ns,
456 * Get an array of image insertions
457 * Skips the names specified in $existing
458 * @param array $existing
461 private function getImageInsertions( $existing = [] ) {
463 $diffs = array_diff_key( $this->mImages
, $existing );
464 foreach ( $diffs as $iname => $dummy ) {
466 'il_from' => $this->mId
,
467 'il_from_namespace' => $this->mTitle
->getNamespace(),
476 * Get an array of externallinks insertions. Skips the names specified in $existing
477 * @param array $existing
480 private function getExternalInsertions( $existing = [] ) {
482 $diffs = array_diff_key( $this->mExternals
, $existing );
483 foreach ( $diffs as $url => $dummy ) {
484 foreach ( wfMakeUrlIndexes( $url ) as $index ) {
486 'el_id' => $this->mDb
->nextSequenceValue( 'externallinks_el_id_seq' ),
487 'el_from' => $this->mId
,
489 'el_index' => $index,
498 * Get an array of category insertions
500 * @param array $existing Mapping existing category names to sort keys. If both
501 * match a link in $this, the link will be omitted from the output
505 private function getCategoryInsertions( $existing = [] ) {
506 global $wgContLang, $wgCategoryCollation;
507 $diffs = array_diff_assoc( $this->mCategories
, $existing );
509 foreach ( $diffs as $name => $prefix ) {
510 $nt = Title
::makeTitleSafe( NS_CATEGORY
, $name );
511 $wgContLang->findVariantLink( $name, $nt, true );
513 if ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
515 } elseif ( $this->mTitle
->getNamespace() == NS_FILE
) {
521 # Treat custom sortkeys as a prefix, so that if multiple
522 # things are forced to sort as '*' or something, they'll
523 # sort properly in the category rather than in page_id
525 $sortkey = Collation
::singleton()->getSortKey(
526 $this->mTitle
->getCategorySortkey( $prefix ) );
529 'cl_from' => $this->mId
,
531 'cl_sortkey' => $sortkey,
532 'cl_timestamp' => $this->mDb
->timestamp(),
533 'cl_sortkey_prefix' => $prefix,
534 'cl_collation' => $wgCategoryCollation,
543 * Get an array of interlanguage link insertions
545 * @param array $existing Mapping existing language codes to titles
549 private function getInterlangInsertions( $existing = [] ) {
550 $diffs = array_diff_assoc( $this->mInterlangs
, $existing );
552 foreach ( $diffs as $lang => $title ) {
554 'll_from' => $this->mId
,
564 * Get an array of page property insertions
565 * @param array $existing
568 function getPropertyInsertions( $existing = [] ) {
569 $diffs = array_diff_assoc( $this->mProperties
, $existing );
572 foreach ( array_keys( $diffs ) as $name ) {
573 $arr[] = $this->getPagePropRowData( $name );
580 * Returns an associative array to be used for inserting a row into
581 * the page_props table. Besides the given property name, this will
582 * include the page id from $this->mId and any property value from
583 * $this->mProperties.
585 * The array returned will include the pp_sortkey field if this
586 * is present in the database (as indicated by $wgPagePropsHaveSortkey).
587 * The sortkey value is currently determined by getPropertySortKeyValue().
589 * @note this assumes that $this->mProperties[$prop] is defined.
591 * @param string $prop The name of the property.
595 private function getPagePropRowData( $prop ) {
596 global $wgPagePropsHaveSortkey;
598 $value = $this->mProperties
[$prop];
601 'pp_page' => $this->mId
,
602 'pp_propname' => $prop,
603 'pp_value' => $value,
606 if ( $wgPagePropsHaveSortkey ) {
607 $row['pp_sortkey'] = $this->getPropertySortKeyValue( $value );
614 * Determines the sort key for the given property value.
615 * This will return $value if it is a float or int,
616 * 1 or resp. 0 if it is a bool, and null otherwise.
618 * @note In the future, we may allow the sortkey to be specified explicitly
619 * in ParserOutput::setProperty.
621 * @param mixed $value
625 private function getPropertySortKeyValue( $value ) {
626 if ( is_int( $value ) ||
is_float( $value ) ||
is_bool( $value ) ) {
627 return floatval( $value );
634 * Get an array of interwiki insertions for passing to the DB
635 * Skips the titles specified by the 2-D array $existing
636 * @param array $existing
639 private function getInterwikiInsertions( $existing = [] ) {
641 foreach ( $this->mInterwikis
as $prefix => $dbkeys ) {
642 $diffs = isset( $existing[$prefix] )
643 ?
array_diff_key( $dbkeys, $existing[$prefix] )
646 foreach ( $diffs as $dbk => $id ) {
648 'iwl_from' => $this->mId
,
649 'iwl_prefix' => $prefix,
659 * Given an array of existing links, returns those links which are not in $this
660 * and thus should be deleted.
661 * @param array $existing
664 private function getLinkDeletions( $existing ) {
666 foreach ( $existing as $ns => $dbkeys ) {
667 if ( isset( $this->mLinks
[$ns] ) ) {
668 $del[$ns] = array_diff_key( $existing[$ns], $this->mLinks
[$ns] );
670 $del[$ns] = $existing[$ns];
678 * Given an array of existing templates, returns those templates which are not in $this
679 * and thus should be deleted.
680 * @param array $existing
683 private function getTemplateDeletions( $existing ) {
685 foreach ( $existing as $ns => $dbkeys ) {
686 if ( isset( $this->mTemplates
[$ns] ) ) {
687 $del[$ns] = array_diff_key( $existing[$ns], $this->mTemplates
[$ns] );
689 $del[$ns] = $existing[$ns];
697 * Given an array of existing images, returns those images which are not in $this
698 * and thus should be deleted.
699 * @param array $existing
702 private function getImageDeletions( $existing ) {
703 return array_diff_key( $existing, $this->mImages
);
707 * Given an array of existing external links, returns those links which are not
708 * in $this and thus should be deleted.
709 * @param array $existing
712 private function getExternalDeletions( $existing ) {
713 return array_diff_key( $existing, $this->mExternals
);
717 * Given an array of existing categories, returns those categories which are not in $this
718 * and thus should be deleted.
719 * @param array $existing
722 private function getCategoryDeletions( $existing ) {
723 return array_diff_assoc( $existing, $this->mCategories
);
727 * Given an array of existing interlanguage links, returns those links which are not
728 * in $this and thus should be deleted.
729 * @param array $existing
732 private function getInterlangDeletions( $existing ) {
733 return array_diff_assoc( $existing, $this->mInterlangs
);
737 * Get array of properties which should be deleted.
738 * @param array $existing
741 function getPropertyDeletions( $existing ) {
742 return array_diff_assoc( $existing, $this->mProperties
);
746 * Given an array of existing interwiki links, returns those links which are not in $this
747 * and thus should be deleted.
748 * @param array $existing
751 private function getInterwikiDeletions( $existing ) {
753 foreach ( $existing as $prefix => $dbkeys ) {
754 if ( isset( $this->mInterwikis
[$prefix] ) ) {
755 $del[$prefix] = array_diff_key( $existing[$prefix], $this->mInterwikis
[$prefix] );
757 $del[$prefix] = $existing[$prefix];
765 * Get an array of existing links, as a 2-D array
769 private function getExistingLinks() {
770 $res = $this->mDb
->select( 'pagelinks', [ 'pl_namespace', 'pl_title' ],
771 [ 'pl_from' => $this->mId
], __METHOD__
, $this->mOptions
);
773 foreach ( $res as $row ) {
774 if ( !isset( $arr[$row->pl_namespace
] ) ) {
775 $arr[$row->pl_namespace
] = [];
777 $arr[$row->pl_namespace
][$row->pl_title
] = 1;
784 * Get an array of existing templates, as a 2-D array
788 private function getExistingTemplates() {
789 $res = $this->mDb
->select( 'templatelinks', [ 'tl_namespace', 'tl_title' ],
790 [ 'tl_from' => $this->mId
], __METHOD__
, $this->mOptions
);
792 foreach ( $res as $row ) {
793 if ( !isset( $arr[$row->tl_namespace
] ) ) {
794 $arr[$row->tl_namespace
] = [];
796 $arr[$row->tl_namespace
][$row->tl_title
] = 1;
803 * Get an array of existing images, image names in the keys
807 private function getExistingImages() {
808 $res = $this->mDb
->select( 'imagelinks', [ 'il_to' ],
809 [ 'il_from' => $this->mId
], __METHOD__
, $this->mOptions
);
811 foreach ( $res as $row ) {
812 $arr[$row->il_to
] = 1;
819 * Get an array of existing external links, URLs in the keys
823 private function getExistingExternals() {
824 $res = $this->mDb
->select( 'externallinks', [ 'el_to' ],
825 [ 'el_from' => $this->mId
], __METHOD__
, $this->mOptions
);
827 foreach ( $res as $row ) {
828 $arr[$row->el_to
] = 1;
835 * Get an array of existing categories, with the name in the key and sort key in the value.
839 private function getExistingCategories() {
840 $res = $this->mDb
->select( 'categorylinks', [ 'cl_to', 'cl_sortkey_prefix' ],
841 [ 'cl_from' => $this->mId
], __METHOD__
, $this->mOptions
);
843 foreach ( $res as $row ) {
844 $arr[$row->cl_to
] = $row->cl_sortkey_prefix
;
851 * Get an array of existing interlanguage links, with the language code in the key and the
852 * title in the value.
856 private function getExistingInterlangs() {
857 $res = $this->mDb
->select( 'langlinks', [ 'll_lang', 'll_title' ],
858 [ 'll_from' => $this->mId
], __METHOD__
, $this->mOptions
);
860 foreach ( $res as $row ) {
861 $arr[$row->ll_lang
] = $row->ll_title
;
868 * Get an array of existing inline interwiki links, as a 2-D array
869 * @return array (prefix => array(dbkey => 1))
871 protected function getExistingInterwikis() {
872 $res = $this->mDb
->select( 'iwlinks', [ 'iwl_prefix', 'iwl_title' ],
873 [ 'iwl_from' => $this->mId
], __METHOD__
, $this->mOptions
);
875 foreach ( $res as $row ) {
876 if ( !isset( $arr[$row->iwl_prefix
] ) ) {
877 $arr[$row->iwl_prefix
] = [];
879 $arr[$row->iwl_prefix
][$row->iwl_title
] = 1;
886 * Get an array of existing categories, with the name in the key and sort key in the value.
888 * @return array Array of property names and values
890 private function getExistingProperties() {
891 $res = $this->mDb
->select( 'page_props', [ 'pp_propname', 'pp_value' ],
892 [ 'pp_page' => $this->mId
], __METHOD__
, $this->mOptions
);
894 foreach ( $res as $row ) {
895 $arr[$row->pp_propname
] = $row->pp_value
;
902 * Return the title object of the page being updated
905 public function getTitle() {
906 return $this->mTitle
;
910 * Returns parser output
912 * @return ParserOutput
914 public function getParserOutput() {
915 return $this->mParserOutput
;
919 * Return the list of images used as generated by the parser
922 public function getImages() {
923 return $this->mImages
;
927 * Set the revision corresponding to this LinksUpdate
931 * @param Revision $revision
933 public function setRevision( Revision
$revision ) {
934 $this->mRevision
= $revision;
939 * @return null|Revision
941 public function getRevision() {
942 return $this->mRevision
;
946 * Set the User who triggered this LinksUpdate
951 public function setTriggeringUser( User
$user ) {
959 public function getTriggeringUser() {
964 * Invalidate any necessary link lists related to page property changes
965 * @param array $changed
967 private function invalidateProperties( $changed ) {
968 global $wgPagePropLinkInvalidations;
970 foreach ( $changed as $name => $value ) {
971 if ( isset( $wgPagePropLinkInvalidations[$name] ) ) {
972 $inv = $wgPagePropLinkInvalidations[$name];
973 if ( !is_array( $inv ) ) {
976 foreach ( $inv as $table ) {
977 DeferredUpdates
::addUpdate( new HTMLCacheUpdate( $this->mTitle
, $table ) );
984 * Fetch page links added by this LinksUpdate. Only available after the update is complete.
986 * @return null|array Array of Titles
988 public function getAddedLinks() {
989 if ( $this->linkInsertions
=== null ) {
993 foreach ( $this->linkInsertions
as $insertion ) {
994 $result[] = Title
::makeTitle( $insertion['pl_namespace'], $insertion['pl_title'] );
1001 * Fetch page links removed by this LinksUpdate. Only available after the update is complete.
1003 * @return null|array Array of Titles
1005 public function getRemovedLinks() {
1006 if ( $this->linkDeletions
=== null ) {
1010 foreach ( $this->linkDeletions
as $ns => $titles ) {
1011 foreach ( $titles as $title => $unused ) {
1012 $result[] = Title
::makeTitle( $ns, $title );
1020 * Update links table freshness
1022 protected function updateLinksTimestamp() {
1024 // The link updates made here only reflect the freshness of the parser output
1025 $timestamp = $this->mParserOutput
->getCacheTime();
1026 $this->mDb
->update( 'page',
1027 [ 'page_links_updated' => $this->mDb
->timestamp( $timestamp ) ],
1028 [ 'page_id' => $this->mId
],
1034 public function getAsJobSpecification() {
1035 if ( $this->user
) {
1037 'userId' => $this->user
->getId(),
1038 'userName' => $this->user
->getName(),
1044 if ( $this->mRevision
) {
1045 $triggeringRevisionId = $this->mRevision
->getId();
1047 $triggeringRevisionId = false;
1051 'wiki' => $this->mDb
->getWikiID(),
1052 'job' => new JobSpecification(
1053 'refreshLinksPrioritized',
1055 // Reuse the parser cache if it was saved
1056 'rootJobTimestamp' => $this->mParserOutput
->getCacheTime(),
1057 'useRecursiveLinksUpdate' => $this->mRecursive
,
1058 'triggeringUser' => $userInfo,
1059 'triggeringRevisionId' => $triggeringRevisionId,
1061 [ 'removeDuplicates' => true ],