protected function getTextAreaAttributes() { global $sfgTabIndex, $sfgFieldNum; // Use a special ID for the free text field - // this was originally done for FCKeditor, but maybe it's // useful for other stuff too. $input_id = $this->mInputName == 'sf_free_text' ? 'sf_free_text' : "input_{$sfgFieldNum}"; if ($this->mUseWikieditor) { // Load modules for all enabled WikiEditor features. // The header for this function was changed in July // 2014, and the function itself was changed // significantly in March 2015 - this call should // hopefully work for all versions. global $wgTitle, $wgOut; $article = new Article($wgTitle); $editPage = new EditPage($article); WikiEditorHooks::editPageShowEditFormInitial($editPage, $wgOut); $className = 'wikieditor '; } else { $className = ''; } $className .= $this->mIsMandatory ? 'mandatoryField' : 'createboxInput'; if (array_key_exists('unique', $this->mOtherArgs)) { $className .= ' uniqueField'; } if (array_key_exists('class', $this->mOtherArgs)) { $className .= ' ' . $this->mOtherArgs['class']; } if (array_key_exists('autogrow', $this->mOtherArgs)) { $className .= ' autoGrow'; } if (array_key_exists('rows', $this->mOtherArgs)) { $rows = $this->mOtherArgs['rows']; } else { $rows = 5; } $textarea_attrs = array('tabindex' => $sfgTabIndex, 'name' => $this->mInputName, 'id' => $input_id, 'class' => $className, 'rows' => $rows); 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', $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 // 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 ($this->mIsDisabled) { $textarea_attrs['disabled'] = 'disabled'; } 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. // 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', $this->mOtherArgs)) { $textarea_attrs['placeholder'] = $this->mOtherArgs['placeholder']; } return $textarea_attrs; }
public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { global $wgOut; global $sfgTabIndex, $sfgFieldNum; // Use a special ID for the free text field, for FCK's needs. $input_id = $input_name == 'free_text' ? 'free_text' : "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 ) ? 'mandatoryField' : '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; } if ( array_key_exists( 'autogrow', $other_args ) ) { $className .= ' autoGrow'; } $textarea_attrs = array( 'tabindex' => $sfgTabIndex, 'id' => $input_id, 'name' => $input_name, 'rows' => $rows, 'class' => $className, ); 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['style'] = 'width: 100%'; } 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['placeholder'] = $other_args['placeholder']; } $text = Html::element( 'textarea', $textarea_attrs, $cur_value ); $spanClass = 'inputSpan'; if ( $is_mandatory ) { $spanClass .= ' mandatoryFieldSpan'; } $text = Html::rawElement( 'span', array( 'class' => $spanClass ), $text ); return $text; }
/** * Render the basic javascript, styles, etc. * * @param $output OutputPage */ private function renderScripts(OutputPage $output) { // include the required JS and CSS files $output->addModules(array('jquery.inlineEditor', 'jquery.inlineEditor.editors.basic')); if (class_exists('WikiEditorHooks')) { $output->addModules(array('jquery.wikiEditor')); if (WikiEditorHooks::isEnabled('toolbar')) { $output->addModules(array('jquery.wikiEditor.toolbar', 'jquery.wikiEditor.toolbar.config')); } if (WikiEditorHooks::isEnabled('dialogs')) { $output->addModules(array('jquery.wikiEditor.dialogs', 'jquery.wikiEditor.dialogs.config')); } } }
/** * Gets a 32 character alphanumeric random string to be used for stats. * @return string */ private static function getEditingStatsId() { if (self::$statsId) { return self::$statsId; } return self::$statsId = MWCryptRand::generateHex(32); }
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 ); } global $sfgTabIndex, $sfgFieldNum; 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['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; 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 = ''; } $text .= self::uploadableHTML( $input_id, $delimiter, $default_filename, $cur_value, $other_args ); } $spanClass = 'inputSpan'; if ( $is_mandatory ) { $spanClass .= ' mandatoryFieldSpan'; } $text = "\n" . Html::rawElement( 'span', array( 'class' => $spanClass ), $text ); return $text; }
/** * MakeGlobalVariablesScript hook * * Adds enabled/disabled switches for WikiEditor modules * @param $vars array * @return bool */ public static function resourceLoaderGetConfigVars(&$vars) { global $wgWikiEditorFeatures; $configurations = array(); foreach (self::$features as $name => $feature) { if (isset($feature['configurations']) && (!isset($wgWikiEditorFeatures[$name]) || self::isEnabled($name))) { foreach ($feature['configurations'] as $configuration) { global ${$configuration}; $configurations[$configuration] = ${$configuration}; } } } if (count($configurations)) { $vars = array_merge($vars, $configurations); } //expose magic words for use by the wikieditor toolbar WikiEditorHooks::getMagicWords($vars); return true; }