r101702 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101701‎ | r101702 | r101703 >
Date:21:28, 2 November 2011
Author:foxtrott
Status:deferred
Tags:
Comment:
followup r101533: next attempt at fixing timing issues when initializing wikieditor, ran stylize on SemanticForms.php
Modified paths:
  • /trunk/extensions/SemanticForms/SemanticForms.php (modified) (history)
  • /trunk/extensions/SemanticForms/includes/forminputs/SF_TextAreaInput.php (modified) (history)
  • /trunk/extensions/SemanticForms/includes/forminputs/SF_TextAreaWithAutocompleteInput.php (modified) (history)
  • /trunk/extensions/SemanticForms/libs/SF_wikieditor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/SemanticForms.php
@@ -235,10 +235,9 @@
236236 'scripts' => 'libs/SF_wikieditor.js',
237237 'styles' => 'skins/SF_wikieditor.css',
238238 'dependencies' => array(
239 - 'jquery.wikiEditor',
240239 'jquery.wikiEditor.toolbar',
241240 'jquery.wikiEditor.toolbar.config',
242 -
 241+
243242 ),
244243 ),
245244 );
@@ -303,7 +302,7 @@
304303 # ##
305304 # Extend the edit form from the internal EditPage class rather than using a
306305 # special page and hacking things up.
307 -#
 306+#
308307 # @note This is experimental and requires updates to EditPage which I have only
309308 # added into MediaWiki 1.14a
310309 # ##
@@ -338,7 +337,7 @@
339338 # Page properties, used for the API
340339 # ##
341340 $wgPageProps['formdefinition'] = 'Definition of the semantic form used on the page';
342 -
 341+
