35 private const CATEGORY_ADDITION = 1;
36 private const CATEGORY_REMOVAL = -1;
58 private $numTemplateLinks = 0;
63 private $newForCategorizationCallback =
null;
66 private $backlinkCache;
78 $this->pageTitle = $pageTitle;
79 $this->revision = $revision;
80 if ( $revision ===
null ) {
85 $this->newForCategorizationCallback = [ RecentChange::class,
'newForCategorization' ];
86 $this->backlinkCache = $backlinkCache;
99 if ( !defined(
'MW_PHPUNIT_TEST' ) ) {
100 throw new MWException(
'Cannot override newForCategorization callback in operation.' );
102 $this->newForCategorizationCallback = $callback;
109 $this->numTemplateLinks = $this->backlinkCache->getNumLinks(
'templatelinks' );
118 $this->createRecentChangesEntry( $categoryTitle, self::CATEGORY_ADDITION );
127 $this->createRecentChangesEntry( $categoryTitle, self::CATEGORY_REMOVAL );
136 private function createRecentChangesEntry(
Title $categoryTitle,
$type ) {
137 $this->notifyCategorization(
141 $this->getChangeMessageText(
143 $this->pageTitle->getPrefixedText(),
144 $this->numTemplateLinks
147 $this->getPreviousRevisionTimestamp(),
149 $type === self::CATEGORY_ADDITION
165 private function notifyCategorization(
167 Title $categoryTitle,
175 $deleted = $revision ? $revision->
getVisibility() & RevisionRecord::SUPPRESSED_USER : 0;
176 $newRevId = $revision ? $revision->
getId() : 0;
187 # If no revision is given, the change was probably triggered by parser functions
188 if ( $revision !==
null ) {
189 $revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
191 $correspondingRc = $revisionStore->getRecentChange( $this->revision ) ??
192 $revisionStore->getRecentChange( $this->revision, RevisionStore::READ_LATEST );
193 if ( $correspondingRc !==
null ) {
194 $bot = $correspondingRc->getAttribute(
'rc_bot' ) ?: 0;
195 $ip = $correspondingRc->getAttribute(
'rc_ip' ) ?:
'';
196 $lastRevId = $correspondingRc->getAttribute(
'rc_last_oldid' ) ?: 0;
201 $rc = ( $this->newForCategorizationCallback )(
230 if ( $this->revision ) {
231 $user = $this->revision->getUser( RevisionRecord::RAW );
237 $username =
wfMessage(
'autochange-username' )->inContentLanguage()->text();
241 $user->addToDatabase();
244 return $user ?:
null;
263 private function getChangeMessageText(
$type, $prefixedText, $numTemplateLinks ) {
265 self::CATEGORY_ADDITION =>
'recentchanges-page-added-to-category',
266 self::CATEGORY_REMOVAL =>
'recentchanges-page-removed-from-category',
269 $msgKey = $array[
$type];
271 if ( intval( $numTemplateLinks ) > 0 ) {
272 $msgKey .=
'-bundled';
275 return wfMessage( $msgKey, $prefixedText )->inContentLanguage()->text();
284 private function getPreviousRevisionTimestamp() {
285 $rl = MediaWikiServices::getInstance()->getRevisionLookup();
286 $latestRev = $rl->getRevisionByTitle( $this->pageTitle );
288 $previousRev = $rl->getPreviousRevision( $latestRev );
289 if ( $previousRev ) {
290 return $previousRev->getTimestamp();
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined('MW_SETUP_CALLBACK'))
Class for fetching backlink lists, approximate backlink counts and partitions.
triggerCategoryRemovedNotification(Title $categoryTitle)
Create a recentchanges entry for category removals.
triggerCategoryAddedNotification(Title $categoryTitle)
Create a recentchanges entry for category additions.
overrideNewForCategorizationCallback(callable $callback)
Overrides the default new for categorization callback This is intended for use while testing and will...
__construct(Title $pageTitle, BacklinkCache $backlinkCache, RevisionRecord $revision=null)
checkTemplateLinks()
Determines the number of template links for recursive link updates.
static newSystemUser( $name, $options=[])
Static factory method for creation of a "system" user from username.