Manual:Logging to Special:Log
This page describes how to log actions to Special:Log.
Contents |
1.19 and later [edit]
This is example code for extensions. The same applies for core, but the configuration is in DefaultSettings.php and messages in different places.
// In your extension setup file. $wgLogTypes[] = 'foo'; /* You can still set $wgLogNames['foo'] = 'foo-name'; $wgLogHeaders['foo'] = 'foo-header'; * But you don't need to, if you follow this naming convention: * log-name-foo for log name * log-description-foo for log description of the log */ $wgLogActionsHandlers['foo/bar'] = 'LogFormatter'; /* Or if you want catch-all, do $wgLogActionsHandlers['foo/*'] = 'LogFormatter'; * Or if you need some extra logic, you can write your own formatter and do $wgLogActionsHandlers['foo/*'] = 'FooLogFormatter'; * See https://svn.wikimedia.org/doc/classLogFormatter.html */ // In your extension.i18n.php file $messages['en'] = array( ... 'log-name-foo' => 'Foo log', 'log-description-foo' => 'These events track when Foo events happen in the system.', 'logentry-foo-bar' => '$1 {{GENDER:$2|did bar}} to page $3', ... ); // Somewhere else in your code where you want to generate a log entry $logEntry = new ManualLogEntry( 'foo', 'bar' ); // Action bar in log foo $logEntry->setPerformer( $user ); // User object, the user who did this action $logEntry->setTarget( $this ); // The page that this log entry affects $logEntry->setComment( $reason ); // User provided comment, optional $logEntry->setParameters( array( // Parameter numbering should start from 4. // These can be used in the messages as $4, $5 and so on // If you want to store stuff that should not be available in messages, // just don't prefix with a number and don't use the colons. // The format is index:format specifier:name. Indexes from 1 to 3 are reserved // and provide the username and target page parameters for the messages. // Format specifier is currently unused, but in future you could say for example // that this param is a number, format it according to the user language. // Name is just for giving identifier for the value, and helps to debug issues // versus unindexed list of parameters. '4::paramname' => 'customparam', 'hiddenparam' => 'ugly stuff', ) ); // Were not done yet, we need to insert the log entry into the database // Insert adds it to the logging table and returns the id of that log entry $logid = $logEntry->insert(); // Then we can publish it in recent changes and the UDP feed of recent changes // if we want. UDP feed is mainly used for echoing the recent change items into IRC. // publish() takes second param with values 'rcandudp' (default), 'rc' and 'udp'. $logEntry->publish( $logid );
Pre 1.19 [edit]
There are ways to use this system but make it forward compatible with the new system by using the message name format described above. Extra parameters are what are causing most of the issues. You can make the messages like above:
'logentry-foo-bar' => '$1 {{GENDER:$2|did bar}} to page $3',
And pass empty value for param $1, because the old system will prepend the username automatically; # for $2 to avoid automatic gender feature using the gender of the reader. Custom parameters should start at $4.
An example of adding a new log type called "foo" for your extension, using the LogPage class. In the MyExtension.php file, add:
// Internal name of the log, Special:Log/foo $wgLogTypes[] = 'foo'; // System message containing the friendly name of the log. Shows up // in the page title and the Special:Log dropdown // Use $wgLogNames['foo'] = 'foo-name'; // System message containing the introductory text on Special:Log when this page is shown $wgLogHeaders['foo'] = 'foo-header';
Create system messages for your extension in MyExtension.i18n.php:
$messages['en'] = array( ... 'foo' => 'Foo', 'foo-name' => 'Foo log', 'foo-header' => 'These events track when Foo events happen in the system.', 'foo-message' => 'A Foo event happened to article [[$1]]', ... );
In the body file MyExtension_body.php, add this code, which adds entries in both Special:Log/foo and Special:RecentChanges:
global $wgTitle, $wgUser; $log = new LogPage( 'foo' ); // See alternative below $log->addEntry( 'bar', $wgTitle, wfMsg( 'foo-message', $wgTitle->getFullText() ), array(), $wgUser );
If you don't want your events to show up in Special:RecentChanges, which might cause watchlist notifications, change the constructor to:
$log = new LogPage( 'foo', false ); // Second arg = false
See also [edit]
| Language: | English • polski |
|---|