r73989 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73988‎ | r73989 | r73990 >
Date:22:07, 29 September 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Follow up to r73986
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialAsk.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialAsk.php
@@ -30,6 +30,11 @@
3131 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
3232 }
3333
 34+ /**
 35+ * Main entrypoint for the special page.
 36+ *
 37+ * @param string $p
 38+ */
3439 public function execute( $p ) {
3540 global $wgOut, $wgRequest, $smwgQEnabled, $smwgRSSEnabled, $smwgMW_1_14;
3641
@@ -48,7 +53,7 @@
4954 $format = $wgRequest->getVal( 'showformatoptions' );
5055 $params = $wgRequest->getArray( 'params' );
5156 $wgOut->disable();
52 - print self::showFormatOptions( $format, $params );
 57+ echo self::showFormatOptions( $format, $params );
5358 } else {
5459 $this->extractQueryParameters( $p );
5560 $this->makeHTMLResult();
@@ -59,10 +64,14 @@
6065 wfProfileOut( 'doSpecialAsk (SMW)' );
6166 }
6267
 68+ /**
 69+ * This code rather hacky since there are many ways to call that special page, the most involved of
 70+ * which is the way that this page calls itself when data is submitted via the form (since the shape
 71+ * of the parameters then is governed by the UI structure, as opposed to being governed by reason).
 72+ *
 73+ * @param string $p
 74+ */
6375 protected function extractQueryParameters( $p ) {
64 - // This code rather hacky since there are many ways to call that special page, the most involved of
65 - // which is the way that this page calls itself when data is submitted via the form (since the shape
66 - // of the parameters then is governed by the UI structure, as opposed to being governed by reason).
6776 global $wgRequest, $smwgQMaxInlineLimit;
6877
6978 // First make all inputs into a simple parameter list that can again be parsed into components later.
@@ -75,9 +84,11 @@
7685 $rawparams = SMWInfolink::decodeParameters( $query_val, false ); // p is used for any additional parameters in certain links
7786 else {
7887 $query_values = $wgRequest->getArray( 'p' );
 88+
7989 foreach ( $query_values as $key => $val ) {
8090 if ( empty( $val ) ) unset( $query_values[$key] );
8191 }
 92+
8293 $rawparams = SMWInfolink::decodeParameters( $query_values, false ); // p is used for any additional parameters in certain links
8394 }
8495 } else { // called from wiki, get all parameters
@@ -98,15 +109,18 @@
99110
100111 foreach ( $ps as $param ) { // add initial ? if omitted (all params considered as printouts)
101112 $param = trim( $param );
 113+
102114 if ( ( $param != '' ) && ( $param { 0 } != '?' ) ) {
103115 $param = '?' . $param;
104116 }
 117+
105118 $rawparams[] = $param;
106119 }
107120 }
108121
109122 // Now parse parameters and rebuilt the param strings for URLs
110123 SMWQueryProcessor::processFunctionParams( $rawparams, $this->m_querystring, $this->m_params, $this->m_printouts );
 124+