343342 # ##
344343 # Global variables for Javascript
345344 # ##
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_TextAreaWithAutocompleteInput.php
@@ -48,35 +48,24 @@
4949
5050 $input_id = 'input_' . $sfgFieldNum;
5151
52 - static $hasRun = false;
53 -
5452 if ( array_key_exists( 'wikieditor', $other_args ) &&
55 - method_exists($wgOut, 'getResourceLoader') &&
56 - in_array( 'jquery.wikiEditor', $wgOut->getResourceLoader()->getModuleNames() ) ) {
5753
58 - if ( !$hasRun ) {
59 -
60 - $hasRun = true;
 54+ method_exists( $wgOut, 'getResourceLoader' ) &&
 55+ in_array( 'jquery.wikiEditor', $wgOut->getResourceLoader()->getModuleNames() ) &&
6156
62 - // one time initialization
63 - WikiEditorHooks::editPageShowEditFormInitial( $this );
64 - $wgOut->addModules( 'ext.semanticforms.wikieditor' );
65 - }
 57+ class_exists( 'WikiEditorHooks' ) &&
 58+ WikiEditorHooks::isEnabled( 'toolbar' ) ) {
6659
 60+
 61+ $wgOut->addModules( 'ext.semanticforms.wikieditor' );
 62+
6763 $jstext = <<<JAVASCRIPT
68 -if ( window.mediaWiki ) {
69 - mediaWiki.loader.using(
70 - [ 'ext.semanticforms.wikieditor', 'jquery.wikiEditor.toolbar.config' ],
71 - function(){
72 - jQuery('#$input_id').SemanticForms_registerInputInit( ext.wikieditor.init, null );
73 - }
74 - );
75 -}
 64+ jQuery( jQuery('#$input_id').SemanticForms_registerInputInit( ext.wikieditor.init, null ) );
7665 JAVASCRIPT;
7766
7867 // write JS code directly to the page's code
7968 $wgOut->addScript( Html::inlineScript( $jstext ) );
80 -
 69+
8170 $className = "wikieditor ";
8271 } else {
8372 $className = "";
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_TextAreaInput.php
@@ -1,4 +1,5 @@
22 <?php
 3+
34 /**
45 * File holding the SFTextAreaInput class
56 *
@@ -12,59 +13,49 @@
1314 * @ingroup SFFormInput
1415 */
1516 class SFTextAreaInput extends SFFormInput {
 17+
1618 public static function getName() {
1719 return 'textarea';
1820 }
1921
2022 public static function getDefaultPropTypes() {
21 - return array( '_txt' => array(), '_cod' => array() );
 23+ return array('_txt' => array(), '_cod' => array());
2224 }
2325
2426 public static function getOtherPropTypesHandled() {
25 - return array( '_wpg', '_str' );
 27+ return array('_wpg', '_str');
2628 }
2729
2830 public static function getOtherPropTypeListsHandled() {
29 - return array( '_wpg', '_str' );
 31+ return array('_wpg', '_str');
3032 }
3133
3234 public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
33 -
 35+
3436 global $wgOut;
3537 global $sfgTabIndex, $sfgFieldNum;
3638
3739 // Use a special ID for the free text field, for FCK's needs.
3840 $input_id = $input_name == 'free_text' ? 'free_text' : "input_$sfgFieldNum";
3941
40 - static $hasRun = false;
41 -
4242 if ( array_key_exists( 'wikieditor', $other_args ) &&
43 - method_exists($wgOut, 'getResourceLoader') &&
44 - in_array( 'jquery.wikiEditor', $wgOut->getResourceLoader()->getModuleNames() ) ) {
45 -
46 - if ( !$hasRun ) {
47 -
48 - $hasRun = true;
 43+
 44+ method_exists( $wgOut, 'getResourceLoader' ) &&
 45+ in_array( 'jquery.wikiEditor', $wgOut->getResourceLoader()->getModuleNames() ) &&
4946
50 - // one time initialization
51 - WikiEditorHooks::editPageShowEditFormInitial( $this );
52 - $wgOut->addModules( 'ext.semanticforms.wikieditor' );
53 - }
 47+ class_exists( 'WikiEditorHooks' ) &&
 48+ WikiEditorHooks::isEnabled( 'toolbar' ) ) {
5449
 50+
 51+ $wgOut->addModules( 'ext.semanticforms.wikieditor' );
 52+
5553 $jstext = <<<JAVASCRIPT
56 -if ( window.mediaWiki ) {
57 - mediaWiki.loader.using(
58 - [ 'ext.semanticforms.wikieditor', 'jquery.wikiEditor.toolbar.config' ],
59 - function(){
60 - jQuery('#$input_id').SemanticForms_registerInputInit( ext.wikieditor.init, null );
61 - }
62 - );
63 -}
 54+ jQuery( jQuery('#$input_id').SemanticForms_registerInputInit( ext.wikieditor.init, null ) );
6455 JAVASCRIPT;
6556
6657 // write JS code directly to the page's code
6758 $wgOut->addScript( Html::inlineScript( $jstext ) );
68 -
 59+
6960 $className = "wikieditor ";
7061 } else {
7162 $className = "";
@@ -135,7 +126,7 @@
136127 if ( $is_mandatory ) {
137128 $spanClass .= ' mandatoryFieldSpan';
138129 }
139 - $text = Xml::tags( 'span', array( 'class' => $spanClass ), $text );
 130+ $text = Xml::tags( 'span', array('class' => $spanClass), $text );
140131
141132 return $text;
142133 }
@@ -180,11 +171,8 @@
181172 */
182173 public function getHtmlText() {
183174 return self::getHTML(
184 - $this->mCurrentValue,
185 - $this->mInputName,
186 - $this->mIsMandatory,
187 - $this->mIsDisabled,
188 - $mOtherArgs
 175+ $this->mCurrentValue, $this->mInputName, $this->mIsMandatory, $this->mIsDisabled, $mOtherArgs
189176 );
190177 }
 178+
191179 }
Index: trunk/extensions/SemanticForms/libs/SF_wikieditor.js
@@ -22,23 +22,25 @@
2323 // setup();
2424 // }
2525
26 - jQuery( document ).ready( function() {
27 - if ( jQuery.wikiEditor.isSupported( jQuery.wikiEditor.modules.toolbar ) ) {
 26+ if ( window.mediaWiki ) {
 27+ mediaWiki.loader.using( 'ext.semanticforms.wikieditor', function(){
 28+ if ( jQuery.wikiEditor.isSupported( jQuery.wikiEditor.modules.toolbar ) ) {
2829
29 - if (jQuery.wikiEditor.modules.toolbar.config !== undefined ) {
30 - jQuery( '#' + input_id ).wikiEditor( 'addModule', jQuery.wikiEditor.modules.toolbar.config.getDefaultConfig() );
31 - } else {
32 -
33 - // TODO: this is nasty. Take it out if at all possible.
34 - var timeout = setTimeout(function () {
3530 if (jQuery.wikiEditor.modules.toolbar.config !== undefined ) {
3631 jQuery( '#' + input_id ).wikiEditor( 'addModule', jQuery.wikiEditor.modules.toolbar.config.getDefaultConfig() );
37 - clearTimeout(timeout);
38 - }
39 - }, 1000);
40 - }
41 - }
42 - });
 32+ } else {
 33+
 34+ // TODO: this is nasty. Take it out if at all possible.
 35+ var timeout = setTimeout(function () {
 36+ if (jQuery.wikiEditor.modules.toolbar.config !== undefined ) {
 37+ jQuery( '#' + input_id ).wikiEditor( 'addModule', jQuery.wikiEditor.modules.toolbar.config.getDefaultConfig() );
 38+ clearTimeout(timeout);
 39+ }
 40+ }, 1000);
 41+ }
 42+ }
 43+ } )
 44+ }
4345 }
4446
4547 };

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r101533followup r101525: next attempt at fixing timing issues when initializing wiki...foxtrott21:37, 1 November 2011