r26050 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r26049‎ | r26050 | r26051 >
Date:01:40, 24 September 2007
Author:yaron
Status:old
Tags:
Comment:
Removed 'Editing help' link at bottom, added capability to specify the six
other form-bottom elements in the form definition, in order to customize or
remove them from the form; also removed extra newlines printed between
templates in form output.
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormPrinter.inc (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.inc
@@ -12,6 +12,8 @@
1313
1414 var $mSemanticTypeHooks;
1515 var $mInputTypeHooks;
 16+ var $standardInputsIncluded;
 17+ var $mPageTitle;
1618
1719 function SFFormPrinter() {
1820 global $smwgContLang;
@@ -38,6 +40,9 @@
3941 $this->setInputTypeHook('datetime with timezone', array('SFFormPrinter', 'dateTimeEntryHTML'), array('include_timezone' => true));
4042 $this->setInputTypeHook('checkbox', array('SFFormPrinter', 'checkboxHTML'), array());
4143 $this->setInputTypeHook('radiobutton', array('SFFormPrinter', 'radioButtonHTML'), array());
 44+
 45+ // initialize other variables
 46+ $this->standardInputsIncluded = false;
4247 }
4348
4449 function setSemanticTypeHook($type, $function_name, $default_args) {
@@ -57,8 +62,8 @@
5863 $sfgTabIndex = 1;
5964 $sfgFieldNum = 1;
6065 // disable all form elements if user doesn't have edit permission
61 - $true_page_title = Title::newFromText($page_title);
62 - if ( $true_page_title->userCanEdit() ) {
 66+ $this->mPageTitle = Title::newFromText($page_title);
 67+ if ( $this->mPageTitle->userCanEdit() ) {
6368 $form_is_disabled = false;
6469 $form_text = "";
6570 } else {
@@ -327,7 +332,7 @@
328333 if ($cur_value && ! is_array($cur_value)) {
329334 $cur_value = Sanitizer::safeEncodeAttribute($cur_value);
330335 }
331 - if (! $cur_value) {
 336+ if ($cur_value == null) {
332337 // set to default value specified in the form, if it's there
333338 $cur_value = $default_value;
334339 }
@@ -367,7 +372,7 @@
368373 }
369374 $free_text_was_included = true;
370375 // add a similar placeholder to the data text
371 - $data_text .= "<free_text>\n\n";
 376+ $data_text .= "<free_text>\n";
372377 }
373378 $section = substr_replace($section, $new_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc);
374379 } else { // this field is part of a template
@@ -486,10 +491,42 @@
487492 $start_position = $brackets_end_loc;
488493 }
489494 }
 495+ } elseif ($tag_title == 'standard input') {
 496+ // set a flag so that the standard 'form bottom' won't get displayed
 497+ $this->standardInputsIncluded = true;
 498+ // handle all the possible values
 499+ $input_name = $tag_components[1];
 500+ $input_label = null;
 501+ // cycle through the other components
 502+ for ($i = 2; $i < count($tag_components); $i++) {
 503+ $component = $tag_components[$i];
 504+ $sub_components = explode('=', $component);
 505+ if (count($sub_components) == 2) {
 506+ if ($sub_components[0] == 'label') {
 507+ $input_label = $sub_components[1];
 508+ }
 509+ }
 510+ }
 511+ if ($input_name == 'summary') {
 512+ $new_text = $this->summaryInputHTML($form_is_disabled, $input_label);
 513+ } elseif ($input_name == 'minor edit') {
 514+ $new_text = $this->minorEditInputHTML($form_is_disabled, $input_label);
 515+ } elseif ($input_name == 'watch') {
 516+ $new_text = $this->watchInputHTML($form_is_disabled, $input_label);
 517+ } elseif ($input_name == 'save') {
 518+ $new_text = $this->saveButtonHTML($form_is_disabled, $input_label);
 519+ } elseif ($input_name == 'preview') {
 520+ $new_text = $this->showPreviewButtonHTML($form_is_disabled, $input_label);
 521+ } elseif ($input_name == 'changes') {
 522+ $new_text = $this->showChangesButtonHTML($form_is_disabled, $input_label);
 523+ } elseif ($input_name == 'cancel') {
 524+ $new_text = $this->cancelLinkHTML($form_is_disabled, $input_label);
 525+ }
 526+ $section = substr_replace($section, $new_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc);
490527 } else { // tag is not one of the three allowed values
491528 // ignore tag
492529 $start_position = $brackets_end_loc;
493 - }
 530+ } // end if
