r66227 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66226‎ | r66227 | r66228 >
Date:21:55, 11 May 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Improved code style
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_ParserExtensions.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ParserExtensions.php
@@ -210,6 +210,7 @@
211211 }
212212
213213 SMWOutputs::commitToParser( $parser );
 214+
214215 return $result;
215216 }
216217
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
@@ -41,6 +41,7 @@
4242 } else {
4343 $queryfeatures = $smwgQFeatures;
4444 }
 45+
4546 $qp = new SMWQueryParser( $queryfeatures );
4647 $qp->setDefaultNamespaces( $smwgQDefaultNamespaces );
4748 $desc = $qp->getQueryDescription( $querystring );
@@ -48,6 +49,7 @@
4950 if ( $format == '' ) {
5051 $format = SMWQueryProcessor::getResultFormat( $params );
5152 }
 53+
5254 if ( $format == 'count' ) {
5355 $querymode = SMWQuery::MODE_COUNT;
5456 } elseif ( $format == 'debug' ) {
@@ -62,6 +64,7 @@
6365 } else {
6466 $mainlabel = $qp->getLabel();
6567 }
 68+
6669 if ( ( $querymode == SMWQuery::MODE_NONE ) ||
6770 ( ( !$desc->isSingleton() ||
6871 ( count( $desc->getPrintRequests() ) + count( $extraprintouts ) == 0 )
@@ -81,8 +84,10 @@
8285 if ( ( array_key_exists( 'offset', $params ) ) && ( is_int( $params['offset'] + 0 ) ) ) {
8386 $query->setOffset( max( 0, trim( $params['offset'] ) + 0 ) );
8487 }
 88+
8589 if ( $query->querymode == SMWQuery::MODE_COUNT ) { // largest possible limit for "count", even inline
8690 global $smwgQMaxLimit;
 91+
8792 $query->setOffset( 0 );
8893 $query->setLimit( $smwgQMaxLimit, false );
8994 } else {
@@ -96,9 +101,11 @@
97102 $query->setLimit( $smwgQDefaultLimit );
98103 }
99104 }
 105+
100106 // determine sortkeys and ascendings:
101107 if ( array_key_exists( 'order', $params ) ) {
102108 $orders = explode( ',', $params['order'] );
 109+
103110 foreach ( $orders as $key => $order ) { // normalise
104111 $order = strtolower( trim( $order ) );
105112 if ( ( $order == 'descending' ) || ( $order == 'reverse' ) || ( $order == 'desc' ) ) {
@@ -112,24 +119,30 @@
113120 } else {
114121 $orders = array();
115122 }
 123+
116124 reset( $orders );
117125
118126 if ( array_key_exists( 'sort', $params ) ) {
119127 $query->sort = true;
120128 $query->sortkeys = array();
 129+
121130 foreach ( explode( ',', trim( $params['sort'] ) ) as $sort ) {
122131 $sort = smwfNormalTitleDBKey( trim( $sort ) ); // slight normalisation
123132 $order = current( $orders );
 133+
124134 if ( $order === false ) { // default
125135 $order = 'ASC';
126136 }
 137+
127138 if ( array_key_exists( $sort, $query->sortkeys ) ) {
128139 // maybe throw an error here?
129140 } else {
130141 $query->sortkeys[$sort] = $order;
131142 }
 143+
132144 next( $orders );
133145 }
 146+
134147 if ( current( $orders ) !== false ) { // sort key remaining, apply to page name
135148 $query->sortkeys[''] = current( $orders );
136149 }
@@ -151,26 +164,31 @@
152165 * objects, which are filled into call-by-ref parameters.
153166 * $showmode is true if the input should be treated as if given by #show
154167 */
155 - static public function processFunctionParams( $rawparams, &$querystring, &$params, &$printouts, $showmode = false ) {
 168+ static public function processFunctionParams( array $rawparams, &$querystring, &$params, &$printouts, $showmode = false ) {
156169 global $wgContLang;
 170+
157171 $querystring = '';
158172 $printouts = array();
159173 $lastprintout = null;
160174 $params = array();
 175+
161176 foreach ( $rawparams as $name => $param ) {
162177 // special handling for arrays - this can happen if the
163178 // param came from a checkboxes input in Special:Ask
164179 if ( is_array( $param ) ) {
165180 $param = implode( ',', array_keys( $param ) );
166181 }
 182+
167183 if ( is_string( $name ) && ( $name != '' ) ) { // accept 'name' => 'value' just as '' => 'name=value'
168184 $param = $name . '=' . $param;
169185 }
 186+
170187 if ( $param == '' ) {
171188 } elseif ( $param { 0 } == '?' ) { // print statement
172189 $param = substr( $param, 1 );
173190 $parts = explode( '=', $param, 2 );
174191 $propparts = explode( '#', $parts[0], 2 );
 192+
175193 if ( trim( $propparts[0] ) == '' ) { // print "this"
176194 $printmode = SMWPrintRequest::PRINT_THIS;
177195 $label = ''; // default
@@ -186,6 +204,7 @@
187205 if ( $title === null ) { // too bad, this is no legal property/category name, ignore
188206 continue;
189207 }
 208+
190209 if ( $title->getNamespace() == SMW_NS_PROPERTY ) {
191210 $printmode = SMWPrintRequest::PRINT_PROP;
192211 $property = SMWPropertyValue::makeUserProperty( trim( $propparts[0] ) );
@@ -197,14 +216,17 @@
198217 $label = $showmode ? '':$title->getText(); // default
199218 } // else?
200219 }
 220+
201221 if ( count( $propparts ) == 1 ) { // no outputformat found, leave empty
202222 $propparts[] = false;
203223 } elseif ( trim( $propparts[1] ) == '' ) { // "plain printout", avoid empty string to avoid confusions with "false"
204224 $propparts[1] = '-';
205225 }
 226+
206227 if ( count( $parts ) > 1 ) { // label found, use this instead of default
207228 $label = trim( $parts[1] );
208229 }
 230+
209231 $lastprintout = new SMWPrintRequest( $printmode, $label, $data, trim( $propparts[1] ) );
210232 $printouts[] = $lastprintout;
211233 } elseif ( $param[0] == '+' ) { // print request parameter
@@ -215,6 +237,7 @@
216238 }
217239 } else { // parameter or query
218240 $parts = explode( '=', $param, 2 );
 241+
219242 if ( count( $parts ) >= 2 ) {
220243 $params[strtolower( trim( $parts[0] ) )] = $parts[1]; // don't trim here, some params care for " "
221244 } else {
@@ -222,6 +245,7 @@
223246 }
224247 }
225248 }
 249+
226250 $querystring = str_replace( array( '&lt;', '&gt;' ), array( '<', '>' ), $querystring );
227251 if ( $showmode ) $querystring = "[[:$querystring]]";
228252 }
@@ -236,7 +260,7 @@
237261 * obtain actual parameters, printout requests, and the query string for
238262 * further processing.
239263 */
240 - static public function getResultFromFunctionParams( $rawparams, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY, $showmode = false ) {
 264+ static public function getResultFromFunctionParams( array $rawparams, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY, $showmode = false ) {
241265 SMWQueryProcessor::processFunctionParams( $rawparams, $querystring, $params, $printouts, $showmode );
242266 return SMWQueryProcessor::getResultFromQueryString( $querystring, $params, $printouts, SMW_OUTPUT_WIKI, $context );
243267 }
@@ -249,7 +273,7 @@
250274 * certain general settings. Finally, $extraprintouts supplies additional
251275 * printout requests for the query results.
252276 */
253 - static public function getResultFromQueryString( $querystring, $params, $extraprintouts, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY ) {
 277+ static public function getResultFromQueryString( $querystring, array $params, $extraprintouts, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY ) {
254278 wfProfileIn( 'SMWQueryProcessor::getResultFromQueryString (SMW)' );
255279 $format = SMWQueryProcessor::getResultFormat( $params );
256280 $query = SMWQueryProcessor::createQuery( $querystring, $params, $context, $format, $extraprintouts );
@@ -258,7 +282,7 @@
259283 return $result;
260284 }
261285
262 - static public function getResultFromQuery( $query, $params, $extraprintouts, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY, $format = '' ) {
 286+ static public function getResultFromQuery( $query, array $params, $extraprintouts, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY, $format = '' ) {
263287 wfProfileIn( 'SMWQueryProcessor::getResultFromQuery (SMW)' );
264288 // Query routing allows extensions to provide alternative stores as data sources
265289 // The while feature is experimental and is not properly integrated with most of SMW's architecture. For instance, some query printers just fetch their own store.
@@ -293,7 +317,7 @@
294318 /**
295319 * Determine format label from parameters.
296320 */
297 - static protected function getResultFormat( $params ) {
 321+ static protected function getResultFormat( array $params ) {
298322 $format = 'auto';
299323 if ( array_key_exists( 'format', $params ) ) {
300324 $format = strtolower( trim( $params['format'] ) );
@@ -324,6 +348,4 @@
325349 return new $formatclass( $format, ( $context != SMWQueryProcessor::SPECIAL_PAGE ) );
326350 }
327351
328 -}
329 -
330 -
 352+}
\ No newline at end of file

Status & tagging log