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

Change subject: re-work exception handling
......................................................................


re-work exception handling

Gergő Tisza was concenred about the fact that the extension was catching 
MWExceptions.
the solution we agreed upon was to use an extension specific exception object 
for user
errors and another for system/non-user correctable errors, which has been 
implemented
in this change-set.

a few files also include php doc clean-up, shortening of lines > 100 
characters, and
removal of a few functions no longer used by the extension.

Change-Id: Ie9493be07ecb74cf382bf3561e1c036af6538ac2
---
M INSTALL
M README
M includes/Adapters/Php/MappingPhpAdapter.php
M includes/Adapters/Php/MediawikiTemplatePhpAdapter.php
M includes/Config.php
A includes/GWTException.php
M includes/Handlers/Ajax/AjaxHandler.php
M includes/Handlers/Forms/FormHandler.php
M includes/Handlers/Forms/MetadataDetectHandler.php
M includes/Handlers/Forms/MetadataMappingHandler.php
M includes/Handlers/SpecialPageHandler.php
M includes/Handlers/UploadHandler.php
M includes/Handlers/Xml/XmlDetectHandler.php
M includes/Handlers/Xml/XmlHandler.php
M includes/Handlers/Xml/XmlMappingHandler.php
M includes/Helpers/FileChecks.php
D includes/Jobs/UploadFromUrlJob.php
M includes/Jobs/UploadMediafileJob.php
M includes/Jobs/UploadMetadataJob.php
M includes/Models/Mapping.php
M includes/Models/MediawikiTemplate.php
M includes/Specials/SpecialGWToolset.php
M includes/functions/functions.php
23 files changed, 158 insertions(+), 224 deletions(-)

Approvals:
  BryanDavis: Looks good to me, approved
  Gergő Tisza: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/INSTALL b/INSTALL
index 1eef597..d97c2a8 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,5 +1,5 @@
-GWToolset v0.0.1
-==================
+GWToolset Install
+=================
 
 1. Licensing
 2. Requirements
diff --git a/README b/README
index bec1006..b2fecd9 100644
--- a/README
+++ b/README
@@ -8,7 +8,7 @@
 
 Contributors
 ------------
-dan entous <[email protected]>
+User:Dan-nl
 
 Reviewers
 ---------
@@ -19,6 +19,7 @@
 User:Bawolff
 User:BryanDavis
 User:CSteipp
+User:Gergő_Tisza
 User:MHolmquist
 User:Parent5446
 User:Peachey88
diff --git a/includes/Adapters/Php/MappingPhpAdapter.php 
b/includes/Adapters/Php/MappingPhpAdapter.php
index 92d7f2a..f6629bd 100644
--- a/includes/Adapters/Php/MappingPhpAdapter.php
+++ b/includes/Adapters/Php/MappingPhpAdapter.php
@@ -11,6 +11,7 @@
 use ContentHandler,
        GWToolset\Adapters\DataAdapterInterface,
        GWToolset\Config,
+       GWToolset\GWTException,
        GWToolset\Helpers\FileChecks,
        GWToolset\Helpers\WikiPages,
        MWException,
@@ -85,6 +86,9 @@
        /**
         * @todo is the content returned by the WikiPage filtered?
         * @param {array} $options
+        *
+        * @throws {GWTException}
+        *
         * @return {string}
         * the content of the wikipage referred to by the wiki title
         */
