51 private $ircActionText;
85 public function __construct( $type, $rc =
true, $udp =
'skipUDP' ) {
87 $this->updateRecentChanges = $rc;
88 $this->sendToUDP = ( $udp ==
'UDP' );
97 $recentChangeStore = $services->getRecentChangeStore();
98 $recentChangeRCFeedNotifier = $services->getRecentChangeRCFeedNotifier();
99 $dbw = $services->getConnectionProvider()->getPrimaryDatabase();
102 $actorId = $services->getActorNormalization()
103 ->acquireActorId( $this->performer, $dbw );
105 'log_type' => $this->type,
106 'log_action' => $this->action,
107 'log_timestamp' => $dbw->timestamp( $now ),
108 'log_actor' => $actorId,
109 'log_namespace' => $this->target->getNamespace(),
110 'log_title' => $this->target->getDBkey(),
111 'log_page' => $this->target->getArticleID(),
112 'log_params' => $this->params
114 $data += $services->getCommentStore()->insert(
119 $dbw->newInsertQueryBuilder()
120 ->insertInto(
'logging' )
122 ->caller( __METHOD__ )->execute();
123 $newId = $dbw->insertId();
126 if ( isset( $logRestrictions[$this->type] ) && $logRestrictions[$this->type] !=
'*' ) {
130 if ( $this->updateRecentChanges ) {
133 $recentChange = $recentChangeStore->createLogRecentChange(
134 $now, $titleObj, $this->performer, $this->
getRcComment(),
'',
135 $this->type, $this->action, $this->target, $this->comment,
138 $recentChangeStore->insertRecentChange( $recentChange );
139 } elseif ( $this->sendToUDP ) {
143 $recentChange = $recentChangeStore->createLogRecentChange(
144 $now, $titleObj, $this->performer, $this->
getRcComment(),
'',
145 $this->type, $this->action, $this->target, $this->comment,
148 $recentChangeRCFeedNotifier->notifyRCFeeds( $recentChange );
160 $rcComment = $this->actionText;
162 if ( $this->comment !=
'' ) {
163 if ( $rcComment ==
'' ) {
164 $rcComment = $this->comment;
166 $rcComment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() .
180 $rcComment = $this->ircActionText;
182 if ( $this->comment !=
'' ) {
183 if ( $rcComment ==
'' ) {
184 $rcComment = $this->comment;
186 $rcComment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() .
199 return $this->comment;
220 return in_array( $type, self::validTypes() );
236 public static function actionText( $type, $action, $title =
null, $skin =
null,
237 $params = [], $filterWikilinks =
false
240 $key =
"$type/$action";
244 if ( isset( $logActions[$key] ) ) {
245 $message = $logActions[$key];
247 wfDebug(
"LogPage::actionText - unknown action $key" );
248 $message =
"log-unknown-action";
252 if ( $skin ===
null ) {
254 $langObjOrNull =
null;
256 $langObj = $langObjOrNull = $skin->getLanguage();
258 if ( $title ===
null ) {
259 $rv =
wfMessage( $message )->inLanguage( $langObj )->escaped();
261 $titleLink = self::getTitleLink( $title, $langObjOrNull );
263 if ( count( $params ) == 0 ) {
264 $rv =
wfMessage( $message )->rawParams( $titleLink )
265 ->inLanguage( $langObj )->escaped();
267 array_unshift( $params, $titleLink );
269 $rv =
wfMessage( $message )->rawParams( $params )
270 ->inLanguage( $langObj )->escaped();
284 if ( $filterWikilinks ) {
285 $rv = str_replace(
'[[',
'', $rv );
286 $rv = str_replace(
']]',
'', $rv );
297 private static function getTitleLink(
Title $title, ?
Language $lang ): string {
303 $linkRenderer = $services->getLinkRenderer();
306 [ $name, $par ] = $services->getSpecialPageFactory()->resolveAlias( $title->
getDBkey() );
308 if ( $name ===
'Log' ) {
309 $logPage =
new LogPage( $par ??
'' );
311 ->rawParams( $linkRenderer->makeLink( $title, $logPage->getName()->text() ) )
312 ->inLanguage( $lang )
317 return $linkRenderer->makeLink( $title );
333 public function addEntry( $action, $target, $comment, $params, $performer ) {
335 if ( !is_array( $params ) ) {
336 $params = [ $params ];
339 # Trim spaces on user supplied text
340 $comment = trim( $comment ??
'' );
342 $this->action = $action;
343 $this->target = $target;
344 $this->comment = $comment;
345 $this->params = self::makeParamBlob( $params );
347 if ( !is_object( $performer ) ) {
348 $performer = User::newFromId( $performer );
351 $this->performer = $performer;
354 $logEntry->setTarget( $target );
355 $logEntry->setPerformer( $performer );
356 $logEntry->setParameters( $params );
360 $logEntry->setLegacy(
true );
363 $context = RequestContext::newExtraneousContext( $target );
364 $formatter->setContext( $context );
366 $this->actionText = $formatter->getPlainActionText();
367 $this->ircActionText = $formatter->getIRCActionText();
369 return $this->saveContent();
379 return implode(
"\n", $params );
389 if ( $blob ===
'' ) {
392 return explode(
"\n", $blob );
405 $key = $logNames[$this->type] ??
'log-name-' . $this->type;
418 $key = $logHeaders[$this->type] ??
'log-description-' . $this->type;
432 return $logRestrictions[$this->type] ??
'';
441 $restriction = $this->getRestriction();
443 return $restriction !==
'' && $restriction !==
'*';
448class_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_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,...