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

Change subject: Add Special:Log Entries
......................................................................


Add Special:Log Entries

Bug: 68277
Change-Id: I7fb4ff8c0145153b19240827846965cc4436b958
---
M GWToolset.php
M i18n/en.json
M i18n/qqq.json
M includes/Jobs/UploadMediafileJob.php
M includes/Jobs/UploadMetadataJob.php
M includes/Utils.php
6 files changed, 176 insertions(+), 16 deletions(-)

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



diff --git a/GWToolset.php b/GWToolset.php
index a8da777..570a839 100644
--- a/GWToolset.php
+++ b/GWToolset.php
@@ -139,3 +139,7 @@
                'jquery.ui.dialog'
        )
 );
+
+// add logging
+$wgLogTypes[] = 'gwtoolset';
+$wgLogActionsHandlers['gwtoolset/*'] = 'LogFormatter';
diff --git a/i18n/en.json b/i18n/en.json
index 91f4a6b..0160d02 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -225,5 +225,12 @@
        "gwtoolset-select-custom-template": "or enter a custom template:",
        "gwtoolset-no-templatedata": "There is no 
<code>&lt;templatedata></code> block for template $1.\n\nIf possible, add a $2 
to the template, or to the template's $3.",
        "gwtoolset-templatedata-link-text": "<code>&lt;templatedata></code> 
block",
-       "gwtoolset-templatebox-link-text": "<code>TemplateBox</code>"
+       "gwtoolset-templatebox-link-text": "<code>TemplateBox</code>",
+       "gwtoolset-title-none": "No title",
+       "gwtoolset-begin-with": "Started with metadata record $1",
+       "log-name-gwtoolset": "GWToolset log",
+       "log-description-gwtoolset": "These events track GWToolset events in 
the wiki.",
+       "logentry-gwtoolset-mediafile-job-failed": "$1 mediafile job failed. 
Metadata record $4. $5. ",
+       "logentry-gwtoolset-mediafile-job-succeeded": "$1 mediafile job 
succeeded. Created $3. Metadata record $4. ",
+       "logentry-gwtoolset-metadata-job": "$1 metadata job created. $4. "
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 88fd546..d983838 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -221,5 +221,12 @@
        "gwtoolset-select-custom-template": "Label for the corresponding field 
in Step 1: Metadata detection.",
        "gwtoolset-no-templatedata": "Message that appears when there is no 
templatedata for a MediaWiki template chosen in Step 1: Metadata detection. 
Parameters:\n* $1 - the name of the chosen template\n* $2 - a link to the 
MediaWiki templatedata help page for adding a templatedata block to a 
template\nLink text used is {{msg-mw|Gwtoolset-templatedata-link-text}}\n* $3 - 
a link to the commons help page for adding templatedata to a template's 
templatebox\nLink text used is {{msg-mw|Gwtoolset-templatebox-link-text}}",
        "gwtoolset-templatedata-link-text": "Text for the templatedata link. 
