r91837 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91836‎ | r91837 | r91838 >
Date:17:33, 10 July 2011
Author:devayon
Status:deferred
Tags:
Comment:
moving towards a test setup, follow up to r91836, r91836
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php
@@ -92,7 +92,7 @@
9393 }
9494 }
9595
96 - protected function makeResults( $p ) {
 96+ protected function makeRes( $p ) {
9797 /*
9898 * TODO: extract parameters from $p and decide:
9999 * (1) if form elements need to be displayed
@@ -246,6 +246,9 @@
247247 $result = "<br>Stub: The Form elements come here<br><br>";
248248 return $result;
249249 }
 250+ protected function makeHtmlResult() {
 251+ // STUB
 252+ }
250253
251254 /**
252255 * A method which generates the form element(s) for the Query-string. Use its
@@ -271,7 +274,8 @@
272275 * @return string
273276 */
274277 protected function processQueryFormBox(WebRequest $wgRequest){
275 - $query = $wgRequest->getVal('q');
 278+ $query="";
 279+ if($wgRequest->getCheck('q')) $query = $wgRequest->getVal('q');
276280 return $query;
277281 }
278282
@@ -350,7 +354,7 @@
351355 foreach ( $ps as $param ) { // add initial ? if omitted (all params considered as printouts)
352356 $param = trim( $param );
353357
354 - if ( ( $param != '' ) && ( $param { 0 } != '?' ) ) {
 358+ if ( ( $param != '' ) && ( $param[0] != '?' ) ) {
355359 $param = '?' . $param;
356360 }
357361
@@ -388,10 +392,6 @@
389393 return $urltail;
390394 }
391395
392 - protected function makeHtmlResult() {
393 - // STUB
394 - }
395 -
396396 /**
397397 * Display a form section showing the options for a given format,
398398 * based on the getParameters() value for that format's query printer.
@@ -622,7 +622,7 @@
623623 // p is used for any additional parameters in certain links.
624624 $params = SMWInfolink::decodeParameters( $query_values, false );
625625 }
626 - return $query_values;
 626+ return $params;
627627 }
628628
629629 /**
@@ -1021,7 +1021,7 @@
10221022 $result->setPrintOuts( $printouts, $enable_validation );
10231023 $result->setQueryString( $query, $enable_validation );
10241024 $result->extractParameters( "" );
1025 - $result->execute();
 1025+ //$result->execute();
10261026 return $result;
10271027 }
10281028 /**
@@ -1052,5 +1052,4 @@
10531053 return 'broadtable';
10541054 }
10551055
1056 -
10571056 }
Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php
@@ -17,10 +17,11 @@
1818 * @author Yaron Koren
1919 * @author Sanyam Goyal
2020 * @author Jeroen De Dauw
 21+ * @author Devayon Das
2122 *
2223 *
2324 */
24 -class SMWQueryCreatorPage extends SpecialPage {
 25+class SMWQueryCreatorPage extends SMWQueryUI {
2526
2627 //protected $m_querystring = '';
2728 protected $m_params = array();
@@ -44,28 +45,58 @@
4546 global $wgOut, $wgRequest, $smwgQEnabled;
4647
4748 $this->setHeaders();
 49+// var_dump(SpecialPage::getSafeTitleFor( 'Ask' )->getLocalURL( "showformatoptions" ));die;
4850
4951 if ( !$smwgQEnabled ) {
5052 $wgOut->addHTML( '<br />' . wfMsg( 'smw_iq_disabled' ) );
5153 } 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+ }
5384 }
5485 SMWOutputs::commitToOutputPage( $wgOut ); // make sure locally collected output data is pushed to the output!
5586 }
5687 /**
57 - * Adds the input query form
 88+ * Adds the input query form. Overloaded from SMWQueryUI
5889 */
59 - protected function makeHTMLForm(){
 90+ protected function makeResults($p){
6091 global $wgOut, $smwgQSortingSupport, $smwgResultFormats, $smwgAutocompleteInSpecialAsk;
6192 $result= "";
62 - $spectitle = $this->getTitleFor( 'Ask' );
 93+ $spectitle = $this->getTitle();
6394 $result .= '<form name="ask" action="' . $spectitle->escapeLocalURL() . '" method="get">' . "\n" .
6495 '<input type="hidden" name="title" value="' . $spectitle->getPrefixedText() . '"/>';
6596
6697 $result .= wfMsg('smw_qc_query_help');
6798 // Main query and printouts.
6899 $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>';
70101 //show|hide additional options and querying help
71102 $result .= '<span id="show_additional_options" style="display:inline"><a href="#addtional" rel="nofollow" onclick="' .
72103 "document.getElementById('additional_options').style.display='block';" .
@@ -88,58 +119,13 @@
89120 if ( $smwgQSortingSupport ) {
90121 $result .= $this->addSortingOptions($result);
91122 }
92 -
93 - $printer = SMWQueryProcessor::getResultPrinter( 'broadtable', SMWQueryProcessor::SPECIAL_PAGE );
94 - $url = SpecialPage::getSafeTitleFor( 'Ask' )->getLocalURL( "showformatoptions=' + this.value + '" );
95 - //@TODO //$url .= '&showformatoptions=broadtable&params[title]=Special:Ask&params[offset]=0&params[limit]=20';
96 - $url .= '&params[title]=Special:Ask&params[offset]=0&params[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 .= '&params[title]=Special:Ask&params[offset]=0&params[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');
138124 $result .= '</div>';
139125 $result .= '<br /><input type="submit" value="' . wfMsg( 'smw_ask_submit' ) . '"/>' .
140126 '<input type="hidden" name="eq" value="no"/>' .
141127 "\n</form>";
142128
143 - $wgOut->addHTML($result);
 129+ return $result;
144130
145131 }
146132
@@ -257,48 +243,6 @@
258244 }
259245
260246
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 -
303247 /**
304248 * Compatibility method to get the skin; MW 1.18 introduces a getSkin method in SpecialPage.
305249 *

Follow-up revisions

RevisionCommit summaryAuthorDate
r92049Added support for info-link, follow up to r91837devayon06:24, 13 July 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r91836added documentation, follow up to r91793devayon16:00, 10 July 2011