https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112712
Revision: 112712
Author: foxtrott
Date: 2012-02-29 20:09:07 +0000 (Wed, 29 Feb 2012)
Log Message:
-----------
enable handling of modules of input types; use associative array for input type
parameters to simplify subclassing
Modified Paths:
--------------
trunk/extensions/SemanticForms/includes/forminputs/SF_FormInput.php
trunk/extensions/SemanticForms/specials/SF_CreateForm.php
Modified: trunk/extensions/SemanticForms/includes/forminputs/SF_FormInput.php
===================================================================
--- trunk/extensions/SemanticForms/includes/forminputs/SF_FormInput.php
2012-02-29 20:07:41 UTC (rev 112711)
+++ trunk/extensions/SemanticForms/includes/forminputs/SF_FormInput.php
2012-02-29 20:09:07 UTC (rev 112712)
@@ -87,27 +87,27 @@
*/
public static function getParameters() {
$params = array();
- $params[] = array(
+ $params['mandatory'] = array(
'name' => 'mandatory',
'type' => 'boolean',
'description' => wfMsg( 'sf_forminputs_mandatory' )
);
- $params[] = array(
+ $params['restricted'] = array(
'name' => 'restricted',
'type' => 'boolean',
'description' => wfMsg( 'sf_forminputs_restricted' )
);
- $params[] = array(
+ $params['class'] = array(
'name' => 'class',
'type' => 'string',
'description' => wfMsg( 'sf_forminputs_class' )
);
- $params[] = array(
+ $params['property'] = array(
'name' => 'property',
'type' => 'string',
'description' => wfMsg( 'sf_forminputs_property' )
);
- $params[] = array(
+ $params['default'] = array(
'name' => 'default',
'type' => 'string',
'description' => wfMsg( 'sf_forminputs_default' )
@@ -165,6 +165,19 @@
public function getJsValidationFunctionData() {
return $this->mJsValidationFunctionData;
}
+
+
+ /**
+ * Returns the names of the resource modules this input type uses.
+ *
+ * Returns the names of the modules as an array or - if there is only
one
+ * module - as a string.
+ *
+ * @return null|string|array
+ */
+ public function getResourceModuleNames() {
+ return null;
+ }
/**
* For each input type one or more JavaScript initialization functions
may
@@ -294,27 +307,38 @@
$input = new $calledClass ( $sfgFieldNum, $cur_value,
$input_name, $is_disabled, $other_args );
+ $modules = $input->getResourceModuleNames();
+
+ // register modules for the input
+ if ( $modules !== null ) {
+ $wgOut->addModuleStyles( $modules );
+ $wgOut->addModuleScripts( $modules );
+ }
+
// create calls to JS initialization and validation
// TODO: This data should be transferred as a JSON blob and
then be evaluated from a dedicated JS file
- $jstext = '';
+ if ( $input->getJsInitFunctionData() ||
$input->getJsValidationFunctionData() ) {
- foreach ( $input->getJsInitFunctionData() as
$jsInitFunctionData ) {
+ $jstext = '';
- $jstext .= <<<JAVASCRIPT
-jQuery(function(){
jQuery('#input_$sfgFieldNum').SemanticForms_registerInputInit({$jsInitFunctionData['name']},
{$jsInitFunctionData['param']} ); });
-JAVASCRIPT;
- }
+ foreach ( $input->getJsInitFunctionData() as
$jsInitFunctionData ) {
+ $jstext .=
"jQuery('#input_$sfgFieldNum').SemanticForms_registerInputInit({$jsInitFunctionData['name']},
{$jsInitFunctionData['param']} );";
+ }
- foreach ( $input->getJsValidationFunctionData() as
$jsValidationFunctionData ) {
+ foreach ( $input->getJsValidationFunctionData() as
$jsValidationFunctionData ) {
+ $jstext .=
"jQuery('#input_$sfgFieldNum').SemanticForms_registerInputValidation(
{$jsValidationFunctionData['name']}, {$jsValidationFunctionData['param']});";
+ }
- $jstext .= <<<JAVASCRIPT
-jQuery(function(){
jQuery('#input_$sfgFieldNum').SemanticForms_registerInputValidation(
{$jsValidationFunctionData['name']}, {$jsValidationFunctionData['param']}); });
-JAVASCRIPT;
+ if ( $modules !== null ) {
+ $jstext = 'mw.loader.using(' . json_encode(
$modules ) . ', function(){' . $jstext . '});';
+ }
+
+ $jstext = 'jQuery(function(){' . $jstext . '});';
+
+ // write JS code directly to the page's code
+ $wgOut->addScript( Html::inlineScript( $jstext ) );
}
- // write JS code directly to the page's code
- $wgOut->addScript( Html::inlineScript( $jstext ) );
-
return $input->getHtmlText();
}
Modified: trunk/extensions/SemanticForms/specials/SF_CreateForm.php
===================================================================
--- trunk/extensions/SemanticForms/specials/SF_CreateForm.php 2012-02-29
20:07:41 UTC (rev 112711)
+++ trunk/extensions/SemanticForms/specials/SF_CreateForm.php 2012-02-29
20:09:07 UTC (rev 112712)
@@ -360,7 +360,8 @@
$params = method_exists( $inputTypeClass, 'getParameters' ) ?
call_user_func( array( $inputTypeClass, 'getParameters' ) ) : array();
- foreach ( $params as $i => $param ) {
+ $i = 0;
+ foreach ( $params as $param ) {
$paramName = $param['name'];
$type = $param['type'];
$desc = $wgParser->parse( $param['description'], new
Title(), new ParserOptions() )->getText();
@@ -387,6 +388,7 @@
if ( $i % 3 == 2 || $i == count( $params ) - 1 ) {
$text .= "<div style=\"clear:
both\";></div></div>\n";
}
+ ++$i;
}
return $text;
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs