58 private $ircActionText;
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 );
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 ) {
131 RecentChange::notifyLog(
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] !=
'*' ) {
145 $rc = RecentChange::newLogEntry(
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 $logActions = $config->get( MainConfigNames::LogActions );
244 $key =
"$type/$action";
246 if ( isset( $logActions[$key] ) ) {
247 if ( $skin ===
null ) {
248 $langObj = MediaWikiServices::getInstance()->getContentLanguage();
249 $langObjOrNull =
null;
252 StubUserLang::unstub(
$wgLang );
257 $rv =
wfMessage( $logActions[$key] )->inLanguage( $langObj )->escaped();
259 $titleLink = self::getTitleLink(
$title, $langObjOrNull );
261 if ( count( $params ) == 0 ) {
262 $rv =
wfMessage( $logActions[$key] )->rawParams( $titleLink )
263 ->inLanguage( $langObj )->escaped();
265 array_unshift( $params, $titleLink );
267 $rv =
wfMessage( $logActions[$key] )->rawParams( $params )
268 ->inLanguage( $langObj )->escaped();
272 $logActionsHandlers = $config->get( MainConfigNames::LogActionsHandlers );
274 if ( isset( $logActionsHandlers[$key] ) ) {
275 $args = func_get_args();
276 $rv = call_user_func_array( $logActionsHandlers[$key], $args );
278 wfDebug(
"LogPage::actionText - unknown action $key" );
293 if ( $filterWikilinks ) {
294 $rv = str_replace(
'[[',
'', $rv );
295 $rv = str_replace(
']]',
'', $rv );
308 return $title->getPrefixedText();
311 $services = MediaWikiServices::getInstance();
312 $linkRenderer = $services->getLinkRenderer();
314 if (
$title->isSpecialPage() ) {
315 [ $name, $par ] = $services->getSpecialPageFactory()->resolveAlias(
$title->getDBkey() );
317 if ( $name ===
'Log' ) {
318 $logPage =
new LogPage( $par );
320 ->rawParams( $linkRenderer->makeLink(
$title, $logPage->getName()->text() ) )
321 ->inLanguage(
$lang )
326 return $linkRenderer->makeLink(
$title );
342 public function addEntry( $action, $target, $comment, $params, $performer ) {
344 if ( !is_array( $params ) ) {
345 $params = [ $params ];
348 # Trim spaces on user supplied text
349 $comment = trim( $comment ??
'' );
351 $this->action = $action;
352 $this->target = $target;
353 $this->comment = $comment;
354 $this->params = self::makeParamBlob( $params );
356 if ( !is_object( $performer ) ) {
360 $this->performer = $performer;
363 $logEntry->setTarget( $target );
364 $logEntry->setPerformer( $performer );
365 $logEntry->setParameters( $params );
369 $logEntry->setLegacy(
true );
371 $formatter = LogFormatter::newFromEntry( $logEntry );
372 $context = RequestContext::newExtraneousContext( $target );
373 $formatter->setContext( $context );
375 $this->actionText = $formatter->getPlainActionText();
376 $this->ircActionText = $formatter->getIRCActionText();
378 return $this->saveContent();
390 if ( !strlen( $field ) || empty( $values ) ) {
396 foreach ( $values as $value ) {
398 'ls_field' => $field,
399 'ls_value' => $value,
400 'ls_log_id' => $logid
405 $dbw->insert(
'log_search', $data, __METHOD__, [
'IGNORE' ] );
417 return implode(
"\n", $params );
427 if (
$blob ===
'' ) {
430 return explode(
"\n",
$blob );
440 $logNames = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogNames );
454 $logHeaders = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogHeaders );
467 $logRestrictions = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogRestrictions );
479 $restriction = $this->getRestriction();
481 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'))
The persistent session ID (if any) loaded at startup.
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 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