https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112829

Revision: 112829
Author:   foxtrott
Date:     2012-03-01 19:26:21 +0000 (Thu, 01 Mar 2012)
Log Message:
-----------
fix issues with wikieditor for textarea; rework textarea and textarea with 
autocompletion; include missing dependencies for ext...main module

Modified Paths:
--------------
    trunk/extensions/SemanticForms/SemanticForms.php
    trunk/extensions/SemanticForms/includes/forminputs/SF_FormInput.php
    trunk/extensions/SemanticForms/includes/forminputs/SF_TextAreaInput.php
    
trunk/extensions/SemanticForms/includes/forminputs/SF_TextAreaWithAutocompleteInput.php
    trunk/extensions/SemanticForms/libs/SF_wikieditor.js

Modified: trunk/extensions/SemanticForms/SemanticForms.php
===================================================================
--- trunk/extensions/SemanticForms/SemanticForms.php    2012-03-01 19:22:27 UTC 
(rev 112828)
+++ trunk/extensions/SemanticForms/SemanticForms.php    2012-03-01 19:26:21 UTC 
(rev 112829)
@@ -208,6 +208,8 @@
                                'jquery.ui.button',
                                'jquery.ui.sortable',
                                'jquery.ui.widget',
+                               'ext.semanticforms.fancybox',
+                               'ext.semanticforms.autogrow',
                        ),
                ),
                'ext.semanticforms.fancybox' => $sfgResourceTemplate + array(
@@ -240,7 +242,11 @@
                'ext.semanticforms.wikieditor' => $sfgResourceTemplate + array(
                        'scripts' => 'libs/SF_wikieditor.js',
                        'styles' => 'skins/SF_wikieditor.css',
+                       'dependencies' => array(
+                               'ext.semanticforms.main',
+                               'jquery.wikiEditor',
                ),
+               ),
                'ext.semanticforms.imagepreview' => $sfgResourceTemplate + 
array(
                        'scripts' => 'libs/SF_imagePreview.js',
                ),

Modified: trunk/extensions/SemanticForms/includes/forminputs/SF_FormInput.php
===================================================================
--- trunk/extensions/SemanticForms/includes/forminputs/SF_FormInput.php 
2012-03-01 19:22:27 UTC (rev 112828)
+++ trunk/extensions/SemanticForms/includes/forminputs/SF_FormInput.php 
2012-03-01 19:26:21 UTC (rev 112829)
@@ -320,17 +320,20 @@
                if ( $input->getJsInitFunctionData() || 
$input->getJsValidationFunctionData() ) {
 
                        $jstext = '';
+                       $input_id = $input_name == 'sf_free_text' ? 
'sf_free_text' : "input_$sfgFieldNum";
 
                        foreach ( $input->getJsInitFunctionData() as 
$jsInitFunctionData ) {
-                               $jstext .= 
"jQuery('#input_$sfgFieldNum').SemanticForms_registerInputInit({$jsInitFunctionData['name']},
 {$jsInitFunctionData['param']} );";
+                               $jstext .= 
"jQuery('#$input_id').SemanticForms_registerInputInit({$jsInitFunctionData['name']},
 {$jsInitFunctionData['param']} );";
                        }
 
                        foreach ( $input->getJsValidationFunctionData() as 
$jsValidationFunctionData ) {
-                               $jstext .= 
"jQuery('#input_$sfgFieldNum').SemanticForms_registerInputValidation( 
{$jsValidationFunctionData['name']}, {$jsValidationFunctionData['param']});";
+                               $jstext .= 
"jQuery('#$input_id').SemanticForms_registerInputValidation( 
{$jsValidationFunctionData['name']}, {$jsValidationFunctionData['param']});";
                        }
 
                        if ( $modules !== null ) {
-                               $jstext = 'mw.loader.using(' . json_encode( 
$modules ) . ', function(){' . $jstext . '});';
+                               $jstext = 'mw.loader.using(' . json_encode( 
$modules )
+                                       . ',function(){' . $jstext
+                                       . '},function(e,module){alert(module+": 
"+e);});';
                        }
 
                        $jstext = 'jQuery(function(){' . $jstext . '});';

