67 private $ircActionText;
101 public function __construct( $type, $rc =
true, $udp =
'skipUDP' ) {
103 $this->updateRecentChanges = $rc;
104 $this->sendToUDP = ( $udp ==
'UDP' );
117 ->acquireActorId( $this->performer, $dbw );
119 'log_type' => $this->type,
120 'log_action' => $this->action,
121 'log_timestamp' => $dbw->timestamp( $now ),
122 'log_actor' => $actorId,
123 'log_namespace' => $this->target->getNamespace(),
124 'log_title' => $this->target->getDBkey(),
125 'log_page' => $this->target->getArticleID(),
126 'log_params' => $this->params
133 $dbw->newInsertQueryBuilder()
134 ->insertInto(
'logging' )
136 ->caller( __METHOD__ )->execute();
137 $newId = $dbw->insertId();
139 # And update recentchanges
140 if ( $this->updateRecentChanges ) {
143 RecentChange::notifyLog(
144 $now, $titleObj, $this->performer, $this->
getRcComment(),
'',
145 $this->type, $this->action, $this->target, $this->comment,
148 } elseif ( $this->sendToUDP ) {
149 # Don't send private logs to UDP
150 if ( isset( $logRestrictions[$this->type] ) && $logRestrictions[$this->type] !=
'*' ) {
157 $rc = RecentChange::newLogEntry(
158 $now, $titleObj, $this->performer, $this->
getRcComment(),
'',
159 $this->type, $this->action, $this->target, $this->comment,
162 $rc->notifyRCFeeds();
174 $rcComment = $this->actionText;
176 if ( $this->comment !=
'' ) {
177 if ( $rcComment ==
'' ) {
178 $rcComment = $this->comment;
180 $rcComment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() .
194 $rcComment = $this->ircActionText;
196 if ( $this->comment !=
'' ) {
197 if ( $rcComment ==
'' ) {
198 $rcComment = $this->comment;
200 $rcComment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() .
213 return $this->comment;
234 return in_array( $type, self::validTypes() );
250 public static function actionText( $type, $action, $title =
null, $skin =
null,
251 $params = [], $filterWikilinks =
false
255 $key =
"$type/$action";
259 if ( isset( $logActions[$key] ) ) {
260 $message = $logActions[$key];
262 wfDebug(
"LogPage::actionText - unknown action $key" );
263 $message =
"log-unknown-action";
267 if ( $skin ===
null ) {
269 $langObjOrNull =
null;
272 StubUserLang::unstub(
$wgLang );
276 if ( $title ===
null ) {
277 $rv =
wfMessage( $message )->inLanguage( $langObj )->escaped();
279 $titleLink = self::getTitleLink( $title, $langObjOrNull );
281 if ( count( $params ) == 0 ) {
282 $rv =
wfMessage( $message )->rawParams( $titleLink )
283 ->inLanguage( $langObj )->escaped();
285 array_unshift( $params, $titleLink );
287 $rv =
wfMessage( $message )->rawParams( $params )
288 ->inLanguage( $langObj )->escaped();
302 if ( $filterWikilinks ) {
303 $rv = str_replace(
'[[',
'', $rv );
304 $rv = str_replace(
']]',
'', $rv );
315 private static function getTitleLink(
Title $title, ?
Language $lang ): string {
321 $linkRenderer = $services->getLinkRenderer();
324 [ $name, $par ] = $services->getSpecialPageFactory()->resolveAlias( $title->
getDBkey() );
326 if ( $name ===
'Log' ) {
327 $logPage =
new LogPage( $par );
329 ->rawParams( $linkRenderer->makeLink( $title, $logPage->getName()->text() ) )
330 ->inLanguage( $lang )
335 return $linkRenderer->makeLink( $title );
351 public function addEntry( $action, $target, $comment, $params, $performer ) {
353 if ( !is_array( $params ) ) {
354 $params = [ $params ];
357 # Trim spaces on user supplied text
358 $comment = trim( $comment ??
'' );
360 $this->action = $action;
361 $this->target = $target;
362 $this->comment = $comment;
363 $this->params = self::makeParamBlob( $params );
365 if ( !is_object( $performer ) ) {
366 $performer = User::newFromId( $performer );
369 $this->performer = $performer;
372 $logEntry->setTarget( $target );
373 $logEntry->setPerformer( $performer );
374 $logEntry->setParameters( $params );
378 $logEntry->setLegacy(
true );
381 $context = RequestContext::newExtraneousContext( $target );
382 $formatter->setContext( $context );
384 $this->actionText = $formatter->getPlainActionText();
385 $this->ircActionText = $formatter->getIRCActionText();
387 return $this->saveContent();
397 return implode(
"\n", $params );
407 if ( $blob ===
'' ) {
410 return explode(
"\n", $blob );
423 $key = $logNames[$this->type] ??
'log-name-' . $this->type;
436 $key = $logHeaders[$this->type] ??
'log-description-' . $this->type;
450 return $logRestrictions[$this->type] ??
'';
459 $restriction = $this->getRestriction();
461 return $restriction !==
'' && $restriction !==
'*';
466class_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(!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,...
The base class for all skins.