jenkins-bot has submitted this change and it was merged.

Change subject: BSApiTasksBase: Added support for logging
......................................................................


BSApiTasksBase: Added support for logging

There are a lot of use cases where the actions that are performed by the
API should be logged to Special:Log. This base method makes it easier to
implement such a behavior.

PatchSet 2:
* Added support for 'comment'
* Fixed CC

Change-Id: I122e4ebbeddfeace15511faf23114c7da2171338
---
M includes/api/BSApiTasksBase.php
1 file changed, 91 insertions(+), 0 deletions(-)

Approvals:
  Mglaser: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/api/BSApiTasksBase.php b/includes/api/BSApiTasksBase.php
index 5645d61..3523871 100644
--- a/includes/api/BSApiTasksBase.php
+++ b/includes/api/BSApiTasksBase.php
@@ -33,6 +33,13 @@
 abstract class BSApiTasksBase extends BSApiBase {
 
        /**
+        * This is the default log the API writes to. It needs to be registered
+        * in $wgLogTypes
+        * @var string
+        */
+       protected $sTaskLogType = null;
+
+       /**
         * Methods that can be called by task param
         * @var array
         */
@@ -95,6 +102,90 @@
        }
 
        /**
+        * Creates a log entry for Special:Log, based on $this->sTaskLogType or
+        * $aOptions['type']. See 
https://www.mediawiki.org/wiki/Manual:Logging_to_Special:Log
+        * @param string $sAction
+        * @param array $aParams for the log entry
+        * @param array $aOptions <br/>
+        * 'performer' of type User<br/>
+        * 'target' of type Title<br/>
+        * 'timestamp' of type string<br/>
+        * 'relations of type array<br/>
+        * 'deleted' of type int<br/>
+        * 'type' of type string; to allow overriding of class default
+        * @param bool $bDoPublish
+        * @return int Id of the newly created log entry or -1 on error
+        */
+       protected function logTaskAction( $sAction, $aParams, $aOptions = 
array(), $bDoPublish = false ) {
+               $aOptions += array(
+                       'performer' => null,
+                       'target' => null,
+                       'timestamp' => null,
+                       'relations' => null,
+                       'comment' => null,
+                       'deleted' =>  null,
+                       'publish' => null,
+                       'type' => null //To allow overriding of class default
+               );
+
+               $oTarget = $aOptions['target'];
+               if ( $oTarget === null ) {
+                       $oTarget = $this->makeDefaultLogTarget();
+               }
+
+               $oPerformer = $aOptions['performer'];
+               if ( $oPerformer === null ) {
+                       $oPerformer = $this->getUser();
+               }
+
+               $sType = $this->sTaskLogType;
+               if ( $aOptions['type'] !== null ) {
+                       $sType = $aOptions['type'];
+               }
+
+               if ( $sType === null ) { //Not set on class, not set as call 
option
+                       return -1;
+               }
+
+               $oLogger = new ManualLogEntry( $sType, $sAction );
+               $oLogger->setPerformer( $oPerformer );
+               $oLogger->setTarget( $oTarget );
+               $oLogger->setParameters( $aParams );
+
+               if ( $aOptions['timestamp'] !== null ) {
+                       $oLogger->setTimestamp( $aOptions['timestamp'] );
+               }
+
+               if ( $aOptions['relations'] !== null ) {
+                       $oLogger->setRelations( $aOptions['relations'] );
+               }
+
+               if ( $aOptions['comment'] !== null ) {
+                       $oLogger->setComment( $aOptions['comment'] );
+               }
+
+               if ( $aOptions['deleted'] !== null ) {
+                       $oLogger->setDeleted( $aOptions['deleted'] );
+               }
+
+               $iLogEntryId = $oLogger->insert();
+
+               if ( $bDoPublish ) {
+                       $oLogger->publish();
+               }
+
+               return $iLogEntryId;
+       }
+
+       /**
+        *
+        * @return Title
+        */
+       protected function makeDefaultLogTarget() {
+               return $this->getTitle();
+       }
+
+       /**
         * Returns an array of allowed parameters
         * @return array
         */

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I122e4ebbeddfeace15511faf23114c7da2171338
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/BlueSpiceFoundation
Gerrit-Branch: master
Gerrit-Owner: Robert Vogel <vo...@hallowelt.biz>
Gerrit-Reviewer: Dvogel hallowelt <daniel.vo...@hallowelt.com>
Gerrit-Reviewer: Ljonka <l.verhovs...@gmail.com>
Gerrit-Reviewer: Mglaser <gla...@hallowelt.biz>
Gerrit-Reviewer: Pwirth <wi...@hallowelt.biz>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to