Modified: 
trunk/extensions/SemanticForms/includes/forminputs/SF_TextAreaInput.php
===================================================================
--- trunk/extensions/SemanticForms/includes/forminputs/SF_TextAreaInput.php     
2012-03-01 19:22:27 UTC (rev 112828)
+++ trunk/extensions/SemanticForms/includes/forminputs/SF_TextAreaInput.php     
2012-03-01 19:26:21 UTC (rev 112829)
@@ -14,6 +14,45 @@
  */
 class SFTextAreaInput extends SFFormInput {
 
+       protected $mUseWikieditor = false;
+       
+       /**
+        * Constructor for the SFTextAreaInput class.
+        *
+        * @param String $input_number
+        *              The number of the input in the form. For a simple HTML 
input element
+        *      this should end up in the id attribute in the format 
'input_<number>'.
+        * @param String $cur_value
+        *              The current value of the input field. For a simple HTML 
input
+        *              element this should end up in the value attribute.
+        * @param String $input_name
+        *              The name of the input. For a simple HTML input element 
this should
+        *              end up in the name attribute.
+        * @param Array $other_args
+        *              An associative array of other parameters that were 
present in the
+        *              input definition.
+        */
+       public function __construct( $input_number, $cur_value, $input_name, 
$disabled, $other_args ) {
+               
+               global $wgOut;
+               
+               parent::__construct( $input_number, $cur_value, $input_name, 
$disabled, $other_args );
+               
+               if (
+                       array_key_exists( 'editor', $this->mOtherArgs ) &&
+                       $this->mOtherArgs['editor'] == 'wikieditor' &&
+                       
+                       method_exists( $wgOut, 'getResourceLoader' ) &&
+                       in_array( 'jquery.wikiEditor', 
$wgOut->getResourceLoader()->getModuleNames() ) &&
+                       
+                       class_exists( 'WikiEditorHooks' )
+               ) {
+                       $this->mUseWikieditor = true;
+                       $this->addJsInitFunctionData( 
'window.ext.wikieditor.init' );
+               }
+       }
+
+       
        public static function getName() {
                return 'textarea';
        }
@@ -30,68 +69,100 @@
                return array( '_wpg', '_str' );
        }
 
