MediaWiki  REL1_31
LogPage.php
Go to the documentation of this file.
1 <?php
31 class LogPage {
32  const DELETED_ACTION = 1;
33  const DELETED_COMMENT = 2;
34  const DELETED_USER = 4;
35  const DELETED_RESTRICTED = 8;
36 
37  // Convenience fields
38  const SUPPRESSED_USER = 12;
39  const SUPPRESSED_ACTION = 9;
40 
43 
45  public $sendToUDP;
46 
48  private $ircActionText;
49 
51  private $actionText;
52 
56  private $type;
57 
60  private $action;
61 
63  private $comment;
64 
66  private $params;
67 
69  private $doer;
70 
72  private $target;
73 
80  public function __construct( $type, $rc = true, $udp = 'skipUDP' ) {
81  $this->type = $type;
82  $this->updateRecentChanges = $rc;
83  $this->sendToUDP = ( $udp == 'UDP' );
84  }
85 
89  protected function saveContent() {
91 
92  $dbw = wfGetDB( DB_MASTER );
93 
94  // @todo FIXME private/protected/public property?
95  $this->timestamp = $now = wfTimestampNow();
96  $data = [
97  'log_type' => $this->type,
98  'log_action' => $this->action,
99  'log_timestamp' => $dbw->timestamp( $now ),
100  'log_namespace' => $this->target->getNamespace(),
101  'log_title' => $this->target->getDBkey(),
102  'log_page' => $this->target->getArticleID(),
103  'log_params' => $this->params
104  ];
105  $data += CommentStore::getStore()->insert( $dbw, 'log_comment', $this->comment );
106  $data += ActorMigration::newMigration()->getInsertValues( $dbw, 'log_user', $this->doer );
107  $dbw->insert( 'logging', $data, __METHOD__ );
108  $newId = $dbw->insertId();
109 
110  # And update recentchanges
111  if ( $this->updateRecentChanges ) {
112  $titleObj = SpecialPage::getTitleFor( 'Log', $this->type );
113 
115  $now, $titleObj, $this->doer, $this->getRcComment(), '',
116  $this->type, $this->action, $this->target, $this->comment,
117  $this->params, $newId, $this->getRcCommentIRC()
118  );
119  } elseif ( $this->sendToUDP ) {
120  # Don't send private logs to UDP
121  if ( isset( $wgLogRestrictions[$this->type] ) && $wgLogRestrictions[$this->type] != '*' ) {
122  return $newId;
123  }
124 
125  # Notify external application via UDP.
126  # We send this to IRC but do not want to add it the RC table.
127  $titleObj = SpecialPage::getTitleFor( 'Log', $this->type );
129  $now, $titleObj, $this->doer, $this->getRcComment(), '',
130  $this->type, $this->action, $this->target, $this->comment,
131  $this->params, $newId, $this->getRcCommentIRC()
132  );
133  $rc->notifyRCFeeds();
134  }
135 
136  return $newId;
137  }
138 
144  public function getRcComment() {
145  $rcComment = $this->actionText;
146 
147  if ( $this->comment != '' ) {
148  if ( $rcComment == '' ) {
149  $rcComment = $this->comment;
150  } else {
151  $rcComment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() .
153  }
154  }
155 
156  return $rcComment;
157  }
158 
164  public function getRcCommentIRC() {
165  $rcComment = $this->ircActionText;
166 
167  if ( $this->comment != '' ) {
168  if ( $rcComment == '' ) {
169  $rcComment = $this->comment;
170  } else {
171  $rcComment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() .
173  }
174  }
175 
176  return $rcComment;
177  }
178 
183  public function getComment() {
184  return $this->comment;
185  }
186 
192  public static function validTypes() {
194 
195  return $wgLogTypes;
196  }
197 
204  public static function isLogType( $type ) {
205  return in_array( $type, self::validTypes() );
206  }
207 
221  public static function actionText( $type, $action, $title = null, $skin = null,
222  $params = [], $filterWikilinks = false
223  ) {
225 
226  if ( is_null( $skin ) ) {
227  $langObj = $wgContLang;
228  $langObjOrNull = null;
229  } else {
230  $langObj = $wgLang;
231  $langObjOrNull = $wgLang;
232  }
233 
234  $key = "$type/$action";
235 
236  if ( isset( $wgLogActions[$key] ) ) {
237  if ( is_null( $title ) ) {
238  $rv = wfMessage( $wgLogActions[$key] )->inLanguage( $langObj )->escaped();
239  } else {
240  $titleLink = self::getTitleLink( $type, $langObjOrNull, $title, $params );
241 
242  if ( count( $params ) == 0 ) {
243  $rv = wfMessage( $wgLogActions[$key] )->rawParams( $titleLink )
244  ->inLanguage( $langObj )->escaped();
245  } else {
246  array_unshift( $params, $titleLink );
247 
248  $rv = wfMessage( $wgLogActions[$key] )->rawParams( $params )
249  ->inLanguage( $langObj )->escaped();
250  }
251  }
252  } else {
254 
255  if ( isset( $wgLogActionsHandlers[$key] ) ) {
256  $args = func_get_args();
257  $rv = call_user_func_array( $wgLogActionsHandlers[$key], $args );
258  } else {
259  wfDebug( "LogPage::actionText - unknown action $key\n" );
260  $rv = "$action";
261  }
262  }
263 
264  // For the perplexed, this feature was added in r7855 by Erik.
265  // The feature was added because we liked adding [[$1]] in our log entries
266  // but the log entries are parsed as Wikitext on RecentChanges but as HTML
267  // on Special:Log. The hack is essentially that [[$1]] represented a link
268  // to the title in question. The first parameter to the HTML version (Special:Log)
269  // is that link in HTML form, and so this just gets rid of the ugly [[]].
270  // However, this is a horrible hack and it doesn't work like you expect if, say,
271  // you want to link to something OTHER than the title of the log entry.
272  // The real problem, which Erik was trying to fix (and it sort-of works now) is
273  // that the same messages are being treated as both wikitext *and* HTML.
274  if ( $filterWikilinks ) {
275  $rv = str_replace( '[[', '', $rv );
276  $rv = str_replace( ']]', '', $rv );
277  }
278 
279  return $rv;
280  }
281 
290  protected static function getTitleLink( $type, $lang, $title, &$params ) {
291  if ( !$lang ) {
292  return $title->getPrefixedText();
293  }
294 
295  if ( $title->isSpecialPage() ) {
296  list( $name, $par ) = SpecialPageFactory::resolveAlias( $title->getDBkey() );
297 
298  # Use the language name for log titles, rather than Log/X
299  if ( $name == 'Log' ) {
300  $logPage = new LogPage( $par );
301  $titleLink = Linker::link( $title, $logPage->getName()->escaped() );
302  $titleLink = wfMessage( 'parentheses' )
303  ->inLanguage( $lang )
304  ->rawParams( $titleLink )
305  ->escaped();
306  } else {
307  $titleLink = Linker::link( $title );
308  }
309  } else {
310  $titleLink = Linker::link( $title );
311  }
312 
313  return $titleLink;
314  }
315 
328  public function addEntry( $action, $target, $comment, $params = [], $doer = null ) {
329  if ( !is_array( $params ) ) {
330  $params = [ $params ];
331  }
332 
333  if ( $comment === null ) {
334  $comment = '';
335  }
336 
337  # Trim spaces on user supplied text
338  $comment = trim( $comment );
339 
340  $this->action = $action;
341  $this->target = $target;
342  $this->comment = $comment;
343  $this->params = self::makeParamBlob( $params );
344 
345  if ( $doer === null ) {
346  global $wgUser;
347  $doer = $wgUser;
348  } elseif ( !is_object( $doer ) ) {
350  }
351 
352  $this->doer = $doer;
353 
354  $logEntry = new ManualLogEntry( $this->type, $action );
355  $logEntry->setTarget( $target );
356  $logEntry->setPerformer( $doer );
357  $logEntry->setParameters( $params );
358  // All log entries using the LogPage to insert into the logging table
359  // are using the old logging system and therefore the legacy flag is
360  // needed to say the LogFormatter the parameters have numeric keys
361  $logEntry->setLegacy( true );
362 
363  $formatter = LogFormatter::newFromEntry( $logEntry );
365  $formatter->setContext( $context );
366 
367  $this->actionText = $formatter->getPlainActionText();
368  $this->ircActionText = $formatter->getIRCActionText();
369 
370  return $this->saveContent();
371  }
372 
381  public function addRelations( $field, $values, $logid ) {
382  if ( !strlen( $field ) || empty( $values ) ) {
383  return false; // nothing
384  }
385 
386  $data = [];
387 
388  foreach ( $values as $value ) {
389  $data[] = [
390  'ls_field' => $field,
391  'ls_value' => $value,
392  'ls_log_id' => $logid
393  ];
394  }
395 
396  $dbw = wfGetDB( DB_MASTER );
397  $dbw->insert( 'log_search', $data, __METHOD__, 'IGNORE' );
398 
399  return true;
400  }
401 
408  public static function makeParamBlob( $params ) {
409  return implode( "\n", $params );
410  }
411 
418  public static function extractParams( $blob ) {
419  if ( $blob === '' ) {
420  return [];
421  } else {
422  return explode( "\n", $blob );
423  }
424  }
425 
431  public function getName() {
433 
434  // BC
435  if ( isset( $wgLogNames[$this->type] ) ) {
436  $key = $wgLogNames[$this->type];
437  } else {
438  $key = 'log-name-' . $this->type;
439  }
440 
441  return wfMessage( $key );
442  }
443 
449  public function getDescription() {
451  // BC
452  if ( isset( $wgLogHeaders[$this->type] ) ) {
453  $key = $wgLogHeaders[$this->type];
454  } else {
455  $key = 'log-description-' . $this->type;
456  }
457 
458  return wfMessage( $key );
459  }
460 
466  public function getRestriction() {
468  if ( isset( $wgLogRestrictions[$this->type] ) ) {
469  $restriction = $wgLogRestrictions[$this->type];
470  } else {
471  // '' always returns true with $user->isAllowed()
472  $restriction = '';
473  }
474 
475  return $restriction;
476  }
477 
483  public function isRestricted() {
484  $restriction = $this->getRestriction();
485 
486  return $restriction !== '' && $restriction !== '*';
487  }
488 }
$wgUser
$wgUser
Definition: Setup.php:902
LogPage\SUPPRESSED_ACTION
const SUPPRESSED_ACTION
Definition: LogPage.php:39
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:614
LogPage\SUPPRESSED_USER
const SUPPRESSED_USER
Definition: LogPage.php:38
LogPage\validTypes
static validTypes()
Get the list of valid log types.
Definition: LogPage.php:192
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 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
LogPage\getTitleLink
static getTitleLink( $type, $lang, $title, &$params)
Definition: LogPage.php:290
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 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
$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:7736
LogPage\extractParams
static extractParams( $blob)
Extract a parameter array from a blob.
Definition: LogPage.php:418
LogPage\isRestricted
isRestricted()
Tells if this log is not viewable by all.
Definition: LogPage.php:483
LogPage\$params
string $params
Blob made of a parameters array.
Definition: LogPage.php:66
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:7756
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:221
ActorMigration\newMigration
static newMigration()
Static constructor.
Definition: ActorMigration.php:89
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:37
LogPage\__construct
__construct( $type, $rc=true, $udp='skipUDP')
Definition: LogPage.php:80
LogPage\getRestriction
getRestriction()
Returns the right needed to read this log type.
Definition: LogPage.php:466
LogPage\getComment
getComment()
Get the comment from the last addEntry() call.
Definition: LogPage.php:183
LogPage\DELETED_COMMENT
const DELETED_COMMENT
Definition: LogPage.php:33
$blob
$blob
Definition: testCompression.php:65
LogPage\DELETED_USER
const DELETED_USER
Definition: LogPage.php:34
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2812
LogPage\isLogType
static isLogType( $type)
Is $type a valid log type.
Definition: LogPage.php:204
LogPage\getDescription
getDescription()
Description of this log type.
Definition: LogPage.php:449
LogPage
Class to simplify the use of log pages.
Definition: LogPage.php:31
LogPage\getName
getName()
Name of the log.
Definition: LogPage.php:431
RecentChange\notifyLog
static notifyLog( $timestamp, &$title, &$user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='')
Definition: RecentChange.php:803
$wgLogTypes
$wgLogTypes
The logging system has two levels: an event type, which describes the general category and can be vie...
Definition: DefaultSettings.php:7652
$wgLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as $wgLang
Definition: design.txt:56
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:964
LogPage\getRcCommentIRC
getRcCommentIRC()
Get the RC comment from the last addEntry() call for IRC.
Definition: LogPage.php:164
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:95
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:2009
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:994
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:32
LogPage\$action
string $action
One of '', 'block', 'protect', 'rights', 'delete', 'upload', 'move', 'move_redir'.
Definition: LogPage.php:60
$value
$value
Definition: styleTest.css.php:45
LogPage\$comment
string $comment
Comment associated with action.
Definition: LogPage.php:63
LogPage\makeParamBlob
static makeParamBlob( $params)
Create a blob from a parameter array.
Definition: LogPage.php:408
$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:7676
Linker\link
static link( $target, $html=null, $customAttribs=[], $query=[], $options=[])
This function returns an HTML link to the given target.
Definition: Linker.php:107
LogPage\$doer
User $doer
The user doing the action.
Definition: LogPage.php:69
LogPage\$sendToUDP
bool $sendToUDP
Definition: LogPage.php:45
LogPage\getRcComment
getRcComment()
Get the RC comment from the last addEntry() call.
Definition: LogPage.php:144
SpecialPageFactory\resolveAlias
static resolveAlias( $alias)
Given a special page name with a possible subpage, return an array where the first element is the spe...
Definition: SpecialPageFactory.php:328
LogPage\saveContent
saveContent()
Definition: LogPage.php:89
LogPage\$type
string $type
One of '', 'block', 'protect', 'rights', 'delete', 'upload', 'move'.
Definition: LogPage.php:56
$wgLogActionsHandlers
$wgLogActionsHandlers
The same as above, but here values are names of classes, not messages.
Definition: DefaultSettings.php:7764
LogPage\addRelations
addRelations( $field, $values, $logid)
Add relations to log_search table.
Definition: LogPage.php:381
$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:2011
LogPage\$ircActionText
string $ircActionText
Plaintext version of the message for IRC.
Definition: LogPage.php:48
$args
if( $line===false) $args
Definition: cdb.php:64
Title
Represents a title within MediaWiki.
Definition: Title.php:39
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
RecentChange\newLogEntry
static newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='', $revId=0, $isPatrollable=false)
Definition: RecentChange.php:836
LogPage\$actionText
string $actionText
Plaintext version of the message.
Definition: LogPage.php:51
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:22
ManualLogEntry
Class for creating log entries manually, to inject them into the database.
Definition: LogEntry.php:432
$wgLogNames
$wgLogNames
Lists the message key string for each log type.
Definition: DefaultSettings.php:7713
LogPage\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: LogPage.php:35
LogPage\$updateRecentChanges
bool $updateRecentChanges
Definition: LogPage.php:42
CommentStore\getStore
static getStore()
Definition: CommentStore.php:130
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:53
LogPage\addEntry
addEntry( $action, $target, $comment, $params=[], $doer=null)
Add a log entry.
Definition: LogPage.php:328
$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:2811
LogPage\$target
Title $target
Definition: LogPage.php:72
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:57
LogFormatter\newFromEntry
static newFromEntry(LogEntry $entry)
Constructs a new formatter suitable for given entry.
Definition: LogFormatter.php:50