Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.inc |
— | — | @@ -12,6 +12,8 @@ |
13 | 13 | |
14 | 14 | var $mSemanticTypeHooks; |
15 | 15 | var $mInputTypeHooks; |
| 16 | + var $standardInputsIncluded; |
| 17 | + var $mPageTitle; |
16 | 18 | |
17 | 19 | function SFFormPrinter() { |
18 | 20 | global $smwgContLang; |
— | — | @@ -38,6 +40,9 @@ |
39 | 41 | $this->setInputTypeHook('datetime with timezone', array('SFFormPrinter', 'dateTimeEntryHTML'), array('include_timezone' => true)); |
40 | 42 | $this->setInputTypeHook('checkbox', array('SFFormPrinter', 'checkboxHTML'), array()); |
41 | 43 | $this->setInputTypeHook('radiobutton', array('SFFormPrinter', 'radioButtonHTML'), array()); |
| 44 | + |
| 45 | + // initialize other variables |
| 46 | + $this->standardInputsIncluded = false; |
42 | 47 | } |
43 | 48 | |
44 | 49 | function setSemanticTypeHook($type, $function_name, $default_args) { |
— | — | @@ -57,8 +62,8 @@ |
58 | 63 | $sfgTabIndex = 1; |
59 | 64 | $sfgFieldNum = 1; |
60 | 65 | // 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() ) { |
63 | 68 | $form_is_disabled = false; |
64 | 69 | $form_text = ""; |
65 | 70 | } else { |
— | — | @@ -327,7 +332,7 @@ |
328 | 333 | if ($cur_value && ! is_array($cur_value)) { |
329 | 334 | $cur_value = Sanitizer::safeEncodeAttribute($cur_value); |
330 | 335 | } |
331 | | - if (! $cur_value) { |
| 336 | + if ($cur_value == null) { |
332 | 337 | // set to default value specified in the form, if it's there |
333 | 338 | $cur_value = $default_value; |
334 | 339 | } |
— | — | @@ -367,7 +372,7 @@ |
368 | 373 | } |
369 | 374 | $free_text_was_included = true; |
370 | 375 | // add a similar placeholder to the data text |
371 | | - $data_text .= "<free_text>\n\n"; |
| 376 | + $data_text .= "<free_text>\n"; |
372 | 377 | } |
373 | 378 | $section = substr_replace($section, $new_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc); |
374 | 379 | } else { // this field is part of a template |
— | — | @@ -486,10 +491,42 @@ |
487 | 492 | $start_position = $brackets_end_loc; |
488 | 493 | } |
489 | 494 | } |
| 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); |
490 | 527 | } else { // tag is not one of the three allowed values |
491 | 528 | // ignore tag |
492 | 529 | $start_position = $brackets_end_loc; |
493 | | - } |
| 530 | + } // end if |
494 | 531 | } // end while |
495 | 532 | |
496 | 533 | if (! $all_instances_printed && ($template_text != '')) { |
— | — | @@ -498,13 +535,7 @@ |
499 | 536 | if (strpos($template_text, "\n")) { |
500 | 537 | $template_text .= "\n"; |
501 | 538 | } |
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"; |
509 | 540 | $data_text .= $template_text; |
510 | 541 | } |
511 | 542 | if ($allow_multiple) { |
— | — | @@ -635,10 +666,7 @@ |
636 | 667 | </script> |
637 | 668 | END; |
638 | 669 | } |
639 | | - |
640 | | - |
641 | 670 | |
642 | | - |
643 | 671 | $chooser_text .= "<p>$choosername:<select id='chooserselect$chooser_count' size='1' onchange='updatechooserbutton(this,\"chooserbutton$chooser_count\")'>"; |
644 | 672 | $chooser_text .= "<option value='invalid'>Choose a field to add</option>"; |
645 | 673 | foreach ($chooser as $chooser_item) { |
— | — | @@ -655,8 +683,11 @@ |
656 | 684 | } |
657 | 685 | |
658 | 686 | $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 | + |
661 | 692 | // add general Javascript code |
662 | 693 | $blank_error_str = wfMsg('sf_blank_error'); |
663 | 694 | $javascript_text .=<<<END |
— | — | @@ -1017,6 +1048,7 @@ |
1018 | 1049 | } |
1019 | 1050 | |
1020 | 1051 | global $sfgTabIndex, $sfgFieldNum; |
| 1052 | + $className = ($is_mandatory) ? "mandatoryField" : "createboxInput"; |
1021 | 1053 | $input_id = "input_$sfgFieldNum"; |
1022 | 1054 | $info_id = "info_$sfgFieldNum"; |
1023 | 1055 | $disabled_text = ($is_disabled) ? "disabled" : ""; |
— | — | @@ -1032,12 +1064,13 @@ |
1033 | 1065 | } |
1034 | 1066 | |
1035 | 1067 | function dropdownHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) { |
1036 | | - global $sfgTabIndex; |
| 1068 | + global $sfgTabIndex, $sfgFieldNum; |
1037 | 1069 | |
1038 | 1070 | $className = ($is_mandatory) ? "mandatoryField" : "createboxInput"; |
| 1071 | + $input_id = "input_$sfgFieldNum"; |
1039 | 1072 | $disabled_text = ($is_disabled) ? "disabled" : ""; |
1040 | 1073 | $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> |
1042 | 1075 | |
1043 | 1076 | END; |
1044 | 1077 | // add a blank value at the beginning if it's a non-mandatory field |
— | — | @@ -1317,6 +1350,132 @@ |
1318 | 1351 | return $text; |
1319 | 1352 | } |
1320 | 1353 | |
| 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 | + |
1321 | 1480 | function redirectText($page_name, $data_text) { |
1322 | 1481 | global $wgUser, $wgRequest; |
1323 | 1482 | |
— | — | @@ -1364,106 +1523,35 @@ |
1365 | 1524 | } |
1366 | 1525 | |
1367 | 1526 | // 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; |
1380 | 1529 | |
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++; |
1396 | 1530 | $disabled_text = ($is_disabled) ? "disabled" : ""; |
| 1531 | + $summary_text = $this->summaryInputHTML($is_disabled); |
1397 | 1532 | $text =<<<END |
1398 | 1533 | <br /><br /> |
1399 | | - <span id='wpSummaryLabel'><label for='wpSummary'>{$summary_text}:</label></span> |
1400 | 1534 | <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 /> |
1402 | 1536 | |
1403 | 1537 | END; |
1404 | | - $minor = wfMsgExt('minoredit', array('parseinline')); |
1405 | 1538 | 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 | + } |
1412 | 1541 | |
1413 | | - $watchthis = wfMsgExt('watchthis', array('parseinline')); |
1414 | 1542 | 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); |
1420 | 1544 | } |
1421 | 1545 | |
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 | | - |
1461 | 1546 | $text .=<<<END |
1462 | 1547 | <br /> |
1463 | 1548 | <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 |
1468 | 1556 | </div><!-- editButtons --> |
1469 | 1557 | </div><!-- editOptions --> |
1470 | 1558 | </form> |