MediaWiki REL1_33
LogPage.php
Go to the documentation of this file.
1<?php
27
33class LogPage {
34 const DELETED_ACTION = 1;
35 const DELETED_COMMENT = 2;
36 const DELETED_USER = 4;
38
39 // Convenience fields
40 const SUPPRESSED_USER = self::DELETED_USER | self::DELETED_RESTRICTED;
41 const SUPPRESSED_ACTION = self::DELETED_ACTION | self::DELETED_RESTRICTED;
42
45
47 public $sendToUDP;
48
51
53 private $actionText;
54
58 private $type;
59
62 private $action;
63
65 private $comment;
66
68 private $params;
69
71 private $doer;
72
74 private $target;
75
82 public function __construct( $type, $rc = true, $udp = 'skipUDP' ) {
83 $this->type = $type;
84 $this->updateRecentChanges = $rc;
85 $this->sendToUDP = ( $udp == 'UDP' );
86 }
87
91 protected function saveContent() {
92 global $wgLogRestrictions;
93
94 $dbw = wfGetDB( DB_MASTER );
95
96 // @todo FIXME private/protected/public property?
97 $this->timestamp = $now = wfTimestampNow();
98 $data = [
99 'log_type' => $this->type,
100 'log_action' => $this->action,
101 'log_timestamp' => $dbw->timestamp( $now ),
102 'log_namespace' => $this->target->getNamespace(),
103 'log_title' => $this->target->getDBkey(),
104 'log_page' => $this->target->getArticleID(),
105 'log_params' => $this->params
106 ];
107 $data += CommentStore::getStore()->insert( $dbw, 'log_comment', $this->comment );
108 $data += ActorMigration::newMigration()->getInsertValues( $dbw, 'log_user', $this->doer );
109 $dbw->insert( 'logging', $data, __METHOD__ );
110 $newId = $dbw->insertId();
111
112 # And update recentchanges
113 if ( $this->updateRecentChanges ) {
114 $titleObj = SpecialPage::getTitleFor( 'Log', $this->type );
115
116 RecentChange::notifyLog(
117 $now, $titleObj, $this->doer, $this->getRcComment(), '',
118 $this->type, $this->action, $this->target, $this->comment,
119 $this->params, $newId, $this->getRcCommentIRC()
120 );
121 } elseif ( $this->sendToUDP ) {
122 # Don't send private logs to UDP
123 if ( isset( $wgLogRestrictions[$this->type] ) && $wgLogRestrictions[$this->type] != '*' ) {
124 return $newId;
125 }
126
127 # Notify external application via UDP.
128 # We send this to IRC but do not want to add it the RC table.
129 $titleObj = SpecialPage::getTitleFor( 'Log', $this->type );
130 $rc = RecentChange::newLogEntry(
131 $now, $titleObj, $this->doer, $this->getRcComment(), '',
132 $this->type, $this->action, $this->target, $this->comment,
133 $this->params, $newId, $this->getRcCommentIRC()
134 );
135 $rc->notifyRCFeeds();
136 }
137
138 return $newId;
139 }
140
146 public function getRcComment() {
147 $rcComment = $this->actionText;
148
149 if ( $this->comment != '' ) {
150 if ( $rcComment == '' ) {
151 $rcComment = $this->comment;
152 } else {
153 $rcComment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() .
155 }
156 }
157
158 return $rcComment;
159 }
160
166 public function getRcCommentIRC() {
167 $rcComment = $this->ircActionText;
168
169 if ( $this->comment != '' ) {
170 if ( $rcComment == '' ) {
171 $rcComment = $this->comment;
172 } else {
173 $rcComment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() .
175 }
176 }
177
178 return $rcComment;
179 }
180
185 public function getComment() {
186 return $this->comment;
187 }
188
194 public static function validTypes() {
195 global $wgLogTypes;
196
197 return $wgLogTypes;
198 }
199
206 public static function isLogType( $type ) {
207 return in_array( $type, self::validTypes() );
208 }
209
223 public static function actionText( $type, $action, $title = null, $skin = null,
224 $params = [], $filterWikilinks = false
225 ) {
226 global $wgLang, $wgLogActions;
227
228 if ( is_null( $skin ) ) {
229 $langObj = MediaWikiServices::getInstance()->getContentLanguage();
230 $langObjOrNull = null;
231 } else {
232 $langObj = $wgLang;
233 $langObjOrNull = $wgLang;
234 }
235
236 $key = "$type/$action";
237
238 if ( isset( $wgLogActions[$key] ) ) {
239 if ( is_null( $title ) ) {
240 $rv = wfMessage( $wgLogActions[$key] )->inLanguage( $langObj )->escaped();
241 } else {
242 $titleLink = self::getTitleLink( $type, $langObjOrNull, $title, $params );
243
244 if ( count( $params ) == 0 ) {
245 $rv = wfMessage( $wgLogActions[$key] )->rawParams( $titleLink )
246 ->inLanguage( $langObj )->escaped();
247 } else {
248 array_unshift( $params, $titleLink );
249
250 $rv = wfMessage( $wgLogActions[$key] )->rawParams( $params )
251 ->inLanguage( $langObj )->escaped();
252 }
253 }
254 } else {
256
257 if ( isset( $wgLogActionsHandlers[$key] ) ) {
258 $args = func_get_args();
259 $rv = call_user_func_array( $wgLogActionsHandlers[$key], $args );
260 } else {
261 wfDebug( "LogPage::actionText - unknown action $key\n" );
262 $rv = "$action";
263 }
264 }
265
266 // For the perplexed, this feature was added in r7855 by Erik.
267 // The feature was added because we liked adding [[$1]] in our log entries
268 // but the log entries are parsed as Wikitext on RecentChanges but as HTML
269 // on Special:Log. The hack is essentially that [[$1]] represented a link
270 // to the title in question. The first parameter to the HTML version (Special:Log)
271 // is that link in HTML form, and so this just gets rid of the ugly [[]].
272 // However, this is a horrible hack and it doesn't work like you expect if, say,
273 // you want to link to something OTHER than the title of the log entry.
274 // The real problem, which Erik was trying to fix (and it sort-of works now) is
275 // that the same messages are being treated as both wikitext *and* HTML.
276 if ( $filterWikilinks ) {
277 $rv = str_replace( '[[', '', $rv );
278 $rv = str_replace( ']]', '', $rv );
279 }
280
281 return $rv;
282 }
283
292 protected static function getTitleLink( $type, $lang, $title, &$params ) {
293 if ( !$lang ) {
294 return $title->getPrefixedText();
295 }
296
297 $services = MediaWikiServices::getInstance();
298 $linkRenderer = $services->getLinkRenderer();
299 if ( $title->isSpecialPage() ) {
300 list( $name, $par ) = $services->getSpecialPageFactory()->
301 resolveAlias( $title->getDBkey() );
302
303 # Use the language name for log titles, rather than Log/X
304 if ( $name == 'Log' ) {
305 $logPage = new LogPage( $par );
306 $titleLink = $linkRenderer->makeLink( $title, $logPage->getName()->text() );
307 $titleLink = wfMessage( 'parentheses' )
308 ->inLanguage( $lang )
309 ->rawParams( $titleLink )
310 ->escaped();
311 } else {
312 $titleLink = $linkRenderer->makeLink( $title );
313 }
314 } else {
315 $titleLink = $linkRenderer->makeLink( $title );
316 }
317
318 return $titleLink;
319 }
320
333 public function addEntry( $action, $target, $comment, $params = [], $doer = null ) {
334 if ( !is_array( $params ) ) {
335 $params = [ $params ];
336 }
337
338 if ( $comment === null ) {
339 $comment = '';
340 }
341
342 # Trim spaces on user supplied text
343 $comment = trim( $comment );
344
345 $this->action = $action;
346 $this->target = $target;
347 $this->comment = $comment;
348 $this->params = self::makeParamBlob( $params );
349
350 if ( $doer === null ) {
351 global $wgUser;
352 $doer = $wgUser;
353 } elseif ( !is_object( $doer ) ) {
355 }
356
357 $this->doer = $doer;
358
359 $logEntry = new ManualLogEntry( $this->type, $action );
360 $logEntry->setTarget( $target );
361 $logEntry->setPerformer( $doer );
362 $logEntry->setParameters( $params );
363 // All log entries using the LogPage to insert into the logging table
364 // are using the old logging system and therefore the legacy flag is
365 // needed to say the LogFormatter the parameters have numeric keys
366 $logEntry->setLegacy( true );
367
368 $formatter = LogFormatter::newFromEntry( $logEntry );
369 $context = RequestContext::newExtraneousContext( $target );
370 $formatter->setContext( $context );
371
372 $this->actionText = $formatter->getPlainActionText();
373 $this->ircActionText = $formatter->getIRCActionText();
374
375 return $this->saveContent();
376 }
377
386 public function addRelations( $field, $values, $logid ) {
387 if ( !strlen( $field ) || empty( $values ) ) {
388 return false;
389 }
390
391 $data = [];
392
393 foreach ( $values as $value ) {
394 $data[] = [
395 'ls_field' => $field,
396 'ls_value' => $value,
397 'ls_log_id' => $logid
398 ];
399 }
400
401 $dbw = wfGetDB( DB_MASTER );
402 $dbw->insert( 'log_search', $data, __METHOD__, 'IGNORE' );
403
404 return true;
405 }
406
413 public static function makeParamBlob( $params ) {
414 return implode( "\n", $params );
415 }
416
423 public static function extractParams( $blob ) {
424 if ( $blob === '' ) {
425 return [];
426 } else {
427 return explode( "\n", $blob );
428 }
429 }
430
436 public function getName() {
437 global $wgLogNames;
438
439 // BC
440 $key = $wgLogNames[$this->type] ?? 'log-name-' . $this->type;
441
442 return wfMessage( $key );
443 }
444
450 public function getDescription() {
451 global $wgLogHeaders;
452 // BC
453 $key = $wgLogHeaders[$this->type] ?? 'log-description-' . $this->type;
454
455 return wfMessage( $key );
456 }
457
463 public function getRestriction() {
464 global $wgLogRestrictions;
465 // '' always returns true with $user->isAllowed()
466 return $wgLogRestrictions[$this->type] ?? '';
467 }
468
474 public function isRestricted() {
475 $restriction = $this->getRestriction();
476
477 return $restriction !== '' && $restriction !== '*';
478 }
479}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$wgLogActions
Lists the message key string for formatting individual events of each type and action when listed in ...
$wgLogNames
Lists the message key string for each log type.
$wgLogTypes
The logging system has two levels: an event type, which describes the general category and can be vie...
$wgLogRestrictions
This restricts log access to those who have a certain right Users without this will not see it in the...
$wgLogHeaders
Lists the message key string for descriptive text to be shown at the top of each log type.
$wgLogActionsHandlers
The same as above, but here values are names of classes, not messages.
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.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
$wgLang
Definition Setup.php:875
if( $line===false) $args
Definition cdb.php:64
static newFromEntry(LogEntry $entry)
Constructs a new formatter suitable for given entry.
Class to simplify the use of log pages.
Definition LogPage.php:33
static actionText( $type, $action, $title=null, $skin=null, $params=[], $filterWikilinks=false)
Generate text for a log entry.
Definition LogPage.php:223
getRestriction()
Returns the right needed to read this log type.
Definition LogPage.php:463
const SUPPRESSED_USER
Definition LogPage.php:40
__construct( $type, $rc=true, $udp='skipUDP')
Definition LogPage.php:82
const DELETED_USER
Definition LogPage.php:36
static makeParamBlob( $params)
Create a blob from a parameter array.
Definition LogPage.php:413
const DELETED_RESTRICTED
Definition LogPage.php:37
string $comment
Comment associated with action.
Definition LogPage.php:65
bool $sendToUDP
Definition LogPage.php:47
string $ircActionText
Plaintext version of the message for IRC.
Definition LogPage.php:50
User $doer
The user doing the action.
Definition LogPage.php:71
string $action
One of '', 'block', 'protect', 'rights', 'delete', 'upload', 'move', 'move_redir'.
Definition LogPage.php:62
isRestricted()
Tells if this log is not viewable by all.
Definition LogPage.php:474
static extractParams( $blob)
Extract a parameter array from a blob.
Definition LogPage.php:423
static isLogType( $type)
Is $type a valid log type.
Definition LogPage.php:206
static getTitleLink( $type, $lang, $title, &$params)
Definition LogPage.php:292
getName()
Name of the log.
Definition LogPage.php:436
string $actionText
Plaintext version of the message.
Definition LogPage.php:53
addEntry( $action, $target, $comment, $params=[], $doer=null)
Add a log entry.
Definition LogPage.php:333
saveContent()
Definition LogPage.php:91
const DELETED_COMMENT
Definition LogPage.php:35
getComment()
Get the comment from the last addEntry() call.
Definition LogPage.php:185
bool $updateRecentChanges
Definition LogPage.php:44
getRcComment()
Get the RC comment from the last addEntry() call.
Definition LogPage.php:146
string $type
One of '', 'block', 'protect', 'rights', 'delete', 'upload', 'move'.
Definition LogPage.php:58
addRelations( $field, $values, $logid)
Add relations to log_search table.
Definition LogPage.php:386
static validTypes()
Get the list of valid log types.
Definition LogPage.php:194
getRcCommentIRC()
Get the RC comment from the last addEntry() call for IRC.
Definition LogPage.php:166
Title $target
Definition LogPage.php:74
string $params
Blob made of a parameters array.
Definition LogPage.php:68
getDescription()
Description of this log type.
Definition LogPage.php:450
const DELETED_ACTION
Definition LogPage.php:34
const SUPPRESSED_ACTION
Definition LogPage.php:41
Class for creating new log entries and inserting them into the database.
Definition LogEntry.php:441
MediaWikiServices is the service locator for the application scope of MediaWiki.
Represents a title within MediaWiki.
Definition Title.php:40
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:48
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition User.php:609
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition hooks.txt:2848
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:955
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place or wrap services the preferred way to define a new service is the $wgServiceWiringFiles array $services
Definition hooks.txt:2290
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt;div ...>$1&lt;/div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:271
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned $skin
Definition hooks.txt:2009
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form before processing starts Return false to skip default processing and return $ret $linkRenderer
Definition hooks.txt:2054
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN type
Definition postgres.txt:30
const DB_MASTER
Definition defines.php:26
if(!isset( $args[0])) $lang