62 private $ircActionText;
96 public function __construct( $type, $rc =
true, $udp =
'skipUDP' ) {
98 $this->updateRecentChanges = $rc;
99 $this->sendToUDP = ( $udp ==
'UDP' );
106 $logRestrictions = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogRestrictions );
108 $dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase();
111 $actorId = MediaWikiServices::getInstance()->getActorNormalization()
112 ->acquireActorId( $this->performer, $dbw );
114 'log_type' => $this->type,
115 'log_action' => $this->action,
116 'log_timestamp' => $dbw->timestamp( $now ),
117 'log_actor' => $actorId,
118 'log_namespace' => $this->target->getNamespace(),
119 'log_title' => $this->target->getDBkey(),
120 'log_page' => $this->target->getArticleID(),
123 $data += MediaWikiServices::getInstance()->getCommentStore()->insert(
128 $dbw->newInsertQueryBuilder()
129 ->insertInto(
'logging' )
131 ->caller( __METHOD__ )->execute();
132 $newId = $dbw->insertId();
134 # And update recentchanges
135 if ( $this->updateRecentChanges ) {
136 $titleObj = SpecialPage::getTitleFor(
'Log', $this->type );
138 RecentChange::notifyLog(
139 $now, $titleObj, $this->performer, $this->
getRcComment(),
'',
140 $this->type, $this->action, $this->target, $this->comment,
143 } elseif ( $this->sendToUDP ) {
144 # Don't send private logs to UDP
145 if ( isset( $logRestrictions[$this->type] ) && $logRestrictions[$this->type] !=
'*' ) {
151 $titleObj = SpecialPage::getTitleFor(
'Log', $this->type );
152 $rc = RecentChange::newLogEntry(
153 $now, $titleObj, $this->performer, $this->
getRcComment(),
'',
154 $this->type, $this->action, $this->target, $this->comment,
157 $rc->notifyRCFeeds();
169 $rcComment = $this->actionText;
171 if ( $this->comment !=
'' ) {
172 if ( $rcComment ==
'' ) {
173 $rcComment = $this->comment;
175 $rcComment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() .
189 $rcComment = $this->ircActionText;
191 if ( $this->comment !=
'' ) {
192 if ( $rcComment ==
'' ) {
193 $rcComment = $this->comment;
195 $rcComment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() .
208 return $this->comment;
217 $logTypes = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogTypes );
229 return in_array( $type, self::validTypes() );
245 public static function actionText( $type, $action, $title =
null, $skin =
null,
246 $params = [], $filterWikilinks =
false
249 $config = MediaWikiServices::getInstance()->getMainConfig();
250 $key =
"$type/$action";
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 );
277 $rv =
wfMessage( $message )->rawParams( $titleLink )
278 ->inLanguage( $langObj )->escaped();
280 array_unshift(
$params, $titleLink );
283 ->inLanguage( $langObj )->escaped();
297 if ( $filterWikilinks ) {
298 $rv = str_replace(
'[[',
'', $rv );
299 $rv = str_replace(
']]',
'', $rv );
310 private static function getTitleLink(
Title $title, ?Language $lang ): string {
315 $services = MediaWikiServices::getInstance();
316 $linkRenderer = $services->getLinkRenderer();
319 [ $name, $par ] = $services->getSpecialPageFactory()->resolveAlias( $title->
getDBkey() );
321 if ( $name ===
'Log' ) {
322 $logPage =
new LogPage( $par );
324 ->rawParams( $linkRenderer->makeLink( $title, $logPage->getName()->text() ) )
325 ->inLanguage( $lang )
330 return $linkRenderer->makeLink( $title );
352 # Trim spaces on user supplied text
353 $comment = trim( $comment ??
'' );
355 $this->action = $action;
356 $this->target = $target;
357 $this->comment = $comment;
358 $this->params = self::makeParamBlob(
$params );
360 if ( !is_object( $performer ) ) {
361 $performer = User::newFromId( $performer );
364 $this->performer = $performer;
367 $logEntry->setTarget( $target );
368 $logEntry->setPerformer( $performer );
369 $logEntry->setParameters(
$params );
373 $logEntry->setLegacy(
true );
375 $formatter = MediaWikiServices::getInstance()->getLogFormatterFactory()->newFromEntry( $logEntry );
376 $context = RequestContext::newExtraneousContext( $target );
377 $formatter->setContext( $context );
379 $this->actionText = $formatter->getPlainActionText();
380 $this->ircActionText = $formatter->getIRCActionText();
382 return $this->saveContent();
394 if ( !strlen( $field ) || !$values ) {
397 $insert = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase()
398 ->newInsertQueryBuilder()
399 ->insertInto(
'log_search' )
401 foreach ( $values as $value ) {
402 $insert->row( [
'ls_field' => $field,
'ls_value' => $value,
'ls_log_id' => $logid ] );
404 $insert->caller( __METHOD__ )->execute();
416 return implode(
"\n",
$params );
426 if ( $blob ===
'' ) {
429 return explode(
"\n", $blob );
439 $logNames = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogNames );
442 $key = $logNames[$this->type] ??
'log-name-' . $this->type;
453 $logHeaders = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogHeaders );
455 $key = $logHeaders[$this->type] ??
'log-description-' . $this->type;
466 $logRestrictions = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogRestrictions );
469 return $logRestrictions[$this->type] ??
'';
478 $restriction = $this->getRestriction();
480 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.