56 private $ircActionText;
90 public function __construct( $type, $rc =
true, $udp =
'skipUDP' ) {
92 $this->updateRecentChanges = $rc;
93 $this->sendToUDP = ( $udp ==
'UDP' );
100 $logRestrictions = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogRestrictions );
105 $actorId = MediaWikiServices::getInstance()->getActorNormalization()
106 ->acquireActorId( $this->performer, $dbw );
108 'log_type' => $this->type,
109 'log_action' => $this->action,
110 'log_timestamp' => $dbw->timestamp( $now ),
111 'log_actor' => $actorId,
112 'log_namespace' => $this->target->getNamespace(),
113 'log_title' => $this->target->getDBkey(),
114 'log_page' => $this->target->getArticleID(),
115 'log_params' => $this->params
117 $data += MediaWikiServices::getInstance()->getCommentStore()->insert(
122 $dbw->insert(
'logging', $data, __METHOD__ );
123 $newId = $dbw->insertId();
125 # And update recentchanges
126 if ( $this->updateRecentChanges ) {
129 RecentChange::notifyLog(
130 $now, $titleObj, $this->performer, $this->
getRcComment(),
'',
131 $this->type, $this->action, $this->target, $this->comment,
134 } elseif ( $this->sendToUDP ) {
135 # Don't send private logs to UDP
136 if ( isset( $logRestrictions[$this->type] ) && $logRestrictions[$this->type] !=
'*' ) {
143 $rc = RecentChange::newLogEntry(
144 $now, $titleObj, $this->performer, $this->
getRcComment(),
'',
145 $this->type, $this->action, $this->target, $this->comment,
148 $rc->notifyRCFeeds();
160 $rcComment = $this->actionText;
162 if ( $this->comment !=
'' ) {
163 if ( $rcComment ==
'' ) {
164 $rcComment = $this->comment;
166 $rcComment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() .
180 $rcComment = $this->ircActionText;
182 if ( $this->comment !=
'' ) {
183 if ( $rcComment ==
'' ) {
184 $rcComment = $this->comment;
186 $rcComment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() .
199 return $this->comment;
208 $logTypes = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogTypes );
220 return in_array(
$type, self::validTypes() );
237 $params = [], $filterWikilinks =
false
240 $config = MediaWikiServices::getInstance()->getMainConfig();
241 $logActions = $config->get( MainConfigNames::LogActions );
242 $key =
"$type/$action";
244 if ( isset( $logActions[$key] ) ) {
245 if ( $skin ===
null ) {
246 $langObj = MediaWikiServices::getInstance()->getContentLanguage();
247 $langObjOrNull =
null;
250 StubUserLang::unstub(
$wgLang );
255 $rv =
wfMessage( $logActions[$key] )->inLanguage( $langObj )->escaped();
257 $titleLink = self::getTitleLink(
$title, $langObjOrNull );
259 if ( count( $params ) == 0 ) {
260 $rv =
wfMessage( $logActions[$key] )->rawParams( $titleLink )
261 ->inLanguage( $langObj )->escaped();
263 array_unshift( $params, $titleLink );
265 $rv =
wfMessage( $logActions[$key] )->rawParams( $params )
266 ->inLanguage( $langObj )->escaped();
270 $logActionsHandlers = $config->get( MainConfigNames::LogActionsHandlers );
272 if ( isset( $logActionsHandlers[$key] ) ) {
273 $args = func_get_args();
274 $rv = call_user_func_array( $logActionsHandlers[$key],
$args );
276 wfDebug(
"LogPage::actionText - unknown action $key" );
291 if ( $filterWikilinks ) {
292 $rv = str_replace(
'[[',
'', $rv );
293 $rv = str_replace(
']]',
'', $rv );
306 return $title->getPrefixedText();
309 $services = MediaWikiServices::getInstance();
310 $linkRenderer = $services->getLinkRenderer();
312 if (
$title->isSpecialPage() ) {
313 [ $name, $par ] = $services->getSpecialPageFactory()->resolveAlias(
$title->getDBkey() );
315 if ( $name ===
'Log' ) {
316 $logPage =
new LogPage( $par );
318 ->rawParams( $linkRenderer->makeLink(
$title, $logPage->getName()->text() ) )
319 ->inLanguage(
$lang )
324 return $linkRenderer->makeLink(
$title );
340 public function addEntry( $action, $target, $comment, $params, $performer ) {
342 if ( !is_array( $params ) ) {
343 $params = [ $params ];
346 if ( $comment ===
null ) {
350 # Trim spaces on user supplied text
351 $comment = trim( $comment );
353 $this->action = $action;
354 $this->target = $target;
355 $this->comment = $comment;
356 $this->params = self::makeParamBlob( $params );
358 if ( !is_object( $performer ) ) {
362 $this->performer = $performer;
365 $logEntry->setTarget( $target );
366 $logEntry->setPerformer( $performer );
367 $logEntry->setParameters( $params );
371 $logEntry->setLegacy(
true );
373 $formatter = LogFormatter::newFromEntry( $logEntry );
374 $context = RequestContext::newExtraneousContext( $target );
375 $formatter->setContext( $context );
377 $this->actionText = $formatter->getPlainActionText();
378 $this->ircActionText = $formatter->getIRCActionText();
380 return $this->saveContent();
392 if ( !strlen( $field ) || empty( $values ) ) {
398 foreach ( $values as $value ) {
400 'ls_field' => $field,
401 'ls_value' => $value,
402 'ls_log_id' => $logid
407 $dbw->insert(
'log_search', $data, __METHOD__, [
'IGNORE' ] );
419 return implode(
"\n", $params );
429 if (
$blob ===
'' ) {
432 return explode(
"\n",
$blob );
442 $logNames = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogNames );
456 $logHeaders = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogHeaders );
469 $logRestrictions = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogRestrictions );
481 $restriction = $this->getRestriction();
483 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,...
Represents a title within MediaWiki.
static newFromId( $id)
Static factory method for creation from a given user ID.
if(!isset( $args[0])) $lang