MediaWiki  1.29.2
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 
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  $log_id = $dbw->nextSequenceValue( 'logging_log_id_seq' );
96 
97  // @todo FIXME private/protected/public property?
98  $this->timestamp = $now = wfTimestampNow();
99  $data = [
100  'log_id' => $log_id,
101  'log_type' => $this->type,
102  'log_action' => $this->action,
103  'log_timestamp' => $dbw->timestamp( $now ),
104  'log_user' => $this->doer->getId(),
105  'log_user_text' => $this->doer->getName(),
106  'log_namespace' => $this->target->getNamespace(),
107  'log_title' => $this->target->getDBkey(),
108  'log_page' => $this->target->getArticleID(),
109  'log_comment' => $this->comment,
110  'log_params' => $this->params
111  ];
112  $dbw->insert( 'logging', $data, __METHOD__ );
113  $newId = !is_null( $log_id ) ? $log_id : $dbw->insertId();
114 
115  # And update recentchanges
116  if ( $this->updateRecentChanges ) {
117  $titleObj = SpecialPage::getTitleFor( 'Log', $this->type );
118 
120  $now, $titleObj, $this->doer, $this->getRcComment(), '',
121  $this->type, $this->action, $this->target, $this->comment,
122  $this->params, $newId, $this->getRcCommentIRC()
123  );
124  } elseif ( $this->sendToUDP ) {
125  # Don't send private logs to UDP
126  if ( isset( $wgLogRestrictions[$this->type] ) && $wgLogRestrictions[$this->type] != '*' ) {
127  return $newId;
128  }
129 
130  # Notify external application via UDP.
131  # We send this to IRC but do not want to add it the RC table.
132  $titleObj = SpecialPage::getTitleFor( 'Log', $this->type );
134  $now, $titleObj, $this->doer, $this->getRcComment(), '',
135  $this->type, $this->action, $this->target, $this->comment,
136  $this->params, $newId, $this->getRcCommentIRC()
137  );
138  $rc->notifyRCFeeds();
139  }
140 
141  return $newId;
142  }
143 
149  public function getRcComment() {
150  $rcComment = $this->actionText;
151 
152  if ( $this->comment != '' ) {
153  if ( $rcComment == '' ) {
154  $rcComment = $this->comment;
155  } else {
156  $rcComment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() .
158  }
159  }
160 
161  return $rcComment;
162  }
163 
169  public function getRcCommentIRC() {
170  $rcComment = $this->ircActionText;
171 
172  if ( $this->comment != '' ) {
173  if ( $rcComment == '' ) {
174  $rcComment = $this->comment;
175  } else {
176  $rcComment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() .
178  }
179  }
180 
181  return $rcComment;
182  }
183 
188  public function getComment() {
189  return $this->comment;
190  }
191 
197  public static function validTypes() {
198  global $wgLogTypes;
199 
200  return $wgLogTypes;
201  }
202 
209  public static function isLogType( $type ) {
210  return in_array( $type, LogPage::validTypes() );
211  }
212 
226  public static function actionText( $type, $action, $title = null, $skin = null,
227  $params = [], $filterWikilinks = false
228  ) {
229  global $wgLang, $wgContLang, $wgLogActions;
230 
231  if ( is_null( $skin ) ) {
232  $langObj = $wgContLang;
233  $langObjOrNull = null;
234  } else {
235  $langObj = $wgLang;
236  $langObjOrNull = $wgLang;
237  }
238 
239  $key = "$type/$action";
240 
241  if ( isset( $wgLogActions[$key] ) ) {
242  if ( is_null( $title ) ) {
243  $rv = wfMessage( $wgLogActions[$key] )->inLanguage( $langObj )->escaped();
244  } else {
245  $titleLink = self::getTitleLink( $type, $langObjOrNull, $title, $params );
246 
247  if ( count( $params ) == 0 ) {
248  $rv = wfMessage( $wgLogActions[$key] )->rawParams( $titleLink )
249  ->inLanguage( $langObj )->escaped();
250  } else {
251  array_unshift( $params, $titleLink );
252 
253  $rv = wfMessage( $wgLogActions[$key] )->rawParams( $params )
254  ->inLanguage( $langObj )->escaped();
255  }
256  }
257  } else {
258  global $wgLogActionsHandlers;
259 
260  if ( isset( $wgLogActionsHandlers[$key] ) ) {
261  $args = func_get_args();
262  $rv = call_user_func_array( $wgLogActionsHandlers[$key], $args );
263  } else {
264  wfDebug( "LogPage::actionText - unknown action $key\n" );
265  $rv = "$action";
266  }
267  }
268 
269  // For the perplexed, this feature was added in r7855 by Erik.
270  // The feature was added because we liked adding [[$1]] in our log entries
271  // but the log entries are parsed as Wikitext on RecentChanges but as HTML
272  // on Special:Log. The hack is essentially that [[$1]] represented a link
273  // to the title in question. The first parameter to the HTML version (Special:Log)
274  // is that link in HTML form, and so this just gets rid of the ugly [[]].
275  // However, this is a horrible hack and it doesn't work like you expect if, say,
276  // you want to link to something OTHER than the title of the log entry.
277  // The real problem, which Erik was trying to fix (and it sort-of works now) is
278  // that the same messages are being treated as both wikitext *and* HTML.
279  if ( $filterWikilinks ) {
280  $rv = str_replace( '[[', '', $rv );
281  $rv = str_replace( ']]', '', $rv );
282  }
283 
284  return $rv;
285  }
286 
295  protected static function getTitleLink( $type, $lang, $title, &$params ) {
296  if ( !$lang ) {
297  return $title->getPrefixedText();
298  }
299 
300  if ( $title->isSpecialPage() ) {
301  list( $name, $par ) = SpecialPageFactory::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 = Linker::link( $title, $logPage->getName()->escaped() );
307  $titleLink = wfMessage( 'parentheses' )
308  ->inLanguage( $lang )
309  ->rawParams( $titleLink )
310  ->escaped();
311  } else {
312  $titleLink = Linker::link( $title );
313  }
314  } else {
315  $titleLink = Linker::link( $title );
316  }
317 
318  return $titleLink;
319  }
320 
333  public function addEntry( $action, $target, $comment, $params = [], $doer = null ) {
335 
336  if ( !is_array( $params ) ) {
337  $params = [ $params ];
338  }
339 
340  if ( $comment === null ) {
341  $comment = '';
342  }
343 
344  # Trim spaces on user supplied text
345  $comment = trim( $comment );
346 
347  # Truncate for whole multibyte characters.
348  $comment = $wgContLang->truncate( $comment, 255 );
349 
350  $this->action = $action;
351  $this->target = $target;
352  $this->comment = $comment;
353  $this->params = LogPage::makeParamBlob( $params );
354 
355  if ( $doer === null ) {
356  global $wgUser;
357  $doer = $wgUser;
358  } elseif ( !is_object( $doer ) ) {
360  }
361 
362  $this->doer = $doer;
363 
364  $logEntry = new ManualLogEntry( $this->type, $action );
365  $logEntry->setTarget( $target );
366  $logEntry->setPerformer( $doer );
367  $logEntry->setParameters( $params );
368  // All log entries using the LogPage to insert into the logging table
369  // are using the old logging system and therefore the legacy flag is
370  // needed to say the LogFormatter the parameters have numeric keys
371  $logEntry->setLegacy( true );
372 
373  $formatter = LogFormatter::newFromEntry( $logEntry );
375  $formatter->setContext( $context );
376 
377  $this->actionText = $formatter->getPlainActionText();
378  $this->ircActionText = $formatter->getIRCActionText();
379 
380  return $this->saveContent();
381  }
382 
391  public function addRelations( $field, $values, $logid ) {
392  if ( !strlen( $field ) || empty( $values ) ) {
393  return false; // nothing
394  }
395 
396  $data = [];
397 
398  foreach ( $values as $value ) {
399  $data[] = [
400  'ls_field' => $field,
401  'ls_value' => $value,
402  'ls_log_id' => $logid
403  ];
404  }
405 
406  $dbw = wfGetDB( DB_MASTER );
407  $dbw->insert( 'log_search', $data, __METHOD__, 'IGNORE' );
408 
409  return true;
410  }
411 
418  public static function makeParamBlob( $params ) {
419  return implode( "\n", $params );
420  }
421 
428  public static function extractParams( $blob ) {
429  if ( $blob === '' ) {
430  return [];
431  } else {
432  return explode( "\n", $blob );
433  }
434  }
435 
441  public function getName() {
442  global $wgLogNames;
443 
444  // BC
445  if ( isset( $wgLogNames[$this->type] ) ) {
446  $key = $wgLogNames[$this->type];
447  } else {
448  $key = 'log-name-' . $this->type;
449  }
450 
451  return wfMessage( $key );
452  }
453 
459  public function getDescription() {
460  global $wgLogHeaders;
461  // BC
462  if ( isset( $wgLogHeaders[$this->type] ) ) {
463  $key = $wgLogHeaders[$this->type];
464  } else {
465  $key = 'log-description-' . $this->type;
466  }
467 
468  return wfMessage( $key );
469  }
470 
476  public function getRestriction() {
477  global $wgLogRestrictions;
478  if ( isset( $wgLogRestrictions[$this->type] ) ) {
479  $restriction = $wgLogRestrictions[$this->type];
480  } else {
481  // '' always returns true with $user->isAllowed()
482  $restriction = '';
483  }
484 
485  return $restriction;
486  }
487 
493  public function isRestricted() {
494  $restriction = $this->getRestriction();
495 
496  return $restriction !== '' && $restriction !== '*';
497  }
498 }
$wgUser
$wgUser
Definition: Setup.php:781
LogPage\SUPPRESSED_ACTION
const SUPPRESSED_ACTION
Definition: LogPage.php:39
$context
error also a ContextSource you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2612
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:579
LogPage\SUPPRESSED_USER
const SUPPRESSED_USER
Definition: LogPage.php:38
LogPage\validTypes
static validTypes()
Get the list of valid log types.
Definition: LogPage.php:197
LogPage\getTitleLink
static getTitleLink( $type, $lang, $title, &$params)
Definition: LogPage.php:295
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
LogPage\extractParams
static extractParams( $blob)
Extract a parameter array from a blob.
Definition: LogPage.php:428
captcha-old.count
count
Definition: captcha-old.py:225
LogPage\isRestricted
isRestricted()
Tells if this log is not viewable by all.
Definition: LogPage.php:493
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:638
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
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:304
LogPage\actionText
static actionText( $type, $action, $title=null, $skin=null, $params=[], $filterWikilinks=false)
Generate text for a log entry.
Definition: LogPage.php:226
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')
Constructor.
Definition: LogPage.php:82
LogPage\getRestriction
getRestriction()
Returns the right needed to read this log type.
Definition: LogPage.php:476
LogPage\getComment
getComment()
Get the comment from the last addEntry() call.
Definition: LogPage.php:188
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
LogPage\DELETED_COMMENT
const DELETED_COMMENT
Definition: LogPage.php:33
$blob
$blob
Definition: testCompression.php:63
LogPage\DELETED_USER
const DELETED_USER
Definition: LogPage.php:34
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3060
LogPage\isLogType
static isLogType( $type)
Is $type a valid log type.
Definition: LogPage.php:209
LogPage\getDescription
getDescription()
Description of this log type.
Definition: LogPage.php:459
LogPage
Class to simplify the use of log pages.
Definition: LogPage.php:31
LogPage\getName
getName()
Name of the log.
Definition: LogPage.php:441
RecentChange\notifyLog
static notifyLog( $timestamp, &$title, &$user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='')
Definition: RecentChange.php:715
$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
LogPage\getRcCommentIRC
getRcCommentIRC()
Get the RC comment from the last addEntry() call for IRC.
Definition: LogPage.php:169
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:2023
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:999
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
captcha-old.action
action
Definition: captcha-old.py:189
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:418
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:149
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:338
LogPage\saveContent
saveContent()
Definition: LogPage.php:91
LogPage\$type
string $type
One of '', 'block', 'protect', 'rights', 'delete', 'upload', 'move'.
Definition: LogPage.php:56
LogPage\addRelations
addRelations( $field, $values, $logid)
Add relations to log_search table.
Definition: LogPage.php:391
LogPage\$ircActionText
string $ircActionText
Plaintext version of the message for IRC.
Definition: LogPage.php:48
$args
if( $line===false) $args
Definition: cdb.php:63
Title
Represents a title within MediaWiki.
Definition: Title.php:39
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
RecentChange\newLogEntry
static newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='', $revId=0, $isPatrollable=false)
Definition: RecentChange.php:748
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: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:1956
ManualLogEntry
Class for creating log entries manually, to inject them into the database.
Definition: LogEntry.php:396
LogPage\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: LogPage.php:35
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
LogPage\$updateRecentChanges
bool $updateRecentChanges
Definition: LogPage.php:42
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:50
LogPage\addEntry
addEntry( $action, $target, $comment, $params=[], $doer=null)
Add a log entry.
Definition: LogPage.php:333
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:56
LogFormatter\newFromEntry
static newFromEntry(LogEntry $entry)
Constructs a new formatter suitable for given entry.
Definition: LogFormatter.php:48