@@ -93,7 +97,7 @@
 
                if ( $options['Metadata-Mapping-Title'] instanceof Title ) {
                        if ( !$options['Metadata-Mapping-Title']->isKnown() ) {
-                               throw new MWException(
+                               throw new GWTException(
                                        wfMessage( 
'gwtoolset-metadata-mapping-not-found' )
                                                ->params( 
$options['metadata-mapping-url'] )
                                                ->parse()
@@ -129,7 +133,6 @@
                $Mapping_Content = ContentHandler::makeContent( 
$options['text'], $options['title'] );
                $Mapping_Page = new WikiPage( $options['title'] );
 
-               set_error_handler( '\GWToolset\swallowErrors' );
                $result = $Mapping_Page->doEditContent(
                        $Mapping_Content,
                        $options['summary'],
diff --git a/includes/Adapters/Php/MediawikiTemplatePhpAdapter.php 
b/includes/Adapters/Php/MediawikiTemplatePhpAdapter.php
index 56c3294..014479d 100644
--- a/includes/Adapters/Php/MediawikiTemplatePhpAdapter.php
+++ b/includes/Adapters/Php/MediawikiTemplatePhpAdapter.php
@@ -10,6 +10,7 @@
 namespace GWToolset\Adapters\Php;
 use GWToolset\Adapters\DataAdapterInterface,
        GWToolset\Config,
+       GWToolset\GWTException,
        MimeMagic,
        MWException,
        MWHttpRequest,
@@ -18,10 +19,6 @@
 
 class MediawikiTemplatePhpAdapter implements DataAdapterInterface {
 
-       /**
-        * @param {string} $table_name
-        * @return {void}
-        */
        public function __construct() {
        }
 
@@ -44,7 +41,7 @@
         * - falls back to a Config::$mediawiki_templates version if not found
         *
         * @param {array} $options
-        * @throws {MWException}
+        * @throws {GWTException}
         * @return {array}
         */
        public function retrieve( array $options = array() ) {
@@ -56,7 +53,7 @@
                if ( !isset(
                        Config::$mediawiki_templates[Filter::evaluate( 
$options['mediawiki_template_name'] )] )
                ) {
-                       throw new MWException(
+                       throw new GWTException(
                                wfMessage( 
'gwtoolset-mediawiki-template-not-found' )
                                        ->rawParams( Filter::evaluate( 
$options['mediawiki_template_name'] ) )
                                        ->escaped()
@@ -69,7 +66,7 @@
                );
 
                if ( !$Title->isKnown() ) {
-                       throw new MWException(
+                       throw new GWTException(
                                wfMessage( 
'gwtoolset-mediawiki-template-does-not-exist' )
                                        ->params( $Title->getBaseTitle() )
                                        ->parse()
@@ -128,11 +125,15 @@
 
                try {
                        \GWToolset\jsonCheckForError();
-               } catch ( MWException $e ) {
+               } catch ( GWTException $e ) {
                        throw new MWException(
-                               wfMessage( 'gwtoolset-json-error' )
-                                       ->rawParams( $e->getMessage() )
-                                       ->parse()
+                               wfMessage( 'gwtoolset-developer-issue' )
+                                       ->params(
+                                               wfMessage( 
'gwtoolset-json-error' )
+                                                       ->params( 
$e->getMessage() )
+                                                       ->escaped()
+                                       )
+                               ->parse()
                        );
                }
 
diff --git a/includes/Config.php b/includes/Config.php
index 572ac96..a6d70a7 100644
--- a/includes/Config.php
+++ b/includes/Config.php
@@ -16,7 +16,7 @@
        public static $url = 
'https://www.mediawiki.org/wiki/Extension:GWToolset';
        public static $descriptionmsg = 'gwtoolset-desc';
        public static $type = 'media';
-       public static $version = '0.1.1';
+       public static $version = '0.1.2';
 
        /**
         * @var {array}
@@ -52,6 +52,8 @@
         * @var {array}
         */
        public static $autoloader_classes = array(
+               'GWToolset\GWTException' => '/includes/GWTException.php',
+
                'GWToolset\Adapters\DataAdapterInterface' => 
'/includes/Adapters/DataAdapterInterface.php',
 
                'GWToolset\Adapters\Php\MappingPhpAdapter' => 
'/includes/Adapters/Php/MappingPhpAdapter.php',
@@ -81,7 +83,6 @@
 
                'GWToolset\Hooks' => '/includes/Hooks/Hooks.php',
 
-               'GWToolset\Jobs\UploadFromUrlJob' => 
'/includes/Jobs/UploadFromUrlJob.php',
                'GWToolset\Jobs\UploadMediafileJob' => 
'/includes/Jobs/UploadMediafileJob.php',
                'GWToolset\Jobs\UploadMetadataJob' => 
'/includes/Jobs/UploadMetadataJob.php',
 
diff --git a/includes/GWTException.php b/includes/GWTException.php
new file mode 100644
index 0000000..6d5baa8
--- /dev/null
+++ b/includes/GWTException.php
@@ -0,0 +1,14 @@
+<?php
+/**
+ * GWToolset
+ *
+ * @file
+ * @ingroup Extensions
+ * @license GNU General Public License 3.0 http://www.gnu.org/licenses/gpl.html
+ */
+
+namespace GWToolset;
+use \Exception;
+
+class GWTException extends Exception {
+}
diff --git a/includes/Handlers/Ajax/AjaxHandler.php 
b/includes/Handlers/Ajax/AjaxHandler.php
index 684dd8d..fb1d4a9 100644
--- a/includes/Handlers/Ajax/AjaxHandler.php
+++ b/includes/Handlers/Ajax/AjaxHandler.php
@@ -17,8 +17,6 @@
        /**
         * gets an html form.
         * not needed in this class
-        *
-        * @return {void}
         */
        public function getHtmlForm() {
        }
@@ -27,8 +25,6 @@
         * entry point
         * a control method that acts as an entry point for the
         * SpecialPageHandler and handles execution of the class methods
-        *
-        * @return {void}
         */
        public function execute() {
                $result = WikiChecks::doesEditTokenMatch( $this->SpecialPage );
@@ -37,8 +33,18 @@
                        $result = $this->processRequest();
                }
 
+               set_error_handler( array( $this, 'swallowErrors' ) );
                header( 'Content-Type: application/json; charset=utf-8' );
                echo json_encode( $result );
                exit();
        }
+
+       /**
+        * intended to swallow notice and warnings when display errors is set 
to true
+        * this should not be the case in a production environment
+        *
+        * @see http://php.net/manual/en/function.set-error-handler.php
+        */
+       function swallowErrors() {
+       }
 }
diff --git a/includes/Handlers/Forms/FormHandler.php 
b/includes/Handlers/Forms/FormHandler.php
index 6300fde..f329caf 100644
--- a/includes/Handlers/Forms/FormHandler.php
+++ b/includes/Handlers/Forms/FormHandler.php
@@ -7,7 +7,8 @@
  * @license GNU General Public License 3.0 http://www.gnu.org/licenses/gpl.html
  */
 namespace GWToolset\Handlers\Forms;
-use    GWToolset\Handlers\SpecialPageHandler,
+use    GWToolset\GWTException,
+       GWToolset\Handlers\SpecialPageHandler,
        GWToolset\Helpers\WikiChecks,
        Html,
        MWException,
@@ -25,10 +26,8 @@
         *
         * @param {array} $expected_options
         *
-        * @throws {MWException}
+        * @throws {GWTException}
         * the exception message has been filtered
-        *
-        * @return {void}
         */
        protected function checkForRequiredFormFields( array &$user_options, 
array $expected_options ) {
                $msg = null;
@@ -51,17 +50,20 @@
 
                if ( $msg !== null ) {
                        $msg =
-                               Html::rawElement( 'p', array( 'class' => 
'error' ) , wfMessage( 'gwtoolset-metadata-user-options-error' )->escaped() ) .
+                               Html::rawElement(
+                                       'p',
+                                       array( 'class' => 'error' ),
+                                       wfMessage( 
'gwtoolset-metadata-user-options-error' )->escaped()
+                               ) .
                                Html::rawElement( 'ul', array(), $msg ) .
                                Html::rawElement( 'p', array(), 
$this->SpecialPage->getBackToFormLink() );
 
-                       throw new MWException( $msg );
+                       throw new GWTException( $msg );
                }
        }
 
        /**
         * @param {string} $module_name
-        *
         * @throws {MWException}
         *
         * @return {string}
@@ -92,7 +94,7 @@
         *
         * @param {string} $module_name
         *
-        * @throws {MWException}
+        * @throws {GWTException}
         *
         * @return {string}
         * the string has not been filtered
@@ -101,7 +103,7 @@
                $form_class = $this->getFormClass( $module_name );
 
                if ( !class_exists( $form_class ) ) {
-                       throw new MWException( wfMessage( 'gwtoolset-no-form' 
)->escaped() );
+                       throw new GWTException( wfMessage( 'gwtoolset-no-form' 
)->escaped() );
                }
 
                return $form_class::getForm( $this->SpecialPage );
@@ -120,7 +122,11 @@
 
                if ( !$result->ok ) {
                        $result =
-                               Html::rawElement( 'h2', array(), wfMessage( 
'gwtoolset-wiki-checks-not-passed' )->escaped() ) .
+                               Html::rawElement(
+                                       'h2',
+                                       array(),
+                                       wfMessage( 
'gwtoolset-wiki-checks-not-passed' )->escaped()
+                               ) .
                                Html::rawElement( 'span', array( 'class' => 
'error' ), $result->getMessage() );
                } else {
                        $result = $this->processRequest();
diff --git a/includes/Handlers/Forms/MetadataDetectHandler.php 
b/includes/Handlers/Forms/MetadataDetectHandler.php
index c772f44..03cab92 100644
--- a/includes/Handlers/Forms/MetadataDetectHandler.php
+++ b/includes/Handlers/Forms/MetadataDetectHandler.php
@@ -9,11 +9,11 @@
 
 namespace GWToolset\Handlers\Forms;
 use ContentHandler,
-       FSFile,
        GWToolset\Adapters\Php\MappingPhpAdapter,
        GWToolset\Adapters\Php\MediawikiTemplatePhpAdapter,
        GWToolset\Config,
        GWToolset\Forms\MetadataMappingForm,
+       GWToolset\GWTException,
        GWToolset\Handlers\UploadHandler,
        GWToolset\Handlers\Xml\XmlDetectHandler,
        GWToolset\Helpers\FileChecks,
@@ -21,7 +21,6 @@
        GWToolset\Helpers\WikiPages,
        GWToolset\Models\Mapping,
        GWToolset\Models\MediawikiTemplate,
-       MWException,
        Php\File,
        Php\Filter,
        RepoGroup,
@@ -82,7 +81,11 @@
                $result = null;
 
                foreach ( $this->_MediawikiTemplate->mediawiki_template_array 
as $parameter => $value ) {
-                       $result .= 
$this->XmlDetectHandler->getMetadataAsTableCells( $parameter, 
$this->_MediawikiTemplate, $this->_Mapping );
+                       $result .= 
$this->XmlDetectHandler->getMetadataAsTableCells(
+                               $parameter,
+                               $this->_MediawikiTemplate,
+                               $this->_Mapping
+                       );
                }
 
                return $result;
@@ -130,7 +133,7 @@
         * - retrieves a metadata mapping if a url to it in the wiki is given
         * - adds this information to the metadata mapping form and presents it 
to the user
         *
-        * @throws {MWException}
+        * @throws {GWTException}
         * @return {string}
         * the html form string has not been filtered in this method,
         * but within the getForm method
@@ -174,7 +177,8 @@
                        $user_options['metadata-stash-key'] = 
$this->_UploadHandler->saveMetadataFileAsStash();
                        $UploadStashFile = 
$this->_UploadHandler->getMetadataFromStash( $user_options );
                } else {
-                       $user_options['Metadata-Title'] = 
$this->_UploadHandler->getTitleFromUrlOrFile( $user_options );
+                       $user_options['Metadata-Title'] =
+                               $this->_UploadHandler->getTitleFromUrlOrFile( 
$user_options );
                }
 
                if ( $UploadStashFile instanceof UploadStashFile ) {
@@ -184,7 +188,7 @@
                        $Metadata_Content = $Metadata_Page->getContent( 
Revision::RAW );
                        $this->XmlDetectHandler->processXml( $user_options, 
$Metadata_Content );
                } else {
-                       throw new MWException(
+                       throw new GWTException(
                                wfMessage( 
'gwtoolset-metadata-file-url-not-present' )
                                        ->params( 
$user_options['metadata-file-url'])
                                        ->escaped()
diff --git a/includes/Handlers/Forms/MetadataMappingHandler.php 
b/includes/Handlers/Forms/MetadataMappingHandler.php
index 35c9a70..6c883d1 100644
--- a/includes/Handlers/Forms/MetadataMappingHandler.php
+++ b/includes/Handlers/Forms/MetadataMappingHandler.php
@@ -10,14 +10,17 @@
 namespace GWToolset\Handlers\Forms;
 use GWToolset\Adapters\Php\MappingPhpAdapter,
        GWToolset\Adapters\Php\MediawikiTemplatePhpAdapter,
+       GWToolset\Adapters\Php\MetadataPhpAdapter,
        GWToolset\Config,
        GWToolset\Forms\PreviewForm,
+       GWToolset\GWTException,
        GWToolset\Jobs\UploadMetadataJob,
        GWToolset\Handlers\UploadHandler,
        GWToolset\Handlers\Xml\XmlMappingHandler,
        GWToolset\Helpers\WikiPages,
        GWToolset\Models\Mapping,
        GWToolset\Models\MediawikiTemplate,
+       GWToolset\Models\Metadata,
        Html,
        JobQueueGroup,
        Linker,
@@ -43,6 +46,11 @@
        protected $_MediawikiTemplate;
 
        /**
+        * @var {Metadata}
+        */
+       protected $_Metadata;
+
+       /**
         * @var {UploadHandler}
         */
        protected $_UploadHandler;
@@ -55,6 +63,8 @@
        /**
         * @param {array} $user_options
         * an array of user options that was submitted in the html form
+        *
+        * @throws {MWException}
         *
         * @return {string}
         * the html string has been escaped and parsed by wfMessage
@@ -90,12 +100,10 @@
                                ->rawParams( $newFilesLink )
                                ->parse();
                } else {
-                       $result = Html::rawElement(
-                               'span',
-                               array( 'class' => 'error' ),
-                               wfMessage( 'gwtoolset-developer-issue' 
)->params(
-                                       wfMessage( 
'gwtoolset-batchjob-metadata-creation-failure' )->escaped()
-                               )->parse()
+                       throw new MWException(
+                               wfMessage( 'gwtoolset-developer-issue' )
+                                       ->params( wfMessage( 
'gwtoolset-batchjob-metadata-creation-failure' )->escaped() )
+                                       ->parse()
                        );
                }
 
@@ -110,8 +118,6 @@
         *
         * @param {array} $user_options
         * an array of user options that was submitted in the html form
-        *
-        * @return {void}
         */
        protected function getGlobalCategories( array &$user_options ) {
                $user_options['categories'] = 
Config::$mediawiki_template_default_category;
@@ -218,26 +224,26 @@
         * @param {array} $user_options
         * an array of user options that was submitted in the html form
         *
-        * @param {array} $element_mapped_to_mediawiki_template
-        * @param {string} $metadata_raw
+        * @param {array} $options
+        *   {array} $options['metadata-as-array']
+        *   {array} $options['metadata-mapped-to-mediawiki-template']
+        *   {string} $options['metadata-raw']
+        *
         * @return {null|Title|bool}
         */
-       public function processMatchingElement(
-               array &$user_options,
-               $element_mapped_to_mediawiki_template,
-               $metadata_raw
-       ) {
+       public function processMatchingElement( array &$user_options, array 
$options ) {
                $result = null;
 
-               $this->_MediawikiTemplate->metadata_raw = $metadata_raw;
-               $this->_MediawikiTemplate->populateFromArray( 
$element_mapped_to_mediawiki_template );
+               $this->_MediawikiTemplate->metadata_raw = 
$options['metadata-raw'];
+               $this->_MediawikiTemplate->populateFromArray(
+                       $options['metadata-mapped-to-mediawiki-template']
+               );
+
+               $this->_Metadata->metadata_raw = $options['metadata-raw'];
+               $this->_Metadata->metadata_as_array = 
$options['metadata-as-array'];
 
                if ( $user_options['save-as-batch-job'] ) {
-                       $result = $this->_UploadHandler->saveMediafileViaJob(
-                               $user_options,
-                               $metadata_raw,
-                               $element_mapped_to_mediawiki_template
-                       );
+                       $result = $this->_UploadHandler->saveMediafileViaJob( 
$user_options, $options );
                } else {
                        $result = 
$this->_UploadHandler->saveMediafileAsContent( $user_options );
                }
@@ -253,7 +259,7 @@
         * @param {array} $user_options
         * an array of user options that was submitted in the html form
         *
-        * @throws {MWException}
+        * @throws {GWTException}
         * @return {array}
         * an array of mediafile Title(s)
         */
@@ -262,6 +268,7 @@
                $UploadStashFile = null;
                $this->_Mapping = null;
                $this->_MediawikiTemplate = null;
+               $this->_Metadata = null;
                $this->_UploadHandler = null;
                $this->_XmlMappingHandler = null;
 
@@ -273,10 +280,13 @@
                $this->_Mapping->setTargetElements();
                $this->_Mapping->reverseMap();
 
+               $this->_Metadata = new Metadata( new MetadataPhpAdapter() );
+
                $this->_UploadHandler = new UploadHandler(
                        array(
                                'Mapping' => $this->_Mapping,
                                'MediawikiTemplate' => 
$this->_MediawikiTemplate,
+                               'Metadata' => $this->_Metadata,
                                'User' => $this->User,
                        )
                );
@@ -311,7 +321,7 @@
                                $Metadata_Content
                        );
                } else {
-                       throw new MWException(
+                       throw new GWTException(
                                wfMessage( 
'gwtoolset-metadata-file-url-not-present' )
                                        ->params( 
$user_options['metadata-file-url'])
                                        ->escaped()
diff --git a/includes/Handlers/SpecialPageHandler.php 
b/includes/Handlers/SpecialPageHandler.php
index 4bb79e7..3fe6f6b 100644
--- a/includes/Handlers/SpecialPageHandler.php
+++ b/includes/Handlers/SpecialPageHandler.php
@@ -23,7 +23,6 @@
 
        /**
         * @param {array} $options
-        * @return {void}
         */
        public function __construct( array $options = array() ) {
                if ( isset( $options['SpecialPage'] ) ) {
diff --git a/includes/Handlers/UploadHandler.php 
b/includes/Handlers/UploadHandler.php
index c7a226b..3b46ea6 100644
--- a/includes/Handlers/UploadHandler.php
+++ b/includes/Handlers/UploadHandler.php
@@ -23,6 +23,7 @@
        Linker,
        LocalRepo,
        MimeMagic,
+       MWException,
        MWHttpRequest,
        Php\File,
        Php\Filter,
@@ -226,13 +227,13 @@
         * xml file uploads as metadata sets
         *
         * @param {array} $accepted_types
-        * @throws {GWTException}
+        * @throws {MWException}
         */
        protected function augmentAllowedExtensions( array $accepted_types = 
array() ) {
                global $wgFileExtensions;
 
                if ( empty( $accepted_types ) ) {
-                       throw new GWTException(
+                       throw new MWException(
                                wfMessage( 'gwtoolset-developer-issue' )
                                        ->params(
                                                wfMessage( 
'gwtoolset-no-accepted-types' )
@@ -768,11 +769,11 @@
         *   - url-to-the-media-file
         *
         * @param {array} $options
-        * @throws {GWTException}
+        * @throws {MWException}
         */
        protected function validatePageOptions( array &$options ) {
                if ( !isset( $options['ignorewarnings'] ) ) {
-                       throw new GWTException(
+                       throw new MWException(
                                wfMessage( 'gwtoolset-developer-issue' )
                                        ->params( wfMessage( 
'gwtoolset-ignorewarnings' )->parse() )
                                        ->parse()
@@ -781,13 +782,13 @@
 
                // assumes that text must be something
                if ( empty( $options['text'] ) ) {
-                       throw new GWTException(
+                       throw new MWException(
                                wfMessage( 'gwtoolset-developer-issue' )
                                        ->params( wfMessage( 
'gwtoolset-no-text' )->escaped() )
                                        ->parse()
                        );
                }if ( empty( $options['title'] ) ) {
-                       throw new GWTException(
+                       throw new MWException(
                                wfMessage( 'gwtoolset-developer-issue' )
                                        ->params( wfMessage( 
'gwtoolset-no-title' )->escaped() )
                                        ->parse()
@@ -795,7 +796,7 @@
                }
 
                if ( empty( $options['url-to-the-media-file'] ) ) {
-                       throw new GWTException(
+                       throw new MWException(
                                wfMessage( 'gwtoolset-developer-issue' )
                                        ->params( wfMessage( 
'gwtoolset-no-url-to-media' )->parse() )
                                        ->parse()
@@ -805,11 +806,11 @@
 
        /**
         * @param {array} $options
-        * @throws {GWTException}
+        * @throws {MWException}
         */
        protected function validateUserOptions( array &$user_options ) {
                if ( !isset( $user_options['comment'] ) ) {
-                       throw new GWTException(
+                       throw new MWException(
                                wfMessage( 'gwtoolset-developer-issue' )
                                        ->params( wfMessage( 
'gwtoolset-no-comment' )->parse() )
                                        ->parse()
@@ -817,7 +818,7 @@
                }
 
                if ( !isset( $user_options['save-as-batch-job'] ) ) {
-                       throw new GWTException(
+                       throw new MWException(
                                wfMessage( 'gwtoolset-developer-issue' )
                                        ->params( wfMessage( 
'gwtoolset-no-save-as-batch' )->parse() )
                                        ->parse()
@@ -825,7 +826,7 @@
                }
 
                if ( !isset( $user_options['upload-media'] ) ) {
-                       throw new GWTException(
+                       throw new MWException(
                                wfMessage( 'gwtoolset-developer-issue' )
                                        ->params( wfMessage( 
'gwtoolset-no-upload-media' )->parse() )
                                        ->parse()
diff --git a/includes/Handlers/Xml/XmlDetectHandler.php 
b/includes/Handlers/Xml/XmlDetectHandler.php
index 30bb1d5..8ff05da 100644
--- a/includes/Handlers/Xml/XmlDetectHandler.php
+++ b/includes/Handlers/Xml/XmlDetectHandler.php
@@ -10,9 +10,10 @@
 namespace GWToolset\Handlers\Xml;
 use Content,
        DOMElement,
-       Html,
+       GWToolset\GWTException,
        GWToolset\Models\Mapping,
        GWToolset\Models\MediawikiTemplate,
+       Html,
        MWException,
        Php\Filter,
        XMLReader;
@@ -46,7 +47,6 @@
 
        /**
         * @param {array} $options
-        * @return {void}
         */
        public function __construct( array $options = array() ) {
                $this->reset();
@@ -66,7 +66,6 @@
         * findExampleDOMNodes(), but only one value is used
         *
         * @param {DOMElement} $DOMElement
-        * @return {void}
         */
        protected function createExampleDOMElement( DOMElement $DOMElement ) {
                foreach ( $DOMElement->childNodes as $DOMNode ) {
@@ -100,7 +99,6 @@
         * an array of user options that was submitted in the html form
         *
         * @throws {MWException}
-        * @return {void}
         */
        protected function findExampleDOMElement( $XMLElement, array 
&$user_options ) {
                $record = null;
@@ -158,7 +156,6 @@
         * not yet present in it
         *
         * @param {DOMElement} $DOMElement
-        * @return {void}
         */
        protected function findExampleDOMNodes( DOMElement $DOMElement ) {
                foreach ( $DOMElement->childNodes as $DOMNode ) {
@@ -399,8 +396,7 @@
         * the assumption is that it has already been uploaded to the wiki 
earlier and
         * is ready for use
         *
-        * @throws {MWException}
-        * @return {void}
+        * @throws {GWTException|MWException}
         */
        public function processXml( array &$user_options, $xml_source = null ) {
                $callback = 'findExampleDOMElement';
@@ -440,16 +436,13 @@
                                        ) .
                                Html::closeElement( 'ul' ) .
                                $this->_SpecialPage->getBackToFormLink();
-                       throw new MWException( $msg );
+                       throw new GWTException( $msg );
                }
 
                ksort( $this->_metadata_example_dom_nodes );
                ksort( $this->_metadata_example_dom_element );
        }
 
-       /**
-        * @return {void}
-        */
        public function reset() {
                $this->_metadata_as_options = null;
                $this->_metadata_example_dom_element = array();
diff --git a/includes/Handlers/Xml/XmlHandler.php 
b/includes/Handlers/Xml/XmlHandler.php
index 362ed2a..7e7ae09 100644
--- a/includes/Handlers/Xml/XmlHandler.php
+++ b/includes/Handlers/Xml/XmlHandler.php
@@ -11,6 +11,7 @@
 use Content,
        DOMDocument,
        DOMXPath,
+       GWToolset\GWTException,
        Html,
        Linker,
        MWException,
@@ -208,7 +209,7 @@
                $errors = libxml_get_errors();
 
                if ( !empty( $errors ) ) {
-                       throw new MWException(
+                       throw new GWTException(
                                wfMessage( 'gwtoolset-xml-error' )->escaped() .
                                Html::rawElement( 'pre', array( 'style' => 
'overflow:auto;' ), print_r( $errors, true ) )
                        );
@@ -242,7 +243,7 @@
                                        ) .
                                Html::closeElement( 'ul' ) .
                                $this->_SpecialPage->getBackToFormLink();
-                       throw new MWException( $msg );
+                       throw new GWTException( $msg );
                }
 
                foreach ( $DOMNodeList as $DOMNode ) {
diff --git a/includes/Handlers/Xml/XmlMappingHandler.php 
b/includes/Handlers/Xml/XmlMappingHandler.php
index 2df9283..b96e5d2 100644
--- a/includes/Handlers/Xml/XmlMappingHandler.php
+++ b/includes/Handlers/Xml/XmlMappingHandler.php
@@ -12,6 +12,7 @@
        DOMDocument,
        DOMElement,
        GWToolset\Config,
+       GWToolset\GWTException,
        GWToolset\Handlers\Forms\MetadataMappingHandler,
        GWToolset\Models\Mapping,
        GWToolset\Models\MediawikiTemplate,
diff --git a/includes/Helpers/FileChecks.php b/includes/Helpers/FileChecks.php
index 58a1e10..0cbc37b 100644
--- a/includes/Helpers/FileChecks.php
+++ b/includes/Helpers/FileChecks.php
@@ -9,6 +9,7 @@
 
 namespace GWToolset\Helpers;
 use GWToolset\Config,
+       GWToolset\GWTException,
        MWException,
        Php\File,
        Php\Filter,
@@ -28,15 +29,14 @@
        public static $current_extension;
 
        /**
-        * @throws {MWException}
-        * @return {void}
+        * @throws {GWTException}
         */
        public static function checkContentLength() {
                if ( isset( $_SERVER["CONTENT_LENGTH"] )
                        && ( (int)$_SERVER["CONTENT_LENGTH"] > 
\GWToolset\getBytes( ini_get('post_max_size') )
                                || (int)$_SERVER["CONTENT_LENGTH"] > 
\GWToolset\getBytes( ini_get('upload_max_filesize') ) )
                ) {
-                       throw new MWException( wfMessage( 
'gwtoolset-over-max-ini' )->parse() );
+                       throw new GWTException( wfMessage( 
'gwtoolset-over-max-ini' )->parse() );
                }
        }
 
diff --git a/includes/Jobs/UploadFromUrlJob.php 
b/includes/Jobs/UploadFromUrlJob.php
deleted file mode 100644
index 6f54d69..0000000
--- a/includes/Jobs/UploadFromUrlJob.php
+++ /dev/null
@@ -1,89 +0,0 @@
-<?php
-/**
- * GWToolset
- *
- * @file
- * @ingroup Extensions
- * @license GNU General Public License 3.0 http://www.gnu.org/licenses/gpl.html
- */
-
-namespace GWToolset\Jobs;
-use Job,
-       UploadBase,
-       UploadFromUrl,
-       User;
-
-/**
- * a proof of concept based on /core/includes/job/jobs/UploadFromUrlJob.php
- */
-class UploadFromUrlJob extends Job {
-
-       /**
-        * @var {UploadFromUrl}
-        */
-       public $Upload;
-
-       /**
-        * @var {User}
-        */
-       protected $_User;
-
-       /**
-        * @param {Title} $title
-        * @param {bool|array} $params
-        * @param {int} $id
-        * @return {void}
-        */
-       public function __construct( $title, $params, $id = 0 ) {
-               parent::__construct( 'gwtoolsetUploadFromUrlJob', $title, 
$params, $id );
-       }
-
-       /**
-        * entry point
-        * @todo: should $result always be true?
-        * @return {bool}
-        */
-       public function run() {
-               // Initialize this object and the upload object
-               $this->Upload = new UploadFromUrl();
-               $this->Upload->initialize(
-                       $this->title->getText(),
-                       $this->params['url-to-the-media-file'],
-                       false
-               );
-
-               $this->_User = User::newFromName( $this->params['username'] );
-
-               // Fetch the file - returns a Status Object
-               $status = $this->Upload->fetchFile();
-               if ( !$status->isOk() ) {
-                       error_log( $status->getWikiText() );
-
-                       return true; //@todo: should this return true? when 
returning false, job stays in queue as orphan
-               }
-
-               // Verify upload - returns a Status value
-               $result = $this->Upload->verifyUpload();
-               if ( $result['status'] !== UploadBase::OK ) {
-                       $status = $this->Upload->convertVerifyErrorToStatus( 
$result );
-                       error_log( $status->getWikiText() );
-
-                       return true; //@todo: should this return true? when 
returning false, job stays in queue as orphan
-               }
-
-               // Perform the upload - returns FileRepoStatus Object
-               $status = $this->Upload->performUpload(
-                       $this->params['comment'],
-                       $this->params['text'],
-                       $this->params['watch'],
-                       $this->_User
-               );
-
-               if ( !$status->isOk() ) {
-                       error_log( $status->getWikiText() );
-                       //@todo: should this return true? when returning false, 
job stays in queue as orphan
-               }
-
-               return true;
-       }
-}
diff --git a/includes/Jobs/UploadMediafileJob.php 
b/includes/Jobs/UploadMediafileJob.php
index 6ea182c..5de8f6e 100644
--- a/includes/Jobs/UploadMediafileJob.php
+++ b/includes/Jobs/UploadMediafileJob.php
@@ -14,8 +14,8 @@
        GWToolset\Models\Mapping,
        GWToolset\Models\MediawikiTemplate,
        GWToolset\Models\Metadata,
+       GWToolset\GWTException,
        GWToolset\Handlers\UploadHandler,
-       MWException,
        Job,
        User;
 
@@ -25,7 +25,6 @@
         * @param {Title} $title
         * @param {bool|array} $params
         * @param {int} $id
-        * @return {void}
         */
        public function __construct( $title, $params, $id = 0 ) {
                parent::__construct( 'gwtoolsetUploadMediafileJob', $title, 
$params, $id );
@@ -94,7 +93,7 @@
 
                try {
                        $result = $this->processMetadata();
-               } catch ( MWException $e ) {
+               } catch ( GWTException $e ) {
                        $this->setLastError(
                                __METHOD__ . ': ' .
                                $e->getMessage() .
diff --git a/includes/Jobs/UploadMetadataJob.php 
b/includes/Jobs/UploadMetadataJob.php
index b72b70a..ca434a6 100644
--- a/includes/Jobs/UploadMetadataJob.php
+++ b/includes/Jobs/UploadMetadataJob.php
@@ -9,7 +9,7 @@
 
 namespace GWToolset\Jobs;
 use Job,
-       MWException,
+       GWToolset\GWTException,
        GWToolset\Handlers\Forms\MetadataMappingHandler,
        User;
 
@@ -32,7 +32,6 @@
         * @param {Title} $title
         * @param {bool|array} $params
         * @param {int} $id
-        * @return {void}
         */
        public function __construct( $title, $params, $id = 0 ) {
                parent::__construct( 'gwtoolsetUploadMetadataJob', $title, 
$params, $id );
@@ -70,7 +69,7 @@
 
                try {
                        $result = $this->processMetadata();
-               } catch ( MWException $e ) {
+               } catch ( GWTException $e ) {
                        $this->setLastError( __METHOD__ . ': ' . 
$e->getMessage() );
                }
 
diff --git a/includes/Models/Mapping.php b/includes/Models/Mapping.php
index 5ba42e3..f96e56c 100644
--- a/includes/Models/Mapping.php
+++ b/includes/Models/Mapping.php
@@ -10,11 +10,11 @@
 namespace GWToolset\Models;
 use GWToolset\Adapters\DataAdapterInterface,
        GWtoolset\Config,
+       GWToolset\GWTException,
        GWToolset\Helpers\FileChecks,
        GWToolset\Helpers\WikiPages,
        Language,
        Linker,
-       MWException,
        Php\Filter;
 
 class Mapping implements ModelInterface {
@@ -56,7 +56,6 @@
 
        /**
         * @param {DataAdapterInterface} $DataAdapter
-        * @return {void}
         */
        public function __construct( DataAdapterInterface $DataAdapter ) {
                $this->reset();
@@ -88,13 +87,13 @@
                try {
                        $result = json_decode( $this->mapping_json, true );
                        \GWToolset\jsonCheckForError();
-               } catch ( MWException $e ) {
+               } catch ( GWTException $e ) {
                        $error_msg = $e->getMessage();
                        if ( isset( $options['Metadata-Mapping-Title'] ) ) {
                                $error_msg .= ' ' . Linker::link( 
$options['Metadata-Mapping-Title'], null, array( 'target' => '_blank' ) );
                        }
 
-                       throw new MWException(
+                       throw new GWTException(
                                wfMessage( 'gwtoolset-metadata-mapping-bad' )
                                        ->rawParams( $error_msg )
                                        ->parse()
@@ -108,7 +107,7 @@
         * relies on a hardcoded path to the metadata mapping url
         *
         * @param {array} $options
-        * @throws {MWException}
+        * @throws {GWTException}
         * @return {string}
         * the string is not filtered
         */
@@ -140,7 +139,7 @@
                                        ->rawParams( $url, $expected_path )
                                        ->escaped();
 
-                               throw new MWException( $msg );
+                               throw new GWTException( $msg );
                        }
 
                        $result = $result[2];
@@ -153,7 +152,7 @@
         * attempts to retrieve a wiki page title that contains the metadata 
mapping json
         *
         * @param {array} $options
-        * @throws {MWException}
+        * @throws {GWTException}
         * @return {null|Title}
         */
        protected function getMappingTitle( array &$options ) {
@@ -166,7 +165,7 @@
                        );
 
                        if ( empty( $result ) ) {
-                               throw new MWException(
+                               throw new GWTException(
                                        wfMessage( 
'gwtoolset-metadata-mapping-not-found' )
                                                ->params( 
$options['metadata-mapping-url'] )
                                                ->parse()
@@ -179,7 +178,6 @@
 
        /**
         * @param {array} $options
-        * @return {void}
         */
        protected function populate( array &$options ) {
                if ( empty( $options ) ) {
@@ -201,9 +199,6 @@
                $this->reverseMap();
        }
 
-       /**
-        * @return {void}
-        */
        public function reset() {
                $this->mapping_array = array();
                $this->mapping_json = null;
@@ -217,8 +212,7 @@
         * @param {array} $options
         * an array of user options that was submitted in the html form
         *
-        * @throws {MWException}
-        * @return {void}
+        * @throws {GWTException}
         */
        public function retrieve( array &$options = array() ) {
                $options['Metadata-Mapping-Title'] = $this->getMappingTitle( 
$options );
@@ -230,9 +224,6 @@
                }
        }
 
-       /**
-        * @return {void}
-        */
        public function reverseMap() {
                foreach ( $this->target_dom_elements as $element ) {
                        foreach ( $this->mapping_array as $mediawiki_parameter 
=> $target_dom_elements ) {
@@ -243,9 +234,6 @@
                }
        }
 
-       /**
-        * @return {void}
-        */
        public function setTargetElements() {
                foreach ( $this->mapping_array as $key => $value ) {
                        foreach ( $value as $item ) {
diff --git a/includes/Models/MediawikiTemplate.php 
b/includes/Models/MediawikiTemplate.php
index ae01d5b..5e0403e 100644
--- a/includes/Models/MediawikiTemplate.php
+++ b/includes/Models/MediawikiTemplate.php
@@ -11,6 +11,7 @@
 use Html,
        GWToolset\Adapters\DataAdapterInterface,
        GWToolset\Config,
+       GWToolset\GWTException,
        GWToolset\Helpers\FileChecks,
        MWException,
        Php\Filter,
@@ -60,7 +61,6 @@
 
        /**
         * @param {DataAdapterInterface} $DataAdapter
-        * @return {void}
         */
        public function __construct( DataAdapterInterface $DataAdapter ) {
                $this->_DataAdapater = $DataAdapter;
@@ -335,21 +335,21 @@
         * @see https://commons.wikimedia.org/wiki/Commons:File_naming
         *
         * @param {array} $options
-        * @throws {MWException}
+        * @throws {GWTException}
         * @return {string} the string is not filtered.
         */
        public function getTitle( array &$options ) {
                $result = null;
 
                if ( empty( $this->mediawiki_template_array['title-identifier'] 
) ) {
-                       throw new MWException(
+                       throw new GWTException(
                                wfMessage( 
'gwtoolset-mapping-no-title-identifier' )
                                        ->escaped()
                        );
                }
 
                if ( empty( $options['evaluated-media-file-extension'] ) ) {
-                       throw new MWException(
+                       throw new GWTException(
                                wfMessage( 
'gwtoolset-mapping-media-file-url-extension-bad' )
                                        ->rawParams( Filter::evaluate( 
$options['url-to-the-media-file'] ) )
                                        ->escaped()
@@ -403,8 +403,7 @@
         * @param {string} $mediawiki_template_name
         * the key within $user_options that holds the name of the mediawiki 
template
         *
-        * @throws {MWException}
-        * @return {void}
+        * @throws {GWTException|MWException}
         */
        public function getMediaWikiTemplate( array &$user_options, 
$mediawiki_template_name = 'mediawiki-template-name' ) {
                if ( !isset( $user_options[$mediawiki_template_name] ) ) {
@@ -419,13 +418,10 @@
                        $this->mediawiki_template_name = 
$user_options[$mediawiki_template_name];
                        $this->retrieve();
                } else {
-                       throw new MWException( wfMessage( 
'gwtoolset-metadata-invalid-template' )->escaped() );
+                       throw new GWTException( wfMessage( 
'gwtoolset-metadata-invalid-template' )->escaped() );
                }
        }
 
-       /**
-        * @return {void}
-        */
        public function populateFromArray( array &$metadata = array() ) {
                foreach ( $this->mediawiki_template_array as $parameter => 
$value ) {
                        $this->mediawiki_template_array[$parameter] = null;
@@ -443,14 +439,13 @@
         * this mediawiki template model
         *
         * @param {array} $options
-        * @throws {MWException}
-        * @return {void}
+        * @throws {GWTException}
         */
        public function retrieve( array &$options = array() ) {
                $result = $this->_DataAdapater->retrieve( array( 
'mediawiki_template_name' => $this->mediawiki_template_name ) );
 
                if ( empty( $result ) ) {
-                       throw new MWException(
+                       throw new GWTException(
                                wfMessage( 
'gwtoolset-mediawiki-template-not-found' )
                                        ->rawParams( Filter::evaluate( 
$this->mediawiki_template_name ) )
                                                ->escaped()
diff --git a/includes/Specials/SpecialGWToolset.php 
b/includes/Specials/SpecialGWToolset.php
index 33c45cf..937b613 100644
--- a/includes/Specials/SpecialGWToolset.php
+++ b/includes/Specials/SpecialGWToolset.php
@@ -9,6 +9,7 @@
 
 namespace GWToolset;
 use GWToolset\Handlers\SpecialPageHandler,
+       GWToolset\GWTException,
        GWToolset\Helpers\FileChecks,
        GWToolset\Helpers\WikiChecks,
        Html,
@@ -71,7 +72,6 @@
        public function execute( $par ) {
                $this->setHeaders();
                $this->outputHeader();
-               set_error_handler( '\GWToolset\handleError' );
 
                if ( $this->wikiChecks() ) {
                        $this->setModuleAndHandler();
@@ -98,7 +98,7 @@
         * a control method that processes a SpecialPage request
         * SpecialPage->getOutput()->addHtml() present the end result of the 
request
         *
-        * @throws {PermissionsError|MWException}
+        * @throws {GWTException|MWException|PermissionsError}
         */
        protected function processRequest() {
                $html = null;
@@ -114,7 +114,7 @@
                                                $this->_Handler->getHtmlForm(
                                                        
$this->_registered_modules[$this->module_key]
                                                );
-                               } catch ( MWException $e ) {
+                               } catch ( GWTException $e ) {
                                        $html .=
                                                Html::rawElement(
                                                        'h2',
@@ -154,7 +154,7 @@
                                }
 
                                $html .= $this->_Handler->execute();
-                       } catch ( MWException $e ) {
+                       } catch ( GWTException $e ) {
                                if ( $e->getCode() === 1000 ) {
                                        throw new PermissionsError( 
$e->getMessage() );
                                } else {
diff --git a/includes/functions/functions.php b/includes/functions/functions.php
index 64b1b44..66905ee 100644
--- a/includes/functions/functions.php
+++ b/includes/functions/functions.php
@@ -13,6 +13,7 @@
        GWToolset\MediaWiki\Api\Client,
        Html,
        Language,
+       MWException,
        SpecialPage,
        Status,
        Title,
@@ -91,7 +92,7 @@
  *   {boolean} $options['must-be-known']
  *   Whether or not the Title must be known; defaults to true
  *
- * @throws {GWTException}
+ * @throws {GWTException|MWException}
  * @return {null|Title}
  */
 function getTitle( $page_title = null, $namespace = NS_MAIN, array $options = 
array() ) {
@@ -105,7 +106,7 @@
        $options = array_merge( $option_defaults, $options );
 
        if ( empty( $page_title ) ) {
-               throw new GWTException(
+               throw new MWException(
                        wfMessage( 'gwtoolset-developer-issue' )
                                ->params( wfMessage( 'gwtoolset-no-page-title' 
)->escaped() )
                                ->parse()

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie9493be07ecb74cf382bf3561e1c036af6538ac2
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/GWToolset
Gerrit-Branch: master
Gerrit-Owner: Dan-nl <[email protected]>
Gerrit-Reviewer: BryanDavis <[email protected]>
Gerrit-Reviewer: Dan-nl <[email protected]>
Gerrit-Reviewer: Gergő Tisza <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to