Adding logging to Thanks extension

Change-Id: I6f58924ae9ec9f581434f9f183cf8842b6142159
This commit is contained in:
kaldari 2013-04-09 20:45:44 -07:00
parent e3a4b724c1
commit ec71096c1a
4 changed files with 45 additions and 0 deletions

View file

@ -7,6 +7,7 @@
*/
class ApiThank extends ApiBase {
public function execute() {
global $wgThanksLogging;
if ( !class_exists( 'EchoNotifier' ) ) {
$this->dieUsage( 'Echo is not installed on this wiki', 'echonotinstalled' );
@ -58,6 +59,14 @@ class ApiThank extends ApiBase {
) );
// Set success message
$result['success'] = '1';
// Log it if we're supposed to log it
if ( $wgThanksLogging ) {
$logEntry = new ManualLogEntry( 'thanks', 'thank' );
$logEntry->setPerformer( $agent );
$target = User::newFromId( $recipient )->getUserPage();
$logEntry->setTarget( $target );
$logid = $logEntry->insert();
}
}
}
$this->getResult()->addValue( null, 'result', $result );

View file

@ -32,6 +32,9 @@ $3
$4',
'notification-thanks-email-batch-body' => '$1 {{GENDER:$1|thanked}} you for your edit on $2.',
'log-name-thanks' => 'Thanks log',
'log-description-thanks' => 'These events track when users thank other users',
'logentry-thanks-thank' => '$1 {{GENDER:$2|thanked}} $3',
);
/** Message documentation (Message documentation) */
@ -70,4 +73,10 @@ Used for <code>$2</code> in {{msg-mw|Notification-thanks}}. Should have capitali
'notification-thanks-email-batch-body' => 'E-mail notification. Parameters:
* $1 is a username. Can be used for GENDER.
* $2 the title of the page the user edited.',
'log-name-thanks' => 'Name of log that appears on Special:Log',
'log-description-thanks' => 'Description of thanks log',
'logentry-thanks-thank' => 'Log entry that is created when a user thanks another user for an edit. Parameters:
* $1 is a user link, for example "Jane Doe (Talk | contribs)"
* $2 is a username. Can be used for GENDER.
* $3 is a user link, for example "John Doe (Talk | contribs)',
);

View file

@ -44,6 +44,7 @@ $dir = __DIR__;
$wgAutoloadClasses['ThanksHooks'] = $dir . '/Thanks.hooks.php';
$wgAutoloadClasses['EchoThanksFormatter'] = $dir . '/ThanksFormatter.php';
$wgAutoloadClasses['ApiThank'] = $dir . '/ApiThank.php';
$wgAutoloadClasses['ThanksLogFormatter'] = $dir . '/ThanksLogFormatter.php';
$wgExtensionMessagesFiles['Thanks'] = $dir . '/Thanks.i18n.php';
// Register APIs
@ -77,11 +78,18 @@ $wgResourceModules['ext.thanks'] = array(
'remoteExtPath' => 'Thanks/modules',
);
// Logging
$wgLogTypes[] = 'thanks';
$wgLogActionsHandlers['thanks/*'] = 'ThanksLogFormatter';
/* Configuration */
// Enable sending thanks to bots
$wgThanksSendToBots = false;
// Whether or not thanks should be logged in Special:Log
$wgThanksLogging = true;
// Set how many thanks can be sent per minute by a single user (default 10)
$wgRateLimits += array(
'thanks-notification' => array( 'user' => array( 10, 60 ) ),

19
ThanksLogFormatter.php Normal file
View file

@ -0,0 +1,19 @@
<?php
/**
* This class formats log entries for thanks
*/
class ThanksLogFormatter extends LogFormatter {
protected function getMessageParameters() {
$params = parent::getMessageParameters();
// Convert target from a pageLink to a userLink since the target is
// actually a user, not a page.
$recipient = User::newFromName( $this->entry->getTarget()->getText(), false );
$params[2] = Message::rawParam( $this->makeUserLink( $recipient ) );
return $params;
}
public function getPreloadTitles() {
// Add the recipient's user talk page to LinkBatch
return array( Title::makeTitle( NS_USER_TALK, $this->entry->getTarget()->getText() ) );
}
}