See {{msg-mw|Gwtoolset-no-templatedata}}",
-       "gwtoolset-templatebox-link-text": "Text for the templatebox link. See 
{{msg-mw|Gwtoolset-no-templatedata}}"
+       "gwtoolset-templatebox-link-text": "Text for the templatebox link. See 
{{msg-mw|Gwtoolset-no-templatedata}}",
+       "gwtoolset-title-none": "Title text used to create a wiki title for 
Special:Log when there is actually no Title to log.",
+       "gwtoolset-begin-with": "Used for the Metadata Job log entry to 
indicate the beginning metadata record number. No period at the end of the 
sentence because this is the last sentence inserted into 
{{logentry-gwtoolset-metadata-job}}, which adds the period to the end of the 
sentence. Parameters:\n* $1 is the record number.",
+       "log-name-gwtoolset": "GWToolset's Special:Log log name.",
+       "log-description-gwtoolset": "Description of the GWToolset log that 
appears on the Special:Log page when filtered by GWToolset logged events.",
+       "logentry-gwtoolset-mediafile-job-failed": "Template for the GWToolset 
log events. The space at the end of the message is intentional because the log 
insert() method adds the summary message at the end of this message without a 
space. Parameters:\n* $1 is the User signature.\n* $4 is the metadata record 
number.\n* $5 is the error message.",
+       "logentry-gwtoolset-mediafile-job-succeeded": "Template for the 
GWToolset log events. The space at the end of the message is intentional 
because the log insert() method adds the summary message at the end of this 
message without a space. Parameters:\n* $1 is the User signature.\n* $3 is the 
page title.\n* $4 is the metadata record number.",
+       "logentry-gwtoolset-metadata-job": "Template for the GWToolset log 
events. The space at the end of the message is intentional because the log 
insert() method adds the summary message at the end of this message without a 
space. Parameters:\n* $1 is the User signature.\n* $4 is any success message."
 }
diff --git a/includes/Jobs/UploadMediafileJob.php 
b/includes/Jobs/UploadMediafileJob.php
index 6a927eb..ce4cdd5 100644
--- a/includes/Jobs/UploadMediafileJob.php
+++ b/includes/Jobs/UploadMediafileJob.php
@@ -11,16 +11,24 @@
 use GWToolset\Adapters\Php\MappingPhpAdapter,
        GWToolset\Adapters\Php\MediawikiTemplatePhpAdapter,
        GWToolset\Adapters\Php\MetadataPhpAdapter,
+       GWToolset\GWTException,
+       GWToolset\Handlers\UploadHandler,
        GWToolset\Models\Mapping,
        GWToolset\Models\MediawikiTemplate,
        GWToolset\Models\Metadata,
-       GWToolset\GWTException,
-       GWToolset\Handlers\UploadHandler,
+       GWToolset\Utils,
        Job,
