MediaWiki  master
LogPage.php
Go to the documentation of this file.
1 <?php
27 
33 class LogPage {
34  const DELETED_ACTION = 1;
35  const DELETED_COMMENT = 2;
36  const DELETED_USER = 4;
37  const DELETED_RESTRICTED = 8;
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 
50  private $ircActionText;
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 += MediaWikiServices::getInstance()->getCommentStore()->insert(
108  $dbw,
109  'log_comment',
110  $this->comment
111  );
112  $data += ActorMigration::newMigration()->getInsertValues( $dbw, 'log_user', $this->doer );
113  $dbw->insert( 'logging', $data, __METHOD__ );
114  $newId = $dbw->insertId();
115 
116  # And update recentchanges
117  if ( $this->updateRecentChanges ) {
118  $titleObj = SpecialPage::getTitleFor( 'Log', $this->type );
119 
121  $now, $titleObj, $this->doer, $this->getRcComment(), '',
122  $this->type, $this->action, $this->target, $this->comment,
123  $this->params, $newId, $this->getRcCommentIRC()
124  );
125  } elseif ( $this->sendToUDP ) {
126  # Don't send private logs to UDP
127  if ( isset( $wgLogRestrictions[$this->type] ) && $wgLogRestrictions[$this->type] != '*' ) {
128  return $newId;
129  }
130 
131  # Notify external application via UDP.
132  # We send this to IRC but do not want to add it the RC table.
133  $titleObj = SpecialPage::getTitleFor( 'Log', $this->type );
135  $now, $titleObj, $this->doer, $this->getRcComment(), '',
136  $this->type, $this->action, $this->target, $this->comment,
137  $this->params, $newId, $this->getRcCommentIRC()
138  );
139  $rc->notifyRCFeeds();
140  }
141 
142  return $newId;
143  }
144 
150  public function getRcComment() {
151  $rcComment = $this->actionText;
152 
153  if ( $this->comment != '' ) {
154  if ( $rcComment == '' ) {
155  $rcComment = $this->comment;
156  } else {
157  $rcComment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() .
159  }
160  }
161 
162  return $rcComment;
163  }
164 
170  public function getRcCommentIRC() {
171  $rcComment = $this->ircActionText;
172 
173  if ( $this->comment != '' ) {
174  if ( $rcComment == '' ) {
175  $rcComment = $this->comment;
176  } else {
177  $rcComment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() .
179  }
180  }
181 
182  return $rcComment;
183  }
184 
189  public function getComment() {
190  return $this->comment;
191  }
192 
198  public static function validTypes() {
199  global $wgLogTypes;
200 
201  return $wgLogTypes;
202  }
203 
210  public static function isLogType( $type ) {
211  return in_array( $type, self::validTypes() );
212  }
213 
227  public static function actionText( $type, $action, $title = null, $skin = null,
228  $params = [], $filterWikilinks = false
229  ) {
230  global $wgLang, $wgLogActions;
231 
232  if ( is_null( $skin ) ) {
233  $langObj = MediaWikiServices::getInstance()->getContentLanguage();
234  $langObjOrNull = null;
235  } else {
236  $langObj = $wgLang;
237  $langObjOrNull = $wgLang;
238  }
239 
240  $key = "$type/$action";
241 
242  if ( isset( $wgLogActions[$key] ) ) {
243  if ( is_null( $title ) ) {
244  $rv = wfMessage( $wgLogActions[$key] )->inLanguage( $langObj )->escaped();
245  } else {
246  $titleLink = self::getTitleLink( $type, $langObjOrNull, $title, $params );
247 
248  if ( count( $params ) == 0 ) {
249  $rv = wfMessage( $wgLogActions[$key] )->rawParams( $titleLink )
250  ->inLanguage( $langObj )->escaped();
251  } else {
252  array_unshift( $params, $titleLink );
253 
254  $rv = wfMessage( $wgLogActions[$key] )->rawParams( $params )
255  ->inLanguage( $langObj )->escaped();
256  }
257  }
258  } else {
259  global $wgLogActionsHandlers;
260 
261  if ( isset( $wgLogActionsHandlers[$key] ) ) {
262  $args = func_get_args();
263  $rv = call_user_func_array( $wgLogActionsHandlers[$key], $args );
264  } else {
265  wfDebug( "LogPage::actionText - unknown action $key\n" );
266  $rv = "$action";
267  }
268  }
269 
270  // For the perplexed, this feature was added in r7855 by Erik.
271  // The feature was added because we liked adding [[$1]] in our log entries
272  // but the log entries are parsed as Wikitext on RecentChanges but as HTML
273  // on Special:Log. The hack is essentially that [[$1]] represented a link
274  // to the title in question. The first parameter to the HTML version (Special:Log)
275  // is that link in HTML form, and so this just gets rid of the ugly [[]].
276  // However, this is a horrible hack and it doesn't work like you expect if, say,
277  // you want to link to something OTHER than the title of the log entry.
278  // The real problem, which Erik was trying to fix (and it sort-of works now) is
279  // that the same messages are being treated as both wikitext *and* HTML.
280  if ( $filterWikilinks ) {
281  $rv = str_replace( '[[', '', $rv );
282  $rv = str_replace( ']]', '', $rv );
283  }
284 
285  return $rv;
286  }
287 
296  protected static function getTitleLink( $type, $lang, $title, &$params ) {
297  if ( !$lang ) {
298  return $title->getPrefixedText();
299  }
300 
301  $services = MediaWikiServices::getInstance();
302  $linkRenderer = $services->getLinkRenderer();
303  if ( $title->isSpecialPage() ) {
304  list( $name, $par ) = $services->getSpecialPageFactory()->
305  resolveAlias( $title->getDBkey() );
306 
307  # Use the language name for log titles, rather than Log/X
308  if ( $name == 'Log' ) {
309  $logPage = new LogPage( $par );
310  $titleLink = $linkRenderer->makeLink( $title, $logPage->getName()->text() );
311  $titleLink = wfMessage( 'parentheses' )
312  ->inLanguage( $lang )
313  ->rawParams( $titleLink )
314  ->escaped();
315  } else {
316  $titleLink = $linkRenderer->makeLink( $title );
317  }
318  } else {
319  $titleLink = $linkRenderer->makeLink( $title );
320  }
321 
322  return $titleLink;
323  }
324 
337  public function addEntry( $action, $target, $comment, $params = [], $doer = null ) {
338  if ( !is_array( $params ) ) {
339  $params = [ $params ];
340  }
341 
342  if ( $comment === null ) {
343  $comment = '';
344  }
345 
346  # Trim spaces on user supplied text
347  $comment = trim( $comment );
348 
349  $this->action = $action;
350  $this->target = $target;
351  $this->comment = $comment;
352  $this->params = self::makeParamBlob( $params );
353 
354  if ( $doer === null ) {
355  global $wgUser;
356  $doer = $wgUser;
357  } elseif ( !is_object( $doer ) ) {
359  }
360 
361  $this->doer = $doer;
362 
363  $logEntry = new ManualLogEntry( $this->type, $action );
364  $logEntry->setTarget( $target );
365  $logEntry->setPerformer( $doer );
366  $logEntry->setParameters( $params );
367  // All log entries using the LogPage to insert into the logging table
368  // are using the old logging system and therefore the legacy flag is
369  // needed to say the LogFormatter the parameters have numeric keys
370  $logEntry->setLegacy( true );
371 
372  $formatter = LogFormatter::newFromEntry( $logEntry );
374  $formatter->setContext( $context );
375 
376  $this->actionText = $formatter->getPlainActionText();
377  $this->ircActionText = $formatter->getIRCActionText();
378 
379  return $this->saveContent();
380  }
381 
390  public function addRelations( $field, $values, $logid ) {
391  if ( !strlen( $field ) || empty( $values ) ) {
392  return false;
393  }
394 
395  $data = [];
396 
397  foreach ( $values as $value ) {
398  $data[] = [
399  'ls_field' => $field,
400  'ls_value' => $value,
401  'ls_log_id' => $logid
402  ];
403  }
404 
405  $dbw = wfGetDB( DB_MASTER );
406  $dbw->insert( 'log_search', $data, __METHOD__, [ 'IGNORE' ] );
407 
408  return true;
409  }
410 
417  public static function makeParamBlob( $params ) {
418  return implode( "\n", $params );
419  }
420 
427  public static function extractParams( $blob ) {
428  if ( $blob === '' ) {
429  return [];
430  } else {
431  return explode( "\n", $blob );
432  }
433  }
434 
440  public function getName() {
441  global $wgLogNames;
442 
443  // BC
444  $key = $wgLogNames[$this->type] ?? 'log-name-' . $this->type;
445 
446  return wfMessage( $key );
447  }
448 
454  public function getDescription() {
455  global $wgLogHeaders;
456  // BC
457  $key = $wgLogHeaders[$this->type] ?? 'log-description-' . $this->type;
458 
459  return wfMessage( $key );
460  }
461 
467  public function getRestriction() {
468  global $wgLogRestrictions;
469  // '' always returns true with $user->isAllowed()
470  return $wgLogRestrictions[$this->type] ?? '';
471  }
472 
478  public function isRestricted() {
479  $restriction = $this->getRestriction();
480 
481  return $restriction !== '' && $restriction !== '*';
482  }
483 }
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
getRestriction()
Returns the right needed to read this log type.
Definition: LogPage.php:467
bool $updateRecentChanges
Definition: LogPage.php:44
__construct( $type, $rc=true, $udp='skipUDP')
Definition: LogPage.php:82
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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:1982
string $ircActionText
Plaintext version of the message for IRC.
Definition: LogPage.php:50
if(!isset( $args[0])) $lang
static newFromEntry(LogEntry $entry)
Constructs a new formatter suitable for given entry.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
$value
string $type
One of &#39;&#39;, &#39;block&#39;, &#39;protect&#39;, &#39;rights&#39;, &#39;delete&#39;, &#39;upload&#39;, &#39;move&#39;.
Definition: LogPage.php:58
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 MediaWikiServices
Definition: injection.txt:23
$wgLogActions
Lists the message key string for formatting individual events of each type and action when listed in ...
$wgLogRestrictions
This restricts log access to those who have a certain right Users without this will not see it in the...
const SUPPRESSED_ACTION
Definition: LogPage.php:41
saveContent()
Definition: LogPage.php:91
$wgLogNames
Lists the message key string for each log type.
const DB_MASTER
Definition: defines.php:26
addRelations( $field, $values, $logid)
Add relations to log_search table.
Definition: LogPage.php:390
User $doer
The user doing the action.
Definition: LogPage.php:71
if( $line===false) $args
Definition: cdb.php:64
Class to simplify the use of log pages.
Definition: LogPage.php:33
isRestricted()
Tells if this log is not viewable by all.
Definition: LogPage.php:478
const DELETED_COMMENT
Definition: LogPage.php:35
$wgLang
Definition: Setup.php:931
static newMigration()
Static constructor.
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
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:2217
static actionText( $type, $action, $title=null, $skin=null, $params=[], $filterWikilinks=false)
Generate text for a log entry.
Definition: LogPage.php:227
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
getRcCommentIRC()
Get the RC comment from the last addEntry() call for IRC.
Definition: LogPage.php:170
getDescription()
Description of this log type.
Definition: LogPage.php:454
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
static newExtraneousContext(Title $title, $request=[])
Create a new extraneous context.
static newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='', $revId=0, $isPatrollable=false)
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
string $actionText
Plaintext version of the message.
Definition: LogPage.php:53
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:1982
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don&#39;t need a full Title object...
Definition: SpecialPage.php:83
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
Definition: distributors.txt:9
const DELETED_RESTRICTED
Definition: LogPage.php:37
$wgLogActionsHandlers
The same as above, but here values are names of classes, not messages.
const DELETED_USER
Definition: LogPage.php:36
const SUPPRESSED_USER
Definition: LogPage.php:40
static isLogType( $type)
Is $type a valid log type.
Definition: LogPage.php:210
static getTitleLink( $type, $lang, $title, &$params)
Definition: LogPage.php:296
Title $target
Definition: LogPage.php:74
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:35
addEntry( $action, $target, $comment, $params=[], $doer=null)
Add a log entry.
Definition: LogPage.php:337
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:618
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 as and are nearing end of 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:22
bool $sendToUDP
Definition: LogPage.php:47
static notifyLog( $timestamp, $title, $user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='')
getRcComment()
Get the RC comment from the last addEntry() call.
Definition: LogPage.php:150
$wgLogHeaders
Lists the message key string for descriptive text to be shown at the top of each log type...
string $params
Blob made of a parameters array.
Definition: LogPage.php:68
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:2633
getName()
Name of the log.
Definition: LogPage.php:440
string $action
One of &#39;&#39;, &#39;block&#39;, &#39;protect&#39;, &#39;rights&#39;, &#39;delete&#39;, &#39;upload&#39;, &#39;move&#39;, &#39;move_redir&#39;.
Definition: LogPage.php:62
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
const DELETED_ACTION
Definition: LogPage.php:34
$wgLogTypes
The logging system has two levels: an event type, which describes the general category and can be vie...
static validTypes()
Get the list of valid log types.
Definition: LogPage.php:198
string $comment
Comment associated with action.
Definition: LogPage.php:65
static makeParamBlob( $params)
Create a blob from a parameter array.
Definition: LogPage.php:417
getComment()
Get the comment from the last addEntry() call.
Definition: LogPage.php:189
static extractParams( $blob)
Extract a parameter array from a blob.
Definition: LogPage.php:427