54 'categoryMembershipChange',
57 'revTimestamp' => $revisionTimestamp,
60 'removeDuplicates' =>
true,
61 'removeDuplicatesIgnoreParams' => [
'revTimestamp' ]
74 parent::__construct(
'categoryMembershipChange',
$title,
$params );
77 $this->removeDuplicates =
true;
80 public function run() {
81 $services = MediaWikiServices::getInstance();
82 $lbFactory = $services->getDBLoadBalancerFactory();
83 $lb = $lbFactory->getMainLB();
84 $dbw = $lb->getConnectionRef(
DB_MASTER );
86 $this->ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ );
88 $page = $services->getWikiPageFactory()->newFromID( $this->params[
'pageId'], WikiPage::READ_LATEST );
90 $this->
setLastError(
"Could not find page #{$this->params['pageId']}" );
96 if ( !$lb->waitForMasterPos(
$dbr ) ) {
97 $this->
setLastError(
"Timed out while pre-waiting for replica DB to catch up" );
102 $lockKey =
"{$dbw->getDomainID()}:CategoryMembershipChange:{$page->getId()}";
103 $scopedLock = $dbw->getScopedLockAndFlush( $lockKey, __METHOD__, 3 );
104 if ( !$scopedLock ) {
105 $this->
setLastError(
"Could not acquire lock '$lockKey'" );
110 if ( !$lb->waitForMasterPos(
$dbr ) ) {
111 $this->
setLastError(
"Timed out while waiting for replica DB to catch up" );
115 $dbr->flushSnapshot( __METHOD__ );
117 $cutoffUnix =
wfTimestamp( TS_UNIX, $this->params[
'revTimestamp'] );
124 $row =
$dbr->selectRow(
126 [
'rev_timestamp',
'rev_id' ],
128 'rev_page' => $page->getId(),
129 'rev_timestamp >= ' .
$dbr->addQuotes(
$dbr->timestamp( $cutoffUnix ) ),
130 'EXISTS (' .
$dbr->selectSQLText(
134 'rc_this_oldid = rev_id',
141 [
'ORDER BY' => [
'rev_timestamp DESC',
'rev_id DESC' ] ]
145 $cutoffUnix =
wfTimestamp( TS_UNIX, $row->rev_timestamp );
146 $lastRevId = (int)$row->rev_id;
153 $encCutoff =
$dbr->addQuotes(
$dbr->timestamp( $cutoffUnix ) );
154 $revisionStore = $services->getRevisionStore();
155 $revQuery = $revisionStore->getQueryInfo();
160 'rev_page' => $page->getId(),
161 "rev_timestamp > $encCutoff" .
162 " OR (rev_timestamp = $encCutoff AND rev_id > $lastRevId)"
165 [
'ORDER BY' => [
'rev_timestamp ASC',
'rev_id ASC' ] ],
170 foreach (
$res as $row ) {
190 if ( $newRev->
isDeleted( RevisionRecord::DELETED_TEXT ) ) {
196 $oldRev = MediaWikiServices::getInstance()
197 ->getRevisionLookup()
198 ->getRevisionById( $newRev->
getParentId(), RevisionLookup::READ_LATEST );
199 if ( !$oldRev || $oldRev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
208 list( $categoryInserts, $categoryDeletes ) = $categoryChanges;
209 if ( !$categoryInserts && !$categoryDeletes ) {
214 $catMembChange->checkTemplateLinks();
216 $batchSize = $config->get(
'UpdateRowsPerQuery' );
219 foreach ( $categoryInserts as $categoryName ) {
221 $catMembChange->triggerCategoryAddedNotification( $categoryTitle );
222 if ( $insertCount++ && ( $insertCount % $batchSize ) == 0 ) {
227 foreach ( $categoryDeletes as $categoryName ) {
229 $catMembChange->triggerCategoryRemovedNotification( $categoryTitle );
230 if ( $insertCount++ && ( $insertCount++ % $batchSize ) == 0 ) {
246 $oldCategories = $oldRev
252 $categoryInserts = array_values( array_diff( $newCategories, $oldCategories ) );
253 $categoryDeletes = array_values( array_diff( $oldCategories, $newCategories ) );
255 return [ $categoryInserts, $categoryDeletes ];
266 $services = MediaWikiServices::getInstance();
268 $options->setTimestamp( $parseTimestamp );
271 ? $services->getParserCache()->get( $page, $options )
274 if ( !$output || $output->getCacheRevisionId() !== $rev->
getId() ) {
275 $output = $services->getRevisionRenderer()->getRenderedRevision( $rev, $options )
276 ->getRevisionParserOutput();
281 return array_map(
'strval', array_keys( $output->getCategories() ) );
285 $info = parent::getDeduplicationInfo();
286 unset( $info[
'params'][
'revTimestamp'] );