protected function logTagAdded($tags, $revId, $user, $reason) { // log it $logEntry = new ManualLogEntry('tag', 'update'); $logEntry->setPerformer($user); $logEntry->setComment($reason); // find the appropriate target page if ($revId) { $rev = Revision::newFromId($revId); if ($rev) { $logEntry->setTarget($rev->getTitle()); } } if (!$logEntry->getTarget()) { // target is required, so we have to set something $logEntry->setTarget(SpecialPage::getTitleFor('Tags')); } $logParams = array('4::revid' => $revId, '6:list:tagsAdded' => $tags, '7:number:tagsAddedCount' => count($tags)); $logEntry->setParameters($logParams); $logEntry->setRelations(array('Tag' => $tags)); $dbw = wfGetDB(DB_MASTER); $logId = $logEntry->insert($dbw); // Only send this to UDP, not RC, similar to patrol events $logEntry->publish($logId, 'udp'); //$logEntry->publish( $logId ); }
/** * Adds and/or removes tags to/from a given change, checking whether it is * allowed first, and adding a log entry afterwards. * * Includes a call to ChangeTag::canUpdateTags(), so your code doesn't need * to do that. However, it doesn't check whether the *_id parameters are a * valid combination. That is up to you to enforce. See ApiTag::execute() for * an example. * * @param array|null $tagsToAdd If none, pass array() or null * @param array|null $tagsToRemove If none, pass array() or null * @param int|null $rc_id The rc_id of the change to add the tags to * @param int|null $rev_id The rev_id of the change to add the tags to * @param int|null $log_id The log_id of the change to add the tags to * @param string $params Params to put in the ct_params field of table * 'change_tag' when adding tags * @param string $reason Comment for the log * @param User $user Who to give credit for the action * @return Status If successful, the value of this Status object will be an * object (stdClass) with the following fields: * - logId: the ID of the added log entry, or null if no log entry was added * (i.e. no operation was performed) * - addedTags: an array containing the tags that were actually added * - removedTags: an array containing the tags that were actually removed * @since 1.25 */ public static function updateTagsWithChecks($tagsToAdd, $tagsToRemove, $rc_id, $rev_id, $log_id, $params, $reason, User $user) { if (is_null($tagsToAdd)) { $tagsToAdd = array(); } if (is_null($tagsToRemove)) { $tagsToRemove = array(); } if (!$tagsToAdd && !$tagsToRemove) { // no-op, don't bother return Status::newGood((object) array('logId' => null, 'addedTags' => array(), 'removedTags' => array())); } // are we allowed to do this? $result = self::canUpdateTags($tagsToAdd, $tagsToRemove, $user); if (!$result->isOK()) { $result->value = null; return $result; } // basic rate limiting if ($user->pingLimiter('changetag')) { return Status::newFatal('actionthrottledtext'); } // do it! list($tagsAdded, $tagsRemoved, $initialTags) = self::updateTags($tagsToAdd, $tagsToRemove, $rc_id, $rev_id, $log_id, $params); if (!$tagsAdded && !$tagsRemoved) { // no-op, don't log it return Status::newGood((object) array('logId' => null, 'addedTags' => array(), 'removedTags' => array())); } // log it $logEntry = new ManualLogEntry('tag', 'update'); $logEntry->setPerformer($user); $logEntry->setComment($reason); // find the appropriate target page if ($rev_id) { $rev = Revision::newFromId($rev_id); if ($rev) { $logEntry->setTarget($rev->getTitle()); } } elseif ($log_id) { // This function is from revision deletion logic and has nothing to do with // change tags, but it appears to be the only other place in core where we // perform logged actions on log items. $logEntry->setTarget(RevDelLogList::suggestTarget(0, array($log_id))); } if (!$logEntry->getTarget()) { // target is required, so we have to set something $logEntry->setTarget(SpecialPage::getTitleFor('Tags')); } $logParams = array('4::revid' => $rev_id, '5::logid' => $log_id, '6:list:tagsAdded' => $tagsAdded, '7:number:tagsAddedCount' => count($tagsAdded), '8:list:tagsRemoved' => $tagsRemoved, '9:number:tagsRemovedCount' => count($tagsRemoved), 'initialTags' => $initialTags); $logEntry->setParameters($logParams); $logEntry->setRelations(array('Tag' => array_merge($tagsAdded, $tagsRemoved))); $dbw = wfGetDB(DB_MASTER); $logId = $logEntry->insert($dbw); // Only send this to UDP, not RC, similar to patrol events $logEntry->publish($logId, 'udp'); return Status::newGood((object) array('logId' => $logId, 'addedTags' => $tagsAdded, 'removedTags' => $tagsRemoved)); }