Cenarium has uploaded a new change for review. https://gerrit.wikimedia.org/r/218266
Change subject: Create ChangeTagsUpdate hook and flags describing update method ...................................................................... Create ChangeTagsUpdate hook and flags describing update method This creates a hook triggered when updating change tags, so that extensions can take actions when tags are updated. It can take as arguments flags that describe the method used to update. These are defined in ChangeTags. Change-Id: Ifb0cdc43252c4185e4f216d23b8a21fb31595a37 --- M docs/hooks.txt M includes/MovePage.php M includes/changes/RecentChange.php M includes/changetags/ChangeTags.php 4 files changed, 39 insertions(+), 10 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/66/218266/1 diff --git a/docs/hooks.txt b/docs/hooks.txt index c7dcb99..8710bdb 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -996,6 +996,18 @@ If you allow users to define tags, it is advised to check that the name is legit with the ChangeTag::canCreate function. +'ChangeTagsAfterUpdateTags': Called immediately after tags have been updated with the +ChangeTags::updateTags function. Params: +$addedTags: tags effectively added in the update +$removedTags: tags effectively removed in the update +$prevTags: tags that were present prior to the update +$rc_id: recentchanges table id +$rev_id: revision table id +$log_id: logging table id +$params: tag params +$user: User who performed the tagging, or tagged user if it was automatic +$flags: bit mask representing the source of the tagging, if done in core, see ChangeTags class + 'Collation::factory': Called if $wgCategoryCollation is an unknown collation. $collationName: Name of the collation in question &$collationObject: Null. Replace with a subclass of the Collation class that diff --git a/includes/MovePage.php b/includes/MovePage.php index 1a21811..ec78ecb 100644 --- a/includes/MovePage.php +++ b/includes/MovePage.php @@ -529,7 +529,8 @@ if ( $wgUseAutoTagging ) { $autoTags = ChangeTagsCore::getAutotagsForMove( $this->oldTitle, $nt, $user ); if ( $autoTags ) { - ChangeTags::addTags( $autoTags, $rc->mAttribs['rc_id'], $nullRevision->getId(), $logid, null ); + ChangeTags::addTags( $autoTags, $rc->mAttribs['rc_id'], $nullRevision->getId(), $logid, + null, $user, $rc, ChangeTags::UPDATE_CORE_MOVE ); } } } diff --git a/includes/changes/RecentChange.php b/includes/changes/RecentChange.php index 1562751..e6189a6 100644 --- a/includes/changes/RecentChange.php +++ b/includes/changes/RecentChange.php @@ -561,12 +561,13 @@ 'pageStatus' => 'changed' ); - DeferredUpdates::addCallableUpdate( function() use ( $rc, $autoTags ) { + DeferredUpdates::addCallableUpdate( function() use ( $rc, $autoTags, $user ) { $rc->save(); // Apply autotags if any if ( count( $autoTags ) ) { ChangeTags::addTags( $autoTags, $rc->mAttribs['rc_id'], - $rc->mAttribs['rc_this_oldid'], null, null ); + $rc->mAttribs['rc_this_oldid'], null, null, + $user, $rc, ChangeTags::UPDATE_CORE_EDITUPDATE ); } if ( $rc->mAttribs['rc_patrolled'] ) { PatrolLog::record( $rc, true, $rc->getPerformer() ); @@ -635,12 +636,13 @@ 'pageStatus' => 'created' ); - DeferredUpdates::addCallableUpdate( function() use ( $rc, $autoTags ) { + DeferredUpdates::addCallableUpdate( function() use ( $rc, $autoTags, $user ) { $rc->save(); // Apply autotags if any if ( count( $autoTags ) ) { ChangeTags::addTags( $autoTags, $rc->mAttribs['rc_id'], - $rc->mAttribs['rc_this_oldid'], null, null ); + $rc->mAttribs['rc_this_oldid'], null, null, + $user, $rc, ChangeTags::UPDATE_CORE_EDITNEW ); } if ( $rc->mAttribs['rc_patrolled'] ) { PatrolLog::record( $rc, true, $rc->getPerformer() ); diff --git a/includes/changetags/ChangeTags.php b/includes/changetags/ChangeTags.php index 95be0eb..19f4d4a 100644 --- a/includes/changetags/ChangeTags.php +++ b/includes/changetags/ChangeTags.php @@ -23,6 +23,17 @@ class ChangeTags { + /* Represents a tag manually applied along an edit by the user who performed it */ + const UPDATE_USER_SELF = 2; + /* Represents a tag manually applied after an edit was saved */ + const UPDATE_USER_POST = 4; + /* Represents a tag applied in core to an edit to an existing page */ + const UPDATE_CORE_EDITUPDATE = 8; + /* Represents a tag applied in core to an edit creating a page */ + const UPDATE_CORE_EDITNEW = 16; + /* Represents a tag applied in core to a page move */ + const UPDATE_CORE_MOVE = 32; + /** * Creates HTML for the given tags * @@ -135,9 +146,9 @@ * @return bool False if no changes are made, otherwise true */ public static function addTags( $tags, $rc_id = null, $rev_id = null, - $log_id = null, $params = null + $log_id = null, $params = null, User $user = null, RecentChange $rc = null, $flags = 0 ) { - $result = self::updateTags( $tags, null, $rc_id, $rev_id, $log_id, $params ); + $result = self::updateTags( $tags, null, $rc_id, $rev_id, $log_id, $params, $user, $rc, $flags ); return (bool)$result[0]; } @@ -169,7 +180,7 @@ * @since 1.25 */ public static function updateTags( $tagsToAdd, $tagsToRemove, &$rc_id = null, - &$rev_id = null, &$log_id = null, $params = null ) { + &$rev_id = null, &$log_id = null, $params = null, User $user = null, RecentChange $rc = null, $flags = 0 ) { $tagsToAdd = array_filter( (array)$tagsToAdd ); // Make sure we're submitting all tags... $tagsToRemove = array_filter( (array)$tagsToRemove ); @@ -261,6 +272,9 @@ } } ChangeTagsContext::clearCachesAfterUpdate( $tagsToAdd, $tagsToRemove ); + + Hooks::run( 'ChangeTagsAfterUpdateTags', array( + $tagsToAdd, $tagsToRemove, $prevTags, $rc_id, $rev_id, $log_id, $params, $user, $rc, $flags ) ); return array( $tagsToAdd, $tagsToRemove, $prevTags ); } @@ -414,7 +428,7 @@ } // do it! - self::addTags( $tags, $rc_id, $rev_id, $log_id, $params ); + self::addTags( $tags, $rc_id, $rev_id, $log_id, $params, $user, null, self::UPDATE_USER_SELF ); return Status::newGood( true ); } @@ -530,7 +544,7 @@ // do it! list( $tagsAdded, $tagsRemoved, $initialTags ) = self::updateTags( $tagsToAdd, - $tagsToRemove, $rc_id, $rev_id, $log_id, $params ); + $tagsToRemove, $rc_id, $rev_id, $log_id, $params, $user, null, self::UPDATE_USER_POST ); if ( !$tagsAdded && !$tagsRemoved ) { // no-op, don't log it return Status::newGood( (object)array( -- To view, visit https://gerrit.wikimedia.org/r/218266 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ifb0cdc43252c4185e4f216d23b8a21fb31595a37 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Cenarium <cenarium.sy...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits