Manual:Registrar en Especial:Registro
Esta página describe cómo registrar acciones en Special:Log
.
(En Manual:Registro estructurado se cubre cómo registrar en el registro de la aplicación.)
Ejemplo
Esto ilustra cómo codificar entradas de Special:Log
para extensiones.
Los mensajes del registro aparecen en la página Special:Log
y se pueden filtrar, por ejemplo, por el nombre del registro, el usuario, el título o el rango de fechas.
En en archivo de configuración de tu extensión
Lo siguiente debería funcionar en extension.json
:
{
"LogTypes": [ "foo" ],
"LogNames": {
"foo": "foo-name"
},
"LogHeaders": {
"foo": "foo-header"
},
"LogActionsHandlers": {
"foo/*": "LogFormatter"
}
}
En el archivo 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"
}
Documentación de mensaje (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"
}
En el código de la extensión
// 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
// De forma opcional, añade parámetros adicionales para utilizar en el mensaje internacionalizado de la entrada del registro.
// La numeración debería empezar desde el 4 y se puede emplear en el mensaje como $4, $5, etc.
//
// Los índices $1, $2 y $3 están reservados y proporcionan los parámetros del nombre de usuario y de la página objetivo para los mensajes.
// $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
//
// Si deseas almacenar información que no debería estar disponible en los mensajes, no prefijes la clave del vector con un número y no utilices el carácter de dos puntos.
//
// 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 );
Añadir enlaces
Para añadir un enlace a las entradas del registro, pasa el nombre de la página, etc. en los parámetros del registro y formatéalos en tu LogFormatter mediante makePageLink()
.
Con otros métodos, la salida que no sea HTML (como la alimentación de datos por UDP a IRC) se romperá.
Véase LogFormatter para un ejemplo de LogFormatter con enlaces.
Véase también
- Manual:$wgLogTypes
- Manual:$wgLogActions
- Manual:$wgLogNames
- Manual:$wgLogHeaders
- Manual:$wgLogActionsHandlers
- Manual:$wgLogRestrictions
- Manual:$wgFilterLogTypes
- Manual:$wgActionFilteredLogs
- T26620 - Las entradas del registro son difíciles de localizar; reescribir sistema de registros