MediaWiki  1.33.0
LinksDeletionUpdate.php
Go to the documentation of this file.
1 <?php
23 use Wikimedia\ScopedCallback;
24 
30  protected $page;
32  protected $timestamp;
33 
40  function __construct( WikiPage $page, $pageId = null, $timestamp = null ) {
41  $this->page = $page;
42  if ( $pageId ) {
43  $this->mId = $pageId; // page ID at time of deletion
44  } elseif ( $page->exists() ) {
45  $this->mId = $page->getId();
46  } else {
47  throw new InvalidArgumentException( "Page ID not known. Page doesn't exist?" );
48  }
49 
50  $this->timestamp = $timestamp ?: wfTimestampNow();
51 
52  $fakePO = new ParserOutput();
53  $fakePO->setCacheTime( $timestamp );
54  parent::__construct( $page->getTitle(), $fakePO, false );
55  }
56 
57  protected function doIncrementalUpdate() {
58  $services = MediaWikiServices::getInstance();
59  $config = $services->getMainConfig();
60  $lbFactory = $services->getDBLoadBalancerFactory();
61  $batchSize = $config->get( 'UpdateRowsPerQuery' );
62 
63  $id = $this->mId;
65 
66  $dbw = $this->getDB(); // convenience
67 
68  parent::doIncrementalUpdate();
69 
70  // Typically, a category is empty when deleted, so check that we don't leave
71  // spurious row in the category table.
72  if ( $title->getNamespace() === NS_CATEGORY ) {
73  // T166757: do the update after the main job DB commit
75  $cat = Category::newFromName( $title->getDBkey() );
76  $cat->refreshCountsIfEmpty();
77  } );
78  }
79 
80  // Delete restrictions for the deleted page
81  $dbw->delete( 'page_restrictions', [ 'pr_page' => $id ], __METHOD__ );
82 
83  // Delete any redirect entry
84  $dbw->delete( 'redirect', [ 'rd_from' => $id ], __METHOD__ );
85 
86  // Find recentchanges entries to clean up...
87  $rcIdsForTitle = $dbw->selectFieldValues(
88  'recentchanges',
89  'rc_id',
90  [
91  'rc_type != ' . RC_LOG,
92  'rc_namespace' => $title->getNamespace(),
93  'rc_title' => $title->getDBkey(),
94  'rc_timestamp < ' .
95  $dbw->addQuotes( $dbw->timestamp( $this->timestamp ) )
96  ],
97  __METHOD__
98  );
99  $rcIdsForPage = $dbw->selectFieldValues(
100  'recentchanges',
101  'rc_id',
102  [ 'rc_type != ' . RC_LOG, 'rc_cur_id' => $id ],
103  __METHOD__
104  );
105 
106  // T98706: delete by PK to avoid lock contention with RC delete log insertions
107  $rcIdBatches = array_chunk( array_merge( $rcIdsForTitle, $rcIdsForPage ), $batchSize );
108  foreach ( $rcIdBatches as $rcIdBatch ) {
109  $dbw->delete( 'recentchanges', [ 'rc_id' => $rcIdBatch ], __METHOD__ );
110  if ( count( $rcIdBatches ) > 1 ) {
111  $lbFactory->commitAndWaitForReplication(
112  __METHOD__, $this->ticket, [ 'domain' => $dbw->getDomainID() ]
113  );
114  }
115  }
116 
117  // Commit and release the lock (if set)
118  ScopedCallback::consume( $scopedLock );
119  }
120 
121  public function getAsJobSpecification() {
122  return [
123  'domain' => $this->getDB()->getDomainID(),
124  'job' => new JobSpecification(
125  'deleteLinks',
126  [ 'pageId' => $this->mId, 'timestamp' => $this->timestamp ],
127  [ 'removeDuplicates' => true ],
128  $this->mTitle
129  )
130  ];
131  }
132 }
ParserOutput
Definition: ParserOutput.php:25
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
captcha-old.count
count
Definition: captcha-old.py:249
LinksUpdate\$mId
int $mId
Page ID of the article linked from.
Definition: LinksUpdate.php:39
RC_LOG
const RC_LOG
Definition: Defines.php:144
LinksDeletionUpdate\$timestamp
string $timestamp
Definition: LinksDeletionUpdate.php:32
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:45
LinksUpdate
Class the manages updates of *_link tables as well as similar extension-managed tables.
Definition: LinksUpdate.php:35
page
target page
Definition: All_system_messages.txt:1267
LinksDeletionUpdate\$page
WikiPage $page
Definition: LinksDeletionUpdate.php:30
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
EnqueueableDataUpdate
Interface that marks a DataUpdate as enqueuable via the JobQueue.
Definition: EnqueueableDataUpdate.php:10
LinksDeletionUpdate\doIncrementalUpdate
doIncrementalUpdate()
Definition: LinksDeletionUpdate.php:57
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
LinksDeletionUpdate\getAsJobSpecification
getAsJobSpecification()
Definition: LinksDeletionUpdate.php:121
WikiPage\getId
getId()
Definition: WikiPage.php:596
WikiPage\getTitle
getTitle()
Get the title object of the article.
Definition: WikiPage.php:294
WikiPage\exists
exists()
Definition: WikiPage.php:606
LinksDeletionUpdate\__construct
__construct(WikiPage $page, $pageId=null, $timestamp=null)
Definition: LinksDeletionUpdate.php:40
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1941
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:78
LinksUpdate\$mTitle
Title $mTitle
Title object of the article linked from.
Definition: LinksUpdate.php:42
LinksDeletionUpdate
Update object handling the cleanup of links tables after a page was deleted.
Definition: LinksDeletionUpdate.php:28
JobSpecification
Job queue task description base code.
Definition: JobSpecification.php:40
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Category\newFromName
static newFromName( $name)
Factory function.
Definition: Category.php:126
$services
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response 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
Definition: hooks.txt:2220
MediaWikiServices
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
LinksUpdate\getDB
getDB()
Definition: LinksUpdate.php:1187
DeferredUpdates\addCallableUpdate
static addCallableUpdate( $callable, $stage=self::POSTSEND, $dbw=null)
Add a callable update.
Definition: DeferredUpdates.php:118