52 private $ircActionText;
86 public function __construct( $type, $rc =
true, $udp =
'skipUDP' ) {
88 $this->updateRecentChanges = $rc;
89 $this->sendToUDP = ( $udp ==
'UDP' );
98 $recentChangeStore = $services->getRecentChangeStore();
99 $recentChangeRCFeedNotifier = $services->getRecentChangeRCFeedNotifier();
100 $dbw = $services->getConnectionProvider()->getPrimaryDatabase();
103 $actorId = $services->getActorNormalization()
104 ->acquireActorId( $this->performer, $dbw );
106 'log_type' => $this->type,
107 'log_action' => $this->action,
108 'log_timestamp' => $dbw->timestamp( $now ),
109 'log_actor' => $actorId,
110 'log_namespace' => $this->target->getNamespace(),
111 'log_title' => $this->target->getDBkey(),
112 'log_page' => $this->target->getArticleID(),
113 'log_params' => $this->params
115 $data += $services->getCommentStore()->insert(
120 $dbw->newInsertQueryBuilder()
121 ->insertInto(
'logging' )
123 ->caller( __METHOD__ )->execute();
124 $newId = $dbw->insertId();
127 if ( isset( $logRestrictions[$this->type] ) && $logRestrictions[$this->type] !=
'*' ) {
131 if ( $this->updateRecentChanges ) {
134 $recentChange = $recentChangeStore->createLogRecentChange(
135 $now, $titleObj, $this->performer, $this->
getRcComment(),
'',
136 $this->type, $this->action, $this->target, $this->comment,
139 $recentChangeStore->insertRecentChange( $recentChange );
140 } elseif ( $this->sendToUDP ) {
144 $recentChange = $recentChangeStore->createLogRecentChange(
145 $now, $titleObj, $this->performer, $this->
getRcComment(),
'',
146 $this->type, $this->action, $this->target, $this->comment,
149 $recentChangeRCFeedNotifier->notifyRCFeeds( $recentChange );
161 $rcComment = $this->actionText;
163 if ( $this->comment !=
'' ) {
164 if ( $rcComment ==
'' ) {
165 $rcComment = $this->comment;
167 $rcComment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() .
181 $rcComment = $this->ircActionText;
183 if ( $this->comment !=
'' ) {
184 if ( $rcComment ==
'' ) {
185 $rcComment = $this->comment;
187 $rcComment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() .
200 return $this->comment;
221 return in_array( $type, self::validTypes() );
237 public static function actionText( $type, $action, $title =
null, $skin =
null,
238 $params = [], $filterWikilinks =
false
242 $key =
"$type/$action";
246 if ( isset( $logActions[$key] ) ) {
247 $message = $logActions[$key];
249 wfDebug(
"LogPage::actionText - unknown action $key" );
250 $message =
"log-unknown-action";
254 if ( $skin ===
null ) {
256 $langObjOrNull =
null;
259 StubUserLang::unstub(
$wgLang );
263 if ( $title ===
null ) {
264 $rv =
wfMessage( $message )->inLanguage( $langObj )->escaped();
266 $titleLink = self::getTitleLink( $title, $langObjOrNull );
268 if ( count( $params ) == 0 ) {
269 $rv =
wfMessage( $message )->rawParams( $titleLink )
270 ->inLanguage( $langObj )->escaped();
272 array_unshift( $params, $titleLink );
274 $rv =
wfMessage( $message )->rawParams( $params )
275 ->inLanguage( $langObj )->escaped();
289 if ( $filterWikilinks ) {
290 $rv = str_replace(
'[[',
'', $rv );
291 $rv = str_replace(
']]',
'', $rv );
302 private static function getTitleLink(
Title $title, ?
Language $lang ): string {
308 $linkRenderer = $services->getLinkRenderer();
311 [ $name, $par ] = $services->getSpecialPageFactory()->resolveAlias( $title->
getDBkey() );
313 if ( $name ===
'Log' ) {
314 $logPage =
new LogPage( $par ??
'' );
316 ->rawParams( $linkRenderer->makeLink( $title, $logPage->getName()->text() ) )
317 ->inLanguage( $lang )
322 return $linkRenderer->makeLink( $title );
338 public function addEntry( $action, $target, $comment, $params, $performer ) {
340 if ( !is_array( $params ) ) {
341 $params = [ $params ];
344 # Trim spaces on user supplied text
345 $comment = trim( $comment ??
'' );
347 $this->action = $action;
348 $this->target = $target;
349 $this->comment = $comment;
350 $this->params = self::makeParamBlob( $params );
352 if ( !is_object( $performer ) ) {
353 $performer = User::newFromId( $performer );
356 $this->performer = $performer;
359 $logEntry->setTarget( $target );
360 $logEntry->setPerformer( $performer );
361 $logEntry->setParameters( $params );
365 $logEntry->setLegacy(
true );
368 $context = RequestContext::newExtraneousContext( $target );
369 $formatter->setContext( $context );
371 $this->actionText = $formatter->getPlainActionText();
372 $this->ircActionText = $formatter->getIRCActionText();
374 return $this->saveContent();
384 return implode(
"\n", $params );
394 if ( $blob ===
'' ) {
397 return explode(
"\n", $blob );
410 $key = $logNames[$this->type] ??
'log-name-' . $this->type;
423 $key = $logHeaders[$this->type] ??
'log-description-' . $this->type;
437 return $logRestrictions[$this->type] ??
'';
446 $restriction = $this->getRestriction();
448 return $restriction !==
'' && $restriction !==
'*';
453class_alias( LogPage::class,
'LogPage' );
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(MW_ENTRY_POINT==='index') if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgLang
if(!defined('MW_SETUP_CALLBACK'))
Group all the pieces relevant to the context of a request into one instance.
Class to simplify the use of log pages.
static validTypes()
Get the list of valid log types.
getComment()
Get the comment from the last addEntry() call.
__construct( $type, $rc=true, $udp='skipUDP')
getRcComment()
Get the RC comment from the last addEntry() call.
getRestriction()
Returns the right needed to read this log type.
getDescription()
Description of this log type.
static actionText( $type, $action, $title=null, $skin=null, $params=[], $filterWikilinks=false)
Generate text for a log entry.
addEntry( $action, $target, $comment, $params, $performer)
Add a log entry.
getRcCommentIRC()
Get the RC comment from the last addEntry() call for IRC.
static makeParamBlob( $params)
Create a blob from a parameter array.
getName()
Name of the log.
static isLogType( $type)
Is $type a valid log type.
bool $updateRecentChanges
isRestricted()
Tells if this log is not viewable by all.
static extractParams( $blob)
Extract a parameter array from a blob.
Class for creating new log entries and inserting them into the database.
A class containing constants representing the names of configuration variables.
const LogRestrictions
Name constant for the LogRestrictions setting, for use with Config::get()
const LogNames
Name constant for the LogNames setting, for use with Config::get()
const LogTypes
Name constant for the LogTypes setting, for use with Config::get()
const LogHeaders
Name constant for the LogHeaders setting, for use with Config::get()
const LogActions
Name constant for the LogActions setting, for use with Config::get()
Parent class for all special pages.
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,...