494531 } // end while
495532
496533 if (! $all_instances_printed && ($template_text != '')) {
@@ -498,13 +535,7 @@
499536 if (strpos($template_text, "\n")) {
500537 $template_text .= "\n";
501538 }
502 - $template_text .= "}}\n\n";
503 - // TODO - should instances of the same template not be separated
504 - // by a blank line? if so, the following code could be used:
505 - //if (($data_text != "") &&
506 - // (! $allow_multiple || $old_template_name != $template_name)) {
507 - // $data_text .= "\n";
508 - //}
 539+ $template_text .= "}}\n";
509540 $data_text .= $template_text;
510541 }
511542 if ($allow_multiple) {
@@ -635,10 +666,7 @@
636667 </script>
637668 END;
638669 }
639 -
640 -
641670
642 -
643671 $chooser_text .= "<p>$choosername:<select id='chooserselect$chooser_count' size='1' onchange='updatechooserbutton(this,\"chooserbutton$chooser_count\")'>";
644672 $chooser_text .= "<option value='invalid'>Choose a field to add</option>";
645673 foreach ($chooser as $chooser_item) {
@@ -655,8 +683,11 @@
656684 }
657685
658686 $form_text = str_replace('<choosers>', $chooser_text, $form_text);
659 -
660 -
 687+
 688+ // add form bottom, if no custom "standard inputs" have been defined
 689+ if (! $this->standardInputsIncluded)
 690+ $form_text .= $this->formBottom($form_is_disabled);
 691+
661692 // add general Javascript code
662693 $blank_error_str = wfMsg('sf_blank_error');
663694 $javascript_text .=<<<END
@@ -1017,6 +1048,7 @@
10181049 }
10191050
10201051 global $sfgTabIndex, $sfgFieldNum;
 1052+ $className = ($is_mandatory) ? "mandatoryField" : "createboxInput";
10211053 $input_id = "input_$sfgFieldNum";
10221054 $info_id = "info_$sfgFieldNum";
10231055 $disabled_text = ($is_disabled) ? "disabled" : "";
@@ -1032,12 +1064,13 @@
10331065 }
10341066
10351067 function dropdownHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
1036 - global $sfgTabIndex;
 1068+ global $sfgTabIndex, $sfgFieldNum;
10371069
10381070 $className = ($is_mandatory) ? "mandatoryField" : "createboxInput";
 1071+ $input_id = "input_$sfgFieldNum";
10391072 $disabled_text = ($is_disabled) ? "disabled" : "";
10401073 $text =<<<END
1041 - <select tabindex="$sfgTabIndex" name="$input_name" class="className" $disabled_text>
 1074+ <select id="$input_id" tabindex="$sfgTabIndex" name="$input_name" class="className" $disabled_text>
