60 private $ircActionText;
94 public function __construct( $type, $rc =
true, $udp =
'skipUDP' ) {
96 $this->updateRecentChanges = $rc;
97 $this->sendToUDP = ( $udp ==
'UDP' );
104 $logRestrictions = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogRestrictions );
109 $actorId = MediaWikiServices::getInstance()->getActorNormalization()
110 ->acquireActorId( $this->performer, $dbw );
112 'log_type' => $this->type,
113 'log_action' => $this->action,
114 'log_timestamp' => $dbw->timestamp( $now ),
115 'log_actor' => $actorId,
116 'log_namespace' => $this->target->getNamespace(),
117 'log_title' => $this->target->getDBkey(),
118 'log_page' => $this->target->getArticleID(),
119 'log_params' => $this->params
121 $data += MediaWikiServices::getInstance()->getCommentStore()->insert(
126 $dbw->insert(
'logging', $data, __METHOD__ );
127 $newId = $dbw->insertId();
129 # And update recentchanges
130 if ( $this->updateRecentChanges ) {
131 $titleObj = SpecialPage::getTitleFor(
'Log', $this->type );
133 RecentChange::notifyLog(
134 $now, $titleObj, $this->performer, $this->
getRcComment(),
'',
135 $this->type, $this->action, $this->target, $this->comment,
138 } elseif ( $this->sendToUDP ) {
139 # Don't send private logs to UDP
140 if ( isset( $logRestrictions[$this->type] ) && $logRestrictions[$this->type] !=
'*' ) {
146 $titleObj = SpecialPage::getTitleFor(
'Log', $this->type );
147 $rc = RecentChange::newLogEntry(
148 $now, $titleObj, $this->performer, $this->
getRcComment(),
'',
149 $this->type, $this->action, $this->target, $this->comment,
152 $rc->notifyRCFeeds();
164 $rcComment = $this->actionText;
166 if ( $this->comment !=
'' ) {
167 if ( $rcComment ==
'' ) {
168 $rcComment = $this->comment;
170 $rcComment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() .
184 $rcComment = $this->ircActionText;
186 if ( $this->comment !=
'' ) {
187 if ( $rcComment ==
'' ) {
188 $rcComment = $this->comment;
190 $rcComment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() .
203 return $this->comment;
212 $logTypes = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogTypes );
224 return in_array( $type, self::validTypes() );
240 public static function actionText( $type, $action, $title =
null, $skin =
null,
241 $params = [], $filterWikilinks =
false
244 $config = MediaWikiServices::getInstance()->getMainConfig();
245 $logActionsHandlers = $config->get( MainConfigNames::LogActionsHandlers );
246 $key =
"$type/$action";
248 if ( isset( $logActionsHandlers[$key] ) ) {
249 $args = func_get_args();
250 $rv = call_user_func_array( $logActionsHandlers[$key], $args );
252 $logActions = $config->get( MainConfigNames::LogActions );
254 if ( isset( $logActions[$key] ) ) {
255 $message = $logActions[$key];
257 wfDebug(
"LogPage::actionText - unknown action $key" );
258 $message =
"log-unknown-action";
262 if ( $skin ===
null ) {
263 $langObj = MediaWikiServices::getInstance()->getContentLanguage();
264 $langObjOrNull =
null;
267 StubUserLang::unstub(
$wgLang );
271 if ( $title ===
null ) {
272 $rv =
wfMessage( $message )->inLanguage( $langObj )->escaped();
274 $titleLink = self::getTitleLink( $title, $langObjOrNull );
276 if ( count( $params ) == 0 ) {
277 $rv =
wfMessage( $message )->rawParams( $titleLink )
278 ->inLanguage( $langObj )->escaped();
280 array_unshift( $params, $titleLink );
282 $rv =
wfMessage( $message )->rawParams( $params )
283 ->inLanguage( $langObj )->escaped();
298 if ( $filterWikilinks ) {
299 $rv = str_replace(
'[[',
'', $rv );
300 $rv = str_replace(
']]',
'', $rv );
311 private static function getTitleLink(
Title $title, ?
Language $lang ): string {
316 $services = MediaWikiServices::getInstance();
317 $linkRenderer = $services->getLinkRenderer();
320 [ $name, $par ] = $services->getSpecialPageFactory()->resolveAlias( $title->
getDBkey() );
322 if ( $name ===
'Log' ) {
323 $logPage =
new LogPage( $par );
325 ->rawParams( $linkRenderer->makeLink( $title, $logPage->getName()->text() ) )
326 ->inLanguage( $lang )
331 return $linkRenderer->makeLink( $title );
347 public function addEntry( $action, $target, $comment, $params, $performer ) {
349 if ( !is_array( $params ) ) {
350 $params = [ $params ];
353 # Trim spaces on user supplied text
354 $comment = trim( $comment ??
'' );
356 $this->action = $action;
357 $this->target = $target;
358 $this->comment = $comment;
359 $this->params = self::makeParamBlob( $params );
361 if ( !is_object( $performer ) ) {
362 $performer = User::newFromId( $performer );
365 $this->performer = $performer;
368 $logEntry->setTarget( $target );
369 $logEntry->setPerformer( $performer );
370 $logEntry->setParameters( $params );
374 $logEntry->setLegacy(
true );
376 $formatter = LogFormatter::newFromEntry( $logEntry );
377 $context = RequestContext::newExtraneousContext( $target );
378 $formatter->setContext( $context );
380 $this->actionText = $formatter->getPlainActionText();
381 $this->ircActionText = $formatter->getIRCActionText();
383 return $this->saveContent();
395 if ( !strlen( $field ) || !$values ) {
401 foreach ( $values as $value ) {
403 'ls_field' => $field,
404 'ls_value' => $value,
405 'ls_log_id' => $logid
410 $dbw->insert(
'log_search', $data, __METHOD__, [
'IGNORE' ] );
422 return implode(
"\n", $params );
432 if ( $blob ===
'' ) {
435 return explode(
"\n", $blob );
445 $logNames = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogNames );
448 $key = $logNames[$this->type] ??
'log-name-' . $this->type;
459 $logHeaders = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogHeaders );
461 $key = $logHeaders[$this->type] ??
'log-description-' . $this->type;
472 $logRestrictions = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogRestrictions );
475 return $logRestrictions[$this->type] ??
'';
484 $restriction = $this->getRestriction();
486 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.
Parent class for all special pages.