MediaWiki  1.32.5
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 += 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 
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 );
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 {
255  global $wgLogActionsHandlers;
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 );
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; // nothing
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  if ( isset( $wgLogNames[$this->type] ) ) {
441  $key = $wgLogNames[$this->type];
442  } else {
443  $key = 'log-name-' . $this->type;
444  }
445 
446  return wfMessage( $key );
447  }
448 
454  public function getDescription() {
455  global $wgLogHeaders;
456  // BC
457  if ( isset( $wgLogHeaders[$this->type] ) ) {
458  $key = $wgLogHeaders[$this->type];
459  } else {
460  $key = 'log-description-' . $this->type;
461  }
462 
463  return wfMessage( $key );
464  }
465 
471  public function getRestriction() {
472  global $wgLogRestrictions;
473  if ( isset( $wgLogRestrictions[$this->type] ) ) {
474  $restriction = $wgLogRestrictions[$this->type];
475  } else {
476  // '' always returns true with $user->isAllowed()
477  $restriction = '';
478  }
479 
480  return $restriction;
481  }
482 
488  public function isRestricted() {
489  $restriction = $this->getRestriction();
490 
491  return $restriction !== '' && $restriction !== '*';
492  }
493 }
LogPage\SUPPRESSED_ACTION
const SUPPRESSED_ACTION
Definition: LogPage.php:41
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:615
LogPage\SUPPRESSED_USER
const SUPPRESSED_USER
Definition: LogPage.php:40
LogPage\validTypes
static validTypes()
Get the list of valid log types.
Definition: LogPage.php:194
LogPage\getTitleLink
static getTitleLink( $type, $lang, $title, &$params)
Definition: LogPage.php:292
$context
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:2683
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
$wgLogHeaders
$wgLogHeaders
Lists the message key string for descriptive text to be shown at the top of each log type.
Definition: DefaultSettings.php:7799
LogPage\extractParams
static extractParams( $blob)
Extract a parameter array from a blob.
Definition: LogPage.php:423
captcha-old.count
count
Definition: captcha-old.py:249
LogPage\isRestricted
isRestricted()
Tells if this log is not viewable by all.
Definition: LogPage.php:488
RecentChange\notifyLog
static notifyLog( $timestamp, $title, $user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='')
Definition: RecentChange.php:822
LogPage\$params
string $params
Blob made of a parameters array.
Definition: LogPage.php:68
RequestContext\newExtraneousContext
static newExtraneousContext(Title $title, $request=[])
Create a new extraneous context.
Definition: RequestContext.php:604
$wgLogActions
$wgLogActions
Lists the message key string for formatting individual events of each type and action when listed in ...
Definition: DefaultSettings.php:7819
$linkRenderer
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:2044
SpecialPage\getTitleFor
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,...
Definition: SpecialPage.php:82
LogPage\actionText
static actionText( $type, $action, $title=null, $skin=null, $params=[], $filterWikilinks=false)
Generate text for a log entry.
Definition: LogPage.php:223
ActorMigration\newMigration
static newMigration()
Static constructor.
Definition: ActorMigration.php:111
php
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
LogPage\__construct
__construct( $type, $rc=true, $udp='skipUDP')
Definition: LogPage.php:82
LogPage\getRestriction
getRestriction()
Returns the right needed to read this log type.
Definition: LogPage.php:471
LogPage\getComment
getComment()
Get the comment from the last addEntry() call.
Definition: LogPage.php:185
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:964
LogPage\DELETED_COMMENT
const DELETED_COMMENT
Definition: LogPage.php:35
$blob
$blob
Definition: testCompression.php:65
LogPage\DELETED_USER
const DELETED_USER
Definition: LogPage.php:36
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2693
LogPage\isLogType
static isLogType( $type)
Is $type a valid log type.
Definition: LogPage.php:206
LogPage\getDescription
getDescription()
Description of this log type.
Definition: LogPage.php:454
$wgLang
$wgLang
Definition: Setup.php:910
LogPage
Class to simplify the use of log pages.
Definition: LogPage.php:33
LogPage\getName
getName()
Name of the log.
Definition: LogPage.php:436
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
$wgLogTypes
$wgLogTypes
The logging system has two levels: an event type, which describes the general category and can be vie...
Definition: DefaultSettings.php:7715
LogPage\getRcCommentIRC
getRcCommentIRC()
Get the RC comment from the last addEntry() call for IRC.
Definition: LogPage.php:166
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1983
DB_MASTER
const DB_MASTER
Definition: defines.php:26
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:988
list
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
LogPage\DELETED_ACTION
const DELETED_ACTION
Definition: LogPage.php:34
captcha-old.action
action
Definition: captcha-old.py:212
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
LogPage\$action
string $action
One of '', 'block', 'protect', 'rights', 'delete', 'upload', 'move', 'move_redir'.
Definition: LogPage.php:62
$value
$value
Definition: styleTest.css.php:49
LogPage\$comment
string $comment
Comment associated with action.
Definition: LogPage.php:65
LogPage\makeParamBlob
static makeParamBlob( $params)
Create a blob from a parameter array.
Definition: LogPage.php:413
$wgLogRestrictions
$wgLogRestrictions
This restricts log access to those who have a certain right Users without this will not see it in the...
Definition: DefaultSettings.php:7739
LogPage\$doer
User $doer
The user doing the action.
Definition: LogPage.php:71
LogPage\$sendToUDP
bool $sendToUDP
Definition: LogPage.php:47
LogPage\getRcComment
getRcComment()
Get the RC comment from the last addEntry() call.
Definition: LogPage.php:146
LogPage\saveContent
saveContent()
Definition: LogPage.php:91
LogPage\$type
string $type
One of '', 'block', 'protect', 'rights', 'delete', 'upload', 'move'.
Definition: LogPage.php:58
$wgLogActionsHandlers
$wgLogActionsHandlers
The same as above, but here values are names of classes, not messages.
Definition: DefaultSettings.php:7827
LogPage\addRelations
addRelations( $field, $values, $logid)
Add relations to log_search table.
Definition: LogPage.php:386
LogPage\$ircActionText
string $ircActionText
Plaintext version of the message for IRC.
Definition: LogPage.php:50
RecentChange\newLogEntry
static newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='', $revId=0, $isPatrollable=false)
Definition: RecentChange.php:855
$args
if( $line===false) $args
Definition: cdb.php:64
Title
Represents a title within MediaWiki.
Definition: Title.php:39
LogPage\$actionText
string $actionText
Plaintext version of the message.
Definition: LogPage.php:53
as
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
$skin
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:2044
ManualLogEntry
Class for creating new log entries and inserting them into the database.
Definition: LogEntry.php:437
$wgLogNames
$wgLogNames
Lists the message key string for each log type.
Definition: DefaultSettings.php:7776
LogPage\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: LogPage.php:37
$services
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:2278
LogPage\$updateRecentChanges
bool $updateRecentChanges
Definition: LogPage.php:44
MediaWikiServices
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
wfMessage
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
CommentStore\getStore
static getStore()
Definition: CommentStore.php:125
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:47
type
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
LogPage\addEntry
addEntry( $action, $target, $comment, $params=[], $doer=null)
Add a log entry.
Definition: LogPage.php:333
LogPage\$target
Title $target
Definition: LogPage.php:74
LogFormatter\newFromEntry
static newFromEntry(LogEntry $entry)
Constructs a new formatter suitable for given entry.
Definition: LogFormatter.php:50