-       public static function getHTML( $cur_value, $input_name, $is_mandatory, 
$is_disabled, $other_args ) {
+       public static function getParameters() {
+               $params = parent::getParameters();
 
-               global $wgOut;
+               $params['preload'] = array(
+                       'name' => 'preload',
+                       'type' => 'string',
+                       'description' => wfMsg( 'sf_forminputs_preload' )
+               );
+               $params['rows'] = array(
+                       'name' => 'rows',
+                       'type' => 'int',
+                       'description' => wfMsg( 'sf_forminputs_rows' )
+               );
+               $params['cols'] = array(
+                       'name' => 'cols',
+                       'type' => 'int',
+                       'description' => wfMsg( 'sf_forminputs_cols' )
+               );
+               $params['maxlength'] = array(
+                       'name' => 'maxlength',
+                       'type' => 'int',
+                       'description' => wfMsg( 'sf_forminputs_maxlength' )
+               );
+               $params['placeholder'] = array(
+                       'name' => 'placeholder',
+                       'type' => 'string',
+                       'description' => wfMsg( 'sf_forminputs_placeholder' )
+               );
+               $params['autogrow'] = array(
+                       'name' => 'autogrow',
+                       'type' => 'boolean',
+                       'description' => wfMsg( 'sf_forminputs_autogrow' )
+               );
+               return $params;
+       }
+
+       /**
+        * 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 
$this->mUseWikieditor?'ext.semanticforms.wikieditor':null;
+       }
+
+       protected function getTextAreaAttributes() {
+
                global $sfgTabIndex, $sfgFieldNum;
 
                // Use a special ID for the free text field, for FCK's needs.
-               $input_id = $input_name == 'sf_free_text' ? 'sf_free_text' : 
"input_$sfgFieldNum";
+               $input_id = $this->mInputName == 'sf_free_text' ? 
'sf_free_text' : "input_$sfgFieldNum";
 
-               if ( array_key_exists( 'editor', $other_args ) &&
-                       $other_args['editor'] == 'wikieditor' &&
+               if ( $this->mUseWikieditor ) {
 
-                       method_exists( $wgOut, 'getResourceLoader' ) &&
-                       in_array( 'jquery.wikiEditor', 
$wgOut->getResourceLoader()->getModuleNames() ) &&
-
-                       class_exists( 'WikiEditorHooks' ) ) {
-
                        // load modules for all enabled features
                        WikiEditorHooks::editPageShowEditFormInitial( $this );
+                       $className = 'wikieditor ';
+               } else {
+                       $className = '';
+               }
 
-                       $wgOut->addModules( 'ext.semanticforms.wikieditor' );
+               $className .= ( $this->mIsMandatory ) ? 'mandatoryField' : 
'createboxInput';
 
-                       $jstext = <<<JAVASCRIPT
-                       jQuery( 
jQuery('#$input_id').SemanticForms_registerInputInit( ext.wikieditor.init, null 
) );
-JAVASCRIPT;
-
-                       // write JS code directly to the page's code
-                       $wgOut->addScript( Html::inlineScript( $jstext ) );
-
-                       $className = "wikieditor ";
-               } else {
-                       $className = "";
+               if ( array_key_exists( 'class', $this->mOtherArgs ) ) {
+                       $className .= ' ' . $this->mOtherArgs['class'];
                }
 
-               $className .= ( $is_mandatory ) ? 'mandatoryField' : 
'createboxInput';
-               if ( array_key_exists( 'class', $other_args ) ) {
-                       $className .= " " . $other_args['class'];
+               if ( array_key_exists( 'autogrow', $this->mOtherArgs ) ) {
+                       $className .= ' autoGrow';
                }
 
-               if ( array_key_exists( 'rows', $other_args ) ) {
-                       $rows = $other_args['rows'];
+               if ( array_key_exists( 'rows', $this->mOtherArgs ) ) {
+                       $rows = $this->mOtherArgs['rows'];
                } else {
                        $rows = 5;
                }
 
-               if ( array_key_exists( 'autogrow', $other_args ) ) {
-                       $className .= ' autoGrow';
-               }
-
                $textarea_attrs = array(
                        'tabindex' => $sfgTabIndex,
+                       'name' => $this->mInputName,
                        'id' => $input_id,
-                       'name' => $input_name,
+                       'class' => $className,
                        'rows' => $rows,
-                       'class' => $className,
                );
 
-               if ( array_key_exists( 'cols', $other_args ) ) {
-                       $textarea_attrs['cols'] = $other_args['cols'];
+               if ( array_key_exists( 'cols', $this->mOtherArgs ) ) {
+                       $textarea_attrs['cols'] = $this->mOtherArgs['cols'];
                        // Needed to prevent CSS from overriding the manually-
                        // set width.
                        $textarea_attrs['style'] = 'width: auto';
-               } elseif ( array_key_exists( 'autogrow', $other_args ) ) {
+               } elseif ( array_key_exists( 'autogrow', $this->mOtherArgs ) ) {
                        // If 'autogrow' has been set, automatically set
                        // the number of columns - otherwise, the Javascript
                        // won't be able to know how many characters there
@@ -103,11 +174,12 @@
                        $textarea_attrs['style'] = 'width: 100%';
                }
 
-               if ( $is_disabled ) {
+               if ( $this->mIsDisabled ) {
                        $textarea_attrs['disabled'] = 'disabled';
                }
-               if ( array_key_exists( 'maxlength', $other_args ) ) {
-                       $maxlength = $other_args['maxlength'];
+
+               if ( array_key_exists( 'maxlength', $this->mOtherArgs ) ) {
+                       $maxlength = $this->mOtherArgs['maxlength'];
                        // For every actual character pressed (i.e., excluding
                        // things like the Shift key), reduce the string to its
                        // allowed length if it's exceeded that.
@@ -119,63 +191,29 @@
                        $textarea_attrs['onKeyDown'] = $maxLengthJSCheck;
                        $textarea_attrs['onKeyUp'] = $maxLengthJSCheck;
                }
-               if ( array_key_exists( 'placeholder', $other_args ) ) {
-                       $textarea_attrs['placeholder'] = 
$other_args['placeholder'];
-               }
 
-               $text = Html::element( 'textarea', $textarea_attrs, $cur_value 
);
-               $spanClass = 'inputSpan';
-               if ( $is_mandatory ) {
-                       $spanClass .= ' mandatoryFieldSpan';
+               if ( array_key_exists( 'placeholder', $this->mOtherArgs ) ) {
+                       $textarea_attrs['placeholder'] = 
$this->mOtherArgs['placeholder'];
                }
-               $text = Html::rawElement( 'span', array( 'class' => $spanClass 
), $text );
 
-               return $text;
+               return $textarea_attrs;
        }
 
-       public static function getParameters() {
-               $params = parent::getParameters();
-               $params[] = array(
-                       'name' => 'preload',
-                       'type' => 'string',
-                       'description' => wfMsg( 'sf_forminputs_preload' )
-               );
-               $params[] = array(
-                       'name' => 'rows',
-                       'type' => 'int',
-                       'description' => wfMsg( 'sf_forminputs_rows' )
-               );
-               $params[] = array(
-                       'name' => 'cols',
-                       'type' => 'int',
-                       'description' => wfMsg( 'sf_forminputs_cols' )
-               );
-               $params[] = array(
-                       'name' => 'maxlength',
-                       'type' => 'int',
-                       'description' => wfMsg( 'sf_forminputs_maxlength' )
-               );
-               $params[] = array(
-                       'name' => 'placeholder',
-                       'type' => 'string',
-                       'description' => wfMsg( 'sf_forminputs_placeholder' )
-               );
-               $params[] = array(
-                       'name' => 'autogrow',
-                       'type' => 'boolean',
-                       'description' => wfMsg( 'sf_forminputs_autogrow' )
-               );
-               return $params;
-       }
-
        /**
         * Returns the HTML code to be included in the output page for this 
input.
         */
        public function getHtmlText() {
 
-               return self::getHTML(
-                               $this->mCurrentValue, $this->mInputName, 
$this->mIsMandatory, $this->mIsDisabled, $this->mOtherArgs
-               );
+               $textarea_attrs = $this->getTextAreaAttributes();
+
+               $text = Html::element( 'textarea', $textarea_attrs, 
$this->mCurrentValue );
+               $spanClass = 'inputSpan';
+               if ( $this->mIsMandatory ) {
+                       $spanClass .= ' mandatoryFieldSpan';
        }
+               $text = Html::rawElement( 'span', array( 'class' => $spanClass 
), $text );
 
+               return $text;
 }
+
+}

