MediaWiki  1.28.0
LogPage.php
Go to the documentation of this file.
1 <?php
32 class LogPage {
33  const DELETED_ACTION = 1;
34  const DELETED_COMMENT = 2;
35  const DELETED_USER = 4;
36  const DELETED_RESTRICTED = 8;
37 
38  // Convenience fields
39  const SUPPRESSED_USER = 12;
40  const SUPPRESSED_ACTION = 9;
41 
44 
46  public $sendToUDP;
47 
49  private $ircActionText;
50 
52  private $actionText;
53 
57  private $type;
58 
61  private $action;
62 
64  private $comment;
65 
67  private $params;
68 
70  private $doer;
71 
73  private $target;
74 
83  public function __construct( $type, $rc = true, $udp = 'skipUDP' ) {
84  $this->type = $type;
85  $this->updateRecentChanges = $rc;
86  $this->sendToUDP = ( $udp == 'UDP' );
87  }
88 
92  protected function saveContent() {
93  global $wgLogRestrictions;
94 
95  $dbw = wfGetDB( DB_MASTER );
96  $log_id = $dbw->nextSequenceValue( 'logging_log_id_seq' );
97 
98  // @todo FIXME private/protected/public property?
99  $this->timestamp = $now = wfTimestampNow();
100  $data = [
101  'log_id' => $log_id,
102  'log_type' => $this->type,
103  'log_action' => $this->action,
104  'log_timestamp' => $dbw->timestamp( $now ),
105  'log_user' => $this->doer->getId(),
106  'log_user_text' => $this->doer->getName(),
107  'log_namespace' => $this->target->getNamespace(),
108  'log_title' => $this->target->getDBkey(),
109  'log_page' => $this->target->getArticleID(),
110  'log_comment' => $this->comment,
111  'log_params' => $this->params
112  ];
113  $dbw->insert( 'logging', $data, __METHOD__ );
114  $newId = !is_null( $log_id ) ? $log_id : $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, LogPage::validTypes() );
212  }
213 
227  public static function actionText( $type, $action, $title = null, $skin = null,
228  $params = [], $filterWikilinks = false
229  ) {
230  global $wgLang, $wgContLang, $wgLogActions;
231 
232  if ( is_null( $skin ) ) {
233  $langObj = $wgContLang;
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  if ( $title->isSpecialPage() ) {
302  list( $name, $par ) = SpecialPageFactory::resolveAlias( $title->getDBkey() );
303 
304  # Use the language name for log titles, rather than Log/X
305  if ( $name == 'Log' ) {
306  $logPage = new LogPage( $par );
307  $titleLink = Linker::link( $title, $logPage->getName()->escaped() );
308  $titleLink = wfMessage( 'parentheses' )
309  ->inLanguage( $lang )
310  ->rawParams( $titleLink )
311  ->escaped();
312  } else {
313  $titleLink = Linker::link( $title );
314  }
315  } else {
316  $titleLink = Linker::link( $title );
317  }
318 
319  return $titleLink;
320  }
321 
334  public function addEntry( $action, $target, $comment, $params = [], $doer = null ) {
336 
337  if ( !is_array( $params ) ) {
338  $params = [ $params ];
339  }
340 
341  if ( $comment === null ) {
342  $comment = '';
343  }
344 
345  # Trim spaces on user supplied text
346  $comment = trim( $comment );
347 
348  # Truncate for whole multibyte characters.
349  $comment = $wgContLang->truncate( $comment, 255 );
350 
351  $this->action = $action;
352  $this->target = $target;
353  $this->comment = $comment;
354  $this->params = LogPage::makeParamBlob( $params );
355 
356  if ( $doer === null ) {
357  global $wgUser;
358  $doer = $wgUser;
359  } elseif ( !is_object( $doer ) ) {
361  }
362 
363  $this->doer = $doer;
364 
365  $logEntry = new ManualLogEntry( $this->type, $action );
366  $logEntry->setTarget( $target );
367  $logEntry->setPerformer( $doer );
368  $logEntry->setParameters( $params );
369  // All log entries using the LogPage to insert into the logging table
370  // are using the old logging system and therefore the legacy flag is
371  // needed to say the LogFormatter the parameters have numeric keys
372  $logEntry->setLegacy( true );
373 
374  $formatter = LogFormatter::newFromEntry( $logEntry );
376  $formatter->setContext( $context );
377 
378  $this->actionText = $formatter->getPlainActionText();
379  $this->ircActionText = $formatter->getIRCActionText();
380 
381  return $this->saveContent();
382  }
383 
392  public function addRelations( $field, $values, $logid ) {
393  if ( !strlen( $field ) || empty( $values ) ) {
394  return false; // nothing
395  }
396 
397  $data = [];
398 
399  foreach ( $values as $value ) {
400  $data[] = [
401  'ls_field' => $field,
402  'ls_value' => $value,
403  'ls_log_id' => $logid
404  ];
405  }
406 
407  $dbw = wfGetDB( DB_MASTER );
408  $dbw->insert( 'log_search', $data, __METHOD__, 'IGNORE' );
409 
410  return true;
411  }
412 
419  public static function makeParamBlob( $params ) {
420  return implode( "\n", $params );
421  }
422 
429  public static function extractParams( $blob ) {
430  if ( $blob === '' ) {
431  return [];
432  } else {
433  return explode( "\n", $blob );
434  }
435  }
436 
442  public function getName() {
443  global $wgLogNames;
444 
445  // BC
446  if ( isset( $wgLogNames[$this->type] ) ) {
447  $key = $wgLogNames[$this->type];
448  } else {
449  $key = 'log-name-' . $this->type;
450  }
451 
452  return wfMessage( $key );
453  }
454 
460  public function getDescription() {
461  global $wgLogHeaders;
462  // BC
463  if ( isset( $wgLogHeaders[$this->type] ) ) {
464  $key = $wgLogHeaders[$this->type];
465  } else {
466  $key = 'log-description-' . $this->type;
467  }
468 
469  return wfMessage( $key );
470  }
471 
477  public function getRestriction() {
478  global $wgLogRestrictions;
479  if ( isset( $wgLogRestrictions[$this->type] ) ) {
480  $restriction = $wgLogRestrictions[$this->type];
481  } else {
482  // '' always returns true with $user->isAllowed()
483  $restriction = '';
484  }
485 
486  return $restriction;
487  }
488 
494  public function isRestricted() {
495  $restriction = $this->getRestriction();
496 
497  return $restriction !== '' && $restriction !== '*';
498  }
499 }
static makeParamBlob($params)
Create a blob from a parameter array.
Definition: LogPage.php:419
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
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
getRestriction()
Returns the right needed to read this log type.
Definition: LogPage.php:477
static actionText($type, $action, $title=null, $skin=null, $params=[], $filterWikilinks=false)
Generate text for a log entry.
Definition: LogPage.php:227
$context
Definition: load.php:50
bool $updateRecentChanges
Definition: LogPage.php:43
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
addRelations($field, $values, $logid)
Add relations to log_search table.
Definition: LogPage.php:392
string $ircActionText
Plaintext version of the message for IRC.
Definition: LogPage.php:49
if(!isset($args[0])) $lang
static newFromEntry(LogEntry $entry)
Constructs a new formatter suitable for given entry.
$value
static newFromId($id)
Static factory method for creation from a given user ID.
Definition: User.php:548
string $type
One of '', 'block', 'protect', 'rights', 'delete', 'upload', 'move'.
Definition: LogPage.php:57
const SUPPRESSED_ACTION
Definition: LogPage.php:40
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
saveContent()
Definition: LogPage.php:92
const DB_MASTER
Definition: defines.php:23
static extractParams($blob)
Extract a parameter array from a blob.
Definition: LogPage.php:429
User $doer
The user doing the action.
Definition: LogPage.php:70
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
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
if($line===false) $args
Definition: cdb.php:64
Class to simplify the use of log pages.
Definition: LogPage.php:32
isRestricted()
Tells if this log is not viewable by all.
Definition: LogPage.php:494
const DELETED_COMMENT
Definition: LogPage.php:34
addEntry($action, $target, $comment, $params=[], $doer=null)
Add a log entry.
Definition: LogPage.php:334
static notifyLog($timestamp, &$title, &$user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC= '')
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 unsetoffset-wrap String Wrap the message in html(usually something like"&lt
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:460
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive false for true for descending in case the handler function wants to provide a converted Content object Note that $result getContentModel() must return $toModel. 'CustomEditor'$rcid is used in generating this variable which contains information about the new such as the revision s whether the revision was marked as a minor edit or etc which include things like revision author revision comment
Definition: hooks.txt:1156
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
static getTitleLink($type, $lang, $title, &$params)
Definition: LogPage.php:296
static newExtraneousContext(Title $title, $request=[])
Create a new extraneous context.
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:953
string $actionText
Plaintext version of the message.
Definition: LogPage.php:52
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:1936
static isLogType($type)
Is $type a valid log type.
Definition: LogPage.php:210
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:36
static link($target, $html=null, $customAttribs=[], $query=[], $options=[])
This function returns an HTML link to the given target.
Definition: Linker.php:203
const DELETED_USER
Definition: LogPage.php:35
const SUPPRESSED_USER
Definition: LogPage.php:39
Title $target
Definition: LogPage.php:73
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
__construct($type, $rc=true, $udp= 'skipUDP')
Constructor.
Definition: LogPage.php:83
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
Class for creating log entries manually, to inject them into the database.
Definition: LogEntry.php:394
bool $sendToUDP
Definition: LogPage.php:46
static resolveAlias($alias)
Given a special page name with a possible subpage, return an array where the first element is the spe...
getRcComment()
Get the RC comment from the last addEntry() call.
Definition: LogPage.php:150
string $params
Blob made of a parameters array.
Definition: LogPage.php:67
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 local content language as $wgContLang
Definition: design.txt:56
getName()
Name of the log.
Definition: LogPage.php:442
string $action
One of '', 'block', 'protect', 'rights', 'delete', 'upload', 'move', 'move_redir'.
Definition: LogPage.php:61
const DELETED_ACTION
Definition: LogPage.php:33
static newLogEntry($timestamp, &$title, &$user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC= '', $revId=0, $isPatrollable=false)
static validTypes()
Get the list of valid log types.
Definition: LogPage.php:198
string $comment
Comment associated with action.
Definition: LogPage.php:64
getComment()
Get the comment from the last addEntry() call.
Definition: LogPage.php:189
$wgUser
Definition: Setup.php:806
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:300