mediawiki/extensions/CentralLogging - Gitiles

MediaWiki extension CentralLogging

Clone this repo:
  1. a6d7d87 build: Updating micromatch to 4.0.8 by libraryupgrader · 8 weeks ago master
  2. 3deb311 build: Updating mediawiki/mediawiki-codesniffer to 44.0.0 by libraryupgrader · 10 weeks ago
  3. f45039a build: Updating eslint-config-wikimedia to 0.28.2 by libraryupgrader · 4 months ago
  4. f3d30d4 build: Updating braces to 3.0.3 by libraryupgrader · 4 months ago
  5. 8d76dbb build: Updating eslint-config-wikimedia to 0.28.0 by libraryupgrader · 5 months ago

CentralLogging

CentralLogging is a MediaWiki extension that lets extensions send log entries to a central wiki. It provides no functionality by itself, rather is a framework for other functions to use.

Configuration

$wgCentralWiki should be set to the database name of the central wiki to log on. Indivdual extensions will be able to override this if they choose to do so. The default value is:

$wgCentralWiki = 'metawiki';

When setting up an extension to use CentralLogging, you need to set a few global variables:

$wgLogTypes[] = 'foo'; // You should do this anyways
$wgLogActionsHandlers['foo/*'] = 'CentralLogFormatter';

Example code

Some example usage would look like:

$entry = new CentralLogEntry( 'foo', 'bar' );

After this step, the next set of code is the same as ManualLogEntry. See https://www.mediawiki.org/wiki/Manual:Logging_to_Special:Log for more details

$entry->setTitle( $title );
$entry->setPerformer( $user );
$entry->setComment( 'comment' );

Now we need to queue the message rather than insert it

$entry->queue( $dbname = null, $publish = true, $to = 'rcandudp' );

All parameters are optional:

  • $dbname: if it is set to null, it defaults to $wgCentralWiki
  • $publish: whether we should call ManualLogEntry::publish afterwards. By default this is true.
  • $to: this will just be passed to ManualLogEntry::publish if it is called. This is 'rcandudp' by default.

Another implementation might look like:

if ( class_exists( 'CentralLogEntry' ) ) {
	$entry = new CentralLogEntry( 'foo', 'bar' );
} else {
	$entry = new ManualLogEntry( 'foo', 'bar' );
}
	$entry->setTitle( $title );
	$entry->setPerformer( $user );
	$entry->setComment( 'comment ');
if ( $entry instanceof CentralLogEntry ) {
	$entry->queue();
} else {
	$logId = $entry->insert();
	$entry->publish( $logId );
}

This will let your extension take advantage of central logging if you have this extension enabled, otherwise it falls back upon the local logging system.