MediaWiki REL1_30
LogPage.php
Go to the documentation of this file.
1<?php
31class LogPage {
32 const DELETED_ACTION = 1;
33 const DELETED_COMMENT = 2;
34 const DELETED_USER = 4;
36
37 // Convenience fields
38 const SUPPRESSED_USER = 12;
40
43
45 public $sendToUDP;
46
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() {
90 global $wgLogRestrictions;
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_user' => $this->doer->getId(),
101 'log_user_text' => $this->doer->getName(),
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::newKey( 'log_comment' )->insert( $dbw, $this->comment );
108 $dbw->insert( 'logging', $data, __METHOD__ );
109 $newId = $dbw->insertId();
110
111 # And update recentchanges
112 if ( $this->updateRecentChanges ) {
113 $titleObj = SpecialPage::getTitleFor( 'Log', $this->type );
114
116 $now, $titleObj, $this->doer, $this->getRcComment(), '',
117 $this->type, $this->action, $this->target, $this->comment,
118 $this->params, $newId, $this->getRcCommentIRC()
119 );
120 } elseif ( $this->sendToUDP ) {
121 # Don't send private logs to UDP
122 if ( isset( $wgLogRestrictions[$this->type] ) && $wgLogRestrictions[$this->type] != '*' ) {
123 return $newId;
124 }
125
126 # Notify external application via UDP.
127 # We send this to IRC but do not want to add it the RC table.
128 $titleObj = SpecialPage::getTitleFor( 'Log', $this->type );
130 $now, $titleObj, $this->doer, $this->getRcComment(), '',
131 $this->type, $this->action, $this->target, $this->comment,
132 $this->params, $newId, $this->getRcCommentIRC()
133 );
134 $rc->notifyRCFeeds();
135 }
136
137 return $newId;
138 }
139
145 public function getRcComment() {
146 $rcComment = $this->actionText;
147
148 if ( $this->comment != '' ) {
149 if ( $rcComment == '' ) {
150 $rcComment = $this->comment;
151 } else {
152 $rcComment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() .
154 }
155 }
156
157 return $rcComment;
158 }
159
165 public function getRcCommentIRC() {
166 $rcComment = $this->ircActionText;
167
168 if ( $this->comment != '' ) {
169 if ( $rcComment == '' ) {
170 $rcComment = $this->comment;
171 } else {
172 $rcComment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() .
174 }
175 }
176
177 return $rcComment;
178 }
179
184 public function getComment() {
185 return $this->comment;
186 }
187
193 public static function validTypes() {
194 global $wgLogTypes;
195
196 return $wgLogTypes;
197 }
198
205 public static function isLogType( $type ) {
206 return in_array( $type, self::validTypes() );
207 }
208
222 public static function actionText( $type, $action, $title = null, $skin = null,
223 $params = [], $filterWikilinks = false
224 ) {
226
227 if ( is_null( $skin ) ) {
228 $langObj = $wgContLang;
229 $langObjOrNull = null;
230 } else {
231 $langObj = $wgLang;
232 $langObjOrNull = $wgLang;
233 }
234
235 $key = "$type/$action";
236
237 if ( isset( $wgLogActions[$key] ) ) {
238 if ( is_null( $title ) ) {
239 $rv = wfMessage( $wgLogActions[$key] )->inLanguage( $langObj )->escaped();
240 } else {
241 $titleLink = self::getTitleLink( $type, $langObjOrNull, $title, $params );
242
243 if ( count( $params ) == 0 ) {
244 $rv = wfMessage( $wgLogActions[$key] )->rawParams( $titleLink )
245 ->inLanguage( $langObj )->escaped();
246 } else {
247 array_unshift( $params, $titleLink );
248
249 $rv = wfMessage( $wgLogActions[$key] )->rawParams( $params )
250 ->inLanguage( $langObj )->escaped();
251 }
252 }
253 } else {
255
256 if ( isset( $wgLogActionsHandlers[$key] ) ) {
257 $args = func_get_args();
258 $rv = call_user_func_array( $wgLogActionsHandlers[$key], $args );
259 } else {
260 wfDebug( "LogPage::actionText - unknown action $key\n" );
261 $rv = "$action";
262 }
263 }
264
265 // For the perplexed, this feature was added in r7855 by Erik.
266 // The feature was added because we liked adding [[$1]] in our log entries
267 // but the log entries are parsed as Wikitext on RecentChanges but as HTML
268 // on Special:Log. The hack is essentially that [[$1]] represented a link
269 // to the title in question. The first parameter to the HTML version (Special:Log)
270 // is that link in HTML form, and so this just gets rid of the ugly [[]].
271 // However, this is a horrible hack and it doesn't work like you expect if, say,
272 // you want to link to something OTHER than the title of the log entry.
273 // The real problem, which Erik was trying to fix (and it sort-of works now) is
274 // that the same messages are being treated as both wikitext *and* HTML.
275 if ( $filterWikilinks ) {
276 $rv = str_replace( '[[', '', $rv );
277 $rv = str_replace( ']]', '', $rv );
278 }
279
280 return $rv;
281 }
282
291 protected static function getTitleLink( $type, $lang, $title, &$params ) {
292 if ( !$lang ) {
293 return $title->getPrefixedText();
294 }
295
296 if ( $title->isSpecialPage() ) {
297 list( $name, $par ) = SpecialPageFactory::resolveAlias( $title->getDBkey() );
298
299 # Use the language name for log titles, rather than Log/X
300 if ( $name == 'Log' ) {
301 $logPage = new LogPage( $par );
302 $titleLink = Linker::link( $title, $logPage->getName()->escaped() );
303 $titleLink = wfMessage( 'parentheses' )
304 ->inLanguage( $lang )
305 ->rawParams( $titleLink )
306 ->escaped();
307 } else {
308 $titleLink = Linker::link( $title );
309 }
310 } else {
311 $titleLink = Linker::link( $title );
312 }
313
314 return $titleLink;
315 }
316
329 public function addEntry( $action, $target, $comment, $params = [], $doer = null ) {
330 if ( !is_array( $params ) ) {
331 $params = [ $params ];
332 }
333
334 if ( $comment === null ) {
335 $comment = '';
336 }
337
338 # Trim spaces on user supplied text
339 $comment = trim( $comment );
340
341 $this->action = $action;
342 $this->target = $target;
343 $this->comment = $comment;
344 $this->params = self::makeParamBlob( $params );
345
346 if ( $doer === null ) {
347 global $wgUser;
348 $doer = $wgUser;
349 } elseif ( !is_object( $doer ) ) {
350 $doer = User::newFromId( $doer );
351 }
352
353 $this->doer = $doer;
354
355 $logEntry = new ManualLogEntry( $this->type, $action );
356 $logEntry->setTarget( $target );
357 $logEntry->setPerformer( $doer );
358 $logEntry->setParameters( $params );
359 // All log entries using the LogPage to insert into the logging table
360 // are using the old logging system and therefore the legacy flag is
361 // needed to say the LogFormatter the parameters have numeric keys
362 $logEntry->setLegacy( true );
363
364 $formatter = LogFormatter::newFromEntry( $logEntry );
366 $formatter->setContext( $context );
367
368 $this->actionText = $formatter->getPlainActionText();
369 $this->ircActionText = $formatter->getIRCActionText();
370
371 return $this->saveContent();
372 }
373
382 public function addRelations( $field, $values, $logid ) {
383 if ( !strlen( $field ) || empty( $values ) ) {
384 return false; // nothing
385 }
386
387 $data = [];
388
389 foreach ( $values as $value ) {
390 $data[] = [
391 'ls_field' => $field,
392 'ls_value' => $value,
393 'ls_log_id' => $logid
394 ];
395 }
396
397 $dbw = wfGetDB( DB_MASTER );
398 $dbw->insert( 'log_search', $data, __METHOD__, 'IGNORE' );
399
400 return true;
401 }
402
409 public static function makeParamBlob( $params ) {
410 return implode( "\n", $params );
411 }
412
419 public static function extractParams( $blob ) {
420 if ( $blob === '' ) {
421 return [];
422 } else {
423 return explode( "\n", $blob );
424 }
425 }
426
432 public function getName() {
433 global $wgLogNames;
434
435 // BC
436 if ( isset( $wgLogNames[$this->type] ) ) {
437 $key = $wgLogNames[$this->type];
438 } else {
439 $key = 'log-name-' . $this->type;
440 }
441
442 return wfMessage( $key );
443 }
444
450 public function getDescription() {
451 global $wgLogHeaders;
452 // BC
453 if ( isset( $wgLogHeaders[$this->type] ) ) {
455 } else {
456 $key = 'log-description-' . $this->type;
457 }
458
459 return wfMessage( $key );
460 }
461
467 public function getRestriction() {
468 global $wgLogRestrictions;
469 if ( isset( $wgLogRestrictions[$this->type] ) ) {
470 $restriction = $wgLogRestrictions[$this->type];
471 } else {
472 // '' always returns true with $user->isAllowed()
473 $restriction = '';
474 }
475
476 return $restriction;
477 }
478
484 public function isRestricted() {
485 $restriction = $this->getRestriction();
486
487 return $restriction !== '' && $restriction !== '*';
488 }
489}
$wgLogActions
Lists the message key string for formatting individual events of each type and action when listed in ...
$wgLogNames
Lists the message key string for each log type.
$wgLogTypes
The logging system has two levels: an event type, which describes the general category and can be vie...
$wgLogRestrictions
This restricts log access to those who have a certain right Users without this will not see it in the...
$wgLogHeaders
Lists the message key string for descriptive text to be shown at the top of each log type.
$wgLogActionsHandlers
The same as above, but here values are names of classes, not messages.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
$wgUser
Definition Setup.php:817
if( $line===false) $args
Definition cdb.php:63
static newKey( $key)
Static constructor for easier chaining.
static link( $target, $html=null, $customAttribs=[], $query=[], $options=[])
This function returns an HTML link to the given target.
Definition Linker.php:107
static newFromEntry(LogEntry $entry)
Constructs a new formatter suitable for given entry.
Class to simplify the use of log pages.
Definition LogPage.php:31
static actionText( $type, $action, $title=null, $skin=null, $params=[], $filterWikilinks=false)
Generate text for a log entry.
Definition LogPage.php:222
getRestriction()
Returns the right needed to read this log type.
Definition LogPage.php:467
const SUPPRESSED_USER
Definition LogPage.php:38
__construct( $type, $rc=true, $udp='skipUDP')
Definition LogPage.php:80
const DELETED_USER
Definition LogPage.php:34
static makeParamBlob( $params)
Create a blob from a parameter array.
Definition LogPage.php:409
const DELETED_RESTRICTED
Definition LogPage.php:35
string $comment
Comment associated with action.
Definition LogPage.php:63
bool $sendToUDP
Definition LogPage.php:45
string $ircActionText
Plaintext version of the message for IRC.
Definition LogPage.php:48
User $doer
The user doing the action.
Definition LogPage.php:69
string $action
One of '', 'block', 'protect', 'rights', 'delete', 'upload', 'move', 'move_redir'.
Definition LogPage.php:60
isRestricted()
Tells if this log is not viewable by all.
Definition LogPage.php:484
static extractParams( $blob)
Extract a parameter array from a blob.
Definition LogPage.php:419
static isLogType( $type)
Is $type a valid log type.
Definition LogPage.php:205
static getTitleLink( $type, $lang, $title, &$params)
Definition LogPage.php:291
getName()
Name of the log.
Definition LogPage.php:432
string $actionText
Plaintext version of the message.
Definition LogPage.php:51
addEntry( $action, $target, $comment, $params=[], $doer=null)
Add a log entry.
Definition LogPage.php:329
saveContent()
Definition LogPage.php:89
const DELETED_COMMENT
Definition LogPage.php:33
getComment()
Get the comment from the last addEntry() call.
Definition LogPage.php:184
bool $updateRecentChanges
Definition LogPage.php:42
getRcComment()
Get the RC comment from the last addEntry() call.
Definition LogPage.php:145
string $type
One of '', 'block', 'protect', 'rights', 'delete', 'upload', 'move'.
Definition LogPage.php:56
addRelations( $field, $values, $logid)
Add relations to log_search table.
Definition LogPage.php:382
static validTypes()
Get the list of valid log types.
Definition LogPage.php:193
getRcCommentIRC()
Get the RC comment from the last addEntry() call for IRC.
Definition LogPage.php:165
Title $target
Definition LogPage.php:72
string $params
Blob made of a parameters array.
Definition LogPage.php:66
getDescription()
Description of this log type.
Definition LogPage.php:450
const DELETED_ACTION
Definition LogPage.php:32
const SUPPRESSED_ACTION
Definition LogPage.php:39
Class for creating log entries manually, to inject them into the database.
Definition LogEntry.php:400
static newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='', $revId=0, $isPatrollable=false)
static notifyLog( $timestamp, &$title, &$user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='')
static newExtraneousContext(Title $title, $request=[])
Create a new extraneous context.
static resolveAlias( $alias)
Given a special page name with a possible subpage, return an array where the first element is the spe...
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,...
Represents a title within MediaWiki.
Definition Title.php:39
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:51
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
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:57
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
info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) action
Definition hooks.txt:1855
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:2780
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;div ...>$1&lt;/div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
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:36
const DB_MASTER
Definition defines.php:26
if(!isset( $args[0])) $lang