Kaldari has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/58450


Change subject: Adding logging to Thanks extension
......................................................................

Adding logging to Thanks extension

Change-Id: I6f58924ae9ec9f581434f9f183cf8842b6142159
---
M ApiThank.php
M Thanks.i18n.php
M Thanks.php
A ThanksLogFormatter.php
4 files changed, 46 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Thanks 
refs/changes/50/58450/1

diff --git a/ApiThank.php b/ApiThank.php
index 095ebb0..29ff0b6 100644
--- a/ApiThank.php
+++ b/ApiThank.php
@@ -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,15 @@
                                ) );
                                // 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 );
+                                       $recipientUser = User::newFromId( 
$recipient );
+                                       $target = $recipientUser->getUserPage();
+                                       $logEntry->setTarget( $target );
+                                       $logid = $logEntry->insert();
+                               }
                        }
                }
                $this->getResult()->addValue( null, 'result', $result );
diff --git a/Thanks.i18n.php b/Thanks.i18n.php
index 8d3e4ba..27e718b 100644
--- a/Thanks.i18n.php
+++ b/Thanks.i18n.php
@@ -32,6 +32,9 @@
 
 $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 @@
        '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)',
 );
diff --git a/Thanks.php b/Thanks.php
index 3fa0da8..f276148 100644
--- a/Thanks.php
+++ b/Thanks.php
@@ -44,6 +44,7 @@
 $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 @@
        '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 ) ),
diff --git a/ThanksLogFormatter.php b/ThanksLogFormatter.php
new file mode 100644
index 0000000..b55c2b2
--- /dev/null
+++ b/ThanksLogFormatter.php
@@ -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() ) );
+       }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/58450
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6f58924ae9ec9f581434f9f183cf8842b6142159
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Thanks
Gerrit-Branch: master
Gerrit-Owner: Kaldari <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to