58 private $ircActionText;
92 public function __construct( $type, $rc =
true, $udp =
'skipUDP' ) {
94 $this->updateRecentChanges = $rc;
95 $this->sendToUDP = ( $udp ==
'UDP' );
102 $logRestrictions = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogRestrictions );
107 $actorId = MediaWikiServices::getInstance()->getActorNormalization()
108 ->acquireActorId( $this->performer, $dbw );
110 'log_type' => $this->type,
111 'log_action' => $this->action,
112 'log_timestamp' => $dbw->timestamp( $now ),
113 'log_actor' => $actorId,
114 'log_namespace' => $this->target->getNamespace(),
115 'log_title' => $this->target->getDBkey(),
116 'log_page' => $this->target->getArticleID(),
117 'log_params' => $this->params
119 $data += MediaWikiServices::getInstance()->getCommentStore()->insert(
124 $dbw->insert(
'logging', $data, __METHOD__ );
125 $newId = $dbw->insertId();
127 # And update recentchanges
128 if ( $this->updateRecentChanges ) {
132 $now, $titleObj, $this->performer, $this->
getRcComment(),
'',
133 $this->type, $this->action, $this->target, $this->comment,
136 } elseif ( $this->sendToUDP ) {
137 # Don't send private logs to UDP
138 if ( isset( $logRestrictions[$this->type] ) && $logRestrictions[$this->type] !=
'*' ) {
146 $now, $titleObj, $this->performer, $this->
getRcComment(),
'',
147 $this->type, $this->action, $this->target, $this->comment,
150 $rc->notifyRCFeeds();
162 $rcComment = $this->actionText;
164 if ( $this->comment !=
'' ) {
165 if ( $rcComment ==
'' ) {
166 $rcComment = $this->comment;
168 $rcComment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() .
182 $rcComment = $this->ircActionText;
184 if ( $this->comment !=
'' ) {
185 if ( $rcComment ==
'' ) {
186 $rcComment = $this->comment;
188 $rcComment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() .
201 return $this->comment;
210 $logTypes = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogTypes );
222 return in_array(
$type, self::validTypes() );
239 $params = [], $filterWikilinks =
false
242 $config = MediaWikiServices::getInstance()->getMainConfig();
243 $logActionsHandlers = $config->get( MainConfigNames::LogActionsHandlers );
244 $key =
"$type/$action";
246 if ( isset( $logActionsHandlers[$key] ) ) {
247 $args = func_get_args();
248 $rv = call_user_func_array( $logActionsHandlers[$key], $args );
250 $logActions = $config->get( MainConfigNames::LogActions );
252 if ( isset( $logActions[$key] ) ) {
253 $message = $logActions[$key];
255 wfDebug(
"LogPage::actionText - unknown action $key" );
256 $message =
"log-unknown-action";
260 if ( $skin ===
null ) {
261 $langObj = MediaWikiServices::getInstance()->getContentLanguage();
262 $langObjOrNull =
null;
265 StubUserLang::unstub(
$wgLang );
270 $rv =
wfMessage( $message )->inLanguage( $langObj )->escaped();
272 $titleLink = self::getTitleLink(
$title, $langObjOrNull );
274 if ( count( $params ) == 0 ) {
275 $rv =
wfMessage( $message )->rawParams( $titleLink )
276 ->inLanguage( $langObj )->escaped();
278 array_unshift( $params, $titleLink );
280 $rv =
wfMessage( $message )->rawParams( $params )
281 ->inLanguage( $langObj )->escaped();
296 if ( $filterWikilinks ) {
297 $rv = str_replace(
'[[',
'', $rv );
298 $rv = str_replace(
']]',
'', $rv );
311 return $title->getPrefixedText();
314 $services = MediaWikiServices::getInstance();
315 $linkRenderer = $services->getLinkRenderer();
317 if (
$title->isSpecialPage() ) {
318 [ $name, $par ] = $services->getSpecialPageFactory()->resolveAlias(
$title->getDBkey() );
320 if ( $name ===
'Log' ) {
321 $logPage =
new LogPage( $par );
323 ->rawParams( $linkRenderer->makeLink(
$title, $logPage->getName()->text() ) )
324 ->inLanguage(
$lang )
329 return $linkRenderer->makeLink(
$title );
345 public function addEntry( $action, $target, $comment, $params, $performer ) {
347 if ( !is_array( $params ) ) {
348 $params = [ $params ];
351 # Trim spaces on user supplied text
352 $comment = trim( $comment ??
'' );
354 $this->action = $action;
355 $this->target = $target;
356 $this->comment = $comment;
357 $this->params = self::makeParamBlob( $params );
359 if ( !is_object( $performer ) ) {
363 $this->performer = $performer;
366 $logEntry->setTarget( $target );
367 $logEntry->setPerformer( $performer );
368 $logEntry->setParameters( $params );
372 $logEntry->setLegacy(
true );
376 $formatter->setContext( $context );
378 $this->actionText = $formatter->getPlainActionText();
379 $this->ircActionText = $formatter->getIRCActionText();
381 return $this->saveContent();
393 if ( !strlen( $field ) || empty( $values ) ) {
399 foreach ( $values as $value ) {
401 'ls_field' => $field,
402 'ls_value' => $value,
403 'ls_log_id' => $logid
408 $dbw->insert(
'log_search', $data, __METHOD__, [
'IGNORE' ] );
420 return implode(
"\n", $params );
430 if (
$blob ===
'' ) {
433 return explode(
"\n",
$blob );
443 $logNames = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogNames );
457 $logHeaders = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogHeaders );
470 $logRestrictions = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogRestrictions );
482 $restriction = $this->getRestriction();
484 return $restriction !==
'' && $restriction !==
'*';
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode) $wgLang
if(!defined('MW_SETUP_CALLBACK'))
Base class for language-specific code.
Class to simplify the use of log pages.
static actionText( $type, $action, $title=null, $skin=null, $params=[], $filterWikilinks=false)
Generate text for a log entry.
getRestriction()
Returns the right needed to read this log type.
__construct( $type, $rc=true, $udp='skipUDP')
static makeParamBlob( $params)
Create a blob from a parameter array.
isRestricted()
Tells if this log is not viewable by all.
static extractParams( $blob)
Extract a parameter array from a blob.
static isLogType( $type)
Is $type a valid log type.
getName()
Name of the log.
getComment()
Get the comment from the last addEntry() call.
bool $updateRecentChanges
getRcComment()
Get the RC comment from the last addEntry() call.
addRelations( $field, $values, $logid)
Add relations to log_search table.
static validTypes()
Get the list of valid log types.
getRcCommentIRC()
Get the RC comment from the last addEntry() call for IRC.
getDescription()
Description of this log type.
addEntry( $action, $target, $comment, $params, $performer)
Add a log entry.
Class for creating new log entries and inserting them into the database.
A class containing constants representing the names of configuration variables.
static newLogEntry( $timestamp, $logPage, $user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='', $revId=0, $isPatrollable=false, $forceBotFlag=null)
static notifyLog( $timestamp, $logPage, $user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='')
static newExtraneousContext(Title $title, $request=[])
Create a new extraneous context.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
static newFromId( $id)
Static factory method for creation from a given user ID.
if(!isset( $args[0])) $lang