36 private const CATEGORY_ADDITION = 1;
37 private const CATEGORY_REMOVAL = -1;
59 private $numTemplateLinks = 0;
64 private $newForCategorizationCallback =
null;
67 private $backlinkCache;
77 $this->pageTitle = $pageTitle;
78 $this->revision = $revision;
79 if ( $revision ===
null ) {
84 $this->newForCategorizationCallback = [ RecentChange::class,
'newForCategorization' ];
85 $this->backlinkCache = $backlinkCache;
96 if ( !defined(
'MW_PHPUNIT_TEST' ) ) {
97 throw new LogicException(
'Cannot override newForCategorization callback in operation.' );
99 $this->newForCategorizationCallback = $callback;
106 $this->numTemplateLinks = $this->backlinkCache->getNumLinks(
'templatelinks' );
115 $this->createRecentChangesEntry( $categoryTitle, self::CATEGORY_ADDITION );
124 $this->createRecentChangesEntry( $categoryTitle, self::CATEGORY_REMOVAL );
133 private function createRecentChangesEntry(
Title $categoryTitle, $type ) {
134 $this->notifyCategorization(
138 $this->getChangeMessageText(
140 $this->pageTitle->getPrefixedText(),
141 $this->numTemplateLinks
144 $this->getPreviousRevisionTimestamp(),
146 $type === self::CATEGORY_ADDITION
160 private function notifyCategorization(
162 Title $categoryTitle,
170 $deleted = $revision ? $revision->
getVisibility() & RevisionRecord::SUPPRESSED_USER : 0;
171 $newRevId = $revision ? $revision->
getId() : 0;
182 # If no revision is given, the change was probably triggered by parser functions
183 if ( $revision !==
null ) {
184 $revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
186 $correspondingRc = $revisionStore->getRecentChange( $this->revision ) ??
187 $revisionStore->getRecentChange( $this->revision, RevisionStore::READ_LATEST );
188 if ( $correspondingRc !==
null ) {
189 $bot = $correspondingRc->getAttribute(
'rc_bot' ) ?: 0;
190 $ip = $correspondingRc->getAttribute(
'rc_ip' ) ?:
'';
191 $lastRevId = $correspondingRc->getAttribute(
'rc_last_oldid' ) ?: 0;
196 $rc = ( $this->newForCategorizationCallback )(
225 if ( $this->revision ) {
226 $user = $this->revision->getUser( RevisionRecord::RAW );
232 $username =
wfMessage(
'autochange-username' )->inContentLanguage()->text();
234 $user = User::newSystemUser( $username );
236 $user->addToDatabase();
239 return $user ?:
null;
258 private function getChangeMessageText( $type, $prefixedText, $numTemplateLinks ) {
260 self::CATEGORY_ADDITION =>
'recentchanges-page-added-to-category',
261 self::CATEGORY_REMOVAL =>
'recentchanges-page-removed-from-category',
264 $msgKey = $array[$type];
266 if ( intval( $numTemplateLinks ) > 0 ) {
267 $msgKey .=
'-bundled';
270 return wfMessage( $msgKey, $prefixedText )->inContentLanguage()->text();
279 private function getPreviousRevisionTimestamp() {
280 $rl = MediaWikiServices::getInstance()->getRevisionLookup();
281 $latestRev = $rl->getRevisionByTitle( $this->pageTitle );
283 $previousRev = $rl->getPreviousRevision( $latestRev );
284 if ( $previousRev ) {
285 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.