r91826 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91825‎ | r91826 | r91827 >
Date:12:27, 10 July 2011
Author:devayon
Status:deferred
Tags:
Comment:
style clean-up
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php
@@ -12,11 +12,11 @@
1313 */
1414 abstract class SMWQueryUI extends SpecialPage {
1515 protected $m_ui_helper;
16 - private $autocompleteenabled=false;
 16+ private $autocompleteenabled = false;
1717
18 - protected function addAutocompletionJavascriptAndCSS(){
 18+ protected function addAutocompletionJavascriptAndCSS() {
1919 global $wgOut, $smwgScriptPath, $smwgJQueryIncluded, $smwgJQueryUIIncluded;
20 - if($this->autocompleteenabled==false){
 20+ if ( $this->autocompleteenabled == false ) {
2121 $wgOut->addExtensionStyle( "$smwgScriptPath/skins/jquery-ui/base/jquery.ui.all.css" );
2222
2323 $scripts = array();
@@ -88,10 +88,10 @@
8989 END;
9090
9191 $wgOut->addScript( $javascript_autocomplete_text );
92 - $this->autocompleteenabled=true;
 92+ $this->autocompleteenabled = true;
9393 }
9494 }
95 - protected function makeResults($p){
 95+ protected function makeResults( $p ) {
9696 /*
9797 * TODO: extract parameters from $p and decide:
9898 * (1) if form elements need to be displayed
@@ -100,36 +100,36 @@
101101 * Most of the code here in this method will anyway be removed later
102102 */
103103 global $wgOut, $wgRequest;
104 - $htmloutput="";
105 - $htmloutput.= $this->getForm();
106 - $param=array();
 104+ $htmloutput = "";
 105+ $htmloutput .= $this->getForm();
 106+ $param = array();
107107
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
110110
111111 // form parameters default values
112112 $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 );
121121
122122 $helper->execute();
123123
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?
126126 }
127127
128 - $htmloutput.= $helper->getHTMLResult();
 128+ $htmloutput .= $helper->getHTMLResult();
129129
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?
132132 }
133 - $wgOut->addHTML($htmloutput);
 133+ $wgOut->addHTML( $htmloutput );
134134 }
135135
136136 /**
@@ -146,7 +146,7 @@
147147 *
148148 * @return string
149149 */
150 - public function getNavigationBar($limit, $offset, $has_further_results) {
 150+ public function getNavigationBar( $limit, $offset, $has_further_results ) {
151151 global $smwgQMaxInlineLimit;
152152 $urltail = $this->getUrlTail();
153153 // Prepare navigation bar.
@@ -231,24 +231,24 @@
232232 *
233233 * @return string Form elements in HTML
234234 */
235 - protected function getForm(){
 235+ protected function getForm() {
236236 /*
237237 * Although the following methods will retuen form elements, which can
238238 * then be placed in wOut as pleased, they will
239239 * also write javascript (if relevant) directly to wgOut.
240240 */
241241
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>";
247247 return $result;
248248 }
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
253253 return $result;
254254 }
255255
@@ -262,11 +262,11 @@
263263 * @param boolean $enableAutocomplete If set to true, adds the relevant JS and CSS to the page
264264 * @return string The HTML code
265265 */
266 - protected function getPOFormBox($content, $enableAutocomplete=true){
267 - if($enableAutocomplete){
 266+ protected function getPOFormBox( $content, $enableAutocomplete = true ) {
 267+ if ( $enableAutocomplete ) {
268268 global $wgOut;
269269
270 - if(!$this->autocompleteenabled) addAutocompletionJavascriptAndCSS();
 270+ if ( !$this->autocompleteenabled ) addAutocompletionJavascriptAndCSS();
271271 $javascript_autocomplete_text = <<<END
272272 <script type="text/javascript">
273273 jQuery(document).ready(function(){
@@ -305,8 +305,8 @@
306306 $wgOut->addScript( $javascript_autocomplete_text );
307307
308308 }
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 );
311311 return $result;
312312 }
313313
@@ -338,7 +338,7 @@
339339 return $urltail;
340340 }
341341 protected function makeHtmlResult() {
342 - //STUB
 342+ // STUB
343343 }
344344 /**
345345 * Display a form section showing the options for a given format,
@@ -600,7 +600,7 @@
601601
602602
603603 // constructor
604 - public function __construct($context = self::SPECIAL_PAGE ) {
 604+ public function __construct( $context = self::SPECIAL_PAGE ) {
605605 $this->context = $context;
606606 }
607607
@@ -608,8 +608,8 @@
609609 return $this->fatal_errors;
610610 }
611611
612 - public function getLimit(){
613 - if(key_exists('limit', $this->m_params)){
 612+ public function getLimit() {
 613+ if ( key_exists( 'limit', $this->m_params ) ) {
614614 return $this->m_params['limit'];
615615 }
616616 else {
@@ -617,24 +617,24 @@
618618 }
619619 }
620620
621 - public function getOffset(){
622 - if(key_exists('offset', $this->m_params)){
 621+ public function getOffset() {
 622+ if ( key_exists( 'offset', $this->m_params ) ) {
623623 return $this->m_params['offset'];
624624 }
625 - else{
 625+ else {
626626 return 20;
627627 }
628628 }
629 - public function hasFurtherResults(){
630 - if(is_a($this->queryresult,'SMWQueryResult')){
 629+ public function hasFurtherResults() {
 630+ if ( is_a( $this->queryresult, 'SMWQueryResult' ) ) {
631631 return $this->queryresult->hasFurtherResults();
632632 }
633 - else{
 633+ else {
634634 return false;
635635 }
636636 }
637637
638 - public function getResultObject(){
 638+ public function getResultObject() {
639639 return $this->getResultObject();
640640 }
641641
@@ -673,7 +673,7 @@
674674 * @param string $querystring The query
675675 * @return array array of errors, if any.
676676 */
677 - public function setQueryString( $querystring = "", $enable_validation=true ) {
 677+ public function setQueryString( $querystring = "", $enable_validation = true ) {
678678 $this -> m_querystring = $querystring;
679679 $errors = array();
680680 if ( $enable_validation ) {
@@ -702,7 +702,7 @@
703703 * @param array $printouts Array of additional properties to be shown in results
704704 * @return array array of errors, if any.
705705 */
706 - public function setPrintOuts( array $printouts = array(), $enable_validation=true ) {
 706+ public function setPrintOuts( array $printouts = array(), $enable_validation = true ) {
707707 $errors = array();
708708 if ( $enable_validation ) {
709709 foreach ( $printouts as $key => $prop ) {
@@ -720,7 +720,7 @@
721721 return $errors;
722722 }
723723
724 - public function setParams( array $params = array(), $enable_validation=true ) {
 724+ public function setParams( array $params = array(), $enable_validation = true ) {
725725 /*
726726 *Validate, and add missing params. *
727727 */
@@ -776,7 +776,7 @@
777777 $errors = array();
778778 $query = SMWQueryProcessor::createQuery( $this->m_querystring, $this->m_params, SMWQueryProcessor::SPECIAL_PAGE , $this->m_params['format'], $this->m_printouts );
779779 $res = smwfGetStore()->getQueryResult( $query );
780 - $this->queryresult=$res;
 780+ $this->queryresult = $res;
781781 $errors = array_merge( $errors, $res->getErrors() );
782782 if ( !empty( $errors ) ) {
783783 $this->fatal_errors = true;
@@ -812,9 +812,9 @@
813813 // END: Try to be smart for rss/ical if no description/title is given and we have a concept query
814814 }
815815
816 - public function getHTMLResult(){
 816+ public function getHTMLResult() {
817817 $result = '';
818 - $res= $this->queryresult;
 818+ $res = $this->queryresult;
819819 $printer = SMWQueryProcessor::getResultPrinter( $this->m_params['format'], SMWQueryProcessor::SPECIAL_PAGE );
820820 $result_mime = $printer->getMimeType( $res );
821821
@@ -871,8 +871,8 @@
872872 return $this->m_querystring;
873873 }
874874
875 - public function getResultCount(){
876 - if(is_a($this->queryresult, 'SMWQueryResult')){
 875+ public function getResultCount() {
 876+ if ( is_a( $this->queryresult, 'SMWQueryResult' ) ) {
877877 return $this->queryresult->getCount();
878878 }
879879 else return 0;
@@ -903,8 +903,8 @@
904904 * @return SMWQueryUIHelper
905905 */
906906 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 );
909909 $result->extractParameters( $p );
910910 $result->execute();
911911 return $result;
@@ -921,8 +921,8 @@
922922 * @return SMWQueryUIHelper
923923 */
924924 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 );
927927 $result->setPrintOuts( $printouts, $enable_validation );
928928 $result->setQueryString( $query, $enable_validation );
929929 $result->extractParameters( "" );