63 private $ircActionText;
97 public function __construct( $type, $rc =
true, $udp =
'skipUDP' ) {
99 $this->updateRecentChanges = $rc;
100 $this->sendToUDP = ( $udp ==
'UDP' );
107 $logRestrictions = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogRestrictions );
109 $dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase();
112 $actorId = MediaWikiServices::getInstance()->getActorNormalization()
113 ->acquireActorId( $this->performer, $dbw );
115 'log_type' => $this->type,
116 'log_action' => $this->action,
117 'log_timestamp' => $dbw->timestamp( $now ),
118 'log_actor' => $actorId,
119 'log_namespace' => $this->target->getNamespace(),
120 'log_title' => $this->target->getDBkey(),
121 'log_page' => $this->target->getArticleID(),
124 $data += MediaWikiServices::getInstance()->getCommentStore()->insert(
129 $dbw->newInsertQueryBuilder()
130 ->insertInto(
'logging' )
132 ->caller( __METHOD__ )->execute();
133 $newId = $dbw->insertId();
135 # And update recentchanges
136 if ( $this->updateRecentChanges ) {
137 $titleObj = SpecialPage::getTitleFor(
'Log', $this->type );
139 RecentChange::notifyLog(
140 $now, $titleObj, $this->performer, $this->
getRcComment(),
'',
141 $this->type, $this->action, $this->target, $this->comment,
144 } elseif ( $this->sendToUDP ) {
145 # Don't send private logs to UDP
146 if ( isset( $logRestrictions[$this->type] ) && $logRestrictions[$this->type] !=
'*' ) {
152 $titleObj = SpecialPage::getTitleFor(
'Log', $this->type );
153 $rc = RecentChange::newLogEntry(
154 $now, $titleObj, $this->performer, $this->
getRcComment(),
'',
155 $this->type, $this->action, $this->target, $this->comment,
158 $rc->notifyRCFeeds();
170 $rcComment = $this->actionText;
172 if ( $this->comment !=
'' ) {
173 if ( $rcComment ==
'' ) {
174 $rcComment = $this->comment;
176 $rcComment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() .
190 $rcComment = $this->ircActionText;
192 if ( $this->comment !=
'' ) {
193 if ( $rcComment ==
'' ) {
194 $rcComment = $this->comment;
196 $rcComment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() .
209 return $this->comment;
218 $logTypes = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogTypes );
230 return in_array( $type, self::validTypes() );
246 public static function actionText( $type, $action, $title =
null, $skin =
null,
247 $params = [], $filterWikilinks =
false
250 $config = MediaWikiServices::getInstance()->getMainConfig();
251 $key =
"$type/$action";
253 $logActions = $config->get( MainConfigNames::LogActions );
255 if ( isset( $logActions[$key] ) ) {
256 $message = $logActions[$key];
258 wfDebug(
"LogPage::actionText - unknown action $key" );
259 $message =
"log-unknown-action";
263 if ( $skin ===
null ) {
264 $langObj = MediaWikiServices::getInstance()->getContentLanguage();
265 $langObjOrNull =
null;
268 StubUserLang::unstub(
$wgLang );
272 if ( $title ===
null ) {
273 $rv =
wfMessage( $message )->inLanguage( $langObj )->escaped();
275 $titleLink = self::getTitleLink( $title, $langObjOrNull );
278 $rv =
wfMessage( $message )->rawParams( $titleLink )
279 ->inLanguage( $langObj )->escaped();
281 array_unshift(
$params, $titleLink );
284 ->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 );
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 = MediaWikiServices::getInstance()->getLogFormatterFactory()->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 ) {
398 $insert = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase()
399 ->newInsertQueryBuilder()
400 ->insertInto(
'log_search' )
402 foreach ( $values as $value ) {
403 $insert->row( [
'ls_field' => $field,
'ls_value' => $value,
'ls_log_id' => $logid ] );
405 $insert->caller( __METHOD__ )->execute();
417 return implode(
"\n",
$params );
427 if ( $blob ===
'' ) {
430 return explode(
"\n", $blob );
440 $logNames = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogNames );
443 $key = $logNames[$this->type] ??
'log-name-' . $this->type;
454 $logHeaders = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogHeaders );
456 $key = $logHeaders[$this->type] ??
'log-description-' . $this->type;
467 $logRestrictions = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogRestrictions );
470 return $logRestrictions[$this->type] ??
'';
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.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgLang
array $params
The job parameters.
if(!defined('MW_SETUP_CALLBACK'))
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.
Group all the pieces relevant to the context of a request into one instance.
A class containing constants representing the names of configuration variables.
Parent class for all special pages.