r103782 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103781‎ | r103782 | r103783 >
Date:20:54, 20 November 2011
Author:foxtrott
Status:deferred
Tags:
Comment:
open scope of some methods; make getHTML work with new-style input types
Modified paths:
  • /trunk/extensions/SemanticForms/includes/forminputs/SF_FormInput.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/forminputs/SF_FormInput.php
@@ -25,12 +25,12 @@
2626 protected $mInputNumber;
2727 protected $mCurrentValue;
2828 protected $mInputName;
29 - protected $mIsMandatory;
 29+ protected $mIsMandatory; // @deprecated, check for array_key_exists('mandatory', $this->mOtherArgs) instead
3030 protected $mIsDisabled;
3131 protected $mOtherArgs;
3232
33 - private $mJsInitFunctionData = array();
34 - private $mJsValidationFunctionData = array();
 33+ protected $mJsInitFunctionData = array();
 34+ protected $mJsValidationFunctionData = array();
3535
3636 /**
3737 * Constructor for the SFFormInput class.
@@ -48,11 +48,13 @@
4949 * An associative array of other parameters that were present in the
5050 * input definition.
5151 */
52 - public function __construct( $input_number, $cur_value, $input_name, $other_args ) {
 52+ public function __construct( $input_number, $cur_value, $input_name, $disabled, $other_args ) {
5353 $this->mInputNumber = $input_number;
5454 $this->mCurrentValue = $cur_value;
5555 $this->mInputName = $input_name;
5656 $this->mOtherArgs = $other_args;
 57+ $this->mIsDisabled = $disabled;
 58+ $this->mIsMandatory = array_key_exists( 'mandatory', $other_args );
5759 }
5860
5961 /**
@@ -72,7 +74,7 @@
7375
7476 /**
7577 * Returns the set of SMW property types which this input can
76 - * handle.
 78+ * handle. See SMW's SMW_DataValueFactory.php
7779 *
7880 * @return Array of Strings
7981 */
@@ -150,7 +152,7 @@
151153 *
152154 * This function is not used yet.
153155 */
154 - final public function getJsInitFunctionData() {
 156+ public function getJsInitFunctionData() {
155157 return $this->mJsInitFunctionData;
156158 }
157159
@@ -160,7 +162,7 @@
161163 *
162164 * This function is not used yet.
163165 */
164 - final public function getJsValidationFunctionData() {
 166+ public function getJsValidationFunctionData() {
165167 return $this->mJsValidationFunctionData;
166168 }
167169
@@ -188,7 +190,7 @@
189191 * @param String $name The name of the initialization function.
190192 * @param String $param The parameter passed to the initialization function.
191193 */
192 - final public function addJsInitFunctionData( $name, $param ) {
 194+ public function addJsInitFunctionData( $name, $param = 'null' ) {
193195 $this->mJsInitFunctionData[] = array( 'name' => $name, 'param' => $param );
194196 }
195197
@@ -216,8 +218,8 @@
217219 * @param String $name The name of the initialization function.
218220 * @param String $param The parameter passed to the initialization function.
219221 */
220 - final public function addJsValidationFunctionData( $name, $param ) {
221 - $this->mJsInitFunctionData[] = array( 'name' => $name, 'param' => $param );
 222+ public function addJsValidationFunctionData( $name, $param = 'null' ) {
 223+ $this->mJsValidationFunctionData[] = array( 'name' => $name, 'param' => $param );
222224 }
223225
224226 /**
@@ -268,4 +270,44 @@
269271 return array();
270272 }
271273
 274+ /**
 275+ * Method to make new style input types compatible with old-style call from
 276+ * the SF parser.
 277+ *
 278+ * @deprecated Do not use/override this in new input type classes
 279+ *
 280+ * TODO: remove/refactor once SF uses forminput objects properly
 281+ */
 282+ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
 283+
 284+ global $sfgFieldNum, $wgOut;
 285+
 286+ // create an input of the called class
 287+ $calledClass = get_called_class();
 288+ $input = new $calledClass ( $sfgFieldNum, $cur_value, $input_name, $is_disabled, $other_args );
 289+
 290+ // create calls to JS initialization and validation
 291+ // TODO: This data should be transferred as a JSON blob and then be evaluated from a dedicated JS file
 292+ $jstext = '';
 293+
 294+ foreach ( $input->getJsInitFunctionData() as $jsInitFunctionData ) {
 295+
 296+ $jstext .= <<<JAVASCRIPT
 297+jQuery(function(){ jQuery('#input_$sfgFieldNum').SemanticForms_registerInputInit({$jsInitFunctionData['name']}, {$jsInitFunctionData['param']} ); });
 298+JAVASCRIPT;
 299+ }
 300+
 301+ foreach ( $input->getJsValidationFunctionData() as $jsValidationFunctionData ) {
 302+
 303+ $jstext .= <<<JAVASCRIPT
 304+jQuery(function(){ jQuery('#input_$sfgFieldNum').SemanticForms_registerInputValidation( {$jsValidationFunctionData['name']}, {$jsValidationFunctionData['param']}); });
 305+JAVASCRIPT;
 306+ }
 307+
 308+ // write JS code directly to the page's code
 309+ $wgOut->addScript( Html::inlineScript( $jstext ) );
 310+
 311+ return $input->getHtmlText();
 312+ }
 313+
272314 }