Modified: 
trunk/extensions/SemanticForms/includes/forminputs/SF_TextAreaWithAutocompleteInput.php
===================================================================
--- 
trunk/extensions/SemanticForms/includes/forminputs/SF_TextAreaWithAutocompleteInput.php
     2012-03-01 19:22:27 UTC (rev 112828)
+++ 
trunk/extensions/SemanticForms/includes/forminputs/SF_TextAreaWithAutocompleteInput.php
     2012-03-01 19:26:21 UTC (rev 112829)
@@ -16,167 +16,32 @@
                return 'textarea with autocomplete';
        }
 
-       public static function getDefaultPropTypes() {
-               return array();
+       public static function getParameters() {
+               $params = parent::getParameters();
+               $params = array_merge( $params, 
SFTextWithAutocompleteInput::getAutocompletionParameters() );
+               return $params;
        }
 
-       public static function getOtherPropTypesHandled() {
-               return array( '_wpg', '_str' );
-       }
+       protected function getTextAreaAttributes() {
 
-       public static function getOtherPropTypeListsHandled() {
-               return array( '_wpg', '_str' );
-       }
+               $textarea_attrs = parent::getTextAreaAttributes();
 
-       public static function getHTML( $cur_value, $input_name, $is_mandatory, 
$is_disabled, $other_args ) {
-
-               // TODO: Lots of duplication of code in the parent class. Needs 
refactoring!
-
-               global $wgOut;
-
                // If 'no autocomplete' was specified, print a regular
                // textarea instead.
-               if ( array_key_exists( 'no autocomplete', $other_args ) &&
-                               $other_args['no autocomplete'] == true ) {
-                       unset( $other_args['autocompletion source'] );
-                       return SFTextAreaInput::getHTML( $cur_value, 
$input_name, $is_mandatory, $is_disabled, $other_args );
-               }
+               if ( !array_key_exists( 'no autocomplete', $this->mOtherArgs ) 
||
+                       $this->mOtherArgs['no autocomplete'] == false ) {
 
-               global $sfgTabIndex, $sfgFieldNum;
+                       list( $autocompleteSettings, $remoteDataType, 
$delimiter ) = SFTextWithAutocompleteInput::setAutocompleteValues( 
$this->mOtherArgs );
 
-               list( $autocompleteSettings, $remoteDataType, $delimiter ) = 
SFTextWithAutocompleteInput::setAutocompleteValues( $other_args );
-
-               $input_id = 'input_' . $sfgFieldNum;
-
-               if ( array_key_exists( 'editor', $other_args ) &&
-                       $other_args['editor'] == 'wikieditor' &&
-
-                       method_exists( $wgOut, 'getResourceLoader' ) &&
-                       in_array( 'jquery.wikiEditor', 
$wgOut->getResourceLoader()->getModuleNames() ) &&
-
-                       class_exists( 'WikiEditorHooks' ) ) {
-
-                       // load modules for all enabled features
-                       WikiEditorHooks::editPageShowEditFormInitial( $this );
-
-                       $wgOut->addModules( 'ext.semanticforms.wikieditor' );
-
-                       $jstext = <<<JAVASCRIPT
-                       jQuery( 
jQuery('#$input_id').SemanticForms_registerInputInit( ext.wikieditor.init, null 
) );
-JAVASCRIPT;
-
-                       // write JS code directly to the page's code
-                       $wgOut->addScript( Html::inlineScript( $jstext ) );
-
-                       $className = "wikieditor ";
-               } else {
-                       $className = "";
-               }
-
-               $className .= ( $is_mandatory ) ? 'autocompleteInput 
mandatoryField' : 'autocompleteInput createboxInput';
-               if ( array_key_exists( 'class', $other_args ) ) {
-                       $className .= ' ' . $other_args['class'];
-               }
-
-               if ( array_key_exists( 'rows', $other_args ) ) {
-                       $rows = $other_args['rows'];
-               } else {
-                       $rows = 5;
-               }
-               $text = '';
-               if ( array_key_exists( 'autogrow', $other_args ) ) {
-                       $className .= ' autoGrow';
-               }
-
-               $textarea_attrs = array(
-                       'tabindex' => $sfgTabIndex,
-                       'id' => $input_id,
-                       'name' => $input_name,
-                       'rows' => $rows,
-                       'class' => $className,
-                       'autocompletesettings' => $autocompleteSettings,
-               );
-
-               if ( array_key_exists( 'cols', $other_args ) ) {
-                       $textarea_attrs['cols'] = $other_args['cols'];
-                       // Needed to prevent CSS from overriding the manually-
-                       // set width.
-                       $textarea_attrs['style'] = 'width: auto';
-               } elseif ( array_key_exists( 'autogrow', $other_args ) ) {
-                       // If 'autogrow' has been set, automatically set
-                       // the number of columns - otherwise, the Javascript
-                       // won't be able to know how many characters there
-                       // are per line, and thus won't work.
-                       $textarea_attrs['cols'] = 90;
-                       $textarea_attrs['style'] = 'width: auto';
-               } else {
-                       $textarea_attrs['cols'] = 90;
-                       $textarea_attrs['style'] = 'width: 100%';
-               }
-
-               if ( array_key_exists( 'origName', $other_args ) ) {
-                       $inputAttrs['origName'] = $other_args['origName'];
-               }
                if ( !is_null( $remoteDataType ) ) {
                        $textarea_attrs['autocompletedatatype'] = 
$remoteDataType;
                }
-               if ( $is_disabled ) {
-                       $textarea_attrs['disabled'] = 'disabled';
-               }
-               if ( array_key_exists( 'maxlength', $other_args ) ) {
-                       $maxlength = $other_args['maxlength'];
-                       // For every actual character pressed (i.e., excluding
-                       // things like the Shift key), reduce the string to
-                       // its allowed length if it's exceeded that.
-                       // This JS code is complicated so that it'll work
-                       // correctly in IE - IE moves the cursor to the end
-                       // whenever this.value is reset, so we'll make sure
-                       // to do that only when we need to.
-                       $maxLengthJSCheck = "if (window.event && 
window.event.keyCode < 48 && window.event.keyCode != 13) return; if 
(this.value.length > $maxlength) { this.value = this.value.substring(0, 
$maxlength); }";
-                       $textarea_attrs['onKeyDown'] = $maxLengthJSCheck;
-                       $textarea_attrs['onKeyUp'] = $maxLengthJSCheck;
-               }
-               if ( array_key_exists( 'placeholder', $other_args ) ) {
-                       $textarea_attrs = $other_args['placeholder'];
-               }
 
-               $textarea_input = Html::element( 'textarea', $textarea_attrs, 
$cur_value );
-               $text .= $textarea_input;
+                       $textarea_attrs['autocompletesettings'] = 
$autocompleteSettings;
 
-               if ( array_key_exists( 'uploadable', $other_args ) && 
$other_args['uploadable'] == true ) {
-                       if ( array_key_exists( 'default filename', $other_args 
) ) {
-                               $default_filename = $other_args['default 
filename'];
-                       } else {
-                               $default_filename = '';
+                       $textarea_attrs['class'] .= ' autocompleteInput';
                        }
-                       $text .= self::uploadableHTML( $input_id, $delimiter, 
$default_filename, $cur_value, $other_args );
-               }
 
-               $spanClass = 'inputSpan';
-               if ( $is_mandatory ) {
-                       $spanClass .= ' mandatoryFieldSpan';
+               return $textarea_attrs;
                }
-               $text = "\n" . Html::rawElement( 'span', array( 'class' => 
$spanClass ), $text );
-
-               return $text;
        }
-
-       public static function getParameters() {
-               $params = parent::getParameters();
-               $params = array_merge( $params, 
SFTextWithAutocompleteInput::getAutocompletionParameters() );
-               return $params;
-       }
-
-       /**
-        * Returns the HTML code to be included in the output page for this 
input.
-        */
-       public function getHtmlText() {
-               return self::getHTML(
-                       $this->mCurrentValue,
-                       $this->mInputName,
-                       $this->mIsMandatory,
-                       $this->mIsDisabled,
-                       $this->mOtherArgs
-               );
-       }
-}

Modified: trunk/extensions/SemanticForms/libs/SF_wikieditor.js
===================================================================
--- trunk/extensions/SemanticForms/libs/SF_wikieditor.js        2012-03-01 
19:22:27 UTC (rev 112828)
+++ trunk/extensions/SemanticForms/libs/SF_wikieditor.js        2012-03-01 
19:26:21 UTC (rev 112829)
@@ -3,13 +3,13 @@
        window.ext = {};
 }
 
-window.ext.wikieditor = new function(){
+window.ext.wikieditor = {
 
        // initialize the wikieditor on the specified element
-       this.init = function init ( input_id, params ) {
+       init : function init ( input_id, params ) {
 
+               jQuery( function() {
                if ( window.mediaWiki ) {
-                       mediaWiki.loader.using( 'ext.semanticforms.wikieditor', 
function(){
 
                                var input = jQuery( '#' + input_id );
 
@@ -41,20 +41,8 @@
                                        }
                                });
 
-                               // load toc
-                               // TODO: Can this be enabled? Should it?
-//                             mediaWiki.loader.using( 
['jquery.wikiEditor.toc' ] , function(){
-//                                     if ( jQuery.wikiEditor.isSupported( 
jQuery.wikiEditor.modules.toc ) ) {
-//
-//                                             input.wikiEditor( 'addModule', 
'toc' );
-//
-//                                     }
-//                             });
-
-
-
-                       } );
                }
-       }
 
+               });
+       }
 };


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

Reply via email to