r82940 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82939‎ | r82940 | r82941 >
Date:17:00, 28 February 2011
Author:yaron
Status:deferred
Tags:
Comment:
Replaced some hardcoded HTML with calls to the Xml class; other improvements
Modified paths:
  • /trunk/extensions/SemanticForms/specials/SF_CreateForm.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/specials/SF_CreateForm.php
@@ -239,33 +239,34 @@
240240 // disable 'save' and 'preview' buttons if user has not yet added any
241241 // templates
242242 $disabled_text = ( count( $form_templates ) == 0 ) ? "disabled" : "";
243 - $save_button_text = wfMsg( 'savearticle' );
244 - $preview_button_text = wfMsg( 'preview' );
245243 $add_button_text = wfMsg( 'sf_createform_add' );
246244 $sk = $wgUser->getSkin();
247245 $create_template_link = SFUtils::linkForSpecialPage( $sk, 'CreateTemplate' );
 246+ $text .= "\t" . Xml::element( 'input', array( 'type' => 'submit', 'name' => 'add_field', 'value' => $add_button_text ) );
248247 $text .= <<<END
249 - <input type="submit" name="add_field" value="$add_button_text" /></p>
 248+</p>
250249 <br />
251 - <div class="editButtons">
252 - <p>
253 - <input type="submit" id="wpSave" name="wpSave" value="$save_button_text" $disabled_text />
254 - <input type="submit" id="wpPreview" name="wpPreview" value="$preview_button_text" $disabled_text />
255 - </p>
256 - </div>
257250
258251 END;
 252+ $saveAttrs = array( 'type' => 'submit', 'id' => 'wpSave', 'name' => 'wpSave', 'value' => wfMsg( 'savearticle' ) );
 253+ if ( count( $form_templates ) == 0 ) { $saveAttrs['disabled'] = 'disabled'; }
 254+ $editButtonsText .= "\t" . Xml::element( 'input', $saveAttrs ) . "\n";
 255+ $previewAttrs = array( 'type' => 'submit', 'id' => 'wpPreview', 'name' => 'wpPreview', 'value' => wfMsg( 'preview' ) );
 256+ if ( count( $form_templates ) == 0 ) { $previewAttrs['disabled'] = 'disabled'; }
 257+ $editButtonsText .= "\t" . Xml::element( 'input', $previewAttrs ) . "\n";
 258+ $text .= "\t" . Xml::tags( 'div', array( 'class' => 'editButtons' ),
 259+ Xml::tags( 'p', array(), $editButtonsText ) . "\n" ) . "\n";
259260 // explanatory message if buttons are disabled because no templates
260261 // have been added
261262 if ( count( $form_templates ) == 0 ) {
262 - $text .= " " . Xml::element( 'p', null, "(" . wfMsg( 'sf_createtemplate_addtemplatebeforesave' ) . ")" );
 263+ $text .= "\t" . Xml::element( 'p', null, "(" . wfMsg( 'sf_createtemplate_addtemplatebeforesave' ) . ")" );
263264 }
264265 $text .= <<<END
265266 </form>
266267 <hr /><br />
267268
268269 END;
269 - $text .= " " . Xml::tags( 'p', null, $create_template_link . '.' );
 270+ $text .= "\t" . Xml::tags( 'p', null, $create_template_link . '.' );
270271
271272 $wgOut->addExtensionStyle( $sfgScriptPath . "/skins/SemanticForms.css" );
272273 $wgOut->addHTML( $text );
@@ -278,23 +279,19 @@
279280 */
280281 public static function inputTypeParamInput( $type, $param_name, $cur_value, array $param, array $paramValues, $fieldFormText ) {
281282 if ( $type == 'int' ) {
282 - return Html::input(
283 - $param_name . '_' . $fieldFormText,
284 - $cur_value,
285 - 'text',
286 - array(
287 - 'size' => 6
288 - )
289 - );
 283+ return Xml::element( 'input', array(
 284+ 'type' => 'text',
 285+ 'name' => $param_name . '_' . $fieldFormText,
 286+ 'value' => $cur_value,
 287+ 'size' => 6
 288+ ) );
290289 } elseif ( $type == 'string' ) {
291 - return Html::input(
292 - $param_name . '_' . $fieldFormText,
293 - $cur_value,
294 - 'text',
295 - array(
296 - 'size' => 32
297 - )
298 - );
 290+ return Xml::element( 'input', array(
 291+ 'type' => 'text',
 292+ 'name' => $param_name . '_' . $fieldFormText,
 293+ 'value' => $cur_value,
 294+ 'size' => 32
 295+ ) );
299296 } elseif ( $type == 'enumeration' ) {
300297 $text = '<select name="p[' . htmlspecialchars( $param_name ) . ']">';
301298 $text .= "\n <option value=''></option>\n";
@@ -317,11 +314,12 @@
318315 }
319316 return $text;
320317 } elseif ( $type == 'boolean' ) {
321 - return Html::input(
322 - $param_name . '_' . $fieldFormText,
323 - null,
324 - 'checkbox'
 318+ $checkboxAttrs = array(
 319+ 'type' => 'checkbox',
 320+ 'name' => $param_name . '_' . $fieldFormText
325321 );
 322+ if ( $cur_value) { $checkboxAttrs['checked'] = 'checked'; }
 323+ return Xml::element( 'input', $checkboxAttrs );
326324 }
327325 }
328326
@@ -365,7 +363,7 @@
366364 $text .= "<div style=\"width: 30%; padding: 5px; float: left;\">$param_name:\n";
367365
368366 $text .= self::inputTypeParamInput( $type, $param_name, $cur_value, $param, array(), $fieldFormText );
369 - $text .= "\n <br /><em>$desc</em>\n</div>\n";
 367+ $text .= "\n<br />" . Xml::element( 'em', null, $desc ) . "\n</div>\n";
370368
371369 if ( $i % 3 == 2 || $i == count( $params ) - 1 ) {
372370 $text .= "<div style=\"clear: both\";></div></div>\n";