Merge "Better logging for botpasswords"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 15 May 2018 00:59:09 +0000 (00:59 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 15 May 2018 00:59:09 +0000 (00:59 +0000)
includes/specials/SpecialBotPasswords.php

index 7b2d1bc..f03565a 100644 (file)
@@ -21,6 +21,8 @@
  * @ingroup SpecialPage
  */
 
+use MediaWiki\Logger\LoggerFactory;
+
 /**
  * Let users manage bot passwords
  *
@@ -40,8 +42,12 @@ class SpecialBotPasswords extends FormSpecialPage {
        /** @var string New password set, for communication between onSubmit() and onSuccess() */
        private $password = null;
 
+       /** @var Psr\Log\LoggerInterface */
+       private $logger = null;
+
        public function __construct() {
                parent::__construct( 'BotPasswords', 'editmyprivateinfo' );
+               $this->logger = LoggerFactory::getInstance( 'authentication' );
        }
 
        /**
@@ -277,6 +283,16 @@ class SpecialBotPasswords extends FormSpecialPage {
                                $bp = BotPassword::newFromCentralId( $this->userId, $this->par );
                                if ( $bp ) {
                                        $bp->delete();
+                                       $this->logger->info(
+                                               "Bot password {op} for {user}@{app_id}",
+                                               [
+                                                       'app_id' => $this->par,
+                                                       'user' => $this->getUser()->getName(),
+                                                       'centralId' => $this->userId,
+                                                       'op' => 'delete',
+                                                       'client_ip' => $this->getRequest()->getIP()
+                                               ]
+                                       );
                                }
                                return Status::newGood();
 
@@ -309,6 +325,18 @@ class SpecialBotPasswords extends FormSpecialPage {
                }
 
                if ( $bp->save( $this->operation, $password ) ) {
+                       $this->logger->info(
+                               "Bot password {op} for {user}@{app_id}",
+                               [
+                                       'op' => $this->operation,
+                                       'user' => $this->getUser()->getName(),
+                                       'app_id' => $this->par,
+                                       'centralId' => $this->userId,
+                                       'restrictions' => $data['restrictions'],
+                                       'grants' => $bp->getGrants(),
+                                       'client_ip' => $this->getRequest()->getIP()
+                               ]
+                       );
                        return Status::newGood();
                } else {
                        // Messages: botpasswords-insert-failed, botpasswords-update-failed