/** * Add a log entry * * @param string $action One of '', 'block', 'protect', 'rights', 'delete', * 'upload', 'move', 'move_redir' * @param Title $target Title object * @param string $comment Description associated * @param array $params Parameters passed later to wfMessage function * @param null|int|User $doer The user doing the action. null for $wgUser * * @return int The log_id of the inserted log entry */ public function addEntry($action, $target, $comment, $params = array(), $doer = null) { global $wgContLang; if (!is_array($params)) { $params = array($params); } if ($comment === null) { $comment = ''; } # Trim spaces on user supplied text $comment = trim($comment); # Truncate for whole multibyte characters. $comment = $wgContLang->truncate($comment, 255); $this->action = $action; $this->target = $target; $this->comment = $comment; $this->params = LogPage::makeParamBlob($params); if ($doer === null) { global $wgUser; $doer = $wgUser; } elseif (!is_object($doer)) { $doer = User::newFromId($doer); } $this->doer = $doer; $logEntry = new ManualLogEntry($this->type, $action); $logEntry->setTarget($target); $logEntry->setPerformer($doer); $logEntry->setParameters($params); // All log entries using the LogPage to insert into the logging table // are using the old logging system and therefore the legacy flag is // needed to say the LogFormatter the parameters have numeric keys $logEntry->setLegacy(true); $formatter = LogFormatter::newFromEntry($logEntry); $context = RequestContext::newExtraneousContext($target); $formatter->setContext($context); $this->actionText = $formatter->getPlainActionText(); $this->ircActionText = $formatter->getIRCActionText(); return $this->saveContent(); }
/** * @deprecated since 1.25 Use LogFormatter::formatParametersForApi instead * @param ApiResult $result * @param array $vals * @param string $params * @param string $type * @param string $action * @param string $ts * @param bool $legacy * @return array */ public static function addLogParams($result, &$vals, $params, $type, $action, $ts, $legacy = false) { wfDeprecated(__METHOD__, '1.25'); $entry = new ManualLogEntry($type, $action); $entry->setParameters($params); $entry->setTimestamp($ts); $entry->setLegacy($legacy); $formatter = LogFormatter::newFromEntry($entry); $vals['params'] = $formatter->formatParametersForApi(); return $vals; }
/** * @param string $expected Expected IRC text without colors codes * @param string $type Log type (move, delete, suppress, patrol ...) * @param string $action A log type action * @param array $params * @param string $comment (optional) A comment for the log action * @param string $msg (optional) A message for PHPUnit :-) */ protected function assertIRCComment($expected, $type, $action, $params, $comment = null, $msg = '', $legacy = false) { $logEntry = new ManualLogEntry($type, $action); $logEntry->setPerformer($this->user); $logEntry->setTarget($this->title); if ($comment !== null) { $logEntry->setComment($comment); } $logEntry->setParameters($params); $logEntry->setLegacy($legacy); $formatter = LogFormatter::newFromEntry($logEntry); $formatter->setContext($this->context); // Apply the same transformation as done in IRCColourfulRCFeedFormatter::getLine for rc_comment $ircRcComment = IRCColourfulRCFeedFormatter::cleanupForIRC($formatter->getIRCActionComment()); $this->assertEquals($expected, $ircRcComment, $msg); }