Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php |
— | — | @@ -92,7 +92,7 @@ |
93 | 93 | } |
94 | 94 | } |
95 | 95 | |
96 | | - protected function makeResults( $p ) { |
| 96 | + protected function makeRes( $p ) { |
97 | 97 | /* |
98 | 98 | * TODO: extract parameters from $p and decide: |
99 | 99 | * (1) if form elements need to be displayed |
— | — | @@ -246,6 +246,9 @@ |
247 | 247 | $result = "<br>Stub: The Form elements come here<br><br>"; |
248 | 248 | return $result; |
249 | 249 | } |
| 250 | + protected function makeHtmlResult() { |
| 251 | + // STUB |
| 252 | + } |
250 | 253 | |
251 | 254 | /** |
252 | 255 | * A method which generates the form element(s) for the Query-string. Use its |
— | — | @@ -271,7 +274,8 @@ |
272 | 275 | * @return string |
273 | 276 | */ |
274 | 277 | protected function processQueryFormBox(WebRequest $wgRequest){ |
275 | | - $query = $wgRequest->getVal('q'); |
| 278 | + $query=""; |
| 279 | + if($wgRequest->getCheck('q')) $query = $wgRequest->getVal('q'); |
276 | 280 | return $query; |
277 | 281 | } |
278 | 282 | |
— | — | @@ -350,7 +354,7 @@ |
351 | 355 | foreach ( $ps as $param ) { // add initial ? if omitted (all params considered as printouts) |
352 | 356 | $param = trim( $param ); |
353 | 357 | |
354 | | - if ( ( $param != '' ) && ( $param { 0 } != '?' ) ) { |
| 358 | + if ( ( $param != '' ) && ( $param[0] != '?' ) ) { |
355 | 359 | $param = '?' . $param; |
356 | 360 | } |
357 | 361 | |
— | — | @@ -388,10 +392,6 @@ |
389 | 393 | return $urltail; |
390 | 394 | } |
391 | 395 | |
392 | | - protected function makeHtmlResult() { |
393 | | - // STUB |
394 | | - } |
395 | | - |
396 | 396 | /** |
397 | 397 | * Display a form section showing the options for a given format, |
398 | 398 | * based on the getParameters() value for that format's query printer. |
— | — | @@ -622,7 +622,7 @@ |
623 | 623 | // p is used for any additional parameters in certain links. |
624 | 624 | $params = SMWInfolink::decodeParameters( $query_values, false ); |
625 | 625 | } |
626 | | - return $query_values; |
| 626 | + return $params; |
627 | 627 | } |
628 | 628 | |
629 | 629 | /** |
— | — | @@ -1021,7 +1021,7 @@ |
1022 | 1022 | $result->setPrintOuts( $printouts, $enable_validation ); |
1023 | 1023 | $result->setQueryString( $query, $enable_validation ); |
1024 | 1024 | $result->extractParameters( "" ); |
1025 | | - $result->execute(); |
| 1025 | + //$result->execute(); |
1026 | 1026 | return $result; |
1027 | 1027 | } |
1028 | 1028 | /** |
— | — | @@ -1052,5 +1052,4 @@ |
1053 | 1053 | return 'broadtable'; |
1054 | 1054 | } |
1055 | 1055 | |
1056 | | - |
1057 | 1056 | } |
Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php |
— | — | @@ -17,10 +17,11 @@ |
18 | 18 | * @author Yaron Koren |
19 | 19 | * @author Sanyam Goyal |
20 | 20 | * @author Jeroen De Dauw |
| 21 | + * @author Devayon Das |
21 | 22 | * |
22 | 23 | * |
23 | 24 | */ |
24 | | -class SMWQueryCreatorPage extends SpecialPage { |
| 25 | +class SMWQueryCreatorPage extends SMWQueryUI { |
25 | 26 | |
26 | 27 | //protected $m_querystring = ''; |
27 | 28 | protected $m_params = array(); |
— | — | @@ -44,28 +45,58 @@ |
45 | 46 | global $wgOut, $wgRequest, $smwgQEnabled; |
46 | 47 | |
47 | 48 | $this->setHeaders(); |
| 49 | +// var_dump(SpecialPage::getSafeTitleFor( 'Ask' )->getLocalURL( "showformatoptions" ));die; |
48 | 50 | |
49 | 51 | if ( !$smwgQEnabled ) { |
50 | 52 | $wgOut->addHTML( '<br />' . wfMsg( 'smw_iq_disabled' ) ); |
51 | 53 | } else { |
52 | | - $this->makeHTMLForm(); |
| 54 | + if(!($this->processFormatOptions($wgRequest))){ |
| 55 | + $params=array_merge( |
| 56 | + array( |
| 57 | + 'format' => $wgRequest->getVal( 'format', 'ol' ), |
| 58 | + 'offset' => $wgRequest->getVal( 'offset', '0' ), |
| 59 | + 'limit' => $wgRequest->getVal( 'limit', '20' ) |
| 60 | + ),$this->processFormatSelectBox($wgRequest)); |
| 61 | + $this->m_ui_helper = SMWQueryUIHelper::makeFromUI( |
| 62 | + $this->processQueryFormBox($wgRequest), |
| 63 | + $params, |
| 64 | + $this->processPOFormBox($wgRequest), |
| 65 | + false); |
| 66 | + if($this->m_ui_helper->getQueryString()!=""){ |
| 67 | + $this->m_ui_helper->execute($p); |
| 68 | + |
| 69 | + } |
| 70 | + $htmloutput=$this->makeResults($p); |
| 71 | + if($this->m_ui_helper->getQueryString()!=""){ |
| 72 | + if ( $this->usesNavigationBar() ) { |
| 73 | + $htmloutput .= $this->getNavigationBar ( $this->m_ui_helper->getLimit(), $this->m_ui_helper->getOffset(), $this->m_ui_helper->hasFurtherResults() ); // ? can we preload offset and limit? |
| 74 | + } |
| 75 | + |
| 76 | + $htmloutput .= "<br/>".$this->m_ui_helper->getHTMLResult()."<br>"; |
| 77 | + |
| 78 | + if ( $this->usesNavigationBar() ) { |
| 79 | + $htmloutput .= $this->getNavigationBar ( $this->m_ui_helper->getLimit(), $this->m_ui_helper->getOffset(), $this->m_ui_helper->hasFurtherResults() ); // ? can we preload offset and limit? |
| 80 | + } |
| 81 | + } |
| 82 | + $wgOut->addHTML( $htmloutput ); |
| 83 | + } |
53 | 84 | } |
54 | 85 | SMWOutputs::commitToOutputPage( $wgOut ); // make sure locally collected output data is pushed to the output! |
55 | 86 | } |
56 | 87 | /** |
57 | | - * Adds the input query form |
| 88 | + * Adds the input query form. Overloaded from SMWQueryUI |
58 | 89 | */ |
59 | | - protected function makeHTMLForm(){ |
| 90 | + protected function makeResults($p){ |
60 | 91 | global $wgOut, $smwgQSortingSupport, $smwgResultFormats, $smwgAutocompleteInSpecialAsk; |
61 | 92 | $result= ""; |
62 | | - $spectitle = $this->getTitleFor( 'Ask' ); |
| 93 | + $spectitle = $this->getTitle(); |
63 | 94 | $result .= '<form name="ask" action="' . $spectitle->escapeLocalURL() . '" method="get">' . "\n" . |
64 | 95 | '<input type="hidden" name="title" value="' . $spectitle->getPrefixedText() . '"/>'; |
65 | 96 | |
66 | 97 | $result .= wfMsg('smw_qc_query_help'); |
67 | 98 | // Main query and printouts. |
68 | 99 | $result .= '<p><strong>' . wfMsg( 'smw_ask_queryhead' ) . "</strong></p>\n"; |
69 | | - $result .= '<p><textarea name="q" rows="6"></textarea></p>'; |
| 100 | + $result .= '<p>'.$this->getQueryFormBox($this->m_ui_helper->getQueryString()).'</p>'; |
70 | 101 | //show|hide additional options and querying help |
71 | 102 | $result .= '<span id="show_additional_options" style="display:inline"><a href="#addtional" rel="nofollow" onclick="' . |
72 | 103 | "document.getElementById('additional_options').style.display='block';" . |
— | — | @@ -88,58 +119,13 @@ |
89 | 120 | if ( $smwgQSortingSupport ) { |
90 | 121 | $result .= $this->addSortingOptions($result); |
91 | 122 | } |
92 | | - |
93 | | - $printer = SMWQueryProcessor::getResultPrinter( 'broadtable', SMWQueryProcessor::SPECIAL_PAGE ); |
94 | | - $url = SpecialPage::getSafeTitleFor( 'Ask' )->getLocalURL( "showformatoptions=' + this.value + '" ); |
95 | | - //@TODO //$url .= '&showformatoptions=broadtable¶ms[title]=Special:Ask¶ms[offset]=0¶ms[limit]=20'; |
96 | | - $url .= '¶ms[title]=Special:Ask¶ms[offset]=0¶ms[limit]=20'; |
97 | | - |
98 | | - $result .= "<br /><br />\n<p>" . wfMsg( 'smw_ask_format_as' ) . ' <input type="hidden" name="eq" value="yes"/>' . "\n" . |
99 | | - '<select id="formatSelector" name="p[format]" onChange="JavaScript:updateOtherOptions(\'' . $url . '\')">' . "\n" . |
100 | | - ' <option value="broadtable">' . |
101 | | - $printer->getName() . ' (' . wfMsg( 'smw_ask_defaultformat' ) . ')</option>' . "\n"; |
102 | | - |
103 | | - $formats = array(); |
104 | | - |
105 | | - foreach ( array_keys( $smwgResultFormats ) as $format ) { |
106 | | - // Special formats "count" and "debug" currently not supported. |
107 | | - if ( $format != 'broadtable' && $format != 'count' && $format != 'debug' ) { |
108 | | - $printer = SMWQueryProcessor::getResultPrinter( $format, SMWQueryProcessor::SPECIAL_PAGE ); |
109 | | - $formats[$format] = $printer->getName(); |
110 | | - } |
111 | | - } |
112 | | - |
113 | | - natcasesort( $formats ); |
114 | | - |
115 | | - foreach ( $formats as $format => $name ) { |
116 | | - $result .= ' <option value="' . $format . '>' . $name . "</option>\n"; |
117 | | - } |
118 | | - //add javascript for updating formating options by ajax |
119 | | - $default_format_url = SpecialPage::getSafeTitleFor( 'Ask' )->getLocalURL( "showformatoptions=broadtable" ); |
120 | | - $default_format_url .= '¶ms[title]=Special:Ask¶ms[offset]=0¶ms[limit]=20'; |
121 | | - $javascript = <<<END |
122 | | -<script type="text/javascript"> |
123 | | -function updateOtherOptions(strURL) { |
124 | | - jQuery.ajax({ url: strURL, context: document.body, success: function(data){ |
125 | | - jQuery("#other_options").html(data); |
126 | | - }}); |
127 | | -} |
128 | | -jQuery(document).ready(updateOtherOptions("{$default_format_url}")); |
129 | | -</script> |
130 | | -END; |
131 | | - |
132 | | - $wgOut->addScript( $javascript ); |
133 | | - |
134 | | - $result .= "</select></p>\n"; |
135 | | - $result .= '<fieldset><legend>' . wfMsg( 'smw_ask_otheroptions' ) . "</legend>\n"; |
136 | | - $result .= "<div id=\"other_options\"></div>"; |
137 | | - $result .= "</fieldset>\n"; |
| 123 | + $result .= "<br><br>" . $this->getFormatSelectBox('broadtable'); |
138 | 124 | $result .= '</div>'; |
139 | 125 | $result .= '<br /><input type="submit" value="' . wfMsg( 'smw_ask_submit' ) . '"/>' . |
140 | 126 | '<input type="hidden" name="eq" value="no"/>' . |
141 | 127 | "\n</form>"; |
142 | 128 | |
143 | | - $wgOut->addHTML($result); |
| 129 | + return $result; |
144 | 130 | |
145 | 131 | } |
146 | 132 | |
— | — | @@ -257,48 +243,6 @@ |
258 | 244 | } |
259 | 245 | |
260 | 246 | |
261 | | - /** |
262 | | - * Returns a Validator style Parameter definition. |
263 | | - * SMW 1.5.x style definitions are converted. |
264 | | - * |
265 | | - * @since 1.6 |
266 | | - * |
267 | | - * @param mixed $param |
268 | | - * |
269 | | - * @return Parameter |
270 | | - */ |
271 | | - protected function toValidatorParam( $param ) { |
272 | | - static $typeMap = array( |
273 | | - 'int' => Parameter::TYPE_INTEGER |
274 | | - ); |
275 | | - |
276 | | - if ( !( $param instanceof Parameter ) ) { |
277 | | - if ( !array_key_exists( 'type', $param ) ) { |
278 | | - $param['type'] = 'string'; |
279 | | - } |
280 | | - |
281 | | - $paramClass = $param['type'] == 'enum-list' ? 'ListParameter' : 'Parameter'; |
282 | | - $paramType = array_key_exists( $param['type'], $typeMap ) ? $typeMap[$param['type']] : Parameter::TYPE_STRING; |
283 | | - |
284 | | - $parameter = new $paramClass( $param['name'], $paramType ); |
285 | | - |
286 | | - if ( array_key_exists( 'description', $param ) ) { |
287 | | - $parameter->setDescription( $param['description'] ); |
288 | | - } |
289 | | - |
290 | | - if ( array_key_exists( 'values', $param ) && is_array( $param['values'] ) ) { |
291 | | - $parameter->addCriteria( new CriterionInArray( $param['values'] ) ); |
292 | | - } |
293 | | - |
294 | | - return $parameter; |
295 | | - } |
296 | | - else { |
297 | | - return $param; |
298 | | - } |
299 | | - } |
300 | | - |
301 | | - |
302 | | - |
303 | 247 | /** |
304 | 248 | * Compatibility method to get the skin; MW 1.18 introduces a getSkin method in SpecialPage. |
305 | 249 | * |