111125 // Try to complete undefined parameter values from dedicated URL params
112126 if ( !array_key_exists( 'format', $this->m_params ) ) {
113127 if ( array_key_exists( 'rss', $this->m_params ) ) { // backwards compatibility (SMW<=1.1 used this)
@@ -118,8 +132,10 @@
119133
120134 if ( !array_key_exists( 'order', $this->m_params ) ) {
121135 $order_values = $wgRequest->getArray( 'order' );
 136+
122137 if ( is_array( $order_values ) ) {
123138 $this->m_params['order'] = '';
 139+
124140 foreach ( $order_values as $order_value ) {
125141 if ( $order_value == '' ) $order_value = 'ASC';
126142 $this->m_params['order'] .= ( $this->m_params['order'] != '' ? ',' : '' ) . $order_value;
@@ -167,7 +183,12 @@
168184 $this->m_editquery = ( $wgRequest->getVal( 'eq' ) == 'yes' ) || ( $this->m_querystring == '' );
169185 }
170186
171 - static protected function addAutocompletionJavascriptAndCSS() {
 187+ /**
 188+ * Creates and adds the JavaScript and JS needed for autocompletion to $wgOut.
 189+ *
 190+ * @since 1.5.2
 191+ */
 192+ protected static function addAutocompletionJavascriptAndCSS() {
172193 global $wgOut, $smwgScriptPath, $smwgJQueryIncluded, $smwgJQueryUIIncluded;
173194
174195 // Add CSS and JavaScript for jQuery and jQuery UI.
@@ -181,6 +202,7 @@
182203 } else {
183204 $scripts[] = "$smwgScriptPath/libs/jquery-1.4.2.min.js";
184205 }
 206+
185207 $smwgJQueryIncluded = true;
186208 }
187209
@@ -295,6 +317,9 @@
296318 $wgOut->addScript( $javascript_autocomplete_text );
297319 }
298320
 321+ /**
 322+ * TODO: document
 323+ */
299324 protected function makeHTMLResult() {
300325 global $wgOut, $smwgAutocompleteInSpecialAsk;
301326
@@ -419,12 +444,13 @@
420445 global $wgRequest;
421446
422447 $hidequery = $wgRequest->getVal( 'eq' ) == 'no';
 448+
423449 // if it's an export format (like CSV, JSON, etc.),
424450 // don't actually export the data if 'eq' is set to
425451 // either 'yes' or 'no' in the query string - just
426452 // show the link instead
427 - if ( $this->m_editquery || $hidequery )
428 - $result_mime = false;
 453+ if ( $this->m_editquery || $hidequery ) $result_mime = false;
 454+
429455 if ( $result_mime == false ) {
430456 if ( $res->getCount() > 0 ) {
431457 if ( $this->m_editquery ) $urltail .= '&eq=yes';
@@ -468,11 +494,18 @@
469495 header( "content-disposition: attachment; filename=$result_name" );
470496 }
471497
472 - print $result;
 498+ echo $result;
473499 }
474500 }
475501
476 -
 502+ /**
 503+ * TODO: document
 504+ *
 505+ * @param string $printoutstring
 506+ * @param string $urltail
 507+ *
 508+ * @return string
 509+ */
477510 protected function getInputForm( $printoutstring, $urltail ) {
478511 global $wgUser, $smwgQSortingSupport, $wgLang, $smwgResultFormats;
479512
@@ -590,6 +623,11 @@
591624 return $result;
592625 }
593626
 627+ /**
 628+ * TODO: document
 629+ *
 630+ * @return string
 631+ */
594632 protected static function getEmbedToggle() {
595633 return '<span id="embed_show"><a href="#" rel="nofollow" onclick="' .
596634 "document.getElementById('inlinequeryembed').style.display='block';" .
@@ -606,8 +644,13 @@
607645
608646 /**
609647 * Build the navigation for some given query result, reuse url-tail parameters.
 648+ *
 649+ * @param SMWQueryResult $res
 650+ * @param string $urltail
 651+ *
 652+ * @return string
610653 */
611 - protected function getNavigationBar( $res, $urltail ) {
 654+ protected function getNavigationBar( SMWQueryResult $res, $urltail ) {
612655 global $wgUser, $smwgQMaxInlineLimit;
613656
614657 $skin = $wgUser->getSkin();
@@ -655,22 +698,27 @@
656699
657700 /**
658701 * Display a form section showing the options for a given format,
659 - * based on the getParameters() value for that format's query printer
 702+ * based on the getParameters() value for that format's query printer.
 703+ *
 704+ * @param string $format
 705+ * @param array $paramValues
 706+ *
 707+ * @return string
660708 */
661 - function showFormatOptions( $format, $param_values ) {
 709+ protected function showFormatOptions( $format, array $paramValues ) {
662710 $text = '';
663711
664712 $printer = SMWQueryProcessor::getResultPrinter( $format, SMWQueryProcessor::SPECIAL_PAGE );
665713
666 -
667714 $params = method_exists( $printer, 'getParameters' ) ? $printer->getParameters() : array();
668715
669716 foreach ( $params as $i => $param ) {
670717 $param_name = $param['name'];
671718 $type = $param['type'];
672719 $desc = $param['description'];
673 - $cur_value = ( array_key_exists( $param_name, $param_values ) ) ? $param_values[$param_name] : '';
674720
 721+ $cur_value = ( array_key_exists( $param_name, $paramValues ) ) ? $paramValues[$param_name] : '';
 722+
675723 // 3 values per row, with alternating colors for rows
676724 if ( $i % 3 == 0 ) {
677725 $bgcolor = ( $i % 6 ) == 0 ? '#dddddd' : 'white';
@@ -690,6 +738,7 @@
691739 $values = $param['values'];
692740 $text .= "<select name=\"p[$param_name]\">\n";
693741 $text .= " <option value=''></option>\n";
 742+
694743 foreach ( $values as $val ) {
695744 if ( $cur_value == $val )
696745 $selected_str = 'selected';
@@ -697,18 +746,19 @@
698747 $selected_str = '';
699748 $text .= " <option value='$val' $selected_str>$val</option>\n";
700749 }
701 - $text .= "</select>";
 750+
 751+ $text .= '</select>';
702752 break;
703753 case 'enum-list':
704754 $all_values = $param['values'];
705755 $cur_values = explode( ',', $cur_value );
706756 foreach ( $all_values as $val ) {
707 - $checked_str = ( in_array( $val, $cur_values ) ) ? "checked" : "";
 757+ $checked_str = ( in_array( $val, $cur_values ) ) ? 'checked' : '';
708758 $text .= "<span style=\"white-space: nowrap; padding-right: 5px;\"><input type=\"checkbox\" name=\"p[$param_name][$val]\" value=\"true\" $checked_str /> <tt>$val</tt></span>\n";
709759 }
710760 break;
711761 case 'boolean':
712 - $checked_str = ( array_key_exists( $param_name, $param_values ) ) ? 'checked' : '';
 762+ $checked_str = ( array_key_exists( $param_name, $paramValues ) ) ? 'checked' : '';
713763 $text .= "<input type=\"checkbox\" name=\"p[$param_name]\" value=\"true\" $checked_str />";
714764 break;
715765 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r73986Changes for 1.5.3 - fixing a whole bunch of style failsjeroendedauw21:39, 29 September 2010

Status & tagging log