r93961 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93960‎ | r93961 | r93962 >
Date:12:01, 5 August 2011
Author:devayon
Status:deferred
Tags:
Comment:
changed return type for getFormatSelectBox, cleanup of format options
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php
@@ -895,9 +895,10 @@
896896
897897 foreach ( $params as $param ) {
898898 // Ignore the format parameter, as we got a special control in the GUI for it already.
899 - if ( $param->getName() == 'format' or $param->getName() == 'limit' or $param->getName() == 'offset' ) {
 899+ if ( $param->getName() == 'format' ) {
900900 continue;
901901 }
 902+
902903 $currentValue = array_key_exists( $param->getName(), $paramValues ) ? $paramValues[$param->getName()] : false;
903904
904905 $optionsHtml[] =
@@ -907,15 +908,15 @@
908909 'style' => 'width: 30%; padding: 5px; float: left;'
909910 ),
910911 htmlspecialchars( $param->getName() ) . ': ' .
911 - $this->getFormatOption( $param, $currentValue ) .
 912+ $this->showFormatOption( $param, $currentValue ) .
912913 '<br />' .
913914 Html::element( 'em', array(), $param->getDescription() )
914915 );
915916 }
916917
917 - for ( $i = 0, $n = count( $optionsHtml ); $i < $n; $i += 1 ) {
 918+ for ( $i = 0, $n = count( $optionsHtml ); $i < $n; $i++ ) {
918919 if ( $i % 3 == 2 || $i == $n - 1 ) {
919 - $optionsHtml[$i] .= Html::element( 'div', array( 'style' => 'clear: both;' ) ) . "\n";
 920+ $optionsHtml[$i] .= "<div style=\"clear: both\";></div>\n";
920921 }
921922 }
922923
@@ -925,7 +926,8 @@
926927
927928 while ( $option = array_shift( $optionsHtml ) ) {
928929 $rowHtml .= $option;
929 - $i += 1;
 930+ $i++;
 931+
930932 $resultHtml .= Html::rawElement(
931933 'div',
932934 array(
@@ -933,22 +935,23 @@
934936 ),
935937 $rowHtml
936938 );
 939+
937940 $rowHtml = '';
938941 }
939942
940943 return $resultHtml;
941944 }
942945
 946+
943947 /**
944948 * Get the HTML for a single parameter input.
945 - * A helper method for showFormatOptions()
946949 *
947950 * @param Parameter $parameter
948 - * @param mixed $currentValue curretly set value of the parameter, or false if unknown.
 951+ * @param mixed $currentValue
949952 *
950 - * @return string generated HTML
 953+ * @return string
951954 */
952 - private function getFormatOption( Parameter $parameter, $currentValue ) {
 955+ protected function showFormatOption( Parameter $parameter, $currentValue ) {
953956 $input = new ParameterInput( $parameter );
954957 $input->setInputName( 'p[' . $parameter->getName() . ']' );
955958
@@ -961,16 +964,19 @@
962965
963966 /**
964967 * Creates form elements for choosing the result-format and their
965 - * associated format. Use in conjunction with processFormatOptions() to
 968+ * associated format.
 969+ *
 970+ * The drop-down list and the format options are returned seperately as
 971+ * elements of an array.Use in conjunction with processFormatOptions() to
966972 * supply formats options using ajax. Also, use its complement
967973 * processFormatSelectBox() to decode form data sent by these elements.
968974 * UI's may overload these methods to change behaviour or form
969975 * parameters.
970976 *
971977 * @param string $defaultformat The default format which remains selected in the form
972 - * @return string
 978+ * @return array The first element contains the format selector, while the second contains the Format options
973979 */
974 - protected function getFormatSelectBox( $defaultformat = 'broadtable' ) {
 980+ protected function getFormatSelectBoxSep( $defaultformat = 'broadtable' ) {
975981 global $smwgResultFormats, $wgOut;
976982
977983 $this->enableJQuery();
@@ -990,7 +996,7 @@
991997 }
992998 }
993999
994 - $result = "\n<p>" . wfMsg( 'smw_ask_format_as' ) . "\n" .
 1000+ $result[0] = "\n<p>" . wfMsg( 'smw_ask_format_as' ) . "\n" .
9951001 '<select id="formatSelector" name="p[format]" onChange="JavaScript:updateOtherOptions(\'' . $url . '\')">' . "\n" .
9961002 '<option value="' . $default_format . '">' . $printer->getName() .
9971003 ' (' . wfMsg( 'smw_ask_defaultformat' ) . ')</option>' . "\n";
@@ -1007,14 +1013,14 @@
10081014
10091015 $params = $this->uiCore->getParameters();
10101016 foreach ( $formats as $format => $name ) {
1011 - $result .= '<option value="' . $format . '"' . ( $params['format'] == $format ? ' selected' : '' ) . '>' . $name . "</option>\n";
 1017+ $result[0] .= '<option value="' . $format . '"' . ( $params['format'] == $format ? ' selected' : '' ) . '>' . $name . "</option>\n";
10121018 }
10131019
1014 - $result .= "</select>";
1015 - $result .= "</p>\n";
1016 - $result .= '<fieldset><legend>' . wfMsg( 'smw_ask_otheroptions' ) . "</legend>\n";
1017 - $result .= "<div id=\"other_options\">" . $this->showFormatOptions( $params['format'], $params ) . " </div>";
1018 - $result .= "</fieldset>\n";
 1020+ $result[0] .= "</select>";
 1021+ $result[0] .= "</p>\n";
 1022+ $result[] .= '<fieldset><legend>' . wfMsg( 'smw_ask_otheroptions' ) . "</legend>\n";
 1023+ $result[1] .= "<div id=\"other_options\">" . $this->showFormatOptions( $params['format'], $params ) . " </div>";
 1024+ $result[1] .= "</fieldset>\n";
10191025
10201026 // BEGIN: add javascript for updating formating options by ajax
10211027 $javascript = <<<END