10421075
10431076 END;
10441077 // add a blank value at the beginning if it's a non-mandatory field
@@ -1317,6 +1350,132 @@
13181351 return $text;
13191352 }
13201353
 1354+ function summaryInputHTML($is_disabled, $label = null) {
 1355+ global $sfgTabIndex;
 1356+
 1357+ $sfgTabIndex++;
 1358+ if ($label == null)
 1359+ $label = wfMsg('summary');
 1360+ $disabled_text = ($is_disabled) ? "disabled" : "";
 1361+ $text =<<<END
 1362+ <span id='wpSummaryLabel'><label for='wpSummary'>$label:</label></span>
 1363+ <input tabindex="$sfgTabIndex" type='text' value="" name='wpSummary' id='wpSummary' maxlength='200' size='60' $disabled_text/>
 1364+
 1365+END;
 1366+ return $text;
 1367+ }
 1368+
 1369+ function minorEditInputHTML($is_disabled, $label = null) {
 1370+ global $sfgTabIndex;
 1371+
 1372+ $sfgTabIndex++;
 1373+ $disabled_text = ($is_disabled) ? "disabled" : "";
 1374+ if ($label == null)
 1375+ $label = wfMsgExt('minoredit', array('parseinline'));
 1376+ $accesskey = wfMsg('accesskey-minoredit');
 1377+ $tooltip = wfMsg('tooltip-minoredit');
 1378+ $text =<<<END
 1379+ <input tabindex="$sfgTabIndex" type="checkbox" value="1" name="wpMinoredit" accesskey="$accesskey" id="wpMinoredit" $disabled_text/>
 1380+ <label for="wpMinoredit" title="$tooltip">$label</label>
 1381+
 1382+END;
 1383+ return $text;
 1384+ }
 1385+
 1386+ function watchInputHTML($is_disabled, $label = null) {
 1387+ global $sfgTabIndex;
 1388+
 1389+ $sfgTabIndex++;
 1390+ $disabled_text = ($is_disabled) ? "disabled" : "";
 1391+ if ($label == null)
 1392+ $label = wfMsgExt('watchthis', array('parseinline'));
 1393+ $accesskey = htmlspecialchars(wfMsg('accesskey-watch'));
 1394+ $tooltip = htmlspecialchars(wfMsg('tooltip-watch'));
 1395+ $text =<<<END
 1396+ <input tabindex="$sfgTabIndex" type="checkbox" name="wpWatchthis" accesskey="$accesskey" id='wpWatchthis' $disabled_text/>
 1397+ <label for="wpWatchthis" title="$tooltip">$label</label>
 1398+
 1399+END;
 1400+ return $text;
 1401+ }
 1402+
 1403+ function saveButtonHTML($is_disabled, $label = null) {
 1404+ global $sfgTabIndex;
 1405+
 1406+ $sfgTabIndex++;
 1407+ $disabled_text = ($is_disabled) ? "disabled" : "";
 1408+ if ($label == null)
 1409+ $label = wfMsg('savearticle');
 1410+ $temp = array(
 1411+ 'id' => 'wpSave',
 1412+ 'name' => 'wpSave',
 1413+ 'type' => 'submit',
 1414+ 'tabindex' => $sfgTabIndex,
 1415+ 'value' => $label,
 1416+ 'accesskey' => wfMsg('accesskey-save'),
 1417+ 'title' => wfMsg('tooltip-save'),
 1418+ $disabled_text => '',
 1419+ );
 1420+ $text = " " . wfElement('input', $temp, '') . "\n";
 1421+ return $text;
 1422+ }
 1423+
 1424+ function showPreviewButtonHTML($is_disabled, $label = null) {
 1425+ global $sfgTabIndex;
 1426+
 1427+ $sfgTabIndex++;
 1428+ $disabled_text = ($is_disabled) ? "disabled" : "";
 1429+ if ($label == null)
 1430+ $label = wfMsg('showpreview');
 1431+ $temp = array(
 1432+ 'id' => 'wpPreview',
 1433+ 'name' => 'wpPreview',
 1434+ 'type' => 'submit',
 1435+ 'tabindex' => $sfgTabIndex,
 1436+ 'value' => $label,
 1437+ 'accesskey' => wfMsg('accesskey-preview'),
 1438+ 'title' => wfMsg('tooltip-preview'),
 1439+ $disabled_text => '',
 1440+ );
 1441+ $text = " " . wfElement('input', $temp, '') . "\n";
 1442+ return $text;
 1443+ }
 1444+
 1445+ function showChangesButtonHTML($is_disabled, $label = null) {
 1446+ global $sfgTabIndex;
 1447+
 1448+ $sfgTabIndex++;
 1449+ $disabled_text = ($is_disabled) ? "disabled" : "";
 1450+ if ($label == null)
 1451+ $label = wfMsg('showdiff');
 1452+ $temp = array(
 1453+ 'id' => 'wpDiff',
 1454+ 'name' => 'wpDiff',
 1455+ 'type' => 'submit',
 1456+ 'tabindex' => $sfgTabIndex,
 1457+ 'value' => $label,
 1458+ 'accesskey' => wfMsg('accesskey-diff'),
 1459+ 'title' => wfMsg('tooltip-diff'),
 1460+ $disabled_text => '',
 1461+ );
 1462+ $text = " " . wfElement('input', $temp, '') . "\n";
 1463+ return $text;
 1464+ }
 1465+
 1466+ function cancelLinkHTML($is_disabled, $label = null) {
 1467+ global $wgUser;
 1468+
 1469+ $sk = $wgUser->getSkin();
 1470+ if ($label == null)
 1471+ $label = wfMsgExt('cancel', array('parseinline'));
 1472+ if ($this->mPageTitle == null)
 1473+ $cancel = '';
 1474+ else
 1475+ $cancel = $sk->makeKnownLink( $this->mPageTitle->getPrefixedText(), $label);
 1476+ $text = " <span class='editHelp'>$cancel</span>\n";
 1477+ return $text;
 1478+ }
 1479+
13211480 function redirectText($page_name, $data_text) {
13221481 global $wgUser, $wgRequest;
13231482
@@ -1364,106 +1523,35 @@
13651524 }
13661525
13671526 // Much of this function is based on MediaWiki's EditPage::showEditForm()
1368 - function formBottom($target_title = null, $is_disabled) {
1369 - global $wgVersion, $wgUser;
1370 - global $sfgTabIndex;
1371 - $sk = $wgUser->getSkin();
1372 -
1373 - $title = new Title();
1374 - $summary_text = wfMsg('summary');
1375 - if ($target_title == null)
1376 - $cancel = '';
1377 - else
1378 - $cancel = $sk->makeKnownLink( $target_title->getPrefixedText(),
1379 - wfMsgExt('cancel', array('parseinline')) );
 1527+ function formBottom($is_disabled) {
 1528+ global $wgUser;
13801529
1381 - //Fix so extension works with MediaWiki 1.7
1382 - if (substr_compare($wgVersion, '1.7', 0, 3) == 0)
1383 - {
1384 - $edithelpurl = $sk->makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ));
1385 - }
1386 - else
1387 - {
1388 - $edithelpurl = Skin::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ));
1389 - }
1390 -
1391 - $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
1392 - htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
1393 - htmlspecialchars( wfMsg( 'newwindow' ) );
1394 -
1395 - $sfgTabIndex++;
13961530 $disabled_text = ($is_disabled) ? "disabled" : "";
 1531+ $summary_text = $this->summaryInputHTML($is_disabled);