-       User,
-       ScopedCallback;
+       ScopedCallback,
+       Title,
+       User;
+
 
 class UploadMediafileJob extends Job {
+
+       /**
+        * @var {User}
+        */
+       protected $User;
 
        /**
         * @param {Title} $title
@@ -50,18 +58,18 @@
                );
 
                $Mapping = new Mapping( new MappingPhpAdapter() );
+
                $Mapping->mapping_array = 
$MediawikiTemplate->getMappingFromArray(
                        $this->params['whitelisted-post']
                );
+
                $Mapping->setTargetElements();
                $Mapping->reverseMap();
-
                $Metadata = new Metadata( new MetadataPhpAdapter() );
-               $User = User::newFromName( $this->params['user-name'] );
 
                // AbuseFilter still looks at $wgUser in an UploadVerifyFile 
hook
                $oldUser = $wgUser;
-               $wgUser = $User;
+               $wgUser = $this->User;
                // This will automatically restore $wgUser, when 
$magicScopeVariable falls out of scope.
                $magicScopeVariable = new ScopedCallback( function() use ( 
$oldUser ) {
                        global $wgUser;
@@ -73,7 +81,7 @@
                                'Mapping' => $Mapping,
                                'MediawikiTemplate' => $MediawikiTemplate,
                                'Metadata' => $Metadata,
-                               'User' => $User,
+                               'User' => $this->User,
                        )
                );
 
@@ -101,25 +109,76 @@
         */
        public function run() {
                $result = false;
+               $message = null;
 
                if ( !$this->validateParams() ) {
                        return $result;
                }
 
+               $this->User = User::newFromName( $this->params['user-name'] );
+
                try {
                        $result = $this->processMetadata();
                } catch ( GWTException $e ) {
+                       $message = $e->getMessage();
+
                        $this->setLastError(
                                __METHOD__ . ': ' .
-                               $e->getMessage() .
+                               $message . PHP_EOL .
                                print_r( $this->params['user-options'], true )
                        );
                }
 
+               if ( $result instanceof Title ) {
+                       $this->specialLog( $message, 'mediafile-job-succeeded', 
$result );
+               } else {
+                       $this->specialLog(
+                               $message,
+                               'mediafile-job-failed',
+                               Title::newFromText(
+                                       wfMessage( 'gwtoolset-title-none' )
+                                               ->inContentLanguage()
+                                               ->escaped(),
+                                       NS_FILE
+                               )
+                       );
+               }
+
                return $result;
        }
 
        /**
+        * @param {string} $message
+        * @param {string} $job_subtype
+        * @param {object} $Title
+        */
+       protected function specialLog( $message, $job_subtype, Title $Title ) {
+               $options = array(
+                       'job-subtype' => $job_subtype,
+                       'Title' => $Title,
+                       'User' => $this->User
+               );
+
+               if ( !empty( $this->params['whitelisted-post']['wpSummary'] ) ) 
{
+                       $options['comment'] = 
$this->params['whitelisted-post']['wpSummary'];
+               }
+
+               // when 0, record nr is unknown
+               $record_nr = 0;
+
+               if ( !empty( 
$this->params['user-options']['gwtoolset-record-begin'] ) ) {
+                       $record_nr = 
(int)$this->params['user-options']['gwtoolset-record-current'];
+               }
+
+               $options['parameters'] = array(
+                       '4::metadata-record-nr' => $record_nr,
+                       '5::message' => $message
+               );
+
+               Utils::specialLog( $options );
+       }
+
+       /**
         * @return {bool}
         */
        protected function validateParams() {
diff --git a/includes/Jobs/UploadMetadataJob.php 
b/includes/Jobs/UploadMetadataJob.php
index c106080..5c00619 100644
--- a/includes/Jobs/UploadMetadataJob.php
+++ b/includes/Jobs/UploadMetadataJob.php
@@ -35,6 +35,11 @@
 class UploadMetadataJob extends Job {
 
        /**
+        * @var {User}
+        */
+       protected $User;
+
+       /**
         * @param {Title} $title
         * @param {bool|array} $params
         * @param {int} $id
@@ -46,11 +51,12 @@
        /**
         * a control method for re-establishing application state so that the 
metadata can be processed
         *
-        * @return {bool|Title}
+        * @return {string|array}
+        * if an array, an array of Titles
         */
        protected function processMetadata() {
                $MetadataMappingHandler = new MetadataMappingHandler(
-                       array( 'User' => User::newFromName( 
$this->params['user-name'] ) )
+                       array( 'User' => $this->User )
                );
 
                return $MetadataMappingHandler->processRequest( 
$this->params['whitelisted-post'] );
@@ -81,7 +87,7 @@
 
                $job = new UploadMetadataJob(
                        Title::newFromText(
-                               User::newFromName( $this->params['user-name'] ) 
. '/' .
+                               $this->User . '/' .
                                Constants::EXTENSION_NAME . '/' .
                                'Metadata Batch Job/' .
                                uniqid(),
@@ -119,6 +125,7 @@
                        return $result;
                }
 
+               $this->User = User::newFromName( $this->params['user-name'] );
                $job_queue_size = JobQueueGroup::singleton()->get( 
'gwtoolsetUploadMediafileJob' )->getSize();
 
                // make sure the overall job queue does not have > 
Config::$mediafile_job_queue_max
@@ -126,28 +133,69 @@
                // in order to try again later to add the UploadMediafileJob’s
                if ( (int)$job_queue_size > 
(int)Config::$mediafile_job_queue_max ) {
                        $result = true;
+
                        try {
                                $this->recreateMetadataJob();
                        } catch ( Exception $e ) {
                                $result = false;
                                $this->setLastError(
                                        __METHOD__ . ': ' .
-                                       wfMessage( 
'gwtoolset-batchjob-metadata-creation-failure' )->escaped()
+                                       wfMessage( 
'gwtoolset-batchjob-metadata-creation-failure' )->escaped() .
+                                       $e->getMessage()
                                );
                        }
+
                        return $result;
                }
 
                try {
                        $result = $this->processMetadata();
+                       $message = $result;
+
+                       if ( isset( 
$this->params['whitelisted-post']['gwtoolset-record-begin'] ) ) {
+                               $message .=
+                                       ' ' .
+                                       wfMessage( 'gwtoolset-begin-with' )
+                                               ->params( 
(int)$this->params['whitelisted-post']['gwtoolset-record-begin'] )
+                                               ->escaped();
+                       }
                } catch ( GWTException $e ) {
-                       $this->setLastError( __METHOD__ . ': ' . 
$e->getMessage() );
+                       $message = $e->getMessage();
+
+                       $this->setLastError(
+                               __METHOD__ . ': ' .
+                               $message
+                       );
                }
 
+               $this->specialLog( $message );
                return $result;
        }
 
        /**
+        * @param {string} $message
+        */
+       protected function specialLog( $message ) {
+               $options = array(
+                       'job-subtype' => 'metadata-job',
+                       'parameters' => array(
+                               '4::message' => $message
+                       ),
+                       'Title' => Title::newFromText(
+                               wfMessage( 'gwtoolset-title-none' )->escaped(),
+                               NS_FILE
+                       ),
+                       'User' => $this->User
+               );
+
+               if ( !empty( $this->params['whitelisted-post']['wpSummary'] ) ) 
{
+                       $options['comment'] = 
$this->params['whitelisted-post']['wpSummary'];
+               }
+
+               Utils::specialLog( $options );
+       }
+
+       /**
         * @return {bool}
         */
        protected function validateParams() {
diff --git a/includes/Utils.php b/includes/Utils.php
index af9a9a2..aa4dd1b 100644
--- a/includes/Utils.php
+++ b/includes/Utils.php
@@ -9,9 +9,11 @@
 
 namespace GWToolset;
 use Language,
+       ManualLogEntry,
        MWException,
        Sanitizer,
        Title;
+
 
 class Utils {
 
@@ -381,6 +383,39 @@
        }
 
        /**
+        * @param {array} $options
+        * @param {string} $options['comment']
+        * @param {string} $options['job-subtype']
+        * @param {array} $options['parameters']
+        * @param {object} $options['Title']
+        * @param {object} $options['User']
+        */
+       public static function specialLog( array $options ) {
+               $logEntry = new ManualLogEntry(
+                       strtolower( Constants::EXTENSION_NAME ),
+                       $options['job-subtype']
+               );
+
+               $logEntry->setPerformer( $options['User'] );
+               $logEntry->setTarget( $options['Title'] );
+
+               if ( !empty( $options['comment'] ) ) {
+                       $logEntry->setComment( $options['comment'] );
+               }
+
+               // these parameters should be localised beforehand when 
necessary
+               // they are passed on to an i18n message that corresponds with 
the
+               // $options['job-subtype'] e.g., logentry-gwtoolset-metadatajob,
+               // which acts as a template placeholder
+               if ( !empty( $options['parameters'] ) ) {
+                       $logEntry->setParameters( $options['parameters'] );
+               }
+
+               $logid = $logEntry->insert();
+               $logEntry->publish( $logid );
+       }
+
+       /**
         * @param {string} $category
         * @return {null|string}
         * the result has not been filtered

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I7fb4ff8c0145153b19240827846965cc4436b958
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/GWToolset
Gerrit-Branch: master
Gerrit-Owner: Dan-nl <[email protected]>
Gerrit-Reviewer: Brian Wolff <[email protected]>
Gerrit-Reviewer: Dan-nl <[email protected]>
Gerrit-Reviewer: GergÅ‘ Tisza <[email protected]>
Gerrit-Reviewer: Gilles <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: MarkTraceur <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to