Manual:Registrando na Special:Log
Appearance
Esta página descreve como registrar ações na Special:Log.
(O registro de dados e operações é coberto em Manual:Registro estruturado.)
Exemplo
Mostraremos como codificar entradas da Special:Log para extensões.
As mensagens de registro aparecem na página Special:Log e podem ser filtradas por, p. ex., nome do registro, usuário, título ou data.
No arquivo de configuração da sua extensão
Isto deve funcionar na extension.json:
{
"LogTypes": [ "foo" ],
"LogNames": {
"foo": "foo-name"
},
"LogHeaders": {
"foo": "foo-header"
},
"LogActionsHandlers": {
"foo/*": "LogFormatter"
}
}
No arquivo i18n/en.json
{
"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"
}
Documentação da mensagem (qqq.json):
{
"log-name-foo": "The Special:Log log name that appears in the drop-down on the Special:Log page",
"log-description-foo": "The Special:Log description that appears on the Special:Log page when you filter logs on this specific log name",
"logentry-foo-bar": "The template of the log entry message"
}
No código da extensão
// Anywhere in your code where you want to generate a log entry
$logEntry = new ManualLogEntry( 'foo', 'bar' ); // Log action 'bar' in the Special:Log for 'foo'
$logEntry->setPerformer( $user ); // User object, the user who performed this action
$logEntry->setTarget( $this ); // The page that this log entry affects, a Title object
$logEntry->setComment( $reason ); // Optional, user provided comment
// Opcionalmente, adicione parâmetros extras para uso na mensagem i18n (traduzida) da entrada de registro.
// A numeração deve começar em 4 e pode ser usada na mensagem como $4, $5 e assim por diante.
//
// Os índices $1, $2 e $3 são reservados e fornecem o nome de usuário e os parâmetros da página de destino para as mensagens.
// $1 is a reference to the user page and user talk page in the wiki
// $2 is used to determine the gender of the user for any gender specific messages
// $3 is a reference to the page on which the action took place
//
// Para armazenar coisas que não devem estar disponíveis nas mensagens, não coloque um número como prefixo da chave do arranjo, nem use dois-pontos.
//
// The format is index:formatspecifier:name.
// 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.
$logEntry->setParameters( [
'4::paramname' => 'customparam',
'hiddenparam' => 'ugly stuff',
] );
// We're 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();
// Optionally, publish the log entry 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 );
Adicionando ligações
Para adicionar uma ligação às entradas de registro, deve-se passar o nome da página, etc., nos parâmetros do registro, e formatá-la no seu LogFormatter usando makePageLink().
Com outros métodos, saídas que não em HTML (como o feed UDP no IRC) não funcionarão.
Veja LogFormatter para um exemplo com ligações.
Ver também
- Manual:$wgLogTypes
- Manual:$wgLogActions
- Manual:$wgLogNames
- Manual:$wgLogHeaders
- Manual:$wgLogActionsHandlers
- Manual:$wgLogRestrictions
- Manual:$wgFilterLogTypes
- Manual:$wgActionFilteredLogs
- T26620 - Dificuldade de localizar entradas de registro; reescrita do sistema de registros