25use Wikimedia\ScopedCallback;
111 parent::__construct();
114 $this->mId = $title->getArticleID( Title::GAID_FOR_UPDATE );
117 throw new InvalidArgumentException(
118 "The Title object yields no ID. Perhaps the page doesn't exist?"
122 $this->mParserOutput = $parserOutput;
124 $this->mLinks = $parserOutput->
getLinks();
125 $this->mImages = $parserOutput->
getImages();
132 # Convert the format of the interlanguage links
133 # I didn't want to change it in the ParserOutput, because that array is passed all
134 # the way back to the skin, so either a skin API break would be required, or an
135 # inefficient back-conversion.
137 $this->mInterlangs = [];
138 foreach ( $ill as
$link ) {
139 list( $key, $title ) = explode(
':',
$link, 2 );
140 $this->mInterlangs[$key] =
$title;
143 foreach ( $this->mCategories as &$sortkey ) {
144 # If the sortkey is longer then 255 bytes,
145 # it truncated by DB, and then doesn't get
146 # matched when comparing existing vs current
147 # categories, causing T27254.
148 # Also. substr behaves weird when given "".
149 if ( $sortkey !==
'' ) {
150 $sortkey = substr( $sortkey, 0, 255 );
154 $this->mRecursive = $recursive;
158 Hooks::run(
'LinksUpdateConstructed', [ &
$linksUpdate ] );
167 if ( $this->ticket ) {
179 ScopedCallback::consume( $scopedLock );
181 $this->
getDB()->onTransactionIdle(
185 Hooks::run(
'LinksUpdateComplete', [ &
$linksUpdate, $this->ticket ] );
202 $key =
"LinksUpdate:$why:pageid:$pageId";
204 if ( !$scopedLock ) {
205 throw new RuntimeException(
"Could not acquire lock '$key'." );
216 $this->
incrTableUpdate(
'pagelinks',
'pl', $this->linkDeletions, $this->linkInsertions );
227 # Invalidate all image description pages which had links added or removed
228 $imageUpdates = $imageDeletes + array_diff_key( $this->mImages, $existingIL );
247 # Inline interwiki links
271 $categoryInserts = array_diff_assoc( $this->mCategories, $existingCL );
272 $categoryUpdates = $categoryInserts + $categoryDeletes;
280 $this->propertyDeletions,
283 # Invalidate the necessary pages
284 $this->propertyInsertions = array_diff_assoc( $this->mProperties, $existingPP );
288 # Invalidate all categories which were added, deleted or changed (set symmetric difference)
292 # Refresh links of all pages including this page
293 # This will be in a separate transaction
294 if ( $this->mRecursive ) {
298 # Update the links table freshness for this title
313 if ( $this->mTitle->getNamespace() ==
NS_FILE ) {
318 $bc = $this->mTitle->getBacklinkCache();
325 foreach ( $bc->getCascadeProtectedLinks() as $title ) {
329 'causeAction' => $action,
330 'causeAgent' => $agent
346 Title $title, $table, $action =
'unknown', $userName =
'unknown'
348 if ( $title->getBacklinkCache()->hasLinks( $table ) ) {
355 "refreshlinks:{$table}:{$title->getPrefixedText()}"
356 ) + [
'causeAction' => $action,
'causeAgent' => $userName ]
378 if ( !$added && !$deleted ) {
382 $domainId = $this->
getDB()->getDomainID();
383 $wp = WikiPage::factory( $this->mTitle );
384 $lbf = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
386 $lbf->commitAndWaitForReplication( __METHOD__, $this->ticket, [
'domain' => $domainId ] );
389 $wp->updateCategoryCounts( $addBatch, [], $this->mId );
390 $lbf->commitAndWaitForReplication(
391 __METHOD__, $this->ticket, [
'domain' => $domainId ] );
395 $wp->updateCategoryCounts( [], $deleteBatch, $this->mId );
396 $lbf->commitAndWaitForReplication(
397 __METHOD__, $this->ticket, [
'domain' => $domainId ] );
416 $services = MediaWikiServices::getInstance();
417 $bSize =
$services->getMainConfig()->get(
'UpdateRowsPerQuery' );
418 $lbf =
$services->getDBLoadBalancerFactory();
420 if ( $table ===
'page_props' ) {
421 $fromField =
'pp_page';
423 $fromField =
"{$prefix}_from";
427 if ( $table ===
'pagelinks' || $table ===
'templatelinks' || $table ===
'iwlinks' ) {
428 $baseKey = ( $table ===
'iwlinks' ) ?
'iwl_prefix' :
"{$prefix}_namespace";
431 $curDeletionBatch = [];
432 $deletionBatches = [];
433 foreach ( $deletions as $ns => $dbKeys ) {
434 foreach ( $dbKeys as $dbKey => $unused ) {
435 $curDeletionBatch[$ns][$dbKey] = 1;
436 if ( ++$curBatchSize >= $bSize ) {
437 $deletionBatches[] = $curDeletionBatch;
438 $curDeletionBatch = [];
443 if ( $curDeletionBatch ) {
444 $deletionBatches[] = $curDeletionBatch;
447 foreach ( $deletionBatches as $deletionBatch ) {
450 $this->
getDB()->makeWhereFrom2d( $deletionBatch, $baseKey,
"{$prefix}_title" )
454 if ( $table ===
'langlinks' ) {
455 $toField =
'll_lang';
456 } elseif ( $table ===
'page_props' ) {
457 $toField =
'pp_propname';
459 $toField = $prefix .
'_to';
462 $deletionBatches = array_chunk( array_keys( $deletions ), $bSize );
463 foreach ( $deletionBatches as $deletionBatch ) {
464 $deleteWheres[] = [ $fromField =>
$this->mId, $toField => $deletionBatch ];
468 $domainId = $this->
getDB()->getDomainID();
470 foreach ( $deleteWheres as $deleteWhere ) {
471 $this->
getDB()->delete( $table, $deleteWhere, __METHOD__ );
472 $lbf->commitAndWaitForReplication(
473 __METHOD__, $this->ticket, [
'domain' => $domainId ]
477 $insertBatches = array_chunk( $insertions, $bSize );
478 foreach ( $insertBatches as $insertBatch ) {
479 $this->
getDB()->insert( $table, $insertBatch, __METHOD__,
'IGNORE' );
480 $lbf->commitAndWaitForReplication(
481 __METHOD__, $this->ticket, [
'domain' => $domainId ]
485 if ( count( $insertions ) ) {
486 Hooks::run(
'LinksUpdateAfterInsert', [ $this, $table, $insertions ] );
498 foreach ( $this->mLinks as $ns => $dbkeys ) {
499 $diffs = isset( $existing[$ns] )
500 ? array_diff_key( $dbkeys, $existing[$ns] )
502 foreach ( $diffs as $dbk => $id ) {
505 'pl_from_namespace' => $this->mTitle->getNamespace(),
506 'pl_namespace' => $ns,
522 foreach ( $this->mTemplates as $ns => $dbkeys ) {
523 $diffs = isset( $existing[$ns] ) ? array_diff_key( $dbkeys, $existing[$ns] ) : $dbkeys;
524 foreach ( $diffs as $dbk => $id ) {
527 'tl_from_namespace' => $this->mTitle->getNamespace(),
528 'tl_namespace' => $ns,
545 $diffs = array_diff_key( $this->mImages, $existing );
546 foreach ( $diffs as $iname => $dummy ) {
549 'il_from_namespace' => $this->mTitle->getNamespace(),
564 $diffs = array_diff_key( $this->mExternals, $existing );
565 foreach ( $diffs as $url => $dummy ) {
570 'el_index' => $index,
588 $diffs = array_diff_assoc( $this->mCategories, $existing );
590 foreach ( $diffs as $name => $prefix ) {
594 if ( $this->mTitle->getNamespace() ==
NS_CATEGORY ) {
596 } elseif ( $this->mTitle->getNamespace() ==
NS_FILE ) {
602 # Treat custom sortkeys as a prefix, so that if multiple
603 # things are forced to sort as '*' or something, they'll
604 # sort properly in the category rather than in page_id
607 $this->mTitle->getCategorySortkey( $prefix ) );
612 'cl_sortkey' => $sortkey,
613 'cl_timestamp' => $this->
getDB()->timestamp(),
614 'cl_sortkey_prefix' => $prefix,
631 $diffs = array_diff_assoc( $this->mInterlangs, $existing );
633 foreach ( $diffs as
$lang => $title ) {
650 $diffs = array_diff_assoc( $this->mProperties, $existing );
653 foreach ( array_keys( $diffs ) as $name ) {
679 $value = $this->mProperties[$prop];
683 'pp_propname' => $prop,
708 return floatval(
$value );
722 foreach ( $this->mInterwikis as $prefix => $dbkeys ) {
723 $diffs = isset( $existing[$prefix] )
724 ? array_diff_key( $dbkeys, $existing[$prefix] )
727 foreach ( $diffs as $dbk => $id ) {
730 'iwl_prefix' => $prefix,
747 foreach ( $existing as $ns => $dbkeys ) {
748 if ( isset( $this->mLinks[$ns] ) ) {
749 $del[$ns] = array_diff_key( $existing[$ns], $this->mLinks[$ns] );
751 $del[$ns] = $existing[$ns];
766 foreach ( $existing as $ns => $dbkeys ) {
767 if ( isset( $this->mTemplates[$ns] ) ) {
768 $del[$ns] = array_diff_key( $existing[$ns], $this->mTemplates[$ns] );
770 $del[$ns] = $existing[$ns];
784 return array_diff_key( $existing, $this->mImages );
794 return array_diff_key( $existing, $this->mExternals );
804 return array_diff_assoc( $existing, $this->mCategories );
814 return array_diff_assoc( $existing, $this->mInterlangs );
823 return array_diff_assoc( $existing, $this->mProperties );
834 foreach ( $existing as $prefix => $dbkeys ) {
835 if ( isset( $this->mInterwikis[$prefix] ) ) {
836 $del[$prefix] = array_diff_key( $existing[$prefix], $this->mInterwikis[$prefix] );
838 $del[$prefix] = $existing[$prefix];
851 $res = $this->
getDB()->select(
'pagelinks', [
'pl_namespace',
'pl_title' ],
852 [
'pl_from' => $this->mId ], __METHOD__ );
854 foreach (
$res as $row ) {
855 if ( !isset( $arr[$row->pl_namespace] ) ) {
856 $arr[$row->pl_namespace] = [];
858 $arr[$row->pl_namespace][$row->pl_title] = 1;
870 $res = $this->
getDB()->select(
'templatelinks', [
'tl_namespace',
'tl_title' ],
871 [
'tl_from' => $this->mId ], __METHOD__ );
873 foreach (
$res as $row ) {
874 if ( !isset( $arr[$row->tl_namespace] ) ) {
875 $arr[$row->tl_namespace] = [];
877 $arr[$row->tl_namespace][$row->tl_title] = 1;
889 $res = $this->
getDB()->select(
'imagelinks', [
'il_to' ],
890 [
'il_from' => $this->mId ], __METHOD__ );
892 foreach (
$res as $row ) {
893 $arr[$row->il_to] = 1;
905 $res = $this->
getDB()->select(
'externallinks', [
'el_to' ],
906 [
'el_from' => $this->mId ], __METHOD__ );
908 foreach (
$res as $row ) {
909 $arr[$row->el_to] = 1;
921 $res = $this->
getDB()->select(
'categorylinks', [
'cl_to',
'cl_sortkey_prefix' ],
922 [
'cl_from' => $this->mId ], __METHOD__ );
924 foreach (
$res as $row ) {
925 $arr[$row->cl_to] = $row->cl_sortkey_prefix;
938 $res = $this->
getDB()->select(
'langlinks', [
'll_lang',
'll_title' ],
939 [
'll_from' => $this->mId ], __METHOD__ );
941 foreach (
$res as $row ) {
942 $arr[$row->ll_lang] = $row->ll_title;
953 $res = $this->
getDB()->select(
'iwlinks', [
'iwl_prefix',
'iwl_title' ],
954 [
'iwl_from' => $this->mId ], __METHOD__ );
956 foreach (
$res as $row ) {
957 if ( !isset( $arr[$row->iwl_prefix] ) ) {
958 $arr[$row->iwl_prefix] = [];
960 $arr[$row->iwl_prefix][$row->iwl_title] = 1;
972 $res = $this->
getDB()->select(
'page_props', [
'pp_propname',
'pp_value' ],
973 [
'pp_page' => $this->mId ], __METHOD__ );
975 foreach (
$res as $row ) {
976 $arr[$row->pp_propname] = $row->pp_value;
1015 $this->mRevision = $revision;
1033 $this->user =
$user;
1051 foreach ( $changed as $name =>
$value ) {
1054 if ( !is_array( $inv ) ) {
1057 foreach ( $inv as $table ) {
1058 DeferredUpdates::addUpdate(
1072 if ( $this->linkInsertions ===
null ) {
1076 foreach ( $this->linkInsertions as $insertion ) {
1077 $result[] = Title::makeTitle( $insertion[
'pl_namespace'], $insertion[
'pl_title'] );
1089 if ( $this->linkDeletions ===
null ) {
1093 foreach ( $this->linkDeletions as $ns =>
$titles ) {
1094 foreach (
$titles as $title => $unused ) {
1095 $result[] = Title::makeTitle( $ns, $title );
1128 $timestamp = $this->mParserOutput->getCacheTime();
1129 $this->
getDB()->update(
'page',
1130 [
'page_links_updated' => $this->
getDB()->timestamp( $timestamp ) ],
1131 [
'page_id' => $this->mId ],
1149 if ( $this->user ) {
1151 'userId' => $this->user->getId(),
1152 'userName' => $this->user->getName(),
1158 if ( $this->mRevision ) {
1159 $triggeringRevisionId = $this->mRevision->getId();
1161 $triggeringRevisionId =
false;
1167 'refreshLinksPrioritized',
1170 'rootJobTimestamp' => $this->mParserOutput->getCacheTime(),
1171 'useRecursiveLinksUpdate' => $this->mRecursive,
1172 'triggeringUser' => $userInfo,
1173 'triggeringRevisionId' => $triggeringRevisionId,
1174 'causeAction' => $this->getCauseAction(),
1175 'causeAgent' => $this->getCauseAgent()
1177 [
'removeDuplicates' =>
true ],
$wgPagePropLinkInvalidations
Page property link table invalidation lists.
$wgCategoryCollation
Specify how category names should be sorted, when listed on a category page.
$wgUpdateRowsPerQuery
Number of rows to update per query.
$wgPagePropsHaveSortkey
Whether the page_props table has a pp_sortkey column.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfMakeUrlIndexes( $url)
Make URL indexes, appropriate for the el_index field of externallinks.
Abstract base class for update jobs that do something with some secondary data extracted from article...
Class to invalidate the HTML cache of all the pages linking to a given title.
static singleton( $domain=false)
Job queue task description base code.
static newRootJobParams( $key)
Get "root job" parameters for a task.
Class the manages updates of *_link tables as well as similar extension-managed tables.
updateCategoryCounts(array $added, array $deleted)
Update all the appropriate counts in the category table.
array $mTemplates
Map of title strings to IDs for the template references, including broken ones.
updateLinksTimestamp()
Update links table freshness.
getTitle()
Return the title object of the page being updated.
getExistingLinks()
Get an array of existing links, as a 2-D array.
getExistingProperties()
Get an array of existing categories, with the name in the key and sort key in the value.
getImageInsertions( $existing=[])
Get an array of image insertions Skips the names specified in $existing.
getInterlangInsertions( $existing=[])
Get an array of interlanguage link insertions.
getExternalInsertions( $existing=[])
Get an array of externallinks insertions.
__construct(Title $title, ParserOutput $parserOutput, $recursive=true)
getPropertyInsertions( $existing=[])
Get an array of page property insertions.
array $mLinks
Map of title strings to IDs for the links in the document.
array $mInterwikis
2-D map of (prefix => DBK => 1)
setTriggeringUser(User $user)
Set the User who triggered this LinksUpdate.
getTemplateDeletions( $existing)
Given an array of existing templates, returns those templates which are not in $this and thus should ...
invalidateCategories( $cats)
null array $propertyInsertions
Added properties if calculated.
doUpdate()
Update link tables with outgoing links from an updated article.
Title $mTitle
Title object of the article linked from.
getPropertySortKeyValue( $value)
Determines the sort key for the given property value.
int $mId
Page ID of the article linked from.
getAddedProperties()
Fetch page properties added by this LinksUpdate.
static queueRecursiveJobsForTable(Title $title, $table, $action='unknown', $userName='unknown')
Queue a RefreshLinks job for any table.
getLinkInsertions( $existing=[])
Get an array of pagelinks insertions for passing to the DB Skips the titles specified by the 2-D arra...
getExistingImages()
Get an array of existing images, image names in the keys.
getRemovedLinks()
Fetch page links removed by this LinksUpdate.
Revision $mRevision
Revision for which this update has been triggered.
setRevision(Revision $revision)
Set the revision corresponding to this LinksUpdate.
getTemplateInsertions( $existing=[])
Get an array of template insertions.
getCategoryDeletions( $existing)
Given an array of existing categories, returns those categories which are not in $this and thus shoul...
getInterwikiInsertions( $existing=[])
Get an array of interwiki insertions for passing to the DB Skips the titles specified by the 2-D arra...
ParserOutput $mParserOutput
null array $linkInsertions
Added links if calculated.
getImages()
Return the list of images used as generated by the parser.
array $mProperties
Map of arbitrary name to value.
getExistingInterlangs()
Get an array of existing interlanguage links, with the language code in the key and the title in the ...
getExistingExternals()
Get an array of existing external links, URLs in the keys.
getParserOutput()
Returns parser output.
getPropertyDeletions( $existing)
Get array of properties which should be deleted.
invalidateProperties( $changed)
Invalidate any necessary link lists related to page property changes.
null array $linkDeletions
Deleted links if calculated.
null array $propertyDeletions
Deleted properties if calculated.
getInterlangDeletions( $existing)
Given an array of existing interlanguage links, returns those links which are not in $this and thus s...
getPagePropRowData( $prop)
Returns an associative array to be used for inserting a row into the page_props table.
getExistingCategories()
Get an array of existing categories, with the name in the key and sort key in the value.
invalidateImageDescriptions( $images)
getAddedLinks()
Fetch page links added by this LinksUpdate.
queueRecursiveJobs()
Queue recursive jobs for this page.
array $mImages
DB keys of the images used, in the array key only.
getImageDeletions( $existing)
Given an array of existing images, returns those images which are not in $this and thus should be del...
array $mInterlangs
Map of language codes to titles.
getLinkDeletions( $existing)
Given an array of existing links, returns those links which are not in $this and thus should be delet...
array $mCategories
Map of category names to sort keys.
bool $mRecursive
Whether to queue jobs for recursive updates.
getCategoryInsertions( $existing=[])
Get an array of category insertions.
getRemovedProperties()
Fetch page properties removed by this LinksUpdate.
getExistingTemplates()
Get an array of existing templates, as a 2-D array.
getExternalDeletions( $existing)
Given an array of existing external links, returns those links which are not in $this and thus should...
static acquirePageLock(IDatabase $dbw, $pageId, $why='atomicity')
Acquire a lock for performing link table updates for a page on a DB.
getInterwikiDeletions( $existing)
Given an array of existing interwiki links, returns those links which are not in $this and thus shoul...
array $mExternals
URLs of external links, array key only.
incrTableUpdate( $table, $prefix, $deletions, $insertions)
Update a table by doing a delete query then an insert query.
getExistingInterwikis()
Get an array of existing inline interwiki links, as a 2-D array.
static invalidatePages(IDatabase $dbw, $namespace, array $dbkeys)
Invalidate the cache of a list of pages from a single namespace.
Job to update link tables for pages.
static newPrioritized(Title $title, array $params)
Represents a title within MediaWiki.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static getWikiIdFromDomain( $domain)
Get the wiki ID of a database domain.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
namespace being checked & $result
namespace and then decline to actually register it file or subcat img or subcat $title
either a unescaped string or a HtmlArmor object after in associative array form externallinks $linksUpdate
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place or wrap services the preferred way to define a new service is the $wgServiceWiringFiles array $services
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Allows to change the fields on the form that will be generated $name
Interface that marks a DataUpdate as enqueuable via the JobQueue.
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
if(count( $args)< 1) $job
if(!isset( $args[0])) $lang