Dan-nl has uploaded a new change for review.
https://gerrit.wikimedia.org/r/97369
Change subject: form-handler
......................................................................
form-handler
crhis steipp requested that FormHandler->getForm() check that the form
class is an expected form class.
Change-Id: Iaf17b4b34197bee23e3f4e1ae8a11977779a90d9
---
M GWToolset.i18n.php
M GWToolset.php
M includes/Forms/MetadataMappingForm.php
M includes/Handlers/Forms/FormHandler.php
M includes/Handlers/Forms/MetadataDetectHandler.php
M includes/Handlers/Forms/MetadataMappingHandler.php
D includes/Handlers/SpecialPageHandler.php
M includes/Specials/SpecialGWToolset.php
8 files changed, 93 insertions(+), 95 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GWToolset
refs/changes/69/97369/1
diff --git a/GWToolset.i18n.php b/GWToolset.i18n.php
index 5f66614..df2cecc 100644
--- a/GWToolset.i18n.php
+++ b/GWToolset.i18n.php
@@ -47,6 +47,7 @@
'gwtoolset-no-file-backend-name' => 'No file backend name provided.',
'gwtoolset-no-file-backend-container' => 'No file backend container
name provided.',
'gwtoolset-no-file-url' => 'No <code>file_url</code> provided to
parse.',
+ 'gwtoolset-no-form-handler' => 'No form handler was created.',
'gwtoolset-no-mapping' => 'No <code>mapping_name</code> provided.',
'gwtoolset-no-mapping-json' => 'No <code>mapping_json</code> provided.',
'gwtoolset-no-mediawiki-template' => 'No
<code>mediawiki-template-name</code> provided.',
@@ -59,7 +60,6 @@
'gwtoolset-no-template-url' => 'No template URL provided to parse.',
'gwtoolset-no-text' => 'No text provided.',
'gwtoolset-no-title' => 'No title provided.',
- 'gwtoolset-no-upload-handler' => 'No upload handler was created.',
'gwtoolset-no-upload-media' =>
"<code>user_options['upload-media']</code> not set.",
'gwtoolset-no-url-to-evaluate' => 'No URL was provided for evaluation.',
'gwtoolset-no-url-to-media' => '<code>url-to-the-media-file</code> not
set.',
@@ -357,6 +357,7 @@
'gwtoolset-no-file-backend-container' => 'Message that appears wher no
file backend container name was provided.',
'gwtoolset-no-file-url' => 'Hint to the developer that appears when no
file_url is provided to parse.',
'gwtoolset-no-form' => 'Message that appears when there is no form for
this module.',
+ 'gwtoolset-no-form-handler' => 'Hint to the developer that appears when
no form handler was created.',
'gwtoolset-no-mapping' => 'Hint to the developer that appears when no
mapping_name is provided.',
'gwtoolset-no-mapping-json' => 'Hint to the developer that appears when
no mapping_json is provided.',
'gwtoolset-no-mediawiki-template' => 'Hint to the developer that
appears when no mediawiki-template-name is provided.',
@@ -370,7 +371,6 @@
'gwtoolset-no-template-url' => 'Hint to the developer that appears when
no template URL is provided to parse.',
'gwtoolset-no-text' => 'Hint to the developer that appears when no text
is provided.',
'gwtoolset-no-title' => 'Hint to the developer that appears when no
title is provided.',
- 'gwtoolset-no-upload-handler' => 'Hint to the developer that appears
when no upload handler was created.',
'gwtoolset-no-upload-media' => "Hint to the developer that appears when
user_options['upload-media'] is not set.",
'gwtoolset-no-url-to-evaluate' => 'Message that appears when no URL was
provided for evaluation.',
'gwtoolset-no-url-to-media' => 'Hint to the developer that appears when
url-to-the-media-file is not set.',
diff --git a/GWToolset.php b/GWToolset.php
index aab5f5b..37bb1d6 100644
--- a/GWToolset.php
+++ b/GWToolset.php
@@ -67,7 +67,6 @@
'GWToolset\Handlers\Forms\FormHandler' => $wgGWToolsetDir .
'/includes/Handlers/Forms/FormHandler.php',
'GWToolset\Handlers\Forms\MetadataDetectHandler' => $wgGWToolsetDir .
'/includes/Handlers/Forms/MetadataDetectHandler.php',
'GWToolset\Handlers\Forms\MetadataMappingHandler' => $wgGWToolsetDir .
'/includes/Handlers/Forms/MetadataMappingHandler.php',
- 'GWToolset\Handlers\SpecialPageHandler' => $wgGWToolsetDir .
'/includes/Handlers/SpecialPageHandler.php',
'GWToolset\Handlers\UploadHandler' => $wgGWToolsetDir .
'/includes/Handlers/UploadHandler.php',
'GWToolset\Handlers\Xml\XmlDetectHandler' => $wgGWToolsetDir .
'/includes/Handlers/Xml/XmlDetectHandler.php',
'GWToolset\Handlers\Xml\XmlHandler' => $wgGWToolsetDir .
'/includes/Handlers/Xml/XmlHandler.php',
diff --git a/includes/Forms/MetadataMappingForm.php
b/includes/Forms/MetadataMappingForm.php
index 247f191..f45f677 100644
--- a/includes/Forms/MetadataMappingForm.php
+++ b/includes/Forms/MetadataMappingForm.php
@@ -21,7 +21,7 @@
/**
* returns an html form for step 2 : Metadata Mapping
*
- * @param {FormHandler} $Handler
+ * @param {GWToolset\Handlers\Forms\FormHandler} $Handler
*
* @param {array} $user_options
* an array of user options that was submitted in the html form
diff --git a/includes/Handlers/Forms/FormHandler.php
b/includes/Handlers/Forms/FormHandler.php
index d964cd7..a1ca8a4 100644
--- a/includes/Handlers/Forms/FormHandler.php
+++ b/includes/Handlers/Forms/FormHandler.php
@@ -9,12 +9,37 @@
namespace GWToolset\Handlers\Forms;
use GWToolset\GWTException,
GWToolset\Utils,
- GWToolset\Handlers\SpecialPageHandler,
GWToolset\Helpers\WikiChecks,
Html,
- MWException;
+ MWException,
+ SpecialPage;
-abstract class FormHandler extends SpecialPageHandler {
+abstract class FormHandler {
+
+ /**
+ * @var {SpecialPage}
+ */
+ public $SpecialPage;
+
+ /**
+ * @var {User}
+ */
+ public $User;
+
+ /**
+ * @param {array} $options
+ */
+ public function __construct( array $options = array() ) {
+ if ( isset( $options['SpecialPage'] ) ) {
+ $this->SpecialPage = $options['SpecialPage'];
+ }
+
+ if ( isset( $options['User'] ) ) {
+ $this->User = $options['User'];
+ } elseif ( isset( $this->SpecialPage ) ) {
+ $this->User = $this->SpecialPage->getUser();
+ }
+ }
/**
* make sure the expected options :
@@ -63,22 +88,49 @@
}
/**
- * @param {string} $module_name
+ * @param {string} $module
* @throws {MWException}
- *
* @return {string}
- * the string has not been filtered
*/
- protected function getFormClass( $module_name ) {
- if ( $module_name === null ) {
+ public function getFormClass( $module = null ) {
+ $registered_modules =
$this->SpecialPage->getRegisteredModules();
+
+ if ( $module === null || !array_key_exists( $module,
$registered_modules ) ) {
throw new MWException(
wfMessage( 'gwtoolset-developer-issue' )
- ->params( wfMessage(
'gwtoolset-no-module' )->escaped() )
- ->parse()
+ ->params(
+ __METHOD__ . ': ' .
+ wfMessage(
'gwtoolset-no-module' )->escaped()
+ )
+ ->escaped()
);
}
- return $module_name['form'];
+ if ( !isset( $registered_modules[$module]['form'] ) ) {
+ throw new MWException(
+ wfMessage( 'gwtoolset-developer-issue' )
+ ->params(
+ __METHOD__ . ': ' .
+ wfMessage(
'gwtoolset-no-module' )->escaped()
+ )
+ ->escaped()
+ );
+ }
+
+ $result = $registered_modules[$module]['form'];
+
+ if ( !class_exists( $result ) ) {
+ throw new MWException(
+ wfMessage( 'gwtoolset-developer-issue' )
+ ->params(
+ __METHOD__ . ': ' .
+ wfMessage(
'gwtoolset-no-module' )->escaped()
+ )
+ ->escaped()
+ );
+ }
+
+ return $result;
}
/**
@@ -99,20 +151,15 @@
* @return {string}
* the string has not been filtered
*/
- public function getHtmlForm( $module_name = null ) {
- $form_class = $this->getFormClass( $module_name );
-
- if ( !class_exists( $form_class ) ) {
- throw new GWTException( wfMessage( 'gwtoolset-no-form'
)->escaped() );
- }
-
+ public function getHtmlForm( $module = null ) {
+ $form_class = $this->getFormClass( $module );
return $form_class::getForm( $this->SpecialPage );
}
/**
* entry point
* a control method that acts as an entry point for the
- * SpecialPageHandler and handles execution of the class methods
+ * FormHandler and handles execution of the class methods
*
* @return {string}
* the string has not been filtered
@@ -134,4 +181,12 @@
return $result;
}
+
+ /**
+ * a control method that processes a SpecialPage request
+ * and returns a response, typically an html form
+ *
+ * @return {string}
+ */
+ abstract protected function processRequest();
}
diff --git a/includes/Handlers/Forms/MetadataDetectHandler.php
b/includes/Handlers/Forms/MetadataDetectHandler.php
index d2109fb..5aeeb1d 100644
--- a/includes/Handlers/Forms/MetadataDetectHandler.php
+++ b/includes/Handlers/Forms/MetadataDetectHandler.php
@@ -13,6 +13,7 @@
GWToolset\Config,
GWToolset\Forms\MetadataMappingForm,
GWToolset\GWTException,
+ GWToolset\Handlers\Forms\FormHandler,
GWToolset\Handlers\UploadHandler,
GWToolset\Handlers\Xml\XmlDetectHandler,
GWToolset\Helpers\GWTFileBackend,
diff --git a/includes/Handlers/Forms/MetadataMappingHandler.php
b/includes/Handlers/Forms/MetadataMappingHandler.php
index 10350cb..e05aab2 100644
--- a/includes/Handlers/Forms/MetadataMappingHandler.php
+++ b/includes/Handlers/Forms/MetadataMappingHandler.php
@@ -17,9 +17,10 @@
GWToolset\Utils,
GWToolset\Forms\PreviewForm,
GWToolset\GWTException,
- GWToolset\Helpers\GWTFileBackend,
+ GWToolset\Handlers\Forms\FormHandler,
GWToolset\Handlers\UploadHandler,
GWToolset\Handlers\Xml\XmlMappingHandler,
+ GWToolset\Helpers\GWTFileBackend,
GWToolset\Jobs\UploadMetadataJob,
GWToolset\Models\Mapping,
GWToolset\Models\MediawikiTemplate,
diff --git a/includes/Handlers/SpecialPageHandler.php
b/includes/Handlers/SpecialPageHandler.php
deleted file mode 100644
index 3fe6f6b..0000000
--- a/includes/Handlers/SpecialPageHandler.php
+++ /dev/null
@@ -1,62 +0,0 @@
-<?php
-/**
- * GWToolset
- *
- * @file
- * @ingroup Extensions
- * @license GNU General Public License 3.0 http://www.gnu.org/licenses/gpl.html
- */
-namespace GWToolset\Handlers;
-use SpecialPage;
-
-abstract class SpecialPageHandler {
-
- /**
- * @var {SpecialPage}
- */
- public $SpecialPage;
-
- /**
- * @var {User}
- */
- public $User;
-
- /**
- * @param {array} $options
- */
- public function __construct( array $options = array() ) {
- if ( isset( $options['SpecialPage'] ) ) {
- $this->SpecialPage = $options['SpecialPage'];
- }
-
- if ( isset( $options['User'] ) ) {
- $this->User = $options['User'];
- } elseif ( isset( $this->SpecialPage ) ) {
- $this->User = $this->SpecialPage->getUser();
- }
- }
-
- /**
- * entry point
- * a control method that acts as an entry point for the
- * SpecialPageHandler and handles execution of the class methods
- *
- * @return {void|string}
- */
- abstract public function execute();
-
- /**
- * a control method that processes a SpecialPage request
- * and returns a response, typically an html form
- *
- * @return {string}
- */
- abstract protected function processRequest();
-
- /**
- * gets an html form
- *
- * @return {string}
- */
- abstract public function getHtmlForm();
-}
diff --git a/includes/Specials/SpecialGWToolset.php
b/includes/Specials/SpecialGWToolset.php
index c1cfe5a..105b050 100644
--- a/includes/Specials/SpecialGWToolset.php
+++ b/includes/Specials/SpecialGWToolset.php
@@ -11,7 +11,7 @@
use GWToolset\Constants,
GWToolset\GWTException,
GWToolset\Utils,
- GWToolset\Handlers\SpecialPageHandler,
+ GWToolset\Handlers\Forms\FormHandler,
GWToolset\Helpers\FileChecks,
GWToolset\Helpers\WikiChecks,
Html,
@@ -29,7 +29,7 @@
public $module_key;
/**
- * @var {SpecialPageHandler}
+ * @var {GWToolset\Handlers\Forms\FormHandler}
*/
protected $_Handler;
@@ -92,6 +92,13 @@
}
/**
+ * @return {array}
+ */
+ public function getRegisteredModules() {
+ return $this->_registered_modules;
+ }
+
+ /**
* a control method that processes a SpecialPage request
* SpecialPage->getOutput()->addHtml() present the end result of the
request
*
@@ -107,10 +114,7 @@
$html .= wfMessage( 'gwtoolset-intro'
)->parseAsBlock();
} else {
try {
- $html .=
- $this->_Handler->getHtmlForm(
-
$this->_registered_modules[$this->module_key]
- );
+ $html .= $this->_Handler->getHtmlForm(
$this->module_key );
} catch ( GWTException $e ) {
$html .=
Html::rawElement(
@@ -129,9 +133,9 @@
try {
FileChecks::checkContentLength();
- if ( !( $this->_Handler instanceof
\GWToolset\Handlers\SpecialPageHandler ) ) {
+ if ( !( $this->_Handler instanceof FormHandler
) ) {
$msg = wfMessage(
'gwtoolset-developer-issue' )
- ->params( wfMessage(
'gwtoolset-no-upload-handler' )->escaped() )
+ ->params( wfMessage(
'gwtoolset-no-form-handler' )->escaped() )
->parse();
if ( ini_get( 'display_errors' )
@@ -144,7 +148,7 @@
print_r(
error_get_last(), true )
);
} else {
- $msg = wfMessage(
'gwtoolset-no-upload-handler' )->escaped();
+ $msg = wfMessage(
'gwtoolset-no-form-handler' )->escaped();
}
throw new MWException( $msg );
--
To view, visit https://gerrit.wikimedia.org/r/97369
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaf17b4b34197bee23e3f4e1ae8a11977779a90d9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GWToolset
Gerrit-Branch: master
Gerrit-Owner: Dan-nl <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits