Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php |
— | — | @@ -12,11 +12,11 @@ |
13 | 13 | */ |
14 | 14 | abstract class SMWQueryUI extends SpecialPage { |
15 | 15 | protected $m_ui_helper; |
16 | | - private $autocompleteenabled=false; |
| 16 | + private $autocompleteenabled = false; |
17 | 17 | |
18 | | - protected function addAutocompletionJavascriptAndCSS(){ |
| 18 | + protected function addAutocompletionJavascriptAndCSS() { |
19 | 19 | global $wgOut, $smwgScriptPath, $smwgJQueryIncluded, $smwgJQueryUIIncluded; |
20 | | - if($this->autocompleteenabled==false){ |
| 20 | + if ( $this->autocompleteenabled == false ) { |
21 | 21 | $wgOut->addExtensionStyle( "$smwgScriptPath/skins/jquery-ui/base/jquery.ui.all.css" ); |
22 | 22 | |
23 | 23 | $scripts = array(); |
— | — | @@ -88,10 +88,10 @@ |
89 | 89 | END; |
90 | 90 | |
91 | 91 | $wgOut->addScript( $javascript_autocomplete_text ); |
92 | | - $this->autocompleteenabled=true; |
| 92 | + $this->autocompleteenabled = true; |
93 | 93 | } |
94 | 94 | } |
95 | | - protected function makeResults($p){ |
| 95 | + protected function makeResults( $p ) { |
96 | 96 | /* |
97 | 97 | * TODO: extract parameters from $p and decide: |
98 | 98 | * (1) if form elements need to be displayed |
— | — | @@ -100,36 +100,36 @@ |
101 | 101 | * Most of the code here in this method will anyway be removed later |
102 | 102 | */ |
103 | 103 | global $wgOut, $wgRequest; |
104 | | - $htmloutput=""; |
105 | | - $htmloutput.= $this->getForm(); |
106 | | - $param=array(); |
| 104 | + $htmloutput = ""; |
| 105 | + $htmloutput .= $this->getForm(); |
| 106 | + $param = array(); |
107 | 107 | |
108 | | - $this->m_ui_helper = $helper = new SMWQueryUIHelper; //or some factory method |
109 | | - //here come some driver lines for testing; this is very temporary |
| 108 | + $this->m_ui_helper = $helper = new SMWQueryUIHelper; // or some factory method |
| 109 | + // here come some driver lines for testing; this is very temporary |
110 | 110 | |
111 | 111 | // form parameters default values |
112 | 112 | $helper->setQueryString( |
113 | | - $wgRequest->getVal('q', '[[Located in:: Germany]]')); |
114 | | - $helper->setParams(array( |
115 | | - 'format' => $wgRequest->getVal('format', 'ol' ), |
116 | | - 'offset' => $wgRequest->getVal('offset', '0' ), |
117 | | - 'limit' => $wgRequest->getVal('limit', '20' ) |
118 | | - )); |
119 | | - $helper->setPrintOuts(array('?Population')); |
120 | | - $helper->extractParameters($p); |
| 113 | + $wgRequest->getVal( 'q', '[[Located in:: Germany]]' ) ); |
| 114 | + $helper->setParams( array( |
| 115 | + 'format' => $wgRequest->getVal( 'format', 'ol' ), |
| 116 | + 'offset' => $wgRequest->getVal( 'offset', '0' ), |
| 117 | + 'limit' => $wgRequest->getVal( 'limit', '20' ) |
| 118 | + ) ); |
| 119 | + $helper->setPrintOuts( array( '?Population' ) ); |
| 120 | + $helper->extractParameters( $p ); |
121 | 121 | |
122 | 122 | $helper->execute(); |
123 | 123 | |
124 | | - if($this->usesNavigationBar()){ |
125 | | - $htmloutput.= $this->getNavigationBar ($helper->getLimit(),$helper->getOffset(),$helper->hasFurtherResults()); //? can we preload offset and limit? |
| 124 | + if ( $this->usesNavigationBar() ) { |
| 125 | + $htmloutput .= $this->getNavigationBar ( $helper->getLimit(), $helper->getOffset(), $helper->hasFurtherResults() ); // ? can we preload offset and limit? |
126 | 126 | } |
127 | 127 | |
128 | | - $htmloutput.= $helper->getHTMLResult(); |
| 128 | + $htmloutput .= $helper->getHTMLResult(); |
129 | 129 | |
130 | | - if($this->usesNavigationBar()){ |
131 | | - $htmloutput.= $this->getNavigationBar ($helper->getLimit(),$helper->getOffset(),$helper->hasFurtherResults()); //? can we preload offset and limit? |
| 130 | + if ( $this->usesNavigationBar() ) { |
| 131 | + $htmloutput .= $this->getNavigationBar ( $helper->getLimit(), $helper->getOffset(), $helper->hasFurtherResults() ); // ? can we preload offset and limit? |
132 | 132 | } |
133 | | - $wgOut->addHTML($htmloutput); |
| 133 | + $wgOut->addHTML( $htmloutput ); |
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
— | — | @@ -146,7 +146,7 @@ |
147 | 147 | * |
148 | 148 | * @return string |
149 | 149 | */ |
150 | | - public function getNavigationBar($limit, $offset, $has_further_results) { |
| 150 | + public function getNavigationBar( $limit, $offset, $has_further_results ) { |
151 | 151 | global $smwgQMaxInlineLimit; |
152 | 152 | $urltail = $this->getUrlTail(); |
153 | 153 | // Prepare navigation bar. |
— | — | @@ -231,24 +231,24 @@ |
232 | 232 | * |
233 | 233 | * @return string Form elements in HTML |
234 | 234 | */ |
235 | | - protected function getForm(){ |
| 235 | + protected function getForm() { |
236 | 236 | /* |
237 | 237 | * Although the following methods will retuen form elements, which can |
238 | 238 | * then be placed in wOut as pleased, they will |
239 | 239 | * also write javascript (if relevant) directly to wgOut. |
240 | 240 | */ |
241 | 241 | |
242 | | - //$result=""; |
243 | | - //$result.= getQueryFormBox($contents, $errors); |
244 | | - //$result.= getPOFormBox($content, $enableAutoComplete); |
245 | | - //$result.= getParamBox($content); //avoid ajax, load form elements in the UI by default |
246 | | - $result="<br>Stub: The Form elements come here<br><br>"; |
| 242 | + // $result=""; |
| 243 | + // $result.= getQueryFormBox($contents, $errors); |
| 244 | + // $result.= getPOFormBox($content, $enableAutoComplete); |
| 245 | + // $result.= getParamBox($content); //avoid ajax, load form elements in the UI by default |
| 246 | + $result = "<br>Stub: The Form elements come here<br><br>"; |
247 | 247 | return $result; |
248 | 248 | } |
249 | | - protected function getQueryFormBox($contents, $errors=""){ |
250 | | - $result=""; |
251 | | - $result= Html::element('textarea', array('name'=>'q', 'id'=>'querybox', 'rows' => '6'), $contents); |
252 | | - //TODO:enable/disable on checking for errors; perhaps show error messages right below the box |
| 249 | + protected function getQueryFormBox( $contents, $errors = "" ) { |
| 250 | + $result = ""; |
| 251 | + $result = Html::element( 'textarea', array( 'name' => 'q', 'id' => 'querybox', 'rows' => '6' ), $contents ); |
| 252 | + // TODO:enable/disable on checking for errors; perhaps show error messages right below the box |
253 | 253 | return $result; |
254 | 254 | } |
255 | 255 | |
— | — | @@ -262,11 +262,11 @@ |
263 | 263 | * @param boolean $enableAutocomplete If set to true, adds the relevant JS and CSS to the page |
264 | 264 | * @return string The HTML code |
265 | 265 | */ |
266 | | - protected function getPOFormBox($content, $enableAutocomplete=true){ |
267 | | - if($enableAutocomplete){ |
| 266 | + protected function getPOFormBox( $content, $enableAutocomplete = true ) { |
| 267 | + if ( $enableAutocomplete ) { |
268 | 268 | global $wgOut; |
269 | 269 | |
270 | | - if(!$this->autocompleteenabled) addAutocompletionJavascriptAndCSS(); |
| 270 | + if ( !$this->autocompleteenabled ) addAutocompletionJavascriptAndCSS(); |
271 | 271 | $javascript_autocomplete_text = <<<END |
272 | 272 | <script type="text/javascript"> |
273 | 273 | jQuery(document).ready(function(){ |
— | — | @@ -305,8 +305,8 @@ |
306 | 306 | $wgOut->addScript( $javascript_autocomplete_text ); |
307 | 307 | |
308 | 308 | } |
309 | | - $result=""; |
310 | | - $result=Html::element('textarea',array('id'=> 'add_property', 'name'=> 'po', 'cols'=>'20', 'rows'=> '6'),$content); |
| 309 | + $result = ""; |
| 310 | + $result = Html::element( 'textarea', array( 'id' => 'add_property', 'name' => 'po', 'cols' => '20', 'rows' => '6' ), $content ); |
311 | 311 | return $result; |
312 | 312 | } |
313 | 313 | |
— | — | @@ -338,7 +338,7 @@ |
339 | 339 | return $urltail; |
340 | 340 | } |
341 | 341 | protected function makeHtmlResult() { |
342 | | - //STUB |
| 342 | + // STUB |
343 | 343 | } |
344 | 344 | /** |
345 | 345 | * Display a form section showing the options for a given format, |
— | — | @@ -600,7 +600,7 @@ |
601 | 601 | |
602 | 602 | |
603 | 603 | // constructor |
604 | | - public function __construct($context = self::SPECIAL_PAGE ) { |
| 604 | + public function __construct( $context = self::SPECIAL_PAGE ) { |
605 | 605 | $this->context = $context; |
606 | 606 | } |
607 | 607 | |
— | — | @@ -608,8 +608,8 @@ |
609 | 609 | return $this->fatal_errors; |
610 | 610 | } |
611 | 611 | |
612 | | - public function getLimit(){ |
613 | | - if(key_exists('limit', $this->m_params)){ |
| 612 | + public function getLimit() { |
| 613 | + if ( key_exists( 'limit', $this->m_params ) ) { |
614 | 614 | return $this->m_params['limit']; |
615 | 615 | } |
616 | 616 | else { |
— | — | @@ -617,24 +617,24 @@ |
618 | 618 | } |
619 | 619 | } |
620 | 620 | |
621 | | - public function getOffset(){ |
622 | | - if(key_exists('offset', $this->m_params)){ |
| 621 | + public function getOffset() { |
| 622 | + if ( key_exists( 'offset', $this->m_params ) ) { |
623 | 623 | return $this->m_params['offset']; |
624 | 624 | } |
625 | | - else{ |
| 625 | + else { |
626 | 626 | return 20; |
627 | 627 | } |
628 | 628 | } |
629 | | - public function hasFurtherResults(){ |
630 | | - if(is_a($this->queryresult,'SMWQueryResult')){ |
| 629 | + public function hasFurtherResults() { |
| 630 | + if ( is_a( $this->queryresult, 'SMWQueryResult' ) ) { |
631 | 631 | return $this->queryresult->hasFurtherResults(); |
632 | 632 | } |
633 | | - else{ |
| 633 | + else { |
634 | 634 | return false; |
635 | 635 | } |
636 | 636 | } |
637 | 637 | |
638 | | - public function getResultObject(){ |
| 638 | + public function getResultObject() { |
639 | 639 | return $this->getResultObject(); |
640 | 640 | } |
641 | 641 | |
— | — | @@ -673,7 +673,7 @@ |
674 | 674 | * @param string $querystring The query |
675 | 675 | * @return array array of errors, if any. |
676 | 676 | */ |
677 | | - public function setQueryString( $querystring = "", $enable_validation=true ) { |
| 677 | + public function setQueryString( $querystring = "", $enable_validation = true ) { |
678 | 678 | $this -> m_querystring = $querystring; |
679 | 679 | $errors = array(); |
680 | 680 | if ( $enable_validation ) { |
— | — | @@ -702,7 +702,7 @@ |
703 | 703 | * @param array $printouts Array of additional properties to be shown in results |
704 | 704 | * @return array array of errors, if any. |
705 | 705 | */ |
706 | | - public function setPrintOuts( array $printouts = array(), $enable_validation=true ) { |
| 706 | + public function setPrintOuts( array $printouts = array(), $enable_validation = true ) { |
707 | 707 | $errors = array(); |
708 | 708 | if ( $enable_validation ) { |
709 | 709 | foreach ( $printouts as $key => $prop ) { |
— | — | @@ -720,7 +720,7 @@ |
721 | 721 | return $errors; |
722 | 722 | } |
723 | 723 | |
724 | | - public function setParams( array $params = array(), $enable_validation=true ) { |
| 724 | + public function setParams( array $params = array(), $enable_validation = true ) { |
725 | 725 | /* |
726 | 726 | *Validate, and add missing params. * |
727 | 727 | */ |
— | — | @@ -776,7 +776,7 @@ |
777 | 777 | $errors = array(); |
778 | 778 | $query = SMWQueryProcessor::createQuery( $this->m_querystring, $this->m_params, SMWQueryProcessor::SPECIAL_PAGE , $this->m_params['format'], $this->m_printouts ); |
779 | 779 | $res = smwfGetStore()->getQueryResult( $query ); |
780 | | - $this->queryresult=$res; |
| 780 | + $this->queryresult = $res; |
781 | 781 | $errors = array_merge( $errors, $res->getErrors() ); |
782 | 782 | if ( !empty( $errors ) ) { |
783 | 783 | $this->fatal_errors = true; |
— | — | @@ -812,9 +812,9 @@ |
813 | 813 | // END: Try to be smart for rss/ical if no description/title is given and we have a concept query |
814 | 814 | } |
815 | 815 | |
816 | | - public function getHTMLResult(){ |
| 816 | + public function getHTMLResult() { |
817 | 817 | $result = ''; |
818 | | - $res= $this->queryresult; |
| 818 | + $res = $this->queryresult; |
819 | 819 | $printer = SMWQueryProcessor::getResultPrinter( $this->m_params['format'], SMWQueryProcessor::SPECIAL_PAGE ); |
820 | 820 | $result_mime = $printer->getMimeType( $res ); |
821 | 821 | |
— | — | @@ -871,8 +871,8 @@ |
872 | 872 | return $this->m_querystring; |
873 | 873 | } |
874 | 874 | |
875 | | - public function getResultCount(){ |
876 | | - if(is_a($this->queryresult, 'SMWQueryResult')){ |
| 875 | + public function getResultCount() { |
| 876 | + if ( is_a( $this->queryresult, 'SMWQueryResult' ) ) { |
877 | 877 | return $this->queryresult->getCount(); |
878 | 878 | } |
879 | 879 | else return 0; |
— | — | @@ -903,8 +903,8 @@ |
904 | 904 | * @return SMWQueryUIHelper |
905 | 905 | */ |
906 | 906 | public static function makeFromInfoLink( $p, $enable_validation = true ) { |
907 | | - //TODO handle validation for infolink parameters |
908 | | - $result = new SMWQueryUIHelper(self::WIKI_LINK ); |
| 907 | + // TODO handle validation for infolink parameters |
| 908 | + $result = new SMWQueryUIHelper( self::WIKI_LINK ); |
909 | 909 | $result->extractParameters( $p ); |
910 | 910 | $result->execute(); |
911 | 911 | return $result; |
— | — | @@ -921,8 +921,8 @@ |
922 | 922 | * @return SMWQueryUIHelper |
923 | 923 | */ |
924 | 924 | public static function makeFromUI( $query, array $params, array $printouts, $enable_validation = true ) { |
925 | | - $result = new SMWQueryUIHelper(self::SPECIAL_PAGE ); |
926 | | - $result->setParams( $params, $enable_validation); |
| 925 | + $result = new SMWQueryUIHelper( self::SPECIAL_PAGE ); |
| 926 | + $result->setParams( $params, $enable_validation ); |
927 | 927 | $result->setPrintOuts( $printouts, $enable_validation ); |
928 | 928 | $result->setQueryString( $query, $enable_validation ); |
929 | 929 | $result->extractParameters( "" ); |