Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ParseData.php |
— | — | @@ -1,9 +1,9 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * The class in this file manages semantic data collected during parsing of an article. |
5 | | - * |
| 5 | + * |
6 | 6 | * @author Markus Krötzsch |
7 | | - * |
| 7 | + * |
8 | 8 | * @file |
9 | 9 | * @ingroup SMW |
10 | 10 | */ |
— | — | @@ -32,55 +32,59 @@ |
33 | 33 | static public function stripMagicWords( &$text, $parser ) { |
34 | 34 | $words = array(); |
35 | 35 | $mw = MagicWord::get( 'SMW_NOFACTBOX' ); |
36 | | - |
| 36 | + |
37 | 37 | if ( $mw->matchAndRemove( $text ) ) { |
38 | 38 | $words[] = 'SMW_NOFACTBOX'; |
39 | 39 | } |
40 | | - |
| 40 | + |
41 | 41 | $mw = MagicWord::get( 'SMW_SHOWFACTBOX' ); |
42 | | - |
| 42 | + |
43 | 43 | if ( $mw->matchAndRemove( $text ) ) { |
44 | 44 | $words[] = 'SMW_SHOWFACTBOX'; |
45 | 45 | } |
46 | | - |
| 46 | + |
47 | 47 | $output = SMWParseData::getOutput( $parser ); |
48 | 48 | $output->mSMWMagicWords = $words; |
49 | | - |
| 49 | + |
50 | 50 | return $words; |
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
54 | 54 | * This function retrieves the SMW data from a given parser, and creates |
55 | 55 | * a new empty container if it is not initiated yet. |
56 | | - * |
| 56 | + * |
57 | 57 | * @retun SMWSemanticData |
58 | 58 | */ |
59 | 59 | static public function getSMWdata( $parser ) { |
60 | 60 | $output = self::getOutput( $parser ); |
61 | 61 | $title = $parser->getTitle(); |
62 | | - |
| 62 | + |
63 | 63 | // No parsing, create error. |
64 | | - if ( !isset( $output ) || !isset( $title ) ) return null; |
65 | | - |
| 64 | + if ( !isset( $output ) || !isset( $title ) ) { |
| 65 | + return null; |
| 66 | + } |
| 67 | + |
66 | 68 | // No data container yet. |
67 | | - if ( !isset( $output->mSMWData ) ) { |
| 69 | + if ( !isset( $output->mSMWData ) ) { |
68 | 70 | $output->mSMWData = new SMWSemanticData( SMWWikiPageValue::makePageFromTitle( $title ) ); |
69 | 71 | } |
70 | | - |
| 72 | + |
71 | 73 | return $output->mSMWData; |
72 | 74 | } |
73 | 75 | |
74 | 76 | /** |
75 | 77 | * Clear all stored data for a given parser. |
76 | | - * |
| 78 | + * |
77 | 79 | * @param Parser $parser |
78 | 80 | */ |
79 | 81 | static public function clearStorage( Parser $parser ) { |
80 | 82 | $output = self::getOutput( $parser ); |
81 | 83 | $title = $parser->getTitle(); |
82 | | - |
83 | | - if ( !isset( $output ) || !isset( $title ) ) return; |
84 | | - |
| 84 | + |
| 85 | + if ( !isset( $output ) || !isset( $title ) ) { |
| 86 | + return; |
| 87 | + } |
| 88 | + |
85 | 89 | $output->mSMWData = new SMWSemanticData( SMWWikiPageValue::makePageFromTitle( $title ) ); |
86 | 90 | } |
87 | 91 | |
— | — | @@ -89,42 +93,41 @@ |
90 | 94 | * intended to be used on user input, and property and value are sepcified by |
91 | 95 | * strings as they might be found in a wiki. The function returns a datavalue |
92 | 96 | * object that contains the result of the operation. |
93 | | - * |
| 97 | + * |
94 | 98 | * @param string $propertyName |
95 | 99 | * @param string $value |
96 | 100 | * @param mixed $caption string or false |
97 | | - * @param Parser $parser |
| 101 | + * @param Parser $parser |
98 | 102 | * @param boolean $storeAnnotation |
99 | | - * |
| 103 | + * |
100 | 104 | * @return SMWDataValue |
101 | 105 | */ |
102 | 106 | static public function addProperty( $propertyName, $value, $caption, Parser $parser, $storeAnnotation = true ) { |
103 | | - wfProfileIn( "SMWParseData::addProperty (SMW)" ); |
104 | | - |
| 107 | + wfProfileIn( 'SMWParseData::addProperty (SMW)' ); |
| 108 | + |
105 | 109 | global $smwgContLang; |
106 | | - |
| 110 | + |
107 | 111 | // See if this property is a special one, such as e.g. "has type". |
108 | 112 | $property = SMWPropertyValue::makeUserProperty( $propertyName ); |
109 | 113 | $result = SMWDataValueFactory::newPropertyObjectValue( $property, $value, $caption ); |
110 | | - |
| 114 | + |
111 | 115 | if ( $property->isInverse() ) { |
112 | 116 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
113 | 117 | $result->addError( wfMsgForContent( 'smw_noinvannot' ) ); |
114 | 118 | } elseif ( $storeAnnotation && ( self::getSMWData( $parser ) !== null ) ) { |
115 | 119 | self::getSMWData( $parser )->addPropertyObjectValue( $property, $result ); |
116 | | - |
| 120 | + |
117 | 121 | // Take note of the error for storage (do this here and not in storage, thus avoiding duplicates). |
118 | | - if ( !$result->isValid() ) { |
| 122 | + if ( !$result->isValid() ) { |
119 | 123 | self::getSMWData( $parser )->addPropertyObjectValue( SMWPropertyValue::makeProperty( '_ERRP' ), $property->getWikiPageValue() ); |
120 | 124 | } |
121 | 125 | } |
122 | | - |
123 | | - wfProfileOut( "SMWParseData::addProperty (SMW)" ); |
124 | | - |
| 126 | + |
| 127 | + wfProfileOut( 'SMWParseData::addProperty (SMW)' ); |
| 128 | + |
125 | 129 | return $result; |
126 | 130 | } |
127 | 131 | |
128 | | - |
129 | 132 | /** |
130 | 133 | * This function takes care of storing the collected semantic data and takes |
131 | 134 | * care of clearing out any outdated entries for the processed page. It assume that |
— | — | @@ -137,28 +140,28 @@ |
138 | 141 | * conversion factors have changed. If so, it triggers SMWUpdateJobs for the relevant articles, |
139 | 142 | * which then asynchronously update the semantic data in the database. |
140 | 143 | * |
141 | | - * @param $parseroutput ParserOutput object that contains the results of parsing which will |
142 | | - * be stored. |
143 | | - * @param $title Title object specifying the page that should be saved. |
144 | | - * @param $makejobs Bool stating whether jobs should be created to trigger further updates if |
145 | | - * this appears to be necessary after this update. |
| 144 | + * @param $parseroutput ParserOutput object that contains the results of parsing which will |
| 145 | + * be stored. |
| 146 | + * @param $title Title object specifying the page that should be saved. |
| 147 | + * @param $makejobs Bool stating whether jobs should be created to trigger further updates if |
| 148 | + * this appears to be necessary after this update. |
146 | 149 | * |
147 | | - * FIXME Some job generations here might create too many jobs at once on a large wiki. Use incremental jobs instead. |
| 150 | + * @todo FIXME: Some job generations here might create too many jobs at once on a large wiki. Use incremental jobs instead. |
148 | 151 | */ |
149 | 152 | static public function storeData( $parseroutput, Title $title, $makejobs = true ) { |
150 | 153 | global $smwgEnableUpdateJobs, $wgContLang, $smwgMW_1_14, $smwgDeclarationProperties; |
151 | | - |
| 154 | + |
152 | 155 | $semdata = $parseroutput->mSMWData; |
153 | 156 | $namespace = $title->getNamespace(); |
154 | 157 | $processSemantics = smwfIsSemanticsProcessed( $namespace ); |
155 | | - |
| 158 | + |
156 | 159 | if ( !isset( $semdata ) ) { // no data at all? |
157 | 160 | $semdata = new SMWSemanticData( SMWWikiPageValue::makePageFromTitle( $title ) ); |
158 | 161 | } |
159 | | - |
| 162 | + |
160 | 163 | if ( $processSemantics ) { |
161 | 164 | $pmdat = SMWPropertyValue::makeProperty( '_MDAT' ); |
162 | | - |
| 165 | + |
163 | 166 | if ( count( $semdata->getPropertyValues( $pmdat ) ) == 0 ) { // no article data present yet, add it here |
164 | 167 | $timestamp = $smwgMW_1_14 ? Revision::getTimeStampFromID( $title, $title->getLatestRevID() ) : Revision::getTimeStampFromID( $title->getLatestRevID() ); |
165 | 168 | $dv = SMWDataValueFactory::newPropertyObjectValue( $pmdat, $wgContLang->sprintfDate( 'd M Y G:i:s', $timestamp ) ); |
— | — | @@ -174,7 +177,7 @@ |
175 | 178 | // even finding uses of a property fails after its type was changed. |
176 | 179 | $updatejobflag = false; |
177 | 180 | $jobs = array(); |
178 | | - |
| 181 | + |
179 | 182 | if ( $makejobs && $smwgEnableUpdateJobs && ( $namespace == SMW_NS_PROPERTY ) ) { |
180 | 183 | // If it is a property, then we need to check if the type or the allowed values have been changed. |
181 | 184 | $ptype = SMWPropertyValue::makeProperty( '_TYPE' ); |
— | — | @@ -195,14 +198,14 @@ |
196 | 199 | if ( $updatejobflag ) { |
197 | 200 | $prop = SMWPropertyValue::makeProperty( $title->getDBkey() ); |
198 | 201 | $subjects = smwfGetStore()->getAllPropertySubjects( $prop ); |
199 | | - |
| 202 | + |
200 | 203 | foreach ( $subjects as $subject ) { |
201 | 204 | $jobs[] = new SMWUpdateJob( $subject->getTitle() ); |
202 | 205 | } |
203 | 206 | wfRunHooks( 'smwUpdatePropertySubjects', array( &$jobs ) ); |
204 | | - |
| 207 | + |
205 | 208 | $subjects = smwfGetStore()->getPropertySubjects( SMWPropertyValue::makeProperty( '_ERRP' ), $prop->getWikiPageValue() ); |
206 | | - |
| 209 | + |
207 | 210 | foreach ( $subjects as $subject ) { |
208 | 211 | $jobs[] = new SMWUpdateJob( $subject->getTitle() ); |
209 | 212 | } |
— | — | @@ -211,36 +214,39 @@ |
212 | 215 | // if it is a type we need to check if the conversion factors have been changed |
213 | 216 | $pconv = SMWPropertyValue::makeProperty( '_CONV' ); |
214 | 217 | $ptype = SMWPropertyValue::makeProperty( '_TYPE' ); |
215 | | - |
| 218 | + |
216 | 219 | $oldfactors = smwfGetStore()->getPropertyValues( $semdata->getSubject(), $pconv ); |
217 | 220 | $newfactors = $semdata->getPropertyValues( $pconv ); |
218 | 221 | $updatejobflag = !self::equalDatavalues( $oldfactors, $newfactors ); |
219 | | - |
| 222 | + |
220 | 223 | if ( $updatejobflag ) { |
221 | 224 | $store = smwfGetStore(); |
222 | | - |
| 225 | + |
223 | 226 | /// FIXME: this will kill large wikis! Use incremental updates! |
224 | 227 | $dv = SMWDataValueFactory::newTypeIdValue( '__typ', $title->getDBkey() ); |
225 | 228 | $proppages = $store->getPropertySubjects( $ptype, $dv ); |
226 | | - |
| 229 | + |
227 | 230 | foreach ( $proppages as $proppage ) { |
228 | 231 | $jobs[] = new SMWUpdateJob( $proppage->getTitle() ); |
229 | 232 | $prop = SMWPropertyValue::makeProperty( $proppage->getDBkey() ); |
230 | 233 | $subjects = $store->getAllPropertySubjects( $prop ); |
231 | | - |
| 234 | + |
232 | 235 | foreach ( $subjects as $subject ) { |
233 | 236 | $jobs[] = new SMWUpdateJob( $subject->getTitle() ); |
234 | 237 | } |
235 | | - |
236 | | - $subjects = smwfGetStore()->getPropertySubjects( SMWPropertyValue::makeProperty( '_ERRP' ), $prop->getWikiPageValue() ); |
237 | | - |
| 238 | + |
| 239 | + $subjects = smwfGetStore()->getPropertySubjects( |
| 240 | + SMWPropertyValue::makeProperty( '_ERRP' ), |
| 241 | + $prop->getWikiPageValue() |
| 242 | + ); |
| 243 | + |
238 | 244 | foreach ( $subjects as $subject ) { |
239 | 245 | $jobs[] = new SMWUpdateJob( $subject->getTitle() ); |
240 | 246 | } |
241 | 247 | } |
242 | 248 | } |
243 | 249 | } |
244 | | - |
| 250 | + |
245 | 251 | // Actually store semantic data, or at least clear it if needed |
246 | 252 | if ( $processSemantics ) { |
247 | 253 | smwfGetStore()->updateData( $semdata ); |
— | — | @@ -252,7 +258,7 @@ |
253 | 259 | if ( $updatejobflag ) { |
254 | 260 | Job::batchInsert( $jobs ); ///NOTE: this only happens if $smwgEnableUpdateJobs was true above |
255 | 261 | } |
256 | | - |
| 262 | + |
257 | 263 | return true; |
258 | 264 | } |
259 | 265 | |
— | — | @@ -266,16 +272,20 @@ |
267 | 273 | // and finally concatenated, thus creating one long hash out of each |
268 | 274 | // of the data value arrays. These are compared. |
269 | 275 | $values = array(); |
270 | | - foreach ( $dv1 as $v ) $values[] = $v->getHash(); |
271 | | - |
| 276 | + foreach ( $dv1 as $v ) { |
| 277 | + $values[] = $v->getHash(); |
| 278 | + } |
| 279 | + |
272 | 280 | sort( $values ); |
273 | | - $dv1hash = implode( "___", $values ); |
274 | | - |
| 281 | + $dv1hash = implode( '___', $values ); |
| 282 | + |
275 | 283 | $values = array(); |
276 | | - foreach ( $dv2 as $v ) $values[] = $v->getHash(); |
277 | | - |
| 284 | + foreach ( $dv2 as $v ) { |
| 285 | + $values[] = $v->getHash(); |
| 286 | + } |
| 287 | + |
278 | 288 | sort( $values ); |
279 | | - $dv2hash = implode( "___", $values ); |
| 289 | + $dv2hash = implode( '___', $values ); |
280 | 290 | |
281 | 291 | return ( $dv1hash == $dv2hash ); |
282 | 292 | } |
— | — | @@ -283,7 +293,7 @@ |
284 | 294 | /** |
285 | 295 | * Get the parser output from a parser object. The result is also stored |
286 | 296 | * in SMWParseData::$mPrevOutput for further reference. |
287 | | - * |
| 297 | + * |
288 | 298 | * @param Parser $parser |
289 | 299 | */ |
290 | 300 | static protected function getOutput( Parser $parser ) { |
— | — | @@ -292,7 +302,7 @@ |
293 | 303 | } else { |
294 | 304 | self::$mPrevOutput = $parser->mOutput; |
295 | 305 | } |
296 | | - |
| 306 | + |
297 | 307 | return self::$mPrevOutput; |
298 | 308 | } |
299 | 309 | |
— | — | @@ -302,11 +312,13 @@ |
303 | 313 | */ |
304 | 314 | static public function onParserAfterTidy( &$parser, &$text ) { |
305 | 315 | global $smwgUseCategoryHierarchy, $smwgCategoriesAsInstances; |
306 | | - |
307 | | - if ( self::getSMWData( $parser ) === null ) return true; |
308 | | - |
| 316 | + |
| 317 | + if ( self::getSMWData( $parser ) === null ) { |
| 318 | + return true; |
| 319 | + } |
| 320 | + |
309 | 321 | $categories = $parser->mOutput->getCategoryLinks(); |
310 | | - |
| 322 | + |
311 | 323 | foreach ( $categories as $name ) { |
312 | 324 | if ( $smwgCategoriesAsInstances && ( self::getSMWData( $parser )->getSubject()->getNamespace() != NS_CATEGORY ) ) { |
313 | 325 | $pinst = SMWPropertyValue::makeProperty( '_INST' ); |
— | — | @@ -314,7 +326,7 @@ |
315 | 327 | $dv->setValues( $name, NS_CATEGORY ); |
316 | 328 | self::getSMWData( $parser )->addPropertyObjectValue( $pinst, $dv ); |
317 | 329 | } |
318 | | - |
| 330 | + |
319 | 331 | if ( $smwgUseCategoryHierarchy && ( self::getSMWData( $parser )->getSubject()->getNamespace() == NS_CATEGORY ) ) { |
320 | 332 | $psubc = SMWPropertyValue::makeProperty( '_SUBC' ); |
321 | 333 | $dv = SMWDataValueFactory::newPropertyObjectValue( $psubc ); |
— | — | @@ -322,10 +334,10 @@ |
323 | 335 | self::getSMWData( $parser )->addPropertyObjectValue( $psubc, $dv ); |
324 | 336 | } |
325 | 337 | } |
326 | | - |
| 338 | + |
327 | 339 | $sortkey = ( $parser->mDefaultSort ? $parser->mDefaultSort : self::getSMWData( $parser )->getSubject()->getText() ); |
328 | 340 | self::getSMWData( $parser )->getSubject()->setSortkey( $sortkey ); |
329 | | - |
| 341 | + |
330 | 342 | return true; |
331 | 343 | } |
332 | 344 | |
— | — | @@ -342,33 +354,37 @@ |
343 | 355 | */ |
344 | 356 | static public function onNewRevisionFromEditComplete( $article, $rev, $baseID ) { |
345 | 357 | global $wgContLang, $smwgContLang; |
346 | | - |
| 358 | + |
347 | 359 | if ( ( $article->mPreparedEdit ) && ( $article->mPreparedEdit->output instanceof ParserOutput ) ) { |
348 | 360 | $output = $article->mPreparedEdit->output; |
349 | 361 | $title = $article->getTitle(); |
350 | | - |
351 | | - if ( !isset( $title ) ) return true; // nothing we can do |
| 362 | + |
| 363 | + if ( !isset( $title ) ) { |
| 364 | + return true; // nothing we can do |
| 365 | + } |
352 | 366 | if ( !isset( $output->mSMWData ) ) { // no data container yet, make one |
353 | 367 | $output->mSMWData = new SMWSemanticData( SMWWikiPageValue::makePageFromTitle( $title ) ); |
354 | 368 | } |
355 | | - |
| 369 | + |
356 | 370 | $semdata = $output->mSMWData; |
357 | 371 | } else { // give up, just keep the old data |
358 | 372 | return true; |
359 | 373 | } |
360 | | - |
| 374 | + |
361 | 375 | $pmdat = SMWPropertyValue::makeProperty( '_MDAT' ); |
362 | | - |
| 376 | + |
363 | 377 | // create a date string that is certainly parsable in the current language: |
364 | 378 | $timestamp = $article->getTimestamp(); |
365 | | - |
366 | | - $date = $wgContLang->sprintfDate( 'd ', $timestamp ) . $smwgContLang->getMonthLabel( ( $wgContLang->sprintfDate( 'm', $timestamp ) + 0 ) ) . $wgContLang->sprintfDate( ' Y G:i:s', $timestamp ); |
| 379 | + |
| 380 | + $date = $wgContLang->sprintfDate( 'd ', $timestamp ) . |
| 381 | + $smwgContLang->getMonthLabel( ( $wgContLang->sprintfDate( 'm', $timestamp ) + 0 ) ) . |
| 382 | + $wgContLang->sprintfDate( ' Y G:i:s', $timestamp ); |
367 | 383 | $dv = SMWDataValueFactory::newPropertyObjectValue( $pmdat, $date ); |
368 | | - |
| 384 | + |
369 | 385 | // The below method is not safe, since "M" as used in MW may not be the month label as used in SMW if SMW falls back to some other language: |
370 | | - // $dv = SMWDataValueFactory::newPropertyObjectValue($pmdat, $wgContLang->sprintfDate('d M Y G:i:s',$article->getTimestamp())); |
| 386 | + // $dv = SMWDataValueFactory::newPropertyObjectValue( $pmdat, $wgContLang->sprintfDate( 'd M Y G:i:s', $article->getTimestamp() ) ); |
371 | 387 | $semdata->addPropertyObjectValue( $pmdat, $dv ); |
372 | | - |
| 388 | + |
373 | 389 | return true; |
374 | 390 | } |
375 | 391 | |
— | — | @@ -380,21 +396,21 @@ |
381 | 397 | $output = $links_update->mParserOutput; |
382 | 398 | } else { // MediaWiki <= 1.13 compatibility |
383 | 399 | $output = self::$mPrevOutput; |
384 | | - |
| 400 | + |
385 | 401 | if ( !isset( $output ) ) { |
386 | 402 | smwfGetStore()->clearData( $links_update->mTitle, SMWFactbox::isNewArticle() ); |
387 | 403 | return true; |
388 | 404 | } |
389 | 405 | } |
390 | | - |
| 406 | + |
391 | 407 | self::storeData( $output, $links_update->mTitle, true ); |
392 | | - |
| 408 | + |
393 | 409 | return true; |
394 | 410 | } |
395 | 411 | |
396 | 412 | /** |
397 | | - * This method will be called whenever an article is deleted so that |
398 | | - * semantic properties are cleared appropriately. |
| 413 | + * This method will be called whenever an article is deleted so that |
| 414 | + * semantic properties are cleared appropriately. |
399 | 415 | */ |
400 | 416 | static public function onArticleDelete( &$article, &$user, &$reason ) { |
401 | 417 | smwfGetStore()->deleteSubject( $article->getTitle() ); |
— | — | @@ -402,8 +418,8 @@ |
403 | 419 | } |
404 | 420 | |
405 | 421 | /** |
406 | | - * This method will be called whenever an article is moved so that |
407 | | - * semantic properties are moved accordingly. |
| 422 | + * This method will be called whenever an article is moved so that |
| 423 | + * semantic properties are moved accordingly. |
408 | 424 | */ |
409 | 425 | static public function onTitleMoveComplete( &$old_title, &$new_title, &$user, $pageid, $redirid ) { |
410 | 426 | smwfGetStore()->changeTitle( $old_title, $new_title, $pageid, $redirid ); |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Record_Descriptions.php |
— | — | @@ -19,13 +19,17 @@ |
20 | 20 | class SMWRecordDescription extends SMWConjunction { |
21 | 21 | |
22 | 22 | public function getQueryString( $asvalue = false ) { |
23 | | - if ( !$asvalue ) return ''; // give up; SMWRecordDescriptions must always be values |
| 23 | + if ( !$asvalue ) { |
| 24 | + return ''; // give up; SMWRecordDescriptions must always be values |
| 25 | + } |
24 | 26 | $fields = array(); |
25 | 27 | $maxpos = - 1; |
26 | 28 | foreach ( $this->m_descriptions as $desc ) { |
27 | 29 | if ( $desc instanceof SMWRecordFieldDescription ) { // everything else would be a bug; ignore |
28 | 30 | $fields[$desc->getPosition()] = $desc->getDescription()->getQueryString( true ); |
29 | | - if ( $maxpos < $desc->getPosition() ) $maxpos = $desc->getPosition(); |
| 31 | + if ( $maxpos < $desc->getPosition() ) { |
| 32 | + $maxpos = $desc->getPosition(); |
| 33 | + } |
30 | 34 | } |
31 | 35 | } |
32 | 36 | if ( $maxpos < 0 ) { |
— | — | @@ -82,7 +86,9 @@ |
83 | 87 | } |
84 | 88 | |
85 | 89 | public function getQueryString( $asvalue = false ) { |
86 | | - if ( !$asvalue ) return ''; // give up; SMWRecordFieldDescriptions must always be values |
| 90 | + if ( !$asvalue ) { |
| 91 | + return ''; // give up; SMWRecordFieldDescriptions must always be values |
| 92 | + } |
87 | 93 | $prefix = ''; |
88 | 94 | for ( $i = 0; $i < $this->m_position; $i++ ) { |
89 | 95 | $prefix .= '?; '; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php |
— | — | @@ -31,7 +31,7 @@ |
32 | 32 | * The format string is used to specify the output format if already |
33 | 33 | * known. Otherwise it will be determined from the parameters when |
34 | 34 | * needed. This parameter is just for optimisation in a common case. |
35 | | - * |
| 35 | + * |
36 | 36 | * @return SMWQuery |
37 | 37 | */ |
38 | 38 | static public function createQuery( $querystring, array $params, $context = SMWQueryProcessor::INLINE_QUERY, $format = '', $extraprintouts = array() ) { |
— | — | @@ -45,7 +45,7 @@ |
46 | 46 | $qp = new SMWQueryParser( $queryfeatures ); |
47 | 47 | $qp->setDefaultNamespaces( $smwgQDefaultNamespaces ); |
48 | 48 | $desc = $qp->getQueryDescription( $querystring ); |
49 | | - |
| 49 | + |
50 | 50 | if ( $format == 'count' ) { |
51 | 51 | $querymode = SMWQuery::MODE_COUNT; |
52 | 52 | } elseif ( $format == 'debug' ) { |
— | — | @@ -58,7 +58,7 @@ |
59 | 59 | $mainlabel = array_key_exists( 'mainlabel', $params ) ? $params['mainlabel'] : ''; |
60 | 60 | if ( ( $querymode == SMWQuery::MODE_NONE ) || |
61 | 61 | ( ( !$desc->isSingleton() || ( count( $desc->getPrintRequests() ) + count( $extraprintouts ) == 0 ) ) |
62 | | - && ( trim($mainlabel) != '-' ) ) ) { |
| 62 | + && ( trim( $mainlabel ) != '-' ) ) ) { |
63 | 63 | $desc->prependPrintRequest( new SMWPrintRequest( SMWPrintRequest::PRINT_THIS, $mainlabel ) ); |
64 | 64 | } |
65 | 65 | |
— | — | @@ -72,7 +72,7 @@ |
73 | 73 | if ( ( array_key_exists( 'offset', $params ) ) && ( is_int( $params['offset'] + 0 ) ) ) { |
74 | 74 | $query->setOffset( max( 0, trim( $params['offset'] ) + 0 ) ); |
75 | 75 | } |
76 | | - |
| 76 | + |
77 | 77 | if ( $query->querymode == SMWQuery::MODE_COUNT ) { // largest possible limit for "count", even inline |
78 | 78 | global $smwgQMaxLimit; |
79 | 79 | $query->setOffset( 0 ); |
— | — | @@ -88,11 +88,11 @@ |
89 | 89 | $query->setLimit( $smwgQDefaultLimit ); |
90 | 90 | } |
91 | 91 | } |
92 | | - |
| 92 | + |
93 | 93 | // determine sortkeys and ascendings: |
94 | 94 | if ( array_key_exists( 'order', $params ) ) { |
95 | 95 | $orders = explode( ',', $params['order'] ); |
96 | | - |
| 96 | + |
97 | 97 | foreach ( $orders as $key => $order ) { // normalise |
98 | 98 | $order = strtolower( trim( $order ) ); |
99 | 99 | if ( ( $order == 'descending' ) || ( $order == 'reverse' ) || ( $order == 'desc' ) ) { |
— | — | @@ -106,35 +106,35 @@ |
107 | 107 | } else { |
108 | 108 | $orders = array(); |
109 | 109 | } |
110 | | - |
| 110 | + |
111 | 111 | reset( $orders ); |
112 | 112 | |
113 | 113 | if ( array_key_exists( 'sort', $params ) ) { |
114 | 114 | $query->sort = true; |
115 | 115 | $query->sortkeys = array(); |
116 | | - |
| 116 | + |
117 | 117 | foreach ( explode( ',', trim( $params['sort'] ) ) as $sort ) { |
118 | 118 | $sort = smwfNormalTitleDBKey( trim( $sort ) ); // slight normalisation |
119 | 119 | $order = current( $orders ); |
120 | 120 | if ( $order === false ) { // default |
121 | 121 | $order = 'ASC'; |
122 | 122 | } |
123 | | - |
| 123 | + |
124 | 124 | if ( array_key_exists( $sort, $query->sortkeys ) ) { |
125 | 125 | // maybe throw an error here? |
126 | 126 | } else { |
127 | 127 | $query->sortkeys[$sort] = $order; |
128 | 128 | } |
129 | | - |
| 129 | + |
130 | 130 | next( $orders ); |
131 | 131 | } |
132 | | - |
| 132 | + |
133 | 133 | if ( current( $orders ) !== false ) { // sort key remaining, apply to page name |
134 | 134 | $query->sortkeys[''] = current( $orders ); |
135 | 135 | } |
136 | 136 | } elseif ( $format == 'rss' ) { // unsorted RSS: use *descending* default order |
137 | | - ///TODO: the default sort field should be "modification date" (now it is the title, but |
138 | | - ///likely to be overwritten by printouts with label "date"). |
| 137 | + // TODO: the default sort field should be "modification date" (now it is the title, but |
| 138 | + // likely to be overwritten by printouts with label "date"). |
139 | 139 | $query->sortkeys[''] = ( current( $orders ) != false ) ? current( $orders ) : 'DESC'; |
140 | 140 | } else { // sort by page title (main column) by default |
141 | 141 | $query->sortkeys[''] = ( current( $orders ) != false ) ? current( $orders ) : 'ASC'; |
— | — | @@ -152,31 +152,31 @@ |
153 | 153 | */ |
154 | 154 | static public function processFunctionParams( array $rawparams, &$querystring, &$params, &$printouts, $showmode = false ) { |
155 | 155 | global $wgContLang; |
156 | | - |
| 156 | + |
157 | 157 | $querystring = ''; |
158 | 158 | $printouts = array(); |
159 | 159 | $lastprintout = null; |
160 | 160 | $params = array(); |
161 | | - |
| 161 | + |
162 | 162 | foreach ( $rawparams as $name => $param ) { |
163 | 163 | // special handling for arrays - this can happen if the |
164 | 164 | // param came from a checkboxes input in Special:Ask |
165 | 165 | if ( is_array( $param ) ) { |
166 | 166 | $param = implode( ',', array_keys( $param ) ); |
167 | 167 | } |
168 | | - |
| 168 | + |
169 | 169 | if ( is_string( $name ) && ( $name != '' ) ) { // accept 'name' => 'value' just as '' => 'name=value' |
170 | 170 | $param = $name . '=' . $param; |
171 | 171 | } |
172 | | - |
| 172 | + |
173 | 173 | if ( $param == '' ) { |
174 | 174 | } elseif ( $param { 0 } == '?' ) { // print statement |
175 | 175 | $param = substr( $param, 1 ); |
176 | 176 | $parts = explode( '=', $param, 2 ); |
177 | 177 | $propparts = explode( '#', $parts[0], 2 ); |
178 | | - |
| 178 | + |
179 | 179 | $data = null; |
180 | | - |
| 180 | + |
181 | 181 | if ( trim( $propparts[0] ) == '' ) { // print "this" |
182 | 182 | $printmode = SMWPrintRequest::PRINT_THIS; |
183 | 183 | $label = ''; // default |
— | — | @@ -190,7 +190,7 @@ |
191 | 191 | if ( $title === null ) { // too bad, this is no legal property/category name, ignore |
192 | 192 | continue; |
193 | 193 | } |
194 | | - |
| 194 | + |
195 | 195 | if ( $title->getNamespace() == NS_CATEGORY ) { |
196 | 196 | $printmode = SMWPrintRequest::PRINT_CCAT; |
197 | 197 | $data = $title; |
— | — | @@ -202,28 +202,30 @@ |
203 | 203 | $label = $showmode ? '' : $property->getWikiValue(); // default |
204 | 204 | } |
205 | 205 | } |
206 | | - |
| 206 | + |
207 | 207 | if ( count( $propparts ) == 1 ) { // no outputformat found, leave empty |
208 | 208 | $propparts[] = false; |
209 | 209 | } elseif ( trim( $propparts[1] ) == '' ) { // "plain printout", avoid empty string to avoid confusions with "false" |
210 | 210 | $propparts[1] = '-'; |
211 | 211 | } |
212 | | - |
| 212 | + |
213 | 213 | if ( count( $parts ) > 1 ) { // label found, use this instead of default |
214 | 214 | $label = trim( $parts[1] ); |
215 | 215 | } |
216 | | - |
| 216 | + |
217 | 217 | $lastprintout = new SMWPrintRequest( $printmode, $label, $data, trim( $propparts[1] ) ); |
218 | 218 | $printouts[] = $lastprintout; |
219 | 219 | } elseif ( $param[0] == '+' ) { // print request parameter |
220 | 220 | if ( $lastprintout !== null ) { |
221 | 221 | $param = substr( $param, 1 ); |
222 | 222 | $parts = explode( '=', $param, 2 ); |
223 | | - if ( count( $parts ) == 2 ) $lastprintout->setParameter( trim( $parts[0] ), $parts[1] ); |
| 223 | + if ( count( $parts ) == 2 ) { |
| 224 | + $lastprintout->setParameter( trim( $parts[0] ), $parts[1] ); |
| 225 | + } |
224 | 226 | } |
225 | 227 | } else { // parameter or query |
226 | 228 | $parts = explode( '=', $param, 2 ); |
227 | | - |
| 229 | + |
228 | 230 | if ( count( $parts ) >= 2 ) { |
229 | 231 | $params[strtolower( trim( $parts[0] ) )] = $parts[1]; // don't trim here, some params care for " " |
230 | 232 | } else { |
— | — | @@ -231,9 +233,11 @@ |
232 | 234 | } |
233 | 235 | } |
234 | 236 | } |
235 | | - |
| 237 | + |
236 | 238 | $querystring = str_replace( array( '<', '>' ), array( '<', '>' ), $querystring ); |
237 | | - if ( $showmode ) $querystring = "[[:$querystring]]"; |
| 239 | + if ( $showmode ) { |
| 240 | + $querystring = "[[:$querystring]]"; |
| 241 | + } |
238 | 242 | } |
239 | 243 | |
240 | 244 | /** |
— | — | @@ -261,93 +265,99 @@ |
262 | 266 | */ |
263 | 267 | static public function getResultFromQueryString( $querystring, array $params, $extraprintouts, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY ) { |
264 | 268 | wfProfileIn( 'SMWQueryProcessor::getResultFromQueryString (SMW)' ); |
265 | | - |
| 269 | + |
266 | 270 | $format = SMWQueryProcessor::getResultFormat( $params ); |
267 | 271 | $query = SMWQueryProcessor::createQuery( $querystring, $params, $context, $format, $extraprintouts ); |
268 | 272 | $result = SMWQueryProcessor::getResultFromQuery( $query, $params, $extraprintouts, $outputmode, $context, $format ); |
269 | | - |
| 273 | + |
270 | 274 | wfProfileOut( 'SMWQueryProcessor::getResultFromQueryString (SMW)' ); |
271 | | - |
| 275 | + |
272 | 276 | return $result; |
273 | 277 | } |
274 | 278 | |
275 | 279 | static public function getResultFromQuery( SMWQuery $query, array $params, $extraprintouts, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY, $format = '' ) { |
276 | 280 | wfProfileIn( 'SMWQueryProcessor::getResultFromQuery (SMW)' ); |
277 | | - |
| 281 | + |
278 | 282 | // Query routing allows extensions to provide alternative stores as data sources |
279 | 283 | // 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. |
280 | | - ///TODO: case-insensitive |
| 284 | + // @todo FIXME: case-insensitive |
281 | 285 | global $smwgQuerySources; |
282 | | - |
| 286 | + |
283 | 287 | if ( array_key_exists( 'source', $params ) && array_key_exists( $params['source'], $smwgQuerySources ) ) { |
284 | 288 | $store = new $smwgQuerySources[$params['source']](); |
285 | 289 | $query->params = $params; // this is a hack |
286 | 290 | } else { |
287 | 291 | $store = smwfGetStore(); // default store |
288 | 292 | } |
289 | | - |
| 293 | + |
290 | 294 | $res = $store->getQueryResult( $query ); |
291 | 295 | |
292 | 296 | if ( ( $query->querymode == SMWQuery::MODE_INSTANCES ) || ( $query->querymode == SMWQuery::MODE_NONE ) ) { |
293 | 297 | wfProfileIn( 'SMWQueryProcessor::getResultFromQuery-printout (SMW)' ); |
294 | | - |
| 298 | + |
295 | 299 | if ( $format == '' ) { |
296 | 300 | $format = SMWQueryProcessor::getResultFormat( $params ); |
297 | 301 | } |
298 | | - |
| 302 | + |
299 | 303 | $printer = SMWQueryProcessor::getResultPrinter( $format, $context, $res ); |
300 | 304 | $result = $printer->getResult( $res, $params, $outputmode ); |
301 | | - |
| 305 | + |
302 | 306 | wfProfileOut( 'SMWQueryProcessor::getResultFromQuery-printout (SMW)' ); |
303 | 307 | wfProfileOut( 'SMWQueryProcessor::getResultFromQuery (SMW)' ); |
304 | | - |
| 308 | + |
305 | 309 | return $result; |
306 | 310 | } else { // result for counting or debugging is just a string |
307 | | - if ( array_key_exists( 'intro', $params ) ) $res = str_replace( '_', ' ', $params['intro'] ) . $res; |
308 | | - if ( array_key_exists( 'outro', $params ) ) $res .= str_replace( '_', ' ', $params['outro'] ); |
309 | | - |
| 311 | + if ( array_key_exists( 'intro', $params ) ) { |
| 312 | + $res = str_replace( '_', ' ', $params['intro'] ) . $res; |
| 313 | + } |
| 314 | + if ( array_key_exists( 'outro', $params ) ) { |
| 315 | + $res .= str_replace( '_', ' ', $params['outro'] ); |
| 316 | + } |
| 317 | + |
310 | 318 | wfProfileOut( 'SMWQueryProcessor::getResultFromQuery (SMW)' ); |
311 | | - |
| 319 | + |
312 | 320 | return $res . smwfEncodeMessages( $query->getErrors() ); |
313 | 321 | } |
314 | 322 | } |
315 | 323 | |
316 | 324 | /** |
317 | 325 | * Determines the format from an array of parameters, and returns it. |
318 | | - * |
| 326 | + * |
319 | 327 | * @param array $params |
320 | | - * |
| 328 | + * |
321 | 329 | * @return string |
322 | 330 | */ |
323 | 331 | static protected function getResultFormat( array $params ) { |
324 | 332 | $format = 'auto'; |
325 | | - |
| 333 | + |
326 | 334 | if ( array_key_exists( 'format', $params ) ) { |
327 | 335 | global $smwgResultFormats; |
328 | | - |
| 336 | + |
329 | 337 | $format = strtolower( trim( $params['format'] ) ); |
330 | | - |
| 338 | + |
331 | 339 | if ( !array_key_exists( $format, $smwgResultFormats ) ) { |
332 | 340 | $isAlias = self::resolveFormatAliases( $format ); |
333 | | - if ( !$isAlias ) $format = 'auto'; // If it is an unknown format, defaults to list/table again |
| 341 | + if ( !$isAlias ) { |
| 342 | + $format = 'auto'; // If it is an unknown format, defaults to list/table again |
| 343 | + } |
334 | 344 | } |
335 | 345 | } |
336 | | - |
| 346 | + |
337 | 347 | return $format; |
338 | 348 | } |
339 | | - |
| 349 | + |
340 | 350 | /** |
341 | 351 | * Turns format aliases into main formats. |
342 | | - * |
| 352 | + * |
343 | 353 | * @param string $format |
344 | | - * |
| 354 | + * |
345 | 355 | * @return boolean Indicates if the passed format was an alias, and thus was changed. |
346 | 356 | */ |
347 | 357 | static protected function resolveFormatAliases( &$format ) { |
348 | 358 | global $smwgResultAliases; |
349 | 359 | |
350 | 360 | $isAlias = false; |
351 | | - |
| 361 | + |
352 | 362 | foreach ( $smwgResultAliases as $mainFormat => $aliases ) { |
353 | 363 | if ( in_array( $format, $aliases ) ) { |
354 | 364 | $format = $mainFormat; |
— | — | @@ -363,20 +373,20 @@ |
364 | 374 | * Find suitable SMWResultPrinter for the given format. The context in which the query is to be |
365 | 375 | * used determines some basic settings of the returned printer object. Possible contexts are |
366 | 376 | * SMWQueryProcessor::SPECIAL_PAGE, SMWQueryProcessor::INLINE_QUERY, SMWQueryProcessor::CONCEPT_DESC. |
367 | | - * |
| 377 | + * |
368 | 378 | * @param string $format |
369 | 379 | * @param $context |
370 | | - * |
| 380 | + * |
371 | 381 | * @return SMWResultPrinter |
372 | 382 | */ |
373 | 383 | static public function getResultPrinter( $format, $context = SMWQueryProcessor::SPECIAL_PAGE ) { |
374 | 384 | global $smwgResultFormats; |
375 | | - |
| 385 | + |
376 | 386 | self::resolveFormatAliases( $format ); |
377 | | - |
| 387 | + |
378 | 388 | // TODO: this seems to contain the same logic as found in getResultFormat - a single function for this might be better. |
379 | 389 | $formatClass = array_key_exists( $format, $smwgResultFormats ) ? $smwgResultFormats[$format] : 'SMWAutoResultPrinter'; |
380 | | - |
| 390 | + |
381 | 391 | return new $formatClass( $format, ( $context != SMWQueryProcessor::SPECIAL_PAGE ) ); |
382 | 392 | } |
383 | 393 | |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php |
— | — | @@ -248,12 +248,18 @@ |
249 | 249 | * particular datatype in mind. |
250 | 250 | */ |
251 | 251 | public function addServiceLinks() { |
252 | | - if ( $this->mHasServiceLinks ) return; |
253 | | - if ( ( $this->m_property === null ) || ( $this->m_property->getWikiPageValue() === null ) ) return; // no property known |
| 252 | + if ( $this->mHasServiceLinks ) { |
| 253 | + return; |
| 254 | + } |
| 255 | + if ( ( $this->m_property === null ) || ( $this->m_property->getWikiPageValue() === null ) ) { |
| 256 | + return; // no property known |
| 257 | + } |
254 | 258 | |
255 | 259 | $args = $this->getServiceLinkParams(); |
256 | 260 | |
257 | | - if ( $args === false ) return; // no services supported |
| 261 | + if ( $args === false ) { |
| 262 | + return; // no services supported |
| 263 | + } |
258 | 264 | |
259 | 265 | array_unshift( $args, '' ); // add a 0 element as placeholder |
260 | 266 | $servicelinks = smwfGetStore()->getPropertyValues( $this->m_property->getWikiPageValue(), SMWPropertyValue::makeProperty( '_SERV' ) ); |
— | — | @@ -401,11 +407,21 @@ |
402 | 408 | $value = $list[2]; |
403 | 409 | |
404 | 410 | switch ( $list[1] ) { |
405 | | - case '<': $comparator = SMW_CMP_LEQ; break; |
406 | | - case '>': $comparator = SMW_CMP_GEQ; break; |
407 | | - case '!': $comparator = SMW_CMP_NEQ; break; |
408 | | - case '~': $comparator = SMW_CMP_LIKE; break; |
409 | | - case '!~': $comparator = SMW_CMP_NLKE; break; |
| 411 | + case '<': |
| 412 | + $comparator = SMW_CMP_LEQ; |
| 413 | + break; |
| 414 | + case '>': |
| 415 | + $comparator = SMW_CMP_GEQ; |
| 416 | + break; |
| 417 | + case '!': |
| 418 | + $comparator = SMW_CMP_NEQ; |
| 419 | + break; |
| 420 | + case '~': |
| 421 | + $comparator = SMW_CMP_LIKE; |
| 422 | + break; |
| 423 | + case '!~': |
| 424 | + $comparator = SMW_CMP_NLKE; |
| 425 | + break; |
410 | 426 | // default: not possible |
411 | 427 | } |
412 | 428 | } |
— | — | @@ -550,8 +566,12 @@ |
551 | 567 | */ |
552 | 568 | public function getShortText( $outputformat, $linker = null ) { |
553 | 569 | switch ( $outputformat ) { |
554 | | - case SMW_OUTPUT_WIKI: return $this->getShortWikiText( $linker ); |
555 | | - case SMW_OUTPUT_HTML: case SMW_OUTPUT_FILE: default: return $this->getShortHTMLText( $linker ); |
| 570 | + case SMW_OUTPUT_WIKI: |
| 571 | + return $this->getShortWikiText( $linker ); |
| 572 | + case SMW_OUTPUT_HTML: |
| 573 | + case SMW_OUTPUT_FILE: |
| 574 | + default: |
| 575 | + return $this->getShortHTMLText( $linker ); |
556 | 576 | } |
557 | 577 | } |
558 | 578 | |
— | — | @@ -565,8 +585,12 @@ |
566 | 586 | */ |
567 | 587 | public function getLongText( $outputformat, $linker = null ) { |
568 | 588 | switch ( $outputformat ) { |
569 | | - case SMW_OUTPUT_WIKI: return $this->getLongWikiText( $linker ); |
570 | | - case SMW_OUTPUT_HTML: case SMW_OUTPUT_FILE: default: return $this->getLongHTMLText( $linker ); |
| 589 | + case SMW_OUTPUT_WIKI: |
| 590 | + return $this->getLongWikiText( $linker ); |
| 591 | + case SMW_OUTPUT_HTML: |
| 592 | + case SMW_OUTPUT_FILE: |
| 593 | + default: |
| 594 | + return $this->getLongHTMLText( $linker ); |
571 | 595 | } |
572 | 596 | } |
573 | 597 | |
— | — | @@ -750,11 +774,18 @@ |
751 | 775 | * Creates an error if the value is illegal. |
752 | 776 | */ |
753 | 777 | protected function checkAllowedValues() { |
754 | | - if ( ( $this->m_property === null ) || ( $this->m_property->getWikiPageValue() === null ) ) return; // no property known |
| 778 | + if ( ( $this->m_property === null ) || ( $this->m_property->getWikiPageValue() === null ) ) { |
| 779 | + return; // no property known |
| 780 | + } |
755 | 781 | |
756 | | - $allowedvalues = smwfGetStore()->getPropertyValues( $this->m_property->getWikiPageValue(), SMWPropertyValue::makeProperty( '_PVAL' ) ); |
| 782 | + $allowedvalues = smwfGetStore()->getPropertyValues( |
| 783 | + $this->m_property->getWikiPageValue(), |
| 784 | + SMWPropertyValue::makeProperty( '_PVAL' ) |
| 785 | + ); |
757 | 786 | |
758 | | - if ( count( $allowedvalues ) == 0 ) return; |
| 787 | + if ( count( $allowedvalues ) == 0 ) { |
| 788 | + return; |
| 789 | + } |
759 | 790 | |
760 | 791 | $hash = $this->getHash(); |
761 | 792 | $value = SMWDataValueFactory::newTypeIDValue( $this->getTypeID() ); |
— | — | @@ -778,7 +809,9 @@ |
779 | 810 | |
780 | 811 | if ( !$accept ) { |
781 | 812 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
782 | | - $this->addError( wfMsgForContent( 'smw_notinenum', $this->getWikiValue(), $valuestring ) ); |
| 813 | + $this->addError( |
| 814 | + wfMsgForContent( 'smw_notinenum', $this->getWikiValue(), $valuestring ) |
| 815 | + ); |
783 | 816 | } |
784 | 817 | } |
785 | 818 | |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Infolink.php |
— | — | @@ -112,7 +112,13 @@ |
113 | 113 | */ |
114 | 114 | public static function newPropertySearchLink( $caption, $propertyName, $propertyValue, $style = 'smwsearch' ) { |
115 | 115 | global $wgContLang; |
116 | | - return new SMWInfolink( true, $caption, $wgContLang->getNsText( NS_SPECIAL ) . ':SearchByProperty', $style, array( $propertyName, $propertyValue ) ); |
| 116 | + return new SMWInfolink( |
| 117 | + true, |
| 118 | + $caption, |
| 119 | + $wgContLang->getNsText( NS_SPECIAL ) . ':SearchByProperty', |
| 120 | + $style, |
| 121 | + array( $propertyName, $propertyValue ) |
| 122 | + ); |
117 | 123 | } |
118 | 124 | |
119 | 125 | /** |
— | — | @@ -121,13 +127,18 @@ |
122 | 128 | * @param string $caption The label for the link. |
123 | 129 | * @param string $subject |
124 | 130 | * @param string $propertyName |
125 | | - * @param mixed $style CSS class of a span to embedd the link into, or false if no extra style is required. |
| 131 | + * @param mixed $style CSS class of a span to embed the link into, or false if no extra style is required. |
126 | 132 | * |
127 | 133 | * @return SMWInfolink |
128 | 134 | */ |
129 | 135 | public static function newInversePropertySearchLink( $caption, $subject, $propertyname, $style = false ) { |
130 | 136 | global $wgContLang; |
131 | | - return new SMWInfolink( true, $caption, $wgContLang->getNsText( NS_SPECIAL ) . ':PageProperty/' . $subject . '::' . $propertyname, $style ); |
| 137 | + return new SMWInfolink( |
| 138 | + true, |
| 139 | + $caption, |
| 140 | + $wgContLang->getNsText( NS_SPECIAL ) . ':PageProperty/' . $subject . '::' . $propertyname, |
| 141 | + $style |
| 142 | + ); |
132 | 143 | } |
133 | 144 | |
134 | 145 | /** |
— | — | @@ -141,7 +152,13 @@ |
142 | 153 | */ |
143 | 154 | public static function newBrowsingLink( $caption, $titleText, $style = 'smwbrowse' ) { |
144 | 155 | global $wgContLang; |
145 | | - return new SMWInfolink( true, $caption, $wgContLang->getNsText( NS_SPECIAL ) . ':Browse', $style, array( $titleText ) ); |
| 156 | + return new SMWInfolink( |
| 157 | + true, |
| 158 | + $caption, |
| 159 | + $wgContLang->getNsText( NS_SPECIAL ) . ':Browse', |
| 160 | + $style, |
| 161 | + array( $titleText ) |
| 162 | + ); |
146 | 163 | } |
147 | 164 | |
148 | 165 | /** |
— | — | @@ -225,9 +242,13 @@ |
226 | 243 | |
227 | 244 | if ( $title !== null ) { |
228 | 245 | if ( $outputformat == SMW_OUTPUT_WIKI ) { |
229 | | - $link = "[" . $title->getFullURL( SMWInfolink::encodeParameters( $this->mParams, false ) ) . " $this->mCaption]"; |
| 246 | + $link = '[' . $title->getFullURL( SMWInfolink::encodeParameters( $this->mParams, false ) ) . " $this->mCaption]"; |
230 | 247 | } else { // SMW_OUTPUT_HTML, SMW_OUTPUT_FILE |
231 | | - $link = $this->getLinker( $linker )->makeKnownLinkObj( $title, $this->mCaption, SMWInfolink::encodeParameters( $this->mParams, false ) ); |
| 248 | + $link = $this->getLinker( $linker )->makeKnownLinkObj( |
| 249 | + $title, |
| 250 | + $this->mCaption, |
| 251 | + SMWInfolink::encodeParameters( $this->mParams, false ) |
| 252 | + ); |
232 | 253 | } |
233 | 254 | } else { |
234 | 255 | return ''; // the title was bad, normally this would indicate a software bug |
— | — | @@ -239,7 +260,7 @@ |
240 | 261 | if ( $outputformat == SMW_OUTPUT_WIKI ) { |
241 | 262 | $link = "[$target $this->mCaption]"; |
242 | 263 | } else { // SMW_OUTPUT_HTML, SMW_OUTPUT_FILE |
243 | | - $link = "<a href=\"" . htmlspecialchars( $target ) . "\">$this->mCaption</a>"; |
| 264 | + $link = '<a href="' . htmlspecialchars( $target ) . "\">$this->mCaption</a>"; |
244 | 265 | } |
245 | 266 | } |
246 | 267 | |
— | — | @@ -304,7 +325,9 @@ |
305 | 326 | * @return Linker |
306 | 327 | */ |
307 | 328 | protected function getLinker( &$linker = null ) { |
308 | | - if ( $linker === null ) $linker = new Linker(); |
| 329 | + if ( $linker === null ) { |
| 330 | + $linker = new Linker(); |
| 331 | + } |
309 | 332 | return $linker; |
310 | 333 | } |
311 | 334 | |
— | — | @@ -330,7 +353,9 @@ |
331 | 354 | |
332 | 355 | if ( $forTitle ) { |
333 | 356 | foreach ( $params as $name => $value ) { |
334 | | - if ( is_string( $name ) && ( $name != '' ) ) $value = $name . '=' . $value; |
| 357 | + if ( is_string( $name ) && ( $name != '' ) ) { |
| 358 | + $value = $name . '=' . $value; |
| 359 | + } |
335 | 360 | // Escape certain problematic values. Use SMW-escape |
336 | 361 | // (like URLencode but - instead of % to prevent double encoding by later MW actions) |
337 | 362 | // |
— | — | @@ -355,7 +380,9 @@ |
356 | 381 | $value |
357 | 382 | ); |
358 | 383 | |
359 | | - if ( $result != '' ) $result .= '/'; |
| 384 | + if ( $result != '' ) { |
| 385 | + $result .= '/'; |
| 386 | + } |
360 | 387 | |
361 | 388 | $result .= $value; |
362 | 389 | } |
— | — | @@ -366,7 +393,9 @@ |
367 | 394 | if ( is_string( $name ) && ( $name != '' ) ) { |
368 | 395 | $value = $name . '=' . rawurlencode( $value ); |
369 | 396 | |
370 | | - if ( $result != '' ) $result .= '&'; |
| 397 | + if ( $result != '' ) { |
| 398 | + $result .= '&'; |
| 399 | + } |
371 | 400 | |
372 | 401 | $result .= $value; |
373 | 402 | } else { |
— | — | @@ -374,7 +403,9 @@ |
375 | 404 | } |
376 | 405 | } |
377 | 406 | if ( count( $q ) > 0 ) { // prepend encoding for unlabelled parameters |
378 | | - if ( $result != '' ) $result = '&' . $result; |
| 407 | + if ( $result != '' ) { |
| 408 | + $result = '&' . $result; |
| 409 | + } |
379 | 410 | $result = 'x=' . rawurlencode( SMWInfolink::encodeParameters( $q, true ) ) . $result; |
380 | 411 | } |
381 | 412 | } |
— | — | @@ -414,7 +445,9 @@ |
415 | 446 | $result = $wgRequest->getValues(); |
416 | 447 | |
417 | 448 | if ( array_key_exists( 'x', $result ) ) { // Considered to be part of the title param. |
418 | | - if ( $titleParam != '' ) $titleParam .= '/'; |
| 449 | + if ( $titleParam != '' ) { |
| 450 | + $titleParam .= '/'; |
| 451 | + } |
419 | 452 | $titleParam .= $result['x']; |
420 | 453 | unset( $result['x'] ); |
421 | 454 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php |
— | — | @@ -22,24 +22,30 @@ |
23 | 23 | |
24 | 24 | protected $m_params; |
25 | 25 | |
26 | | - /** Text to print *before* the output in case it is *not* empty; assumed to be wikitext. |
27 | | - * Normally this is handled in SMWResultPrinter and can be ignored by subclasses. */ |
| 26 | + /** |
| 27 | + * Text to print *before* the output in case it is *not* empty; assumed to be wikitext. |
| 28 | + * Normally this is handled in SMWResultPrinter and can be ignored by subclasses. |
| 29 | + */ |
28 | 30 | protected $mIntro = ''; |
29 | 31 | |
30 | | - /** Text to print *after* the output in case it is *not* empty; assumed to be wikitext. |
31 | | - * Normally this is handled in SMWResultPrinter and can be ignored by subclasses. */ |
| 32 | + /** |
| 33 | + * Text to print *after* the output in case it is *not* empty; assumed to be wikitext. |
| 34 | + * Normally this is handled in SMWResultPrinter and can be ignored by subclasses. |
| 35 | + */ |
32 | 36 | protected $mOutro = ''; |
33 | 37 | |
34 | | - /** Text to use for link to further results, or empty if link should not be shown. |
35 | | - * Unescaped! Use SMWResultPrinter::getSearchLabel() and SMWResultPrinter::linkFurtherResults() |
36 | | - * instead of accessing this directly. */ |
| 38 | + /** |
| 39 | + * Text to use for link to further results, or empty if link should not be shown. |
| 40 | + * Unescaped! Use SMWResultPrinter::getSearchLabel() and SMWResultPrinter::linkFurtherResults() |
| 41 | + * instead of accessing this directly. |
| 42 | + */ |
37 | 43 | protected $mSearchlabel = null; |
38 | 44 | |
39 | 45 | /** Default return value for empty queries. Unescaped. Normally not used in sub-classes! */ |
40 | 46 | protected $mDefault = ''; |
41 | 47 | |
42 | 48 | // parameters relevant for printers in general: |
43 | | - protected $mFormat; // a string identifier describing a valid format |
| 49 | + protected $mFormat; // a string identifier describing a valid format |
44 | 50 | protected $mLinkFirst; // should article names of the first column be linked? |
45 | 51 | protected $mLinkOthers; // should article names of other columns (besides the first) be linked? |
46 | 52 | protected $mShowHeaders = SMW_HEADERS_SHOW; // should the headers (property names) be printed? |
— | — | @@ -74,8 +80,8 @@ |
75 | 81 | * Return serialised results in specified format. |
76 | 82 | * Implemented by subclasses. |
77 | 83 | */ |
78 | | - abstract protected function getResultText( /* SMWQueryResult */ $res, $outputmode ); |
79 | | - |
| 84 | + abstract protected function getResultText( /* SMWQueryResult */ $res, $outputmode ); |
| 85 | + |
80 | 86 | /** |
81 | 87 | * Constructor. The parameter $format is a format string |
82 | 88 | * that may influence the processing details. |
— | — | @@ -113,66 +119,66 @@ |
114 | 120 | * effectively can get down to level 3. The basic maximal depth of 2 can be changed by setting the |
115 | 121 | * variable SMWResultPrinter::$maxRecursionDepth (in LocalSettings.php, after enableSemantics()). |
116 | 122 | * Do this at your own risk. |
117 | | - * |
| 123 | + * |
118 | 124 | * @param SMWQueryResult $results |
119 | 125 | * @param array $params |
120 | 126 | * @param $outputmode |
121 | | - * |
| 127 | + * |
122 | 128 | * @return string |
123 | 129 | */ |
124 | 130 | public function getResult( $results, $params, $outputmode ) { |
125 | 131 | global $wgParser; |
126 | | - |
| 132 | + |
127 | 133 | $this->isHTML = false; |
128 | 134 | $this->hasTemplates = false; |
129 | 135 | $this->readParameters( $params, $outputmode ); |
130 | 136 | |
131 | 137 | // Default output for normal printers: |
132 | 138 | if ( ( $outputmode != SMW_OUTPUT_FILE ) && // not in FILE context, |
133 | | - ( $results->getCount() == 0 ) && // no results, |
134 | | - ( $this->getMimeType( $results ) === false ) ) { // normal printer -> take over processing |
| 139 | + ( $results->getCount() == 0 ) && // no results, |
| 140 | + ( $this->getMimeType( $results ) === false ) ) { // normal printer -> take over processing |
135 | 141 | if ( !$results->hasFurtherResults() ) { |
136 | 142 | return $this->escapeText( $this->mDefault, $outputmode ) . $this->getErrorString( $results ); |
137 | 143 | } elseif ( $this->mInline ) { |
138 | 144 | $label = $this->mSearchlabel; |
139 | | - |
| 145 | + |
140 | 146 | if ( $label === null ) { // apply defaults |
141 | 147 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
142 | 148 | $label = wfMsgForContent( 'smw_iq_moreresults' ); |
143 | 149 | } |
144 | | - |
| 150 | + |
145 | 151 | if ( $label != '' ) { |
146 | 152 | $link = $results->getQueryLink( $this->escapeText( $label, $outputmode ) ); |
147 | 153 | $result = $link->getText( $outputmode, $this->mLinker ); |
148 | 154 | } else { |
149 | 155 | $result = ''; |
150 | 156 | } |
151 | | - |
| 157 | + |
152 | 158 | $result .= $this->getErrorString( $results ); |
153 | | - |
| 159 | + |
154 | 160 | return $result; |
155 | 161 | } |
156 | 162 | } |
157 | 163 | |
158 | 164 | // Get output from printer: |
159 | 165 | $result = $this->getResultText( $results, $outputmode ); |
160 | | - |
| 166 | + |
161 | 167 | if ( $outputmode == SMW_OUTPUT_FILE ) { // just return result in file mode |
162 | 168 | return $result; |
163 | 169 | } |
164 | | - |
| 170 | + |
165 | 171 | $result .= $this->getErrorString( $results ); // append errors |
166 | | - |
| 172 | + |
167 | 173 | if ( ( !$this->isHTML ) && ( $this->hasTemplates ) ) { // preprocess embedded templates if needed |
168 | 174 | if ( ( $wgParser->getTitle() instanceof Title ) && ( $wgParser->getOptions() instanceof ParserOptions ) ) { |
169 | 175 | SMWResultPrinter::$mRecursionDepth++; |
170 | | - |
| 176 | + |
171 | 177 | if ( SMWResultPrinter::$mRecursionDepth <= SMWResultPrinter::$maxRecursionDepth ) { // restrict recursion |
172 | 178 | $result = '[[SMW::off]]' . $wgParser->replaceVariables( $result ) . '[[SMW::on]]'; |
173 | 179 | } else { |
174 | 180 | $result = ''; /// TODO: explain problem (too much recursive parses) |
175 | 181 | } |
176 | | - |
| 182 | + |
177 | 183 | SMWResultPrinter::$mRecursionDepth--; |
178 | 184 | } else { // not during parsing, no preprocessing needed, still protect the result |
179 | 185 | $result = '[[SMW::off]]' . $result . '[[SMW::on]]'; |
— | — | @@ -183,18 +189,18 @@ |
184 | 190 | $result = array( $result, 'isHTML' => true ); |
185 | 191 | } elseif ( ( !$this->isHTML ) && ( $outputmode == SMW_OUTPUT_HTML ) ) { |
186 | 192 | SMWResultPrinter::$mRecursionDepth++; |
187 | | - |
| 193 | + |
188 | 194 | // check whether we are in an existing parse, or if we should start a new parse for $wgTitle |
189 | 195 | if ( SMWResultPrinter::$mRecursionDepth <= SMWResultPrinter::$maxRecursionDepth ) { // retrict recursion |
190 | 196 | if ( ( $wgParser->getTitle() instanceof Title ) && ( $wgParser->getOptions() instanceof ParserOptions ) ) { |
191 | 197 | $result = $wgParser->recursiveTagParse( $result ); |
192 | 198 | } else { |
193 | 199 | global $wgTitle; |
194 | | - |
| 200 | + |
195 | 201 | $popt = new ParserOptions(); |
196 | 202 | $popt->setEditSection( false ); |
197 | 203 | $pout = $wgParser->parse( $result . '__NOTOC__', $wgTitle, $popt ); |
198 | | - |
| 204 | + |
199 | 205 | /// NOTE: as of MW 1.14SVN, there is apparently no better way to hide the TOC |
200 | 206 | SMWOutputs::requireFromParserOutput( $pout ); |
201 | 207 | $result = $pout->getText(); |
— | — | @@ -202,7 +208,7 @@ |
203 | 209 | } else { |
204 | 210 | $result = ''; /// TODO: explain problem (too much recursive parses) |
205 | 211 | } |
206 | | - |
| 212 | + |
207 | 213 | SMWResultPrinter::$mRecursionDepth--; |
208 | 214 | } |
209 | 215 | |
— | — | @@ -231,46 +237,46 @@ |
232 | 238 | * Read an array of parameter values given as key-value-pairs and |
233 | 239 | * initialise internal member fields accordingly. Possibly overwritten |
234 | 240 | * (extended) by subclasses. |
235 | | - * |
| 241 | + * |
236 | 242 | * @param array $params |
237 | 243 | * @param $outputmode |
238 | 244 | */ |
239 | 245 | protected function readParameters( /* array */ $params, $outputmode ) { |
240 | 246 | $this->m_params = $params; |
241 | | - |
| 247 | + |
242 | 248 | if ( array_key_exists( 'intro', $params ) ) { |
243 | 249 | $this->mIntro = str_replace( '_', ' ', $params['intro'] ); |
244 | 250 | } |
245 | | - |
| 251 | + |
246 | 252 | if ( array_key_exists( 'outro', $params ) ) { |
247 | 253 | $this->mOutro = str_replace( '_', ' ', $params['outro'] ); |
248 | 254 | } |
249 | | - |
| 255 | + |
250 | 256 | if ( array_key_exists( 'searchlabel', $params ) ) { |
251 | 257 | $this->mSearchlabel = $params['searchlabel']; |
252 | 258 | } |
253 | | - |
| 259 | + |
254 | 260 | if ( array_key_exists( 'link', $params ) ) { |
255 | 261 | switch ( strtolower( trim( $params['link'] ) ) ) { |
256 | 262 | case 'head': case 'subject': |
257 | 263 | $this->mLinkFirst = true; |
258 | | - $this->mLinkOthers = false; |
| 264 | + $this->mLinkOthers = false; |
259 | 265 | break; |
260 | 266 | case 'all': |
261 | 267 | $this->mLinkFirst = true; |
262 | | - $this->mLinkOthers = true; |
| 268 | + $this->mLinkOthers = true; |
263 | 269 | break; |
264 | 270 | case 'none': |
265 | 271 | $this->mLinkFirst = false; |
266 | | - $this->mLinkOthers = false; |
| 272 | + $this->mLinkOthers = false; |
267 | 273 | break; |
268 | 274 | } |
269 | 275 | } |
270 | | - |
| 276 | + |
271 | 277 | if ( array_key_exists( 'default', $params ) ) { |
272 | 278 | $this->mDefault = str_replace( '_', ' ', $params['default'] ); |
273 | 279 | } |
274 | | - |
| 280 | + |
275 | 281 | if ( array_key_exists( 'headers', $params ) ) { |
276 | 282 | if ( strtolower( trim( $params['headers'] ) ) == 'hide' ) { |
277 | 283 | $this->mShowHeaders = SMW_HEADERS_HIDE; |
— | — | @@ -346,7 +352,7 @@ |
347 | 353 | * refer to messages here. The format name is normally not used in |
348 | 354 | * wiki text but only in forms etc. hence the user language should be |
349 | 355 | * used when retrieving messages. |
350 | | - * |
| 356 | + * |
351 | 357 | * @return string |
352 | 358 | */ |
353 | 359 | public function getName() { |
— | — | @@ -357,7 +363,7 @@ |
358 | 364 | * Provides a simple formatted string of all the error messages that occurred. |
359 | 365 | * Can be used if not specific error formatting is desired. Compatible with HTML |
360 | 366 | * and Wiki. |
361 | | - * |
| 367 | + * |
362 | 368 | * @return string |
363 | 369 | */ |
364 | 370 | public function getErrorString( $res ) { |
— | — | @@ -366,7 +372,7 @@ |
367 | 373 | |
368 | 374 | /** |
369 | 375 | * Set whether errors should be shown. By default they are. |
370 | | - * |
| 376 | + * |
371 | 377 | * @param boolean $show |
372 | 378 | */ |
373 | 379 | public function setShowErrors( $show ) { |
— | — | @@ -376,7 +382,7 @@ |
377 | 383 | /** |
378 | 384 | * If $outputmode is SMW_OUTPUT_HTML, escape special characters occuring in the |
379 | 385 | * given text. Otherwise return text as is. |
380 | | - * |
| 386 | + * |
381 | 387 | * @return string |
382 | 388 | */ |
383 | 389 | protected function escapeText( $text, $outputmode ) { |
— | — | @@ -386,7 +392,7 @@ |
387 | 393 | /** |
388 | 394 | * Get the string the user specified as a text for the "further results" link, |
389 | 395 | * properly escaped for the current output mode. |
390 | | - * |
| 396 | + * |
391 | 397 | * @return string |
392 | 398 | */ |
393 | 399 | protected function getSearchLabel( $outputmode ) { |
— | — | @@ -397,7 +403,7 @@ |
398 | 404 | * Check whether a "further results" link would normally be generated for this |
399 | 405 | * result set with the given parameters. Individual result printers may decide to |
400 | 406 | * create or hide such a link independent of that, but this is the default. |
401 | | - * |
| 407 | + * |
402 | 408 | * @return boolean |
403 | 409 | */ |
404 | 410 | protected function linkFurtherResults( $results ) { |
— | — | @@ -408,9 +414,9 @@ |
409 | 415 | * Return an array describing the parameters of specifically text-based |
410 | 416 | * formats, like 'list' and 'table', for use in their getParameters() |
411 | 417 | * functions |
412 | | - * |
| 418 | + * |
413 | 419 | * @since 1.5.0 |
414 | | - * |
| 420 | + * |
415 | 421 | * @return array |
416 | 422 | */ |
417 | 423 | protected function textDisplayParameters() { |
— | — | @@ -424,9 +430,9 @@ |
425 | 431 | /** |
426 | 432 | * Return an array describing the parameters of the export formats |
427 | 433 | * like 'rss' and 'csv', for use in their getParameters() functions |
428 | | - * |
| 434 | + * |
429 | 435 | * @since 1.5.0 |
430 | | - * |
| 436 | + * |
431 | 437 | * @return array |
432 | 438 | */ |
433 | 439 | protected function exportFormatParameters() { |
— | — | @@ -442,9 +448,9 @@ |
443 | 449 | * A function to describe the allowed parameters of a query using |
444 | 450 | * any specific format - most query printers should override this |
445 | 451 | * function |
446 | | - * |
| 452 | + * |
447 | 453 | * @since 1.5.0 |
448 | | - * |
| 454 | + * |
449 | 455 | * @return array |
450 | 456 | */ |
451 | 457 | public function getParameters() { |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ParserExtensions.php |
— | — | @@ -21,19 +21,19 @@ |
22 | 22 | protected static $mTempStoreAnnotations; |
23 | 23 | |
24 | 24 | /** |
25 | | - * This method will be called before an article is displayed or previewed. |
26 | | - * For display and preview we strip out the semantic properties and append them |
27 | | - * at the end of the article. |
28 | | - * |
29 | | - * @param Parser $parser |
30 | | - * @param string $text |
| 25 | + * This method will be called before an article is displayed or previewed. |
| 26 | + * For display and preview we strip out the semantic properties and append them |
| 27 | + * at the end of the article. |
| 28 | + * |
| 29 | + * @param Parser $parser |
| 30 | + * @param string $text |
31 | 31 | */ |
32 | 32 | static public function onInternalParseBeforeLinks( &$parser, &$text ) { |
33 | 33 | global $smwgStoreAnnotations, $smwgLinksInValues; |
34 | | - |
| 34 | + |
35 | 35 | SMWParseData::stripMagicWords( $text, $parser ); |
36 | | - |
37 | | - // Store the results if enabled (we have to parse them in any case, |
| 36 | + |
| 37 | + // Store the results if enabled (we have to parse them in any case, |
38 | 38 | // in order to clean the wiki source for further processing). |
39 | 39 | $smwgStoreAnnotations = smwfIsSemanticsProcessed( $parser->getTitle()->getNamespace() ); |
40 | 40 | SMWParserExtensions::$mTempStoreAnnotations = true; // used for [[SMW::on]] and [[SMW:off]] |
— | — | @@ -43,7 +43,7 @@ |
44 | 44 | if ( $rt !== null ) { |
45 | 45 | $p = SMWPropertyValue::makeProperty( '_REDI' ); |
46 | 46 | $dv = SMWDataValueFactory::newPropertyObjectValue( $p, $rt->getPrefixedText() ); |
47 | | - |
| 47 | + |
48 | 48 | if ( $smwgStoreAnnotations ) { |
49 | 49 | SMWParseData::getSMWData( $parser )->addPropertyObjectValue( $p, $dv ); |
50 | 50 | } |
— | — | @@ -51,7 +51,7 @@ |
52 | 52 | |
53 | 53 | // only used in subsequent callbacks, forgotten afterwards |
54 | 54 | SMWParserExtensions::$mTempParser = $parser; |
55 | | - |
| 55 | + |
56 | 56 | // In the regexp matches below, leading ':' escapes the markup, as known for Categories. |
57 | 57 | // Parse links to extract semantic properties. |
58 | 58 | if ( $smwgLinksInValues ) { // More complex regexp -- lib PCRE may cause segfaults if text is long :-( |
— | — | @@ -99,7 +99,7 @@ |
100 | 100 | static public function simpleParsePropertiesCallback( $semanticLink ) { |
101 | 101 | $value = ''; |
102 | 102 | $caption = false; |
103 | | - |
| 103 | + |
104 | 104 | if ( array_key_exists( 2, $semanticLink ) ) { |
105 | 105 | $parts = explode( '|', $semanticLink[2] ); |
106 | 106 | if ( array_key_exists( 0, $parts ) ) { |
— | — | @@ -109,7 +109,7 @@ |
110 | 110 | $caption = $parts[1]; |
111 | 111 | } |
112 | 112 | } |
113 | | - |
| 113 | + |
114 | 114 | if ( $caption !== false ) { |
115 | 115 | return SMWParserExtensions::parsePropertiesCallback( array( $semanticLink[0], $semanticLink[1], $value, $caption ) ); |
116 | 116 | } else { |
— | — | @@ -123,21 +123,21 @@ |
124 | 124 | */ |
125 | 125 | static public function parsePropertiesCallback( $semanticLink ) { |
126 | 126 | global $smwgInlineErrors, $smwgStoreAnnotations; |
127 | | - |
| 127 | + |
128 | 128 | wfProfileIn( 'smwfParsePropertiesCallback (SMW)' ); |
129 | | - |
| 129 | + |
130 | 130 | if ( array_key_exists( 1, $semanticLink ) ) { |
131 | 131 | $property = $semanticLink[1]; |
132 | 132 | } else { |
133 | 133 | $property = ''; |
134 | 134 | } |
135 | | - |
| 135 | + |
136 | 136 | if ( array_key_exists( 2, $semanticLink ) ) { |
137 | 137 | $value = $semanticLink[2]; |
138 | 138 | } else { |
139 | 139 | $value = ''; |
140 | 140 | } |
141 | | - |
| 141 | + |
142 | 142 | if ( $value == '' ) { // silently ignore empty values |
143 | 143 | wfProfileOut( 'smwfParsePropertiesCallback (SMW)' ); |
144 | 144 | return ''; |
— | — | @@ -164,19 +164,19 @@ |
165 | 165 | |
166 | 166 | // Extract annotations and create tooltip. |
167 | 167 | $properties = preg_split( '/:[=:]/u', $property ); |
168 | | - |
| 168 | + |
169 | 169 | foreach ( $properties as $singleprop ) { |
170 | 170 | $dv = SMWParseData::addProperty( $singleprop, $value, $valueCaption, SMWParserExtensions::$mTempParser, $smwgStoreAnnotations && SMWParserExtensions::$mTempStoreAnnotations ); |
171 | 171 | } |
172 | | - |
| 172 | + |
173 | 173 | $result = $dv->getShortWikitext( true ); |
174 | | - |
| 174 | + |
175 | 175 | if ( ( $smwgInlineErrors && $smwgStoreAnnotations && SMWParserExtensions::$mTempStoreAnnotations ) && ( !$dv->isValid() ) ) { |
176 | 176 | $result .= $dv->getErrorText(); |
177 | 177 | } |
178 | | - |
| 178 | + |
179 | 179 | wfProfileOut( 'smwfParsePropertiesCallback (SMW)' ); |
180 | | - |
| 180 | + |
181 | 181 | return $result; |
182 | 182 | } |
183 | 183 | |
— | — | @@ -192,11 +192,11 @@ |
193 | 193 | $parser->setFunctionHook( 'concept', array( 'SMWParserExtensions', 'doConcept' ) ); |
194 | 194 | $parser->setFunctionHook( 'set', array( 'SMWParserExtensions', 'doSet' ) ); |
195 | 195 | $parser->setFunctionHook( 'set_recurring_event', array( 'SMWParserExtensions', 'doSetRecurringEvent' ) ); |
196 | | - |
| 196 | + |
197 | 197 | if ( defined( 'SFH_OBJECT_ARGS' ) ) { // only available since MediaWiki 1.13 |
198 | 198 | $parser->setFunctionHook( 'declare', array( 'SMWParserExtensions', 'doDeclare' ), SFH_OBJECT_ARGS ); |
199 | 199 | } |
200 | | - |
| 200 | + |
201 | 201 | return true; // Always return true, in order not to stop MW's hook processing! |
202 | 202 | } |
203 | 203 | |
— | — | @@ -206,21 +206,21 @@ |
207 | 207 | */ |
208 | 208 | static public function doAsk( &$parser ) { |
209 | 209 | global $smwgQEnabled, $smwgIQRunningNumber; |
210 | | - |
| 210 | + |
211 | 211 | if ( $smwgQEnabled ) { |
212 | 212 | $smwgIQRunningNumber++; |
213 | | - |
| 213 | + |
214 | 214 | $params = func_get_args(); |
215 | 215 | array_shift( $params ); // We already know the $parser ... |
216 | | - |
| 216 | + |
217 | 217 | $result = SMWQueryProcessor::getResultFromFunctionParams( $params, SMW_OUTPUT_WIKI ); |
218 | 218 | } else { |
219 | 219 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
220 | 220 | $result = smwfEncodeMessages( array( wfMsgForContent( 'smw_iq_disabled' ) ) ); |
221 | 221 | } |
222 | | - |
| 222 | + |
223 | 223 | SMWOutputs::commitToParser( $parser ); |
224 | | - |
| 224 | + |
225 | 225 | return $result; |
226 | 226 | } |
227 | 227 | |
— | — | @@ -230,19 +230,19 @@ |
231 | 231 | */ |
232 | 232 | static public function doShow( &$parser ) { |
233 | 233 | global $smwgQEnabled, $smwgIQRunningNumber; |
234 | | - |
| 234 | + |
235 | 235 | if ( $smwgQEnabled ) { |
236 | 236 | $smwgIQRunningNumber++; |
237 | | - |
| 237 | + |
238 | 238 | $params = func_get_args(); |
239 | 239 | array_shift( $params ); // We already know the $parser ... |
240 | | - |
| 240 | + |
241 | 241 | $result = SMWQueryProcessor::getResultFromFunctionParams( $params, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY, true ); |
242 | 242 | } else { |
243 | 243 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
244 | 244 | $result = smwfEncodeMessages( array( wfMsgForContent( 'smw_iq_disabled' ) ) ); |
245 | 245 | } |
246 | | - |
| 246 | + |
247 | 247 | SMWOutputs::commitToParser( $parser ); |
248 | 248 | return $result; |
249 | 249 | } |
— | — | @@ -253,12 +253,12 @@ |
254 | 254 | */ |
255 | 255 | static public function doConcept( &$parser ) { |
256 | 256 | global $smwgQDefaultNamespaces, $smwgQMaxSize, $smwgQMaxDepth, $wgContLang; |
257 | | - |
| 257 | + |
258 | 258 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
259 | | - |
| 259 | + |
260 | 260 | $title = $parser->getTitle(); |
261 | 261 | $pconc = SMWPropertyValue::makeProperty( '_CONC' ); |
262 | | - |
| 262 | + |
263 | 263 | if ( $title->getNamespace() != SMW_NS_CONCEPT ) { |
264 | 264 | $result = smwfEncodeMessages( array( wfMsgForContent( 'smw_no_concept_namespace' ) ) ); |
265 | 265 | SMWOutputs::commitToParser( $parser ); |
— | — | @@ -272,20 +272,20 @@ |
273 | 273 | // process input: |
274 | 274 | $params = func_get_args(); |
275 | 275 | array_shift( $params ); // We already know the $parser ... |
276 | | - |
| 276 | + |
277 | 277 | // Use first parameter as concept (query) string. |
278 | 278 | $concept_input = str_replace( array( '>', '<' ), array( '>', '<' ), array_shift( $params ) ); |
279 | | - |
| 279 | + |
280 | 280 | // second parameter, if any, might be a description |
281 | 281 | $concept_docu = array_shift( $params ); |
282 | | - |
| 282 | + |
283 | 283 | // NOTE: the str_replace above is required in MediaWiki 1.11, but not in MediaWiki 1.14 |
284 | 284 | $query = SMWQueryProcessor::createQuery( $concept_input, array( 'limit' => 20, 'format' => 'list' ), SMWQueryProcessor::CONCEPT_DESC ); |
285 | 285 | $concept_text = $query->getDescription()->getQueryString(); |
286 | 286 | |
287 | 287 | $dv = SMWDataValueFactory::newPropertyObjectValue( $pconc ); |
288 | 288 | $dv->setValues( $concept_text, $concept_docu, $query->getDescription()->getQueryFeatures(), $query->getDescription()->getSize(), $query->getDescription()->getDepth() ); |
289 | | - |
| 289 | + |
290 | 290 | if ( SMWParseData::getSMWData( $parser ) !== null ) { |
291 | 291 | SMWParseData::getSMWData( $parser )->addPropertyObjectValue( $pconc, $dv ); |
292 | 292 | } |
— | — | @@ -300,7 +300,7 @@ |
301 | 301 | '</span>' . '<span class="smwrdflink">' . $rdflink->getWikiText() . '</span>' . '<br />' . |
302 | 302 | ( $concept_docu ? "<p>$concept_docu</p>" : '' ) . |
303 | 303 | '<pre>' . str_replace( '[', '[', $concept_text ) . "</pre>\n</div>"; |
304 | | - |
| 304 | + |
305 | 305 | SMWOutputs::commitToParser( $parser ); |
306 | 306 | return $result; |
307 | 307 | } |
— | — | @@ -313,10 +313,10 @@ |
314 | 314 | static public function doInfo( &$parser ) { |
315 | 315 | $params = func_get_args(); |
316 | 316 | array_shift( $params ); // We already know the $parser ... |
317 | | - |
| 317 | + |
318 | 318 | $content = array_shift( $params ); // Use only first parameter, ignore the rest (may get meaning later). |
319 | 319 | $result = smwfEncodeMessages( array( $content ), 'info' ); |
320 | | - |
| 320 | + |
321 | 321 | SMWOutputs::commitToParser( $parser ); |
322 | 322 | return $result; |
323 | 323 | } |
— | — | @@ -331,27 +331,27 @@ |
332 | 332 | * | area = 396 km² |
333 | 333 | * | sea = Adria |
334 | 334 | * }} |
335 | | - * |
| 335 | + * |
336 | 336 | * This creates annotations with the properties as stated on the left side, and the |
337 | 337 | * values on the right side. |
338 | 338 | * |
339 | 339 | * @param Parser &$parser The current parser |
340 | | - * |
| 340 | + * |
341 | 341 | * @return empty string |
342 | 342 | */ |
343 | 343 | static public function doSet( &$parser ) { |
344 | 344 | $params = func_get_args(); |
345 | 345 | array_shift( $params ); // We already know the $parser ... |
346 | | - |
| 346 | + |
347 | 347 | foreach ( $params as $param ) { |
348 | 348 | $parts = explode( '=', trim( $param ), 2 ); |
349 | | - |
| 349 | + |
350 | 350 | // Only add the property when there is both a name and a value. |
351 | 351 | if ( count( $parts ) == 2 ) { |
352 | 352 | SMWParseData::addProperty( $parts[0], $parts[1], false, $parser, true ); |
353 | 353 | } |
354 | 354 | } |
355 | | - |
| 355 | + |
356 | 356 | SMWOutputs::commitToParser( $parser ); // not obviously required, but let us be sure |
357 | 357 | return ''; |
358 | 358 | } |
— | — | @@ -375,84 +375,91 @@ |
376 | 376 | // Set values from the parameters. |
377 | 377 | foreach ( $params as $param ) { |
378 | 378 | $parts = explode( '=', trim( $param ) ); |
379 | | - |
380 | | - if ( count( $parts ) != 2 ) continue; |
381 | | - |
| 379 | + |
| 380 | + if ( count( $parts ) != 2 ) { |
| 381 | + continue; |
| 382 | + } |
| 383 | + |
382 | 384 | list( $name, $value ) = $parts; |
383 | | - |
| 385 | + |
384 | 386 | switch( $name ) { |
385 | | - case 'property' : |
| 387 | + case 'property': |
386 | 388 | $property_name = $value; |
387 | 389 | break; |
388 | | - case 'start' : |
| 390 | + case 'start': |
389 | 391 | $start_date = SMWDataValueFactory::newTypeIDValue( '_dat', $value ); |
390 | 392 | break; |
391 | | - case 'end' : |
| 393 | + case 'end': |
392 | 394 | $end_date = SMWDataValueFactory::newTypeIDValue( '_dat', $value ); |
393 | 395 | break; |
394 | | - case 'unit' : |
| 396 | + case 'unit': |
395 | 397 | $unit = $value; |
396 | 398 | break; |
397 | | - case 'period' : |
| 399 | + case 'period': |
398 | 400 | $period = (int)$value; |
399 | 401 | break; |
400 | | - case 'week number' : |
| 402 | + case 'week number': |
401 | 403 | $week_num = (int)$value; |
402 | 404 | break; |
403 | | - case 'include' : |
| 405 | + case 'include': |
404 | 406 | $included_dates = explode( ';', $value ); |
405 | | - break; |
406 | | - case 'exclude' : |
| 407 | + break; |
| 408 | + case 'exclude': |
407 | 409 | $excluded_dates = explode( ';', $value ); |
408 | | - |
| 410 | + |
409 | 411 | foreach ( $excluded_dates as $date_str ) { |
410 | 412 | $date = SMWDataValueFactory::newTypeIDValue( '_dat', $date_str ); |
411 | 413 | $excluded_dates_jd[] = $date->getValueKey(); |
412 | | - } |
413 | | - break; |
| 414 | + } |
| 415 | + break; |
414 | 416 | default: |
415 | 417 | $unused_params[] = $param; |
416 | 418 | } |
417 | 419 | } |
418 | | - |
| 420 | + |
419 | 421 | // We need at least a property and start date - if either one is null, exit here. |
420 | | - if ( is_null( $property_name ) || is_null( $start_date ) ) return; |
421 | | - |
| 422 | + if ( is_null( $property_name ) || is_null( $start_date ) ) { |
| 423 | + return; |
| 424 | + } |
| 425 | + |
422 | 426 | // If the period is null, or outside of normal bounds, set it to 1. |
423 | | - if ( is_null( $period ) || $period < 1 || $period > 500 ) $period = 1; |
| 427 | + if ( is_null( $period ) || $period < 1 || $period > 500 ) { |
| 428 | + $period = 1; |
| 429 | + } |
424 | 430 | |
425 | 431 | // Handle 'week number', but only if it's of unit 'month'. |
426 | 432 | if ( $unit == 'month' && ! is_null( $week_num ) ) { |
427 | 433 | $unit = 'dayofweekinmonth'; |
428 | | - |
| 434 | + |
429 | 435 | if ( $week_num < -4 || $week_num > 5 || $week_num == 0 ) { |
430 | 436 | $week_num = null; |
431 | 437 | } |
432 | 438 | } |
433 | | - |
434 | | - if ( $unit == 'dayofweekinmonth' && is_null( $week_num ) ) |
435 | | - $week_num = ceil($start_date->getDay() / 7); |
436 | 439 | |
| 440 | + if ( $unit == 'dayofweekinmonth' && is_null( $week_num ) ) { |
| 441 | + $week_num = ceil( $start_date->getDay() / 7 ); |
| 442 | + } |
| 443 | + |
437 | 444 | // Get the Julian day value for both the start and end date. |
438 | 445 | $start_date_jd = $start_date->getValueKey(); |
439 | | - |
| 446 | + |
440 | 447 | if ( !is_null( $end_date ) ) { |
441 | 448 | $end_date_jd = $end_date->getValueKey(); |
442 | 449 | } |
443 | | - |
| 450 | + |
444 | 451 | $cur_date = $start_date; |
445 | 452 | $cur_date_jd = $start_date->getValueKey(); |
446 | 453 | $i = 0; |
447 | 454 | $reached_end_date = false; |
448 | | - |
| 455 | + |
449 | 456 | do { |
450 | 457 | $i++; |
451 | 458 | $exclude_date = ( in_array( $cur_date_jd, $excluded_dates_jd ) ); |
452 | | - |
| 459 | + |
453 | 460 | if ( !$exclude_date ) { |
454 | 461 | $all_date_strings[] = $cur_date->getLongWikiText(); |
455 | 462 | } |
456 | | - |
| 463 | + |
457 | 464 | // Now get the next date. |
458 | 465 | // Handling is different depending on whether it's |
459 | 466 | // month/year or week/day since the latter is a set |
— | — | @@ -462,7 +469,7 @@ |
463 | 470 | $cur_month = $cur_date->getMonth(); |
464 | 471 | $cur_day = $cur_date->getDay(); |
465 | 472 | $cur_time = $cur_date->getTimeString(); |
466 | | - |
| 473 | + |
467 | 474 | if ( $unit == 'year' ) { |
468 | 475 | $cur_year += $period; |
469 | 476 | $display_month = $cur_month; |
— | — | @@ -472,7 +479,7 @@ |
473 | 480 | $cur_month %= 12; |
474 | 481 | $display_month = ( $cur_month == 0 ) ? 12 : $cur_month; |
475 | 482 | } |
476 | | - |
| 483 | + |
477 | 484 | $date_str = "$cur_year-$display_month-$cur_day $cur_time"; |
478 | 485 | $cur_date = SMWDataValueFactory::newTypeIDValue( '_dat', $date_str ); |
479 | 486 | $cur_date_jd = $cur_date->getValueKey(); |
— | — | @@ -480,35 +487,35 @@ |
481 | 488 | // e.g., "3rd Monday of every month" |
482 | 489 | $prev_month = $cur_date->getMonth(); |
483 | 490 | $prev_year = $cur_date->getYear(); |
484 | | - |
| 491 | + |
485 | 492 | $new_month = ( $prev_month + $period ) % 12; |
486 | 493 | if ( $new_month == 0 ) $new_month = 12; |
487 | | - |
| 494 | + |
488 | 495 | $new_year = $prev_year + floor( ( $prev_month + $period - 1 ) / 12 ); |
489 | 496 | $cur_date_jd += ( 28 * $period ) - 7; |
490 | | - |
| 497 | + |
491 | 498 | // We're sometime before the actual date now - |
492 | 499 | // keep incrementing by a week, until we get there. |
493 | 500 | do { |
494 | 501 | $cur_date_jd += 7; |
495 | 502 | $cur_date = SMWDataValueFactory::newTypeIDValue( '_dat', $cur_date_jd ); |
496 | 503 | $right_month = ( $cur_date->getMonth() == $new_month ); |
497 | | - |
| 504 | + |
498 | 505 | if ( $week_num < 0 ) { |
499 | 506 | $next_week_jd = $cur_date_jd; |
500 | | - |
| 507 | + |
501 | 508 | do { |
502 | 509 | $next_week_jd += 7; |
503 | 510 | $next_week_date = SMWDataValueFactory::newTypeIDValue( '_dat', $next_week_jd ); |
504 | 511 | $right_week = ( $next_week_date->getMonth() != $new_month ) || ( $next_week_date->getYear() != $new_year ); |
505 | 512 | } while ( !$right_week ); |
506 | | - |
| 513 | + |
507 | 514 | $cur_date_jd = $next_week_jd + ( 7 * $week_num ); |
508 | 515 | $cur_date = SMWDataValueFactory::newTypeIDValue( '_dat', $cur_date_jd ); |
509 | 516 | } else { |
510 | 517 | $cur_week_num = ceil( $cur_date->getDay() / 7 ); |
511 | 518 | $right_week = ( $cur_week_num == $week_num ); |
512 | | - |
| 519 | + |
513 | 520 | if ( $week_num == 5 && ( $cur_date->getMonth() % 12 == ( $new_month + 1 ) % 12 ) ) { |
514 | 521 | $cur_date_jd -= 7; |
515 | 522 | $cur_date = SMWDataValueFactory::newTypeIDValue( '_dat', $cur_date_jd ); |
— | — | @@ -600,7 +607,7 @@ |
601 | 608 | if ( trim( $arg ) != '' ) { |
602 | 609 | $expanded = trim( $frame->expand( $arg ) ); |
603 | 610 | $parts = explode( '=', $expanded, 2 ); |
604 | | - |
| 611 | + |
605 | 612 | if ( count( $parts ) == 1 ) { |
606 | 613 | $propertystring = $expanded; |
607 | 614 | $argumentname = $expanded; |
— | — | @@ -608,19 +615,19 @@ |
609 | 616 | $propertystring = $parts[0]; |
610 | 617 | $argumentname = $parts[1]; |
611 | 618 | } |
612 | | - |
| 619 | + |
613 | 620 | $property = SMWPropertyValue::makeUserProperty( $propertystring ); |
614 | 621 | $argument = $frame->getArgument( $argumentname ); |
615 | 622 | $valuestring = $frame->expand( $argument ); |
616 | | - |
| 623 | + |
617 | 624 | if ( $property->isValid() ) { |
618 | 625 | $type = $property->getPropertyTypeID(); |
619 | | - |
| 626 | + |
620 | 627 | if ( $type == '_wpg' ) { |
621 | 628 | $matches = array(); |
622 | 629 | preg_match_all( '/\[\[([^\[\]]*)\]\]/', $valuestring, $matches ); |
623 | 630 | $objects = $matches[1]; |
624 | | - |
| 631 | + |
625 | 632 | if ( count( $objects ) == 0 ) { |
626 | 633 | if ( trim( $valuestring ) != '' ) { |
627 | 634 | SMWParseData::addProperty( $propertystring, $valuestring, false, $parser, true ); |
— | — | @@ -635,7 +642,7 @@ |
636 | 643 | SMWParseData::addProperty( $propertystring, $valuestring, false, $parser, true ); |
637 | 644 | } |
638 | 645 | } |
639 | | - |
| 646 | + |
640 | 647 | $value = SMWDataValueFactory::newPropertyObjectValue( $property, $valuestring ); |
641 | 648 | // if (!$value->isValid()) continue; |
642 | 649 | } |
— | — | @@ -643,7 +650,7 @@ |
644 | 651 | } else { |
645 | 652 | // @todo Save as metadata |
646 | 653 | } |
647 | | - |
| 654 | + |
648 | 655 | SMWOutputs::commitToParser( $parser ); // Not obviously required, but let us be sure. |
649 | 656 | return ''; |
650 | 657 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryParser.php |
— | — | @@ -48,36 +48,36 @@ |
49 | 49 | * Compute an SMWDescription from a query string. Returns whatever descriptions could be |
50 | 50 | * wrestled from the given string (the most general result being SMWThingDescription if |
51 | 51 | * no meaningful condition was extracted). |
52 | | - * |
| 52 | + * |
53 | 53 | * @param string $querystring |
54 | | - * |
| 54 | + * |
55 | 55 | * @return SMWDescription |
56 | 56 | */ |
57 | 57 | public function getQueryDescription( $querystring ) { |
58 | 58 | wfProfileIn( 'SMWQueryParser::getQueryDescription (SMW)' ); |
59 | | - |
| 59 | + |
60 | 60 | $this->m_errors = array(); |
61 | 61 | $this->m_curstring = $querystring; |
62 | 62 | $this->m_sepstack = array(); |
63 | 63 | $setNS = false; |
64 | 64 | $result = $this->getSubqueryDescription( $setNS ); |
65 | | - |
| 65 | + |
66 | 66 | if ( !$setNS ) { // add default namespaces if applicable |
67 | 67 | $result = $this->addDescription( $this->m_defaultns, $result ); |
68 | 68 | } |
69 | | - |
| 69 | + |
70 | 70 | if ( $result === null ) { // parsing went wrong, no default namespaces |
71 | 71 | $result = new SMWThingDescription(); |
72 | 72 | } |
73 | | - |
| 73 | + |
74 | 74 | wfProfileOut( 'SMWQueryParser::getQueryDescription (SMW)' ); |
75 | | - |
| 75 | + |
76 | 76 | return $result; |
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
80 | 80 | * Return array of error messages (possibly empty). |
81 | | - * |
| 81 | + * |
82 | 82 | * @return array |
83 | 83 | */ |
84 | 84 | public function getErrors() { |
— | — | @@ -86,7 +86,7 @@ |
87 | 87 | |
88 | 88 | /** |
89 | 89 | * Return error message or empty string if no error occurred. |
90 | | - * |
| 90 | + * |
91 | 91 | * @return string |
92 | 92 | */ |
93 | 93 | public function getErrorString() { |
— | — | @@ -113,22 +113,22 @@ |
114 | 114 | * Note that $setNS is no means to switch on or off default namespaces in general, |
115 | 115 | * but just controls query generation. For general effect, the default namespaces |
116 | 116 | * should be set to NULL. |
117 | | - * |
| 117 | + * |
118 | 118 | * @return SMWDescription or null |
119 | 119 | */ |
120 | 120 | protected function getSubqueryDescription( &$setNS ) { |
121 | 121 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
122 | | - |
| 122 | + |
123 | 123 | $conjunction = null; // used for the current inner conjunction |
124 | 124 | $disjuncts = array(); // (disjunctive) array of subquery conjunctions |
125 | 125 | $hasNamespaces = false; // does the current $conjnuction have its own namespace restrictions? |
126 | | - $mustSetNS = $setNS; // must ns restrictions be set? (may become true even if $setNS is false) |
| 126 | + $mustSetNS = $setNS; // must NS restrictions be set? (may become true even if $setNS is false) |
127 | 127 | |
128 | 128 | $continue = ( $chunk = $this->readChunk() ) != ''; // skip empty subquery completely, thorwing an error |
129 | | - |
| 129 | + |
130 | 130 | while ( $continue ) { |
131 | 131 | $setsubNS = false; |
132 | | - |
| 132 | + |
133 | 133 | switch ( $chunk ) { |
134 | 134 | case '[[': // start new link block |
135 | 135 | $ld = $this->getLinkDescription( $setsubNS ); |
— | — | @@ -140,29 +140,32 @@ |
141 | 141 | $this->pushDelimiter( '</q>' ); |
142 | 142 | $conjunction = $this->addDescription( $conjunction, $this->getSubqueryDescription( $setsubNS ) ); |
143 | 143 | break; |
144 | | - case 'OR': case '||': case '': case '</q>': // finish disjunction and maybe subquery |
| 144 | + case 'OR': |
| 145 | + case '||': |
| 146 | + case '': |
| 147 | + case '</q>': // finish disjunction and maybe subquery |
145 | 148 | if ( $this->m_defaultns !== null ) { // possibly add namespace restrictions |
146 | 149 | if ( $hasNamespaces && !$mustSetNS ) { |
147 | | - // add ns restrictions to all earlier conjunctions (all of which did not have them yet) |
| 150 | + // add NS restrictions to all earlier conjunctions (all of which did not have them yet) |
148 | 151 | $mustSetNS = true; // enforce NS restrictions from now on |
149 | 152 | $newdisjuncts = array(); |
150 | | - |
| 153 | + |
151 | 154 | foreach ( $disjuncts as $conj ) { |
152 | 155 | $newdisjuncts[] = $this->addDescription( $conj, $this->m_defaultns ); |
153 | 156 | } |
154 | | - |
| 157 | + |
155 | 158 | $disjuncts = $newdisjuncts; |
156 | 159 | } elseif ( !$hasNamespaces && $mustSetNS ) { |
157 | 160 | // add ns restriction to current result |
158 | 161 | $conjunction = $this->addDescription( $conjunction, $this->m_defaultns ); |
159 | 162 | } |
160 | 163 | } |
161 | | - |
| 164 | + |
162 | 165 | $disjuncts[] = $conjunction; |
163 | 166 | // start anew |
164 | 167 | $conjunction = null; |
165 | 168 | $hasNamespaces = false; |
166 | | - |
| 169 | + |
167 | 170 | // finish subquery? |
168 | 171 | if ( $chunk == '</q>' ) { |
169 | 172 | if ( $this->popDelimiter( '</q>' ) ) { |
— | — | @@ -181,11 +184,11 @@ |
182 | 185 | $this->m_errors[] = wfMsgForContent( 'smw_unexpectedpart', $chunk ); |
183 | 186 | // return null; // Try to go on, it can only get better ... |
184 | 187 | } |
185 | | - |
| 188 | + |
186 | 189 | if ( $setsubNS ) { // namespace restrictions encountered in current conjunct |
187 | 190 | $hasNamespaces = true; |
188 | 191 | } |
189 | | - |
| 192 | + |
190 | 193 | if ( $continue ) { // read on only if $continue remained true |
191 | 194 | $chunk = $this->readChunk(); |
192 | 195 | } |
— | — | @@ -193,7 +196,7 @@ |
194 | 197 | |
195 | 198 | if ( count( $disjuncts ) > 0 ) { // make disjunctive result |
196 | 199 | $result = null; |
197 | | - |
| 200 | + |
198 | 201 | foreach ( $disjuncts as $d ) { |
199 | 202 | if ( $d === null ) { |
200 | 203 | $this->m_errors[] = wfMsgForContent( 'smw_emptysubquery' ); |
— | — | @@ -208,7 +211,7 @@ |
209 | 212 | $setNS = false; |
210 | 213 | return null; |
211 | 214 | } |
212 | | - |
| 215 | + |
213 | 216 | $setNS = $mustSetNS; // NOTE: also false if namespaces were given but no default NS descs are available |
214 | 217 | |
215 | 218 | return $result; |
— | — | @@ -224,15 +227,15 @@ |
225 | 228 | // This method is called when we encountered an opening '[['. The following |
226 | 229 | // block could be a Category-statement, fixed object, or property statement. |
227 | 230 | $chunk = $this->readChunk( '', true, false ); // NOTE: untrimmed, initial " " escapes prop. chains |
228 | | - |
| 231 | + |
229 | 232 | if ( ( smwfNormalTitleText( $chunk ) == $this->m_categoryprefix ) || // category statement or |
230 | 233 | ( smwfNormalTitleText( $chunk ) == $this->m_conceptprefix ) ) { // concept statement |
231 | 234 | return $this->getClassDescription( $setNS, ( smwfNormalTitleText( $chunk ) == $this->m_categoryprefix ) ); |
232 | 235 | } else { // fixed subject, namespace restriction, property query, or subquery |
233 | 236 | $sep = $this->readChunk( '', false ); // do not consume hit, "look ahead" |
234 | | - |
| 237 | + |
235 | 238 | if ( ( $sep == '::' ) || ( $sep == ':=' ) ) { |
236 | | - if ( $chunk { 0 } != ':' ) { // property statement |
| 239 | + if ( $chunk{0} != ':' ) { // property statement |
237 | 240 | return $this->getPropertyDescription( $chunk, $setNS ); |
238 | 241 | } else { // escaped article description, read part after :: to get full contents |
239 | 242 | $chunk .= $this->readChunk( '\[\[|\]\]|\|\||\|' ); |
— | — | @@ -253,21 +256,21 @@ |
254 | 257 | // note: no subqueries allowed here, inline disjunction allowed, wildcards allowed |
255 | 258 | $result = null; |
256 | 259 | $continue = true; |
257 | | - |
| 260 | + |
258 | 261 | while ( $continue ) { |
259 | 262 | $chunk = $this->readChunk(); |
260 | | - |
| 263 | + |
261 | 264 | if ( $chunk == '+' ) { |
262 | 265 | // wildcard, ignore for categories (semantically meaningless, everything is in some class) |
263 | 266 | } else { // assume category/concept title |
264 | 267 | /// NOTE: use m_c...prefix to prevent problems with, e.g., [[Category:Template:Test]] |
265 | | - $class = Title::newFromText( ( $category ? $this->m_categoryprefix:$this->m_conceptprefix ) . $chunk ); |
| 268 | + $class = Title::newFromText( ( $category ? $this->m_categoryprefix : $this->m_conceptprefix ) . $chunk ); |
266 | 269 | if ( $class !== null ) { |
267 | | - $desc = $category ? new SMWClassDescription( $class ):new SMWConceptDescription( $class ); |
| 270 | + $desc = $category ? new SMWClassDescription( $class ) : new SMWConceptDescription( $class ); |
268 | 271 | $result = $this->addDescription( $result, $desc, false ); |
269 | 272 | } |
270 | 273 | } |
271 | | - |
| 274 | + |
272 | 275 | $chunk = $this->readChunk(); |
273 | 276 | $continue = ( $chunk == '||' ) && $category; // disjunctions only for cateories |
274 | 277 | } |
— | — | @@ -284,26 +287,26 @@ |
285 | 288 | protected function getPropertyDescription( $propertyname, &$setNS ) { |
286 | 289 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
287 | 290 | $this->readChunk(); // consume separator ":=" or "::" |
288 | | - |
| 291 | + |
289 | 292 | // first process property chain syntax (e.g. "property1.property2::value"), escaped by initial " ": |
290 | | - $propertynames = ( $propertyname { 0 } == ' ' ) ? array( $propertyname ):explode( '.', $propertyname ); |
| 293 | + $propertynames = ( $propertyname{0} == ' ' ) ? array( $propertyname ):explode( '.', $propertyname ); |
291 | 294 | $properties = array(); |
292 | 295 | $typeid = '_wpg'; |
293 | 296 | $inverse = false; |
294 | | - |
| 297 | + |
295 | 298 | foreach ( $propertynames as $name ) { |
296 | 299 | if ( $typeid != '_wpg' ) { // non-final property in chain was no wikipage: not allowed |
297 | 300 | $this->m_errors[] = wfMsgForContent( 'smw_valuesubquery', $prevname ); |
298 | 301 | return null; ///TODO: read some more chunks and try to finish [[ ]] |
299 | 302 | } |
300 | | - |
| 303 | + |
301 | 304 | $property = SMWPropertyValue::makeUserProperty( $name ); |
302 | | - |
| 305 | + |
303 | 306 | if ( !$property->isValid() ) { // illegal property identifier |
304 | 307 | $this->m_errors = array_merge( $this->m_errors, $property->getErrors() ); |
305 | 308 | return null; ///TODO: read some more chunks and try to finish [[ ]] |
306 | 309 | } |
307 | | - |
| 310 | + |
308 | 311 | $typeid = $property->getPropertyTypeID(); |
309 | 312 | $inverse = $property->isInverse(); |
310 | 313 | $prevname = $name; |
— | — | @@ -312,10 +315,10 @@ |
313 | 316 | |
314 | 317 | $innerdesc = null; |
315 | 318 | $continue = true; |
316 | | - |
| 319 | + |
317 | 320 | while ( $continue ) { |
318 | 321 | $chunk = $this->readChunk(); |
319 | | - |
| 322 | + |
320 | 323 | switch ( $chunk ) { |
321 | 324 | case '+': // wildcard, add namespaces for page-type properties |
322 | 325 | if ( ( $this->m_defaultns !== null ) && ( ( $typeid == '_wpg' ) || $inverse ) ) { |
— | — | @@ -351,7 +354,8 @@ |
352 | 355 | case ']]': // close [[ ]] |
353 | 356 | $open--; |
354 | 357 | break; |
355 | | - case '|': case '||': // terminates only outermost [[ ]] |
| 358 | + case '|': |
| 359 | + case '||': // terminates only outermost [[ ]] |
356 | 360 | if ( $open == 1 ) { |
357 | 361 | $open = 0; |
358 | 362 | } |
— | — | @@ -375,19 +379,19 @@ |
376 | 380 | |
377 | 381 | if ( $innerdesc === null ) { // make a wildcard search |
378 | 382 | $innerdesc = ( ( $this->m_defaultns !== null ) && ( $typeid == '_wpg' ) ) ? |
379 | | - $this->addDescription( $innerdesc, $this->m_defaultns, false ): |
380 | | - $this->addDescription( $innerdesc, new SMWThingDescription(), false ); |
| 383 | + $this->addDescription( $innerdesc, $this->m_defaultns, false ) : |
| 384 | + $this->addDescription( $innerdesc, new SMWThingDescription(), false ); |
381 | 385 | $this->m_errors[] = wfMsgForContent( 'smw_propvalueproblem', $property->getWikiValue() ); |
382 | 386 | } |
383 | | - |
| 387 | + |
384 | 388 | $properties = array_reverse( $properties ); |
385 | | - |
| 389 | + |
386 | 390 | foreach ( $properties as $property ) { |
387 | 391 | $innerdesc = new SMWSomeProperty( $property, $innerdesc ); |
388 | 392 | } |
389 | | - |
| 393 | + |
390 | 394 | $result = $innerdesc; |
391 | | - |
| 395 | + |
392 | 396 | return $this->finishLinkDescription( $chunk, false, $result, $setNS ); |
393 | 397 | } |
394 | 398 | |
— | — | @@ -400,40 +404,40 @@ |
401 | 405 | */ |
402 | 406 | protected function getArticleDescription( $firstchunk, &$setNS ) { |
403 | 407 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
404 | | - |
| 408 | + |
405 | 409 | $chunk = $firstchunk; |
406 | 410 | $result = null; |
407 | 411 | $continue = true; |
408 | 412 | // $innerdesc = null; |
409 | | - |
| 413 | + |
410 | 414 | while ( $continue ) { |
411 | 415 | if ( $chunk == '<q>' ) { // no subqueries of the form [[<q>...</q>]] (not needed) |
412 | 416 | $this->m_errors[] = wfMsgForContent( 'smw_misplacedsubquery' ); |
413 | 417 | return null; |
414 | 418 | } |
415 | | - |
| 419 | + |
416 | 420 | $list = preg_split( '/:/', $chunk, 3 ); // ":Category:Foo" "User:bar" ":baz" ":+" |
417 | | - |
| 421 | + |
418 | 422 | if ( ( $list[0] == '' ) && ( count( $list ) == 3 ) ) { |
419 | 423 | $list = array_slice( $list, 1 ); |
420 | 424 | } |
421 | 425 | if ( ( count( $list ) == 2 ) && ( $list[1] == '+' ) ) { // try namespace restriction |
422 | 426 | global $wgContLang; |
423 | 427 | $idx = $wgContLang->getNsIndex( $list[0] ); |
424 | | - |
| 428 | + |
425 | 429 | if ( $idx !== false ) { |
426 | 430 | $result = $this->addDescription( $result, new SMWNamespaceDescription( $idx ), false ); |
427 | 431 | } |
428 | 432 | } else { |
429 | 433 | $value = SMWDataValueFactory::newTypeIDValue( '_wpg', $chunk ); |
430 | | - |
| 434 | + |
431 | 435 | if ( $value->isValid() ) { |
432 | 436 | $result = $this->addDescription( $result, new SMWValueDescription( $value ), false ); |
433 | 437 | } |
434 | 438 | } |
435 | 439 | |
436 | 440 | $chunk = $this->readChunk( '\[\[|\]\]|\|\||\|' ); |
437 | | - |
| 441 | + |
438 | 442 | if ( $chunk == '||' ) { |
439 | 443 | $chunk = $this->readChunk( '\[\[|\]\]|\|\||\|' ); |
440 | 444 | $continue = true; |
— | — | @@ -447,14 +451,14 @@ |
448 | 452 | |
449 | 453 | protected function finishLinkDescription( $chunk, $hasNamespaces, $result, &$setNS ) { |
450 | 454 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
451 | | - |
| 455 | + |
452 | 456 | if ( $result === null ) { // no useful information or concrete error found |
453 | 457 | $this->m_errors[] = wfMsgForContent( 'smw_badqueryatom' ); |
454 | 458 | } elseif ( !$hasNamespaces && $setNS && ( $this->m_defaultns !== null ) ) { |
455 | 459 | $result = $this->addDescription( $result, $this->m_defaultns ); |
456 | 460 | $hasNamespaces = true; |
457 | 461 | } |
458 | | - |
| 462 | + |
459 | 463 | $setNS = $hasNamespaces; |
460 | 464 | |
461 | 465 | if ( $chunk == '|' ) { // skip content after single |, but report a warning |
— | — | @@ -467,17 +471,17 @@ |
468 | 472 | } |
469 | 473 | $this->m_errors[] = wfMsgForContent( 'smw_unexpectedpart', htmlspecialchars( $labelpart ) ); |
470 | 474 | } |
471 | | - |
| 475 | + |
472 | 476 | if ( $chunk != ']]' ) { |
473 | 477 | // What happended? We found some chunk that could not be processed as |
474 | | - // link content (as in [[Category:Test<q>]]), or the closing ]] are |
| 478 | + // link content (as in [[Category:Test<q>]]), or the closing ]] are |
475 | 479 | // just missing entirely. |
476 | 480 | if ( $chunk != '' ) { |
477 | 481 | $this->m_errors[] = wfMsgForContent( 'smw_misplacedsymbol', htmlspecialchars( $chunk ) ); |
478 | | - |
| 482 | + |
479 | 483 | // try to find a later closing ]] to finish this misshaped subpart |
480 | 484 | $chunk = $this->readChunk( '\]\]' ); |
481 | | - |
| 485 | + |
482 | 486 | if ( $chunk != ']]' ) { |
483 | 487 | $chunk = $this->readChunk( '\]\]' ); |
484 | 488 | } |
— | — | @@ -486,7 +490,7 @@ |
487 | 491 | $this->m_errors[] = wfMsgForContent( 'smw_noclosingbrackets' ); |
488 | 492 | } |
489 | 493 | } |
490 | | - |
| 494 | + |
491 | 495 | return $result; |
492 | 496 | } |
493 | 497 | |
— | — | @@ -517,23 +521,25 @@ |
518 | 522 | if ( $consume ) { |
519 | 523 | $this->m_curstring = ''; |
520 | 524 | } |
521 | | - |
522 | | - return $trim ? trim( $chunks[0] ):$chunks[0]; |
| 525 | + |
| 526 | + return $trim ? trim( $chunks[0] ) : $chunks[0]; |
523 | 527 | } elseif ( count( $chunks ) == 3 ) { // this should generally happen if count is not 1 |
524 | 528 | if ( $chunks[0] == '' ) { // string started with delimiter |
525 | 529 | if ( $consume ) { |
526 | 530 | $this->m_curstring = $chunks[2]; |
527 | 531 | } |
528 | | - |
529 | | - return $trim ? trim( $chunks[1] ):$chunks[1]; |
| 532 | + |
| 533 | + return $trim ? trim( $chunks[1] ) : $chunks[1]; |
530 | 534 | } else { |
531 | 535 | if ( $consume ) { |
532 | 536 | $this->m_curstring = $chunks[1] . $chunks[2]; |
533 | 537 | } |
534 | | - |
535 | | - return $trim ? trim( $chunks[0] ):$chunks[0]; |
| 538 | + |
| 539 | + return $trim ? trim( $chunks[0] ) : $chunks[0]; |
536 | 540 | } |
537 | | - } else { return false; } // should never happen |
| 541 | + } else { |
| 542 | + return false; |
| 543 | + } // should never happen |
538 | 544 | } |
539 | 545 | |
540 | 546 | /** |
— | — | @@ -584,18 +590,18 @@ |
585 | 591 | } else { |
586 | 592 | $allowed = true; |
587 | 593 | } |
588 | | - |
| 594 | + |
589 | 595 | if ( !$allowed ) { |
590 | 596 | $this->m_errors[] = wfMsgForContent( $notallowedmessage, str_replace( '[', '[', $newdesc->getQueryString() ) ); |
591 | 597 | return $curdesc; |
592 | 598 | } |
593 | | - |
| 599 | + |
594 | 600 | if ( $newdesc === null ) { |
595 | 601 | return $curdesc; |
596 | 602 | } elseif ( $curdesc === null ) { |
597 | 603 | return $newdesc; |
598 | 604 | } else { // we already found descriptions |
599 | | - if ( ( ( $conjunction ) && ( $curdesc instanceof SMWConjunction ) ) || |
| 605 | + if ( ( ( $conjunction ) && ( $curdesc instanceof SMWConjunction ) ) || |
600 | 606 | ( ( !$conjunction ) && ( $curdesc instanceof SMWDisjunction ) ) ) { // use existing container |
601 | 607 | $curdesc->addDescription( $newdesc ); |
602 | 608 | return $curdesc; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Outputs.php |
— | — | @@ -22,7 +22,7 @@ |
23 | 23 | * |
24 | 24 | * @file SMW_Ouputs.php |
25 | 25 | * @ingroup SMW |
26 | | - * |
| 26 | + * |
27 | 27 | * @author Markus Krötzsch |
28 | 28 | */ |
29 | 29 | class SMWOutputs { |
— | — | @@ -49,7 +49,7 @@ |
50 | 50 | * @param $id string or predefined constant for identifying a head item |
51 | 51 | * @param $item string containing a complete HTML-compatibly text snippet that |
52 | 52 | * should go into the HTML header; only required if $id is no built-in constant. |
53 | | - * |
| 53 | + * |
54 | 54 | * FIXME: switch on precence of the resource loader (introduced in MW 1.17). |
55 | 55 | * SMW_sorttable.js uses addOnloadHook and breaks as it is now on 1.17. |
56 | 56 | */ |
— | — | @@ -60,11 +60,11 @@ |
61 | 61 | switch ( $id ) { |
62 | 62 | case SMW_HEADER_TOOLTIP: |
63 | 63 | self::requireHeadItem( SMW_HEADER_STYLE ); |
64 | | - self::$mHeadItems['smw_tt'] = '<script type="text/javascript" src="' . $smwgScriptPath . '/skins/SMW_tooltip.js"></script>'; |
| 64 | + self::$mHeadItems['smw_tt'] = '<script type="text/javascript" src="' . $smwgScriptPath . '/skins/SMW_tooltip.js"></script>'; |
65 | 65 | break; |
66 | 66 | case SMW_HEADER_SORTTABLE: |
67 | 67 | self::requireHeadItem( SMW_HEADER_STYLE ); |
68 | | - self::$mHeadItems['smw_st'] = '<script type="text/javascript" src="' . $smwgScriptPath . '/skins/SMW_sorttable.js"></script>'; |
| 68 | + self::$mHeadItems['smw_st'] = '<script type="text/javascript" src="' . $smwgScriptPath . '/skins/SMW_sorttable.js"></script>'; |
69 | 69 | break; |
70 | 70 | case SMW_HEADER_STYLE: |
71 | 71 | global $wgContLang; |
— | — | @@ -118,7 +118,9 @@ |
119 | 119 | $po = $parser->mOutput; |
120 | 120 | } |
121 | 121 | |
122 | | - if ( isset( $po ) ) self::commitToParserOutput( $po ); |
| 122 | + if ( isset( $po ) ) { |
| 123 | + self::commitToParserOutput( $po ); |
| 124 | + } |
123 | 125 | } |
124 | 126 | |
125 | 127 | /** |
— | — | @@ -151,5 +153,5 @@ |
152 | 154 | |
153 | 155 | self::$mHeadItems = array(); |
154 | 156 | } |
155 | | - |
| 157 | + |
156 | 158 | } |
\ No newline at end of file |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_RefreshTab.php |
— | — | @@ -4,16 +4,18 @@ |
5 | 5 | * @ingroup SMW |
6 | 6 | */ |
7 | 7 | |
8 | | -/* |
| 8 | +/** |
9 | 9 | * Protect against register_globals vulnerabilities. |
10 | 10 | * This line must be present before any global variable is referenced. |
11 | 11 | */ |
12 | | -if ( !defined( 'MEDIAWIKI' ) ) die(); |
| 12 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 13 | + die(); |
| 14 | +} |
13 | 15 | |
14 | 16 | global $wgHooks; |
15 | 17 | |
16 | | -$wgHooks[ 'SkinTemplateTabs' ][] = 'smwfAddRefreshTab'; // basic tab addition |
17 | | -$wgHooks[ 'SkinTemplateNavigation' ][] = 'smwfAddStructuredRefreshTab'; // structured version for "Vector"-type skins |
| 18 | +$wgHooks['SkinTemplateTabs'][] = 'smwfAddRefreshTab'; // basic tab addition |
| 19 | +$wgHooks['SkinTemplateNavigation'][] = 'smwfAddStructuredRefreshTab'; // structured version for "Vector"-type skins |
18 | 20 | |
19 | 21 | /** |
20 | 22 | * Extends the provided array of content actions with an action that refreshes the article, |
— | — | @@ -21,7 +23,7 @@ |
22 | 24 | */ |
23 | 25 | function smwfAddRefreshTab( $skin, &$content_actions ) { |
24 | 26 | global $wgUser; |
25 | | - if ( $wgUser->isAllowed( 'purge' ) ) { |
| 27 | + if ( $wgUser->isAllowed( 'purge' ) ) { |
26 | 28 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
27 | 29 | $content_actions['purge'] = array( |
28 | 30 | 'class' => false, |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php |
— | — | @@ -19,20 +19,20 @@ |
20 | 20 | */ |
21 | 21 | static public function getFactboxText( SMWSemanticData $semdata, $showfactbox = SMW_FACTBOX_NONEMPTY ) { |
22 | 22 | global $wgContLang; |
23 | | - wfProfileIn( "SMWFactbox::printFactbox (SMW)" ); |
| 23 | + wfProfileIn( 'SMWFactbox::printFactbox (SMW)' ); |
24 | 24 | switch ( $showfactbox ) { |
25 | | - case SMW_FACTBOX_HIDDEN: // show never |
26 | | - wfProfileOut( "SMWFactbox::printFactbox (SMW)" ); |
| 25 | + case SMW_FACTBOX_HIDDEN: // never show |
| 26 | + wfProfileOut( 'SMWFactbox::printFactbox (SMW)' ); |
27 | 27 | return ''; |
28 | 28 | case SMW_FACTBOX_SPECIAL: // show only if there are special properties |
29 | 29 | if ( !$semdata->hasVisibleSpecialProperties() ) { |
30 | | - wfProfileOut( "SMWFactbox::printFactbox (SMW)" ); |
| 30 | + wfProfileOut( 'SMWFactbox::printFactbox (SMW)' ); |
31 | 31 | return ''; |
32 | 32 | } |
33 | 33 | break; |
34 | 34 | case SMW_FACTBOX_NONEMPTY: // show only if non-empty |
35 | 35 | if ( !$semdata->hasVisibleProperties() ) { |
36 | | - wfProfileOut( "SMWFactbox::printFactbox (SMW)" ); |
| 36 | + wfProfileOut( 'SMWFactbox::printFactbox (SMW)' ); |
37 | 37 | return ''; |
38 | 38 | } |
39 | 39 | break; |
— | — | @@ -44,9 +44,18 @@ |
45 | 45 | if ( wfRunHooks( 'smwShowFactbox', array( &$text, $semdata ) ) ) { |
46 | 46 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
47 | 47 | SMWOutputs::requireHeadItem( SMW_HEADER_STYLE ); |
48 | | - $rdflink = SMWInfolink::newInternalLink( wfMsgForContent( 'smw_viewasrdf' ), $wgContLang->getNsText( NS_SPECIAL ) . ':ExportRDF/' . $semdata->getSubject()->getWikiValue(), 'rdflink' ); |
| 48 | + $rdflink = SMWInfolink::newInternalLink( |
| 49 | + wfMsgForContent( 'smw_viewasrdf' ), |
| 50 | + $wgContLang->getNsText( NS_SPECIAL ) . ':ExportRDF/' . |
| 51 | + $semdata->getSubject()->getWikiValue(), |
| 52 | + 'rdflink' |
| 53 | + ); |
49 | 54 | |
50 | | - $browselink = SMWInfolink::newBrowsingLink( $semdata->getSubject()->getText(), $semdata->getSubject()->getWikiValue(), 'swmfactboxheadbrowse' ); |
| 55 | + $browselink = SMWInfolink::newBrowsingLink( |
| 56 | + $semdata->getSubject()->getText(), |
| 57 | + $semdata->getSubject()->getWikiValue(), |
| 58 | + 'swmfactboxheadbrowse' |
| 59 | + ); |
51 | 60 | $text .= '<div class="smwfact">' . |
52 | 61 | '<span class="smwfactboxhead">' . wfMsgForContent( 'smw_factbox_head', $browselink->getWikiText() ) . '</span>' . |
53 | 62 | '<span class="smwrdflink">' . $rdflink->getWikiText() . '</span>' . |
— | — | @@ -82,7 +91,7 @@ |
83 | 92 | } |
84 | 93 | $text .= '</table></div>'; |
85 | 94 | } |
86 | | - wfProfileOut( "SMWFactbox::printFactbox (SMW)" ); |
| 95 | + wfProfileOut( 'SMWFactbox::printFactbox (SMW)' ); |
87 | 96 | return $text; |
88 | 97 | } |
89 | 98 | |
— | — | @@ -94,7 +103,7 @@ |
95 | 104 | */ |
96 | 105 | static public function getFactboxTextFromOutput( $parseroutput, $title ) { |
97 | 106 | global $wgRequest, $smwgShowFactboxEdit, $smwgShowFactbox; |
98 | | - $mws = ( isset( $parseroutput->mSMWMagicWords ) ) ? $parseroutput->mSMWMagicWords:array(); |
| 107 | + $mws = ( isset( $parseroutput->mSMWMagicWords ) ) ? $parseroutput->mSMWMagicWords : array(); |
99 | 108 | if ( in_array( 'SMW_SHOWFACTBOX', $mws ) ) { |
100 | 109 | $showfactbox = SMW_FACTBOX_NONEMPTY; |
101 | 110 | } elseif ( in_array( 'SMW_NOFACTBOX', $mws ) ) { |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php |
— | — | @@ -72,31 +72,30 @@ |
73 | 73 | /** |
74 | 74 | * Return true if semantic data should be processed and displayed for a page |
75 | 75 | * in the given namespace. |
76 | | - * @return bool |
| 76 | + * @return boolean |
77 | 77 | */ |
78 | 78 | function smwfIsSemanticsProcessed( $namespace ) { |
79 | 79 | global $smwgNamespacesWithSemanticLinks; |
80 | 80 | return !empty( $smwgNamespacesWithSemanticLinks[$namespace] ); |
81 | 81 | } |
82 | 82 | |
83 | | - |
84 | 83 | /** |
85 | 84 | * Takes a title text and turns it safely into its DBKey. This function |
86 | 85 | * reimplements most of the title normalization as done in Title.php in order |
87 | 86 | * to achieve conversion with less overhead. The official code could be called |
88 | 87 | * here if more advanced normalization is needed. |
89 | | - * |
| 88 | + * |
90 | 89 | * @param string $text |
91 | 90 | */ |
92 | 91 | function smwfNormalTitleDBKey( $text ) { |
93 | 92 | global $wgCapitalLinks; |
94 | | - |
| 93 | + |
95 | 94 | $text = trim( $text ); |
96 | | - |
| 95 | + |
97 | 96 | if ( $wgCapitalLinks ) { |
98 | 97 | $text = ucfirst( $text ); |
99 | 98 | } |
100 | | - |
| 99 | + |
101 | 100 | return str_replace( ' ', '_', $text ); |
102 | 101 | } |
103 | 102 | |
— | — | @@ -105,25 +104,25 @@ |
106 | 105 | * reimplements the title normalization as done in Title.php in order to |
107 | 106 | * achieve conversion with less overhead. The official code could be called |
108 | 107 | * here if more advanced normalization is needed. |
109 | | - * |
| 108 | + * |
110 | 109 | * @param string $text |
111 | 110 | */ |
112 | 111 | function smwfNormalTitleText( $text ) { |
113 | 112 | global $wgCapitalLinks; |
114 | | - |
| 113 | + |
115 | 114 | $text = trim( $text ); |
116 | | - |
| 115 | + |
117 | 116 | if ( $wgCapitalLinks ) { |
118 | 117 | $text = ucfirst( $text ); |
119 | 118 | } |
120 | | - |
| 119 | + |
121 | 120 | return str_replace( '_', ' ', $text ); |
122 | 121 | } |
123 | 122 | |
124 | 123 | /** |
125 | 124 | * Escapes text in a way that allows it to be used as XML content (e.g. as a |
126 | 125 | * string value for some property). |
127 | | - * |
| 126 | + * |
128 | 127 | * @param string $text |
129 | 128 | */ |
130 | 129 | function smwfXMLContentEncode( $text ) { |
— | — | @@ -133,7 +132,7 @@ |
134 | 133 | /** |
135 | 134 | * Decodes character references and inserts Unicode characters instead, using |
136 | 135 | * the MediaWiki Sanitizer. |
137 | | - * |
| 136 | + * |
138 | 137 | * @param string $text |
139 | 138 | */ |
140 | 139 | function smwfHTMLtoUTF8( $text ) { |
— | — | @@ -144,14 +143,14 @@ |
145 | 144 | * This method formats a float number value according to the given language and |
146 | 145 | * precision settings, with some intelligence to produce readable output. Used |
147 | 146 | * to format a number that was not hand-formatted by a user. |
148 | | -* |
| 147 | +* |
149 | 148 | * @param mixed $value input number |
150 | 149 | * @param integer $decplaces optional positive integer, controls how many digits after |
151 | 150 | * the decimal point are shown |
152 | 151 | */ |
153 | 152 | function smwfNumberFormat( $value, $decplaces = 3 ) { |
154 | 153 | global $smwgMaxNonExpNumber; |
155 | | - |
| 154 | + |
156 | 155 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
157 | 156 | $decseparator = wfMsgForContent( 'smw_decseparator' ); |
158 | 157 | |
— | — | @@ -161,7 +160,7 @@ |
162 | 161 | // using number_format. This may lead to 1.200, so then use trim to |
163 | 162 | // remove trailing zeroes. |
164 | 163 | $doScientific = false; |
165 | | - |
| 164 | + |
166 | 165 | // @todo: Don't do all this magic for integers, since the formatting does not fit there |
167 | 166 | // correctly. E.g. one would have integers formatted as 1234e6, not as 1.234e9, right? |
168 | 167 | // The "$value!=0" is relevant: we want to scientify numbers that are close to 0, but never 0! |
— | — | @@ -182,7 +181,7 @@ |
183 | 182 | } |
184 | 183 | } |
185 | 184 | } |
186 | | - |
| 185 | + |
187 | 186 | if ( $doScientific ) { |
188 | 187 | // Should we use decimal places here? |
189 | 188 | $value = sprintf( "%1.6e", $value ); |
— | — | @@ -203,7 +202,7 @@ |
204 | 203 | // Assumes substr is faster than a regular expression replacement. |
205 | 204 | $end = $decseparator . str_repeat( '0', $decplaces ); |
206 | 205 | $lenEnd = strlen( $end ); |
207 | | - |
| 206 | + |
208 | 207 | if ( substr( $value, - $lenEnd ) === $end ) { |
209 | 208 | $value = substr( $value, 0, - $lenEnd ); |
210 | 209 | } else { |
— | — | @@ -212,7 +211,7 @@ |
213 | 212 | $value = preg_replace( "/(\\$decseparator\\d+?)0*$/u", '$1', $value, 1 ); |
214 | 213 | } |
215 | 214 | } |
216 | | - |
| 215 | + |
217 | 216 | return $value; |
218 | 217 | } |
219 | 218 | |
— | — | @@ -229,7 +228,9 @@ |
230 | 229 | function smwfEncodeMessages( array $messages, $icon = 'warning', $seperator = ' <!--br-->' ) { |
231 | 230 | if ( count( $messages ) > 0 ) { |
232 | 231 | SMWOutputs::requireHeadItem( SMW_HEADER_TOOLTIP ); |
233 | | - foreach( $messages as &$message ) $message = htmlspecialchars( $message ); |
| 232 | + foreach( $messages as &$message ) { |
| 233 | + $message = htmlspecialchars( $message ); |
| 234 | + } |
234 | 235 | $messageString = implode( $seperator, $messages ); |
235 | 236 | return '<span class="smwttpersist"><span class="smwtticon">' . $icon . '.png</span><span class="smwttcontent">' . $messageString . '</span> </span>'; |
236 | 237 | } else { |
— | — | @@ -242,10 +243,10 @@ |
243 | 244 | * wfLoadExtensionMessages function will no longer be needed (or supported). |
244 | 245 | * This function is used for maintaining compatibility with MediaWiki 1.15 or |
245 | 246 | * below. |
246 | | - * |
| 247 | + * |
247 | 248 | * @param string $extensionName The extension name for finding the the message |
248 | 249 | * file; same as in wfLoadExtensionMessages() |
249 | | - * |
| 250 | + * |
250 | 251 | * @since 1.5.1 |
251 | 252 | */ |
252 | 253 | function smwfLoadExtensionMessages( $extensionName ) { |
— | — | @@ -260,21 +261,21 @@ |
261 | 262 | * infrastructure allows to set up load balancing and task-dependent use of |
262 | 263 | * stores (e.g. using other stores for fast querying than for storing new |
263 | 264 | * facts), somewhat similar to MediaWiki's DB implementation. |
264 | | - * |
| 265 | + * |
265 | 266 | * @return SMWStore |
266 | 267 | */ |
267 | 268 | function &smwfGetStore() { |
268 | 269 | global $smwgMasterStore, $smwgDefaultStore, $smwgIP; |
269 | | - |
| 270 | + |
270 | 271 | // No autoloading for RAP store, since autoloaded classes are in rare cases loaded by MW even if not used in code. |
271 | 272 | // This is not possible for RAPstore, which depends on RAP being installed. |
272 | | - if ( $smwgDefaultStore == 'SMWRAPStore2' ) { |
| 273 | + if ( $smwgDefaultStore == 'SMWRAPStore2' ) { |
273 | 274 | include_once( $smwgIP . 'includes/storage/SMW_RAPStore2.php' ); |
274 | 275 | } |
275 | | - |
| 276 | + |
276 | 277 | if ( $smwgMasterStore === null ) { |
277 | 278 | $smwgMasterStore = new $smwgDefaultStore(); |
278 | 279 | } |
279 | | - |
| 280 | + |
280 | 281 | return $smwgMasterStore; |
281 | 282 | } |
\ No newline at end of file |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php |
— | — | @@ -3,10 +3,10 @@ |
4 | 4 | * The class in this file manages (special) mProperties that are |
5 | 5 | * associated with a certain subject (article). It is used as a |
6 | 6 | * container for chunks of subject-centred data. |
7 | | - * |
| 7 | + * |
8 | 8 | * @file |
9 | 9 | * @ingroup SMW |
10 | | - * |
| 10 | + * |
11 | 11 | * @author Markus Krötzsch |
12 | 12 | * @author Jeroen De Dauw |
13 | 13 | */ |
— | — | @@ -15,82 +15,82 @@ |
16 | 16 | * Class for representing chunks of semantic data for one given |
17 | 17 | * article (subject), similar what is typically displayed in the factbox. |
18 | 18 | * This is a light-weight data container. |
19 | | - * |
| 19 | + * |
20 | 20 | * @ingroup SMW |
21 | 21 | */ |
22 | 22 | class SMWSemanticData { |
23 | | - |
| 23 | + |
24 | 24 | /** |
25 | 25 | * States whether this is a stub object. Stubbing might happen on serialisation to save DB space. |
26 | | - * |
| 26 | + * |
27 | 27 | * @var boolean |
28 | 28 | */ |
29 | | - public $stubObject = true; |
30 | | - |
| 29 | + public $stubObject = true; |
| 30 | + |
31 | 31 | /** |
32 | 32 | * Cache for the local version of "Property:" |
33 | | - * |
| 33 | + * |
34 | 34 | * @var mixed |
35 | 35 | */ |
36 | | - static protected $mPropertyPrefix = false; |
37 | | - |
| 36 | + static protected $mPropertyPrefix = false; |
| 37 | + |
38 | 38 | /** |
39 | 39 | * Text keys and arrays of datavalue objects. |
40 | | - * |
| 40 | + * |
41 | 41 | * @var array |
42 | | - */ |
| 42 | + */ |
43 | 43 | protected $mPropVals = array(); |
44 | | - |
| 44 | + |
45 | 45 | /** |
46 | 46 | * Text keys and title objects. |
47 | | - * |
| 47 | + * |
48 | 48 | * @var array |
49 | 49 | */ |
50 | 50 | protected $mProperties = array(); |
51 | | - |
| 51 | + |
52 | 52 | /** |
53 | 53 | * Stub property data that is not part of $propvals and $mProperties yet. Entries use |
54 | 54 | * property DB keys as keys. The value is an array of DBkey-arrays that define individual |
55 | 55 | * datavalues. The stubs will be set up when first accessed. |
56 | | - * |
| 56 | + * |
57 | 57 | * @var array |
58 | 58 | */ |
59 | 59 | protected $mStubPropVals = array(); |
60 | | - |
| 60 | + |
61 | 61 | /** |
62 | 62 | * States whether the container holds any normal properties. |
63 | | - * |
| 63 | + * |
64 | 64 | * @var boolean |
65 | 65 | */ |
66 | 66 | protected $mHasVisibleProps = false; |
67 | | - |
| 67 | + |
68 | 68 | /** |
69 | 69 | * States whether the container holds any displayable special mProperties (some are internal only without a display name). |
70 | | - * |
| 70 | + * |
71 | 71 | * @var boolean |
72 | 72 | */ |
73 | 73 | protected $mHasVisibleSpecs = false; |
74 | | - |
| 74 | + |
75 | 75 | /** |
76 | | - * States whether repeated values should be avoided. Not needing duplicte elimination |
77 | | - * (e.g. when loading from store) can save much time, since objects can remain stubs until someone |
78 | | - * really acesses their value. |
79 | | - * |
80 | | - * @var boolean |
| 76 | + * States whether repeated values should be avoided. Not needing duplicte elimination |
| 77 | + * (e.g. when loading from store) can save much time, since objects can remain stubs until someone |
| 78 | + * really acesses their value. |
| 79 | + * |
| 80 | + * @var boolean |
81 | 81 | */ |
82 | 82 | protected $mNoDuplicates; |
83 | 83 | |
84 | 84 | /** |
85 | 85 | * SMWWikiPageValue object that is the subject of this container. |
86 | 86 | * Subjects that are NULL are used to represent "internal objects" only. |
87 | | - * |
| 87 | + * |
88 | 88 | * @var SMWWikiPageValue |
89 | 89 | */ |
90 | 90 | protected $mSubject; |
91 | 91 | |
92 | 92 | /** |
93 | 93 | * Constructor. |
94 | | - * |
| 94 | + * |
95 | 95 | * @param SMWWikiPageValue $subject |
96 | 96 | * @param boolean $noDuplicates |
97 | 97 | */ |
— | — | @@ -106,9 +106,9 @@ |
107 | 107 | * subject is serialised, yielding a minimal stub data container after unserialisation. This is a little safer than serialising |
108 | 108 | * nothing: if, for any reason, SMW should ever access an unserialised parser output, then the Semdata container will at least |
109 | 109 | * look as if properly initialised (though empty). |
110 | | - * |
| 110 | + * |
111 | 111 | * @note It might be even better to have other members with stub object data that is used for serializing, thus using much less data. |
112 | | - * |
| 112 | + * |
113 | 113 | * @return array |
114 | 114 | */ |
115 | 115 | public function __sleep() { |
— | — | @@ -117,7 +117,7 @@ |
118 | 118 | |
119 | 119 | /** |
120 | 120 | * Return subject to which the stored semantic annotation refer to. |
121 | | - * |
| 121 | + * |
122 | 122 | * @return SMWWikiPageValue subject |
123 | 123 | */ |
124 | 124 | public function getSubject() { |
— | — | @@ -130,36 +130,36 @@ |
131 | 131 | public function getProperties() { |
132 | 132 | $this->unstubProperties(); |
133 | 133 | ksort( $this->mProperties, SORT_STRING ); |
134 | | - |
| 134 | + |
135 | 135 | return $this->mProperties; |
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | 139 | * Get the array of all stored values for some property. |
140 | | - * |
| 140 | + * |
141 | 141 | * @param SMWPropertyValue $property |
142 | | - * |
| 142 | + * |
143 | 143 | * @return array |
144 | 144 | */ |
145 | 145 | public function getPropertyValues( SMWPropertyValue $property ) { |
146 | 146 | if ( array_key_exists( $property->getDBkey(), $this->mStubPropVals ) ) { |
147 | 147 | // Unstub those entries completely. |
148 | 148 | $this->unstubProperty( $property->getDBkey(), $property ); |
149 | | - |
| 149 | + |
150 | 150 | foreach ( $this->mStubPropVals[$property->getDBkey()] as $dbkeys ) { |
151 | 151 | $dv = SMWDataValueFactory::newPropertyObjectValue( $property ); |
152 | 152 | $dv->setDBkeys( $dbkeys ); |
153 | | - |
| 153 | + |
154 | 154 | if ( $this->mNoDuplicates ) { |
155 | 155 | $this->mPropVals[$property->getDBkey()][$dv->getHash()] = $dv; |
156 | 156 | } else { |
157 | 157 | $this->mPropVals[$property->getDBkey()][] = $dv; |
158 | 158 | } |
159 | 159 | } |
160 | | - |
| 160 | + |
161 | 161 | unset( $this->mStubPropVals[$property->getDBkey()] ); |
162 | 162 | } |
163 | | - |
| 163 | + |
164 | 164 | if ( array_key_exists( $property->getDBkey(), $this->mPropVals ) ) { |
165 | 165 | return $this->mPropVals[$property->getDBkey()]; |
166 | 166 | } else { |
— | — | @@ -171,33 +171,33 @@ |
172 | 172 | * Generate a hash value to simplify the comparison of this data container with other |
173 | 173 | * containers. The hash uses PHP's md5 implementation, which is among the fastest hash |
174 | 174 | * algorithms that PHP offers. |
175 | | - * |
| 175 | + * |
176 | 176 | * @return string |
177 | 177 | */ |
178 | 178 | public function getHash() { |
179 | 179 | $ctx = hash_init( 'md5' ); |
180 | | - |
| 180 | + |
181 | 181 | if ( $this->mSubject !== null ) { // here and below, use "_#_" to separate values; really not much care needed here |
182 | 182 | hash_update( $ctx, '_#_' . $this->mSubject->getHash() ); |
183 | 183 | } |
184 | | - |
| 184 | + |
185 | 185 | foreach ( $this->getProperties() as $property ) { |
186 | 186 | hash_update( $ctx, '_#_' . $property->getHash() . '##' ); |
187 | | - |
| 187 | + |
188 | 188 | foreach ( $this->getPropertyValues( $property ) as $dv ) { |
189 | 189 | hash_update( $ctx, '_#_' . $dv->getHash() ); |
190 | 190 | } |
191 | 191 | } |
192 | | - |
| 192 | + |
193 | 193 | return hash_final( $ctx ); |
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
197 | 197 | * Return true if there are any visible properties. |
198 | | - * |
| 198 | + * |
199 | 199 | * @note While called "visible" this check actually refers to the function |
200 | 200 | * SMWPropertyValue::isShown(). The name is kept for compatibility. |
201 | | - * |
| 201 | + * |
202 | 202 | * @return boolean |
203 | 203 | */ |
204 | 204 | public function hasVisibleProperties() { |
— | — | @@ -208,10 +208,10 @@ |
209 | 209 | /** |
210 | 210 | * Return true if there are any special properties that can |
211 | 211 | * be displayed. |
212 | | - * |
| 212 | + * |
213 | 213 | * @note While called "visible" this check actually refers to the function |
214 | 214 | * SMWPropertyValue::isShown(). The name is kept for compatibility. |
215 | | - * |
| 215 | + * |
216 | 216 | * @return boolean |
217 | 217 | */ |
218 | 218 | public function hasVisibleSpecialProperties() { |
— | — | @@ -222,32 +222,34 @@ |
223 | 223 | /** |
224 | 224 | * Store a value for a property identified by its title object. Duplicate |
225 | 225 | * value entries are usually ignored. |
226 | | - * |
| 226 | + * |
227 | 227 | * @note Attention: there is no check whether the type of the given datavalue agrees |
228 | 228 | * with what SMWDataValueFactory is producing (based on predefined property records and |
229 | 229 | * the current DB content). Always use SMWDataValueFactory to produce fitting values! |
230 | | - * |
| 230 | + * |
231 | 231 | * @param SMWPropertyValue $property |
232 | 232 | * @param SMWDataValue $value |
233 | 233 | */ |
234 | 234 | public function addPropertyObjectValue( SMWPropertyValue $property, SMWDataValue $value ) { |
235 | | - if ( !$property->isValid() ) return; // nothing we can do |
236 | | - |
| 235 | + if ( !$property->isValid() ) { |
| 236 | + return; // nothing we can do |
| 237 | + } |
| 238 | + |
237 | 239 | if ( !array_key_exists( $property->getDBkey(), $this->mPropVals ) ) { |
238 | 240 | $this->mPropVals[$property->getDBkey()] = array(); |
239 | 241 | $this->mProperties[$property->getDBkey()] = $property; |
240 | 242 | } |
241 | | - |
| 243 | + |
242 | 244 | if ( $this->mNoDuplicates ) { |
243 | 245 | $this->mPropVals[$property->getDBkey()][$value->getHash()] = $value; |
244 | 246 | } else { |
245 | 247 | $this->mPropVals[$property->getDBkey()][] = $value; |
246 | 248 | } |
247 | | - |
| 249 | + |
248 | 250 | if ( !$property->isUserDefined() ) { |
249 | 251 | if ( $property->isShown() ) { |
250 | | - $this->mHasVisibleSpecs = true; |
251 | | - $this->mHasVisibleProps = true; |
| 252 | + $this->mHasVisibleSpecs = true; |
| 253 | + $this->mHasVisibleProps = true; |
252 | 254 | } |
253 | 255 | } else { |
254 | 256 | $this->mHasVisibleProps = true; |
— | — | @@ -257,13 +259,13 @@ |
258 | 260 | /** |
259 | 261 | * Store a value for a given property identified by its text label (without |
260 | 262 | * namespace prefix). Duplicate value entries are usually ignored. |
261 | | - * |
| 263 | + * |
262 | 264 | * @param string $propertyName |
263 | 265 | * @param SMWDataValue $value |
264 | 266 | */ |
265 | 267 | public function addPropertyValue( $propertyName, SMWDataValue $value ) { |
266 | 268 | $propertykey = smwfNormalTitleDBKey( $propertyName ); |
267 | | - |
| 269 | + |
268 | 270 | if ( array_key_exists( $propertykey, $this->mProperties ) ) { |
269 | 271 | $property = $this->mProperties[$propertykey]; |
270 | 272 | } else { |
— | — | @@ -271,14 +273,14 @@ |
272 | 274 | global $wgContLang; |
273 | 275 | self::$mPropertyPrefix = $wgContLang->getNsText( SMW_NS_PROPERTY ) . ':'; |
274 | 276 | } // explicitly use prefix to cope with things like [[Property:User:Stupid::somevalue]] |
275 | | - |
| 277 | + |
276 | 278 | $property = SMWPropertyValue::makeUserProperty( self::$mPropertyPrefix . $propertyName ); |
277 | | - |
| 279 | + |
278 | 280 | if ( !$property->isValid() ) { // error, maybe illegal title text |
279 | 281 | return; |
280 | 282 | } |
281 | 283 | } |
282 | | - |
| 284 | + |
283 | 285 | $this->addPropertyObjectValue( $property, $value ); |
284 | 286 | } |
285 | 287 | |
— | — | @@ -294,7 +296,7 @@ |
295 | 297 | $propertyKey = $property->getDBkey(); |
296 | 298 | $this->unstubProperty( $propertyKey, $property ); |
297 | 299 | } |
298 | | - |
| 300 | + |
299 | 301 | $this->mStubPropVals[$propertyKey][] = $valueKeys; |
300 | 302 | } |
301 | 303 | |
— | — | @@ -322,7 +324,7 @@ |
323 | 325 | * Unstub a single property from the stub data array. If available, an existing object |
324 | 326 | * for that property might be provided, so we do not need to make a new one. It is not |
325 | 327 | * checked if the object matches the property name. |
326 | | - * |
| 328 | + * |
327 | 329 | * @param string $propertyName |
328 | 330 | * @param $propertyObject |
329 | 331 | */ |
— | — | @@ -331,13 +333,13 @@ |
332 | 334 | if ( $propertyObject === null ) { |
333 | 335 | $propertyObject = SMWPropertyValue::makeProperty( $propertyName ); |
334 | 336 | } |
335 | | - |
| 337 | + |
336 | 338 | $this->mProperties[$propertyName] = $propertyObject; |
337 | | - |
| 339 | + |
338 | 340 | if ( !$propertyObject->isUserDefined() ) { |
339 | 341 | if ( $propertyObject->isShown() ) { |
340 | | - $this->mHasVisibleSpecs = true; |
341 | | - $this->mHasVisibleProps = true; |
| 342 | + $this->mHasVisibleSpecs = true; |
| 343 | + $this->mHasVisibleProps = true; |
342 | 344 | } |
343 | 345 | } else { |
344 | 346 | $this->mHasVisibleProps = true; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php |
— | — | @@ -1,10 +1,10 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * This file contains the SMWDataValueFactory class. |
5 | | - * |
| 5 | + * |
6 | 6 | * @author Markus Krötzsch |
7 | 7 | * @author Jeroen De Dauw |
8 | | - * |
| 8 | + * |
9 | 9 | * @file |
10 | 10 | * @ingroup SMWDataValues |
11 | 11 | */ |
— | — | @@ -28,21 +28,21 @@ |
29 | 29 | |
30 | 30 | /** |
31 | 31 | * Array of type labels indexed by type ids. Used for datatype resolution. |
32 | | - * |
| 32 | + * |
33 | 33 | * @var array |
34 | 34 | */ |
35 | 35 | static private $mTypeLabels; |
36 | | - |
| 36 | + |
37 | 37 | /** |
38 | 38 | * Array of ids indexed by type aliases. Used for datatype resolution. |
39 | | - * |
| 39 | + * |
40 | 40 | * @var array |
41 | 41 | */ |
42 | 42 | static private $mTypeAliases; |
43 | | - |
| 43 | + |
44 | 44 | /** |
45 | 45 | * Array of class names for creating new SMWDataValue, indexed by type id. |
46 | | - * |
| 46 | + * |
47 | 47 | * @var array of SMWDataValue |
48 | 48 | */ |
49 | 49 | static private $mTypeClasses; |
— | — | @@ -51,7 +51,7 @@ |
52 | 52 | * Create an SMWDataValue object that can hold values for the type that the |
53 | 53 | * given SMWTypesValue object specifies. If no $value is given, an empty |
54 | 54 | * container is created, the value of which can be set later on. |
55 | | - * |
| 55 | + * |
56 | 56 | * @param SMWTypesValue $typevalue Represents the type of the object |
57 | 57 | * @param mixed $value user value string, or false if unknown |
58 | 58 | * @param mixed $caption user-defined caption or false if none given |
— | — | @@ -61,39 +61,43 @@ |
62 | 62 | if ( !$typeValue->isValid() ) { // just return the error, pass it through |
63 | 63 | $result = self::newTypeIDValue( '__err' ); |
64 | 64 | $result->addError( $typeValue->getErrors() ); |
65 | | - |
| 65 | + |
66 | 66 | return $result; |
67 | 67 | } |
68 | | - |
| 68 | + |
69 | 69 | return self::newTypeIDValue( $typeValue->getDBkey(), $value, $caption, $property ); |
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | 73 | * Create a value from a type id. If no $value is given, an empty container |
74 | 74 | * is created, the value of which can be set later on. |
75 | | - * |
| 75 | + * |
76 | 76 | * @param $typeid id string for the given type |
77 | 77 | * @param mixed $value user value string, or false if unknown |
78 | 78 | * @param mixed $caption user-defined caption or false if none given |
79 | 79 | * @param SMWPropertyValue $property Property object for which this value was made, or NULL |
80 | | - * |
| 80 | + * |
81 | 81 | * @return SMWDataValue |
82 | 82 | */ |
83 | 83 | static public function newTypeIDValue( $typeid, $value = false, $caption = false, $property = null ) { |
84 | 84 | self::initDatatypes(); |
85 | | - |
| 85 | + |
86 | 86 | if ( array_key_exists( $typeid, self::$mTypeClasses ) ) { // direct response for basic types |
87 | 87 | $result = new self::$mTypeClasses[$typeid]( $typeid ); |
88 | | - } elseif ( ( $typeid != '' ) && ( $typeid { 0 } != '_' ) ) { // custom type with linear conversion |
| 88 | + } elseif ( ( $typeid != '' ) && ( $typeid{0} != '_' ) ) { // custom type with linear conversion |
89 | 89 | $result = new self::$mTypeClasses['__lin']( $typeid ); |
90 | 90 | } else { // type really unknown |
91 | 91 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
92 | 92 | return new SMWErrorValue( wfMsgForContent( 'smw_unknowntype', $typeid ), $value, $caption ); |
93 | 93 | } |
94 | | - |
95 | | - if ( $property !== null ) $result->setProperty( $property ); |
96 | | - if ( $value !== false ) $result->setUserValue( $value, $caption ); |
97 | | - |
| 94 | + |
| 95 | + if ( $property !== null ) { |
| 96 | + $result->setProperty( $property ); |
| 97 | + } |
| 98 | + if ( $value !== false ) { |
| 99 | + $result->setUserValue( $value, $caption ); |
| 100 | + } |
| 101 | + |
98 | 102 | return $result; |
99 | 103 | } |
100 | 104 | |
— | — | @@ -101,11 +105,11 @@ |
102 | 106 | * Create a value for the given property, provided as an SMWPropertyValue |
103 | 107 | * object. If no value is given, an empty container is created, the value |
104 | 108 | * of which can be set later on. |
105 | | - * |
| 109 | + * |
106 | 110 | * @param SMWPropertyValue $property |
107 | 111 | * @param mixed $value |
108 | 112 | * @param mixed $caption |
109 | | - * |
| 113 | + * |
110 | 114 | * @return SMWDataValue |
111 | 115 | */ |
112 | 116 | static public function newPropertyObjectValue( SMWPropertyValue $property, $value = false, $caption = false ) { |
— | — | @@ -122,14 +126,14 @@ |
123 | 127 | */ |
124 | 128 | static protected function initDatatypes() { |
125 | 129 | global $smwgContLang; |
126 | | - |
| 130 | + |
127 | 131 | if ( is_array( self::$mTypeLabels ) ) { |
128 | 132 | return; // init happened before |
129 | 133 | } |
130 | | - |
| 134 | + |
131 | 135 | self::$mTypeLabels = $smwgContLang->getDatatypeLabels(); |
132 | 136 | self::$mTypeAliases = $smwgContLang->getDatatypeAliases(); |
133 | | - |
| 137 | + |
134 | 138 | // Setup built-in datatypes. |
135 | 139 | // NOTE: all ids must start with underscores, where two underscores indicate |
136 | 140 | // truly internal (non user-acessible types). All others should also get a |
— | — | @@ -167,21 +171,21 @@ |
168 | 172 | '__imp' => 'SMWImportValue', // Special import vocabulary type |
169 | 173 | '__pro' => 'SMWPropertyValue', // Property type (possibly predefined, no always based on a page) |
170 | 174 | ); |
171 | | - |
| 175 | + |
172 | 176 | wfRunHooks( 'smwInitDatatypes' ); |
173 | 177 | } |
174 | 178 | |
175 | 179 | /** |
176 | 180 | * A function for registering/overwriting datatypes for SMW. Should be |
177 | 181 | * called from within the hook 'smwInitDatatypes'. |
178 | | - * |
| 182 | + * |
179 | 183 | * @param string $id |
180 | 184 | * @param string $className |
181 | 185 | * @param mixed $label |
182 | 186 | */ |
183 | 187 | static public function registerDatatype( $id, $className, $label = false ) { |
184 | 188 | self::$mTypeClasses[$id] = $className; |
185 | | - |
| 189 | + |
186 | 190 | if ( $label != false ) { |
187 | 191 | self::$mTypeLabels[$id] = $label; |
188 | 192 | } |
— | — | @@ -192,7 +196,7 @@ |
193 | 197 | * should have a primary label, either provided by SMW or registered with |
194 | 198 | * registerDatatype(). This function should be called from within the hook |
195 | 199 | * 'smwInitDatatypes'. |
196 | | - * |
| 200 | + * |
197 | 201 | * @param string $id |
198 | 202 | * @param string $label |
199 | 203 | */ |
— | — | @@ -209,14 +213,14 @@ |
210 | 214 | * |
211 | 215 | * This method may or may not take aliases into account. For unknown |
212 | 216 | * labels, the normalised (DB-version) label is used as an ID. |
213 | | - * |
| 217 | + * |
214 | 218 | * @param string $label |
215 | 219 | * @param boolean $useAlias |
216 | 220 | */ |
217 | 221 | static public function findTypeID( $label, $useAlias = true ) { |
218 | 222 | self::initDatatypes(); |
219 | 223 | $id = array_search( $label, self::$mTypeLabels ); |
220 | | - |
| 224 | + |
221 | 225 | if ( $id !== false ) { |
222 | 226 | return $id; |
223 | 227 | } elseif ( ( $useAlias ) && ( array_key_exists( $label, self::$mTypeAliases ) ) ) { |
— | — | @@ -230,13 +234,13 @@ |
231 | 235 | * Get the translated user label for a given internal ID. If the ID does |
232 | 236 | * not have a label associated with it in the current language, the ID |
233 | 237 | * itself is transformed into a label (appropriate for user defined types). |
234 | | - * |
| 238 | + * |
235 | 239 | * @param string $id |
236 | 240 | */ |
237 | 241 | static public function findTypeLabel( $id ) { |
238 | 242 | self::initDatatypes(); |
239 | | - |
240 | | - if ( $id { 0 } === '_' ) { |
| 243 | + |
| 244 | + if ( $id{0} === '_' ) { |
241 | 245 | if ( array_key_exists( $id, self::$mTypeLabels ) ) { |
242 | 246 | return self::$mTypeLabels[$id]; |
243 | 247 | } else { // internal type without translation to user space; |
— | — | @@ -254,7 +258,7 @@ |
255 | 259 | * a property, and that are internal (i.e. not user defined). No labels are |
256 | 260 | * returned for internal types without user labels (e.g. the special types |
257 | 261 | * for some special properties), and for user defined types. |
258 | | - * |
| 262 | + * |
259 | 263 | * @return array |
260 | 264 | */ |
261 | 265 | static public function getKnownTypeLabels() { |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php |
— | — | @@ -19,16 +19,16 @@ |
20 | 20 | * |
21 | 21 | * This function also sets up all autoloading, such that all SMW classes are |
22 | 22 | * available as early on. Moreover, jobs and special pages are registered. |
23 | | - * |
| 23 | + * |
24 | 24 | * @param mixed $namespace |
25 | 25 | * @param boolean $complete |
26 | | - * |
| 26 | + * |
27 | 27 | * @return true |
28 | 28 | */ |
29 | 29 | function enableSemantics( $namespace = null, $complete = false ) { |
30 | 30 | global $wgVersion, $wgExtensionFunctions, $wgAutoloadClasses, $wgSpecialPages, $wgSpecialPageGroups, $wgHooks, $wgExtensionMessagesFiles; |
31 | 31 | global $smwgIP, $smwgNamespace, $wgJobClasses, $wgExtensionAliasesFiles, $wgServer; |
32 | | - |
| 32 | + |
33 | 33 | // The dot tells that the domain is not complete. It will be completed |
34 | 34 | // in the Export since we do not want to create a title object here when |
35 | 35 | // it is not needed in many cases. |
— | — | @@ -49,16 +49,15 @@ |
50 | 50 | |
51 | 51 | $wgHooks['ParserTestTables'][] = 'smwfOnParserTestTables'; |
52 | 52 | $wgHooks['AdminLinks'][] = 'smwfAddToAdminLinks'; |
53 | | - |
| 53 | + |
54 | 54 | if ( version_compare( $wgVersion, '1.17alpha', '>=' ) ) { |
55 | 55 | // For MediaWiki 1.17 alpha and later. |
56 | 56 | $wgHooks['ExtensionTypes'][] = 'smwfAddSemanticExtensionType'; |
57 | | - } |
58 | | - else { |
| 57 | + } else { |
59 | 58 | // For pre-MediaWiki 1.17 alpha. |
60 | | - $wgHooks['SpecialVersionExtensionTypes'][] = 'smwfOldAddSemanticExtensionType'; |
| 59 | + $wgHooks['SpecialVersionExtensionTypes'][] = 'smwfOldAddSemanticExtensionType'; |
61 | 60 | } |
62 | | - |
| 61 | + |
63 | 62 | // Register special pages aliases file |
64 | 63 | $wgExtensionAliasesFiles['SemanticMediaWiki'] = $smwgIP . 'languages/SMW_Aliases.php'; |
65 | 64 | |
— | — | @@ -72,14 +71,14 @@ |
73 | 72 | $wgAutoloadClasses['SMWResultPrinter'] = $smwgIP . 'includes/SMW_QueryPrinter.php'; |
74 | 73 | $wgAutoloadClasses['SMWDataValueFactory'] = $smwgIP . 'includes/SMW_DataValueFactory.php'; |
75 | 74 | $wgAutoloadClasses['SMWDataValue'] = $smwgIP . 'includes/SMW_DataValue.php'; |
76 | | - |
| 75 | + |
77 | 76 | // Article pages |
78 | 77 | $apDir = $smwgIP . 'includes/articlepages/'; |
79 | 78 | $wgAutoloadClasses['SMWOrderedListPage'] = $apDir . 'SMW_OrderedListPage.php'; |
80 | 79 | $wgAutoloadClasses['SMWTypePage'] = $apDir . 'SMW_TypePage.php'; |
81 | 80 | $wgAutoloadClasses['SMWPropertyPage'] = $apDir . 'SMW_PropertyPage.php'; |
82 | | - $wgAutoloadClasses['SMWConceptPage'] = $apDir . 'SMW_ConceptPage.php'; |
83 | | - |
| 81 | + $wgAutoloadClasses['SMWConceptPage'] = $apDir . 'SMW_ConceptPage.php'; |
| 82 | + |
84 | 83 | // Printers |
85 | 84 | $qpDir = $smwgIP . 'includes/queryprinters/'; |
86 | 85 | $wgAutoloadClasses['SMWAutoResultPrinter'] = $qpDir . 'SMW_QP_Auto.php'; |
— | — | @@ -90,7 +89,7 @@ |
91 | 90 | $wgAutoloadClasses['SMWRSSResultPrinter'] = $qpDir . 'SMW_QP_RSSlink.php'; |
92 | 91 | $wgAutoloadClasses['SMWCsvResultPrinter'] = $qpDir . 'SMW_QP_CSV.php'; |
93 | 92 | $wgAutoloadClasses['SMWJSONResultPrinter'] = $qpDir . 'SMW_QP_JSONlink.php'; |
94 | | - |
| 93 | + |
95 | 94 | // Datavalues |
96 | 95 | $dvDir = $smwgIP . 'includes/datavalues/'; |
97 | 96 | $wgAutoloadClasses['SMWContainerValue'] = $dvDir . 'SMW_DV_Container.php'; |
— | — | @@ -111,7 +110,7 @@ |
112 | 111 | $wgAutoloadClasses['SMWBoolValue'] = $dvDir . 'SMW_DV_Bool.php'; |
113 | 112 | $wgAutoloadClasses['SMWConceptValue'] = $dvDir . 'SMW_DV_Concept.php'; |
114 | 113 | $wgAutoloadClasses['SMWImportValue'] = $dvDir . 'SMW_DV_Import.php'; |
115 | | - |
| 114 | + |
116 | 115 | // Export |
117 | 116 | $expDir = $smwgIP . 'includes/export/'; |
118 | 117 | $wgAutoloadClasses['SMWExporter'] = $expDir . 'SMW_Exporter.php'; |
— | — | @@ -119,13 +118,13 @@ |
120 | 119 | $wgAutoloadClasses['SMWExpElement'] = $expDir . 'SMW_Exp_Element.php'; |
121 | 120 | $wgAutoloadClasses['SMWExpLiteral'] = $expDir . 'SMW_Exp_Element.php'; |
122 | 121 | $wgAutoloadClasses['SMWExpResource'] = $expDir . 'SMW_Exp_Element.php'; |
123 | | - |
| 122 | + |
124 | 123 | // Stores & queries |
125 | 124 | $wgAutoloadClasses['SMWQueryProcessor'] = $smwgIP . 'includes/SMW_QueryProcessor.php'; |
126 | 125 | $wgAutoloadClasses['SMWQueryParser'] = $smwgIP . 'includes/SMW_QueryParser.php'; |
127 | 126 | $wgAutoloadClasses['SMWRecordDescription'] = $smwgIP . 'includes/SMW_Record_Descriptions.php'; |
128 | 127 | $wgAutoloadClasses['SMWRecordFieldDescription'] = $smwgIP . 'includes/SMW_Record_Descriptions.php'; |
129 | | - |
| 128 | + |
130 | 129 | $stoDir = $smwgIP . 'includes/storage/'; |
131 | 130 | $wgAutoloadClasses['SMWQuery'] = $stoDir . 'SMW_Query.php'; |
132 | 131 | $wgAutoloadClasses['SMWQueryResult'] = $stoDir . 'SMW_QueryResult.php'; |
— | — | @@ -144,7 +143,7 @@ |
145 | 144 | $wgAutoloadClasses['SMWSQLStore2'] = $stoDir . 'SMW_SQLStore2.php'; |
146 | 145 | $wgAutoloadClasses['SMWSQLStore2Table'] = $stoDir . 'SMW_SQLStore2Table.php'; |
147 | 146 | $wgAutoloadClasses['SMWSQLHelpers'] = $stoDir . 'SMW_SQLHelpers.php'; |
148 | | - |
| 147 | + |
149 | 148 | // Do not autoload RAPStore, since some special pages load all autoloaded classes, which causes |
150 | 149 | // troubles with RAP store if RAP is not installed (require_once fails). |
151 | 150 | // $wgAutoloadClasses['SMWRAPStore'] = $smwgIP . 'includes/storage/SMW_RAPStore.php'; |
— | — | @@ -244,7 +243,7 @@ |
245 | 244 | $wgHooks['MonoBookTemplateToolboxEnd'][] = 'smwfShowBrowseLink'; |
246 | 245 | } |
247 | 246 | } |
248 | | - |
| 247 | + |
249 | 248 | if ( version_compare( $wgVersion, '1.14alpha', '>=' ) ) { |
250 | 249 | $wgHooks['SkinAfterContent'][] = 'SMWFactbox::onSkinAfterContent'; // draw Factbox below categories |
251 | 250 | $smwgMW_1_14 = true; // assume latest 1.14 API |
— | — | @@ -269,11 +268,11 @@ |
270 | 269 | |
271 | 270 | /** |
272 | 271 | * Adds the 'semantic' extension type to the type list. |
273 | | - * |
| 272 | + * |
274 | 273 | * @since 1.5.2 |
275 | | - * |
| 274 | + * |
276 | 275 | * @param $aExtensionTypes Array |
277 | | - * |
| 276 | + * |
278 | 277 | * @return true |
279 | 278 | */ |
280 | 279 | function smwfAddSemanticExtensionType( array &$aExtensionTypes ) { |
— | — | @@ -284,12 +283,12 @@ |
285 | 284 | |
286 | 285 | /** |
287 | 286 | * @see smwfAddSemanticExtensionType |
288 | | - * |
| 287 | + * |
289 | 288 | * @since 1.5.2 |
290 | | - * |
| 289 | + * |
291 | 290 | * @param $oSpecialVersion SpecialVersion |
292 | 291 | * @param $aExtensionTypes Array |
293 | | - * |
| 292 | + * |
294 | 293 | * @return true |
295 | 294 | */ |
296 | 295 | function smwfOldAddSemanticExtensionType( SpecialVersion &$oSpecialVersion, array &$aExtensionTypes ) { |
— | — | @@ -298,38 +297,38 @@ |
299 | 298 | |
300 | 299 | /** |
301 | 300 | * Adds links to Admin Links page. |
302 | | - **/ |
| 301 | + */ |
303 | 302 | function smwfAddToAdminLinks( &$admin_links_tree ) { |
304 | 303 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
305 | | - |
| 304 | + |
306 | 305 | $data_structure_section = new ALSection( wfMsg( 'smw_adminlinks_datastructure' ) ); |
307 | | - |
| 306 | + |
308 | 307 | $smw_row = new ALRow( 'smw' ); |
309 | 308 | $smw_row->addItem( ALItem::newFromSpecialPage( 'Categories' ) ); |
310 | 309 | $smw_row->addItem( ALItem::newFromSpecialPage( 'Properties' ) ); |
311 | 310 | $smw_row->addItem( ALItem::newFromSpecialPage( 'UnusedProperties' ) ); |
312 | 311 | $smw_row->addItem( ALItem::newFromSpecialPage( 'SemanticStatistics' ) ); |
313 | | - |
| 312 | + |
314 | 313 | $data_structure_section->addRow( $smw_row ); |
315 | 314 | $smw_admin_row = new ALRow( 'smw_admin' ); |
316 | 315 | $smw_admin_row->addItem( ALItem::newFromSpecialPage( 'SMWAdmin' ) ); |
317 | | - |
| 316 | + |
318 | 317 | $data_structure_section->addRow( $smw_admin_row ); |
319 | 318 | $smw_docu_row = new ALRow( 'smw_docu' ); |
320 | 319 | $smw_name = wfMsg( 'specialpages-group-smw_group' ); |
321 | 320 | $smw_docu_label = wfMsg( 'adminlinks_documentation', $smw_name ); |
322 | | - $smw_docu_row->addItem( AlItem::newFromExternalLink( "http://semantic-mediawiki.org/wiki/Help:User_manual", $smw_docu_label ) ); |
323 | | - |
| 321 | + $smw_docu_row->addItem( AlItem::newFromExternalLink( 'http://semantic-mediawiki.org/wiki/Help:User_manual', $smw_docu_label ) ); |
| 322 | + |
324 | 323 | $data_structure_section->addRow( $smw_docu_row ); |
325 | 324 | $admin_links_tree->addSection( $data_structure_section, wfMsg( 'adminlinks_browsesearch' ) ); |
326 | 325 | $smw_row = new ALRow( 'smw' ); |
327 | 326 | $displaying_data_section = new ALSection( wfMsg( 'smw_adminlinks_displayingdata' ) ); |
328 | | - $smw_row->addItem( AlItem::newFromExternalLink( "http://semantic-mediawiki.org/wiki/Help:Inline_queries", wfMsg( 'smw_adminlinks_inlinequerieshelp' ) ) ); |
| 327 | + $smw_row->addItem( AlItem::newFromExternalLink( 'http://semantic-mediawiki.org/wiki/Help:Inline_queries', wfMsg( 'smw_adminlinks_inlinequerieshelp' ) ) ); |
329 | 328 | |
330 | 329 | $displaying_data_section->addRow( $smw_row ); |
331 | 330 | $admin_links_tree->addSection( $displaying_data_section, wfMsg( 'adminlinks_browsesearch' ) ); |
332 | 331 | $browse_search_section = $admin_links_tree->getSection( wfMsg( 'adminlinks_browsesearch' ) ); |
333 | | - |
| 332 | + |
334 | 333 | $smw_row = new ALRow( 'smw' ); |
335 | 334 | $smw_row->addItem( ALItem::newFromSpecialPage( 'Browse' ) ); |
336 | 335 | $smw_row->addItem( ALItem::newFromSpecialPage( 'Ask' ) ); |
— | — | @@ -343,15 +342,15 @@ |
344 | 343 | /** |
345 | 344 | * Register special classes for displaying semantic content on Property/Type |
346 | 345 | * pages. |
347 | | - * |
| 346 | + * |
348 | 347 | * @param $title: Title |
349 | 348 | * @param $article: Article or null |
350 | | - * |
| 349 | + * |
351 | 350 | * @return true |
352 | 351 | */ |
353 | 352 | function smwfOnArticleFromTitle( Title &$title, /* Article */ &$article ) { |
354 | 353 | global $smwgIP; |
355 | | - |
| 354 | + |
356 | 355 | if ( $title->getNamespace() == SMW_NS_TYPE ) { |
357 | 356 | $article = new SMWTypePage( $title ); |
358 | 357 | } elseif ( $title->getNamespace() == SMW_NS_PROPERTY ) { |
— | — | @@ -359,7 +358,7 @@ |
360 | 359 | } elseif ( $title->getNamespace() == SMW_NS_CONCEPT ) { |
361 | 360 | $article = new SMWConceptPage( $title ); |
362 | 361 | } |
363 | | - |
| 362 | + |
364 | 363 | return true; |
365 | 364 | } |
366 | 365 | |
— | — | @@ -391,10 +390,10 @@ |
392 | 391 | if ( $skintemplate->data['isarticle'] ) { |
393 | 392 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
394 | 393 | $browselink = SMWInfolink::newBrowsingLink( wfMsg( 'smw_browselink' ), |
395 | | - $skintemplate->data['titleprefixeddbkey'], false ); |
396 | | - echo "<li id=\"t-smwbrowselink\">" . $browselink->getHTML() . "</li>"; |
397 | | - } |
398 | | - return true; |
| 394 | + $skintemplate->data['titleprefixeddbkey'], false ); |
| 395 | + echo '<li id="t-smwbrowselink">' . $browselink->getHTML() . '</li>'; |
| 396 | + } |
| 397 | + return true; |
399 | 398 | } |
400 | 399 | |
401 | 400 | /**********************************************/ |
— | — | @@ -424,7 +423,9 @@ |
425 | 424 | smwfInitContentLanguage( $wgLanguageCode ); |
426 | 425 | |
427 | 426 | // Register namespace identifiers |
428 | | - if ( !is_array( $wgExtraNamespaces ) ) { $wgExtraNamespaces = array(); } |
| 427 | + if ( !is_array( $wgExtraNamespaces ) ) { |
| 428 | + $wgExtraNamespaces = array(); |
| 429 | + } |
429 | 430 | $wgExtraNamespaces = $wgExtraNamespaces + $smwgContLang->getNamespaces(); |
430 | 431 | $wgNamespaceAliases = $wgNamespaceAliases + $smwgContLang->getNamespaceAliases(); |
431 | 432 | |
— | — | @@ -470,13 +471,15 @@ |
471 | 472 | */ |
472 | 473 | function smwfInitContentLanguage( $langcode ) { |
473 | 474 | global $smwgIP, $smwgContLang; |
474 | | - |
475 | | - if ( !empty( $smwgContLang ) ) { return; } |
| 475 | + |
| 476 | + if ( !empty( $smwgContLang ) ) { |
| 477 | + return; |
| 478 | + } |
476 | 479 | wfProfileIn( 'smwfInitContentLanguage (SMW)' ); |
477 | 480 | |
478 | 481 | $smwContLangFile = 'SMW_Language' . str_replace( '-', '_', ucfirst( $langcode ) ); |
479 | 482 | $smwContLangClass = 'SMWLanguage' . str_replace( '-', '_', ucfirst( $langcode ) ); |
480 | | - |
| 483 | + |
481 | 484 | if ( file_exists( $smwgIP . 'languages/' . $smwContLangFile . '.php' ) ) { |
482 | 485 | include_once( $smwgIP . 'languages/' . $smwContLangFile . '.php' ); |
483 | 486 | } |
— | — | @@ -486,7 +489,7 @@ |
487 | 490 | include_once( $smwgIP . 'languages/SMW_LanguageEn.php' ); |
488 | 491 | $smwContLangClass = 'SMWLanguageEn'; |
489 | 492 | } |
490 | | - |
| 493 | + |
491 | 494 | $smwgContLang = new $smwContLangClass(); |
492 | 495 | |
493 | 496 | wfProfileOut( 'smwfInitContentLanguage (SMW)' ); |