13971532 $text =<<<END
13981533 <br /><br />
1399 - <span id='wpSummaryLabel'><label for='wpSummary'>{$summary_text}:</label></span>
14001534 <div class='editOptions'>
1401 - <input tabindex="$sfgTabIndex" type='text' value="" name='wpSummary' id='wpSummary' maxlength='200' size='60' $disabled_text/><br />
 1535+$summary_text <br />
14021536
14031537 END;
1404 - $minor = wfMsgExt('minoredit', array('parseinline'));
14051538 if ( $wgUser->isAllowed('minoredit') ) {
1406 - $sfgTabIndex++;
1407 - $text .=
1408 - "<input tabindex='$sfgTabIndex' type='checkbox' value='1' name='wpMinoredit'" .
1409 - " accesskey='".wfMsg('accesskey-minoredit')."' id='wpMinoredit' $disabled_text/>\n".
1410 - "<label for='wpMinoredit' title='".wfMsg('tooltip-minoredit')."'>{$minor}</label>\n";
1411 - }
 1539+ $text .= $this->minorEditInputHTML($is_disabled);
 1540+ }
14121541
1413 - $watchthis = wfMsgExt('watchthis', array('parseinline'));
14141542 if ( $wgUser->isLoggedIn() ) {
1415 - $sfgTabIndex++;
1416 - $text .= "<input tabindex='$sfgTabIndex' type='checkbox' name='wpWatchthis'".
1417 - " accesskey=\"".htmlspecialchars(wfMsg('accesskey-watch'))."\" id='wpWatchthis' $disabled_text/>\n".
1418 - "<label for='wpWatchthis' title=\"" .
1419 - htmlspecialchars(wfMsg('tooltip-watch'))."\">{$watchthis}</label>\n";
 1543+ $text .= $this->watchInputHTML($is_disabled);
14201544 }
14211545
1422 - $sfgTabIndex++;
1423 - $temp = array(
1424 - 'id' => 'wpSave',
1425 - 'name' => 'wpSave',
1426 - 'type' => 'submit',
1427 - 'tabindex' => $sfgTabIndex,
1428 - 'value' => wfMsg('savearticle'),
1429 - 'accesskey' => wfMsg('accesskey-save'),
1430 - 'title' => wfMsg('tooltip-save'),
1431 - $disabled_text => '',
1432 - );
1433 - $save_button = wfElement('input', $temp, '');
1434 -
1435 - $sfgTabIndex++;
1436 - $temp = array(
1437 - 'id' => 'wpPreview',
1438 - 'name' => 'wpPreview',
1439 - 'type' => 'submit',
1440 - 'tabindex' => $sfgTabIndex,
1441 - 'value' => wfMsg('showpreview'),
1442 - 'accesskey' => wfMsg('accesskey-preview'),
1443 - 'title' => wfMsg('tooltip-preview'),
1444 - $disabled_text => '',
1445 - );
1446 - $preview_button = wfElement('input', $temp, '');
1447 -
1448 - $sfgTabIndex++;
1449 - $temp = array(
1450 - 'id' => 'wpDiff',
1451 - 'name' => 'wpDiff',
1452 - 'type' => 'submit',
1453 - 'tabindex' => $sfgTabIndex,
1454 - 'value' => wfMsg('showdiff'),
1455 - 'accesskey' => wfMsg('accesskey-diff'),
1456 - 'title' => wfMsg('tooltip-diff'),
1457 - $disabled_text => '',
1458 - );
1459 - $diff_button = wfElement('input', $temp, '');
1460 -
14611546 $text .=<<<END
14621547 <br />
14631548 <div class='editButtons'>
1464 - $save_button
1465 - $preview_button
1466 - $diff_button
1467 - <span class='editHelp'>{$cancel} | {$edithelp}</span>
 1549+
 1550+END;
 1551+ $text .= $this->saveButtonHTML($is_disabled);
 1552+ $text .= $this->showPreviewButtonHTML($is_disabled);
 1553+ $text .= $this->showChangesButtonHTML($is_disabled);
 1554+ $text .= $this->cancelLinkHTML($is_disabled);
 1555+ $text .=<<<END
14681556 </div><!-- editButtons -->
14691557 </div><!-- editOptions -->
14701558 </form>

Status & tagging log