61 private $ircActionText;
95 public function __construct( $type, $rc =
true, $udp =
'skipUDP' ) {
97 $this->updateRecentChanges = $rc;
98 $this->sendToUDP = ( $udp ==
'UDP' );
105 $logRestrictions = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogRestrictions );
107 $dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase();
110 $actorId = MediaWikiServices::getInstance()->getActorNormalization()
111 ->acquireActorId( $this->performer, $dbw );
113 'log_type' => $this->type,
114 'log_action' => $this->action,
115 'log_timestamp' => $dbw->timestamp( $now ),
116 'log_actor' => $actorId,
117 'log_namespace' => $this->target->getNamespace(),
118 'log_title' => $this->target->getDBkey(),
119 'log_page' => $this->target->getArticleID(),
122 $data += MediaWikiServices::getInstance()->getCommentStore()->insert(
127 $dbw->newInsertQueryBuilder()
128 ->insertInto(
'logging' )
130 ->caller( __METHOD__ )->execute();
131 $newId = $dbw->insertId();
133 # And update recentchanges
134 if ( $this->updateRecentChanges ) {
135 $titleObj = SpecialPage::getTitleFor(
'Log', $this->type );
137 RecentChange::notifyLog(
138 $now, $titleObj, $this->performer, $this->
getRcComment(),
'',
139 $this->type, $this->action, $this->target, $this->comment,
142 } elseif ( $this->sendToUDP ) {
143 # Don't send private logs to UDP
144 if ( isset( $logRestrictions[$this->type] ) && $logRestrictions[$this->type] !=
'*' ) {
150 $titleObj = SpecialPage::getTitleFor(
'Log', $this->type );
151 $rc = RecentChange::newLogEntry(
152 $now, $titleObj, $this->performer, $this->
getRcComment(),
'',
153 $this->type, $this->action, $this->target, $this->comment,
156 $rc->notifyRCFeeds();
168 $rcComment = $this->actionText;
170 if ( $this->comment !=
'' ) {
171 if ( $rcComment ==
'' ) {
172 $rcComment = $this->comment;
174 $rcComment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() .
188 $rcComment = $this->ircActionText;
190 if ( $this->comment !=
'' ) {
191 if ( $rcComment ==
'' ) {
192 $rcComment = $this->comment;
194 $rcComment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() .
207 return $this->comment;
216 $logTypes = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogTypes );
228 return in_array( $type, self::validTypes() );
244 public static function actionText( $type, $action, $title =
null, $skin =
null,
245 $params = [], $filterWikilinks =
false
248 $config = MediaWikiServices::getInstance()->getMainConfig();
249 $key =
"$type/$action";
251 $logActions = $config->get( MainConfigNames::LogActions );
253 if ( isset( $logActions[$key] ) ) {
254 $message = $logActions[$key];
256 wfDebug(
"LogPage::actionText - unknown action $key" );
257 $message =
"log-unknown-action";
261 if ( $skin ===
null ) {
262 $langObj = MediaWikiServices::getInstance()->getContentLanguage();
263 $langObjOrNull =
null;
266 StubUserLang::unstub(
$wgLang );
270 if ( $title ===
null ) {
271 $rv =
wfMessage( $message )->inLanguage( $langObj )->escaped();
273 $titleLink = self::getTitleLink( $title, $langObjOrNull );
276 $rv =
wfMessage( $message )->rawParams( $titleLink )
277 ->inLanguage( $langObj )->escaped();
279 array_unshift(
$params, $titleLink );
282 ->inLanguage( $langObj )->escaped();
296 if ( $filterWikilinks ) {
297 $rv = str_replace(
'[[',
'', $rv );
298 $rv = str_replace(
']]',
'', $rv );
309 private static function getTitleLink(
Title $title, ?
Language $lang ): string {
314 $services = MediaWikiServices::getInstance();
315 $linkRenderer = $services->getLinkRenderer();
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 );
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 ) ) {
360 $performer = User::newFromId( $performer );
363 $this->performer = $performer;
366 $logEntry->setTarget( $target );
367 $logEntry->setPerformer( $performer );
368 $logEntry->setParameters(
$params );
372 $logEntry->setLegacy(
true );
374 $formatter = LogFormatter::newFromEntry( $logEntry );
375 $context = RequestContext::newExtraneousContext( $target );
376 $formatter->setContext( $context );
378 $this->actionText = $formatter->getPlainActionText();
379 $this->ircActionText = $formatter->getIRCActionText();
381 return $this->saveContent();
393 if ( !strlen( $field ) || !$values ) {
396 $insert = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase()
397 ->newInsertQueryBuilder()
398 ->insertInto(
'log_search' )
400 foreach ( $values as $value ) {
401 $insert->row( [
'ls_field' => $field,
'ls_value' => $value,
'ls_log_id' => $logid ] );
403 $insert->caller( __METHOD__ )->execute();
415 return implode(
"\n",
$params );
425 if ( $blob ===
'' ) {
428 return explode(
"\n", $blob );
438 $logNames = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogNames );
441 $key = $logNames[$this->type] ??
'log-name-' . $this->type;
452 $logHeaders = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogHeaders );
454 $key = $logHeaders[$this->type] ??
'log-description-' . $this->type;
465 $logRestrictions = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogRestrictions );
468 return $logRestrictions[$this->type] ??
'';
477 $restriction = $this->getRestriction();
479 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'))
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.
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.