MediaWiki extension CentralLogging

Clone this repo:
  1. 0f1efa0 build: Updating eslint-config-wikimedia to 0.27.0 by libraryupgrader · 7 days ago master
  2. 97378b8 build: Updating mediawiki/mediawiki-codesniffer to 43.0.0 by libraryupgrader · 6 weeks ago REL1_42
  3. 1353e5c build: Updating dependencies by libraryupgrader · 3 months ago
  4. cb87a20 build: Updating npm dependencies by libraryupgrader · 3 months ago
  5. 7018849 build: Updating eslint-config-wikimedia to 0.25.1 by libraryupgrader · 3 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.