Index: trunk/extensions/SubPageList3/SubPageList3.php |
— | — | @@ -35,6 +35,8 @@ |
36 | 36 | |
37 | 37 | /** |
38 | 38 | * Hook in function |
| 39 | + * |
| 40 | + * @param $parser Parser |
39 | 41 | */ |
40 | 42 | function efSubpageList3( &$parser ) { |
41 | 43 | $parser->setHook( 'splist', 'efRenderSubpageList3' ); |
— | — | @@ -45,8 +47,6 @@ |
46 | 48 | * Function called by the Hook, returns the wiki text |
47 | 49 | */ |
48 | 50 | function efRenderSubpageList3( $input, $args, $parser ) { |
49 | | - global $wgVersion; |
50 | | - |
51 | 51 | $list = new SubpageList3( $parser ); |
52 | 52 | $list->options( $args ); |
53 | 53 | |
— | — | @@ -75,8 +75,7 @@ |
76 | 76 | var $title; |
77 | 77 | |
78 | 78 | /** |
79 | | - * ptitle object |
80 | | - * @var object ptitle object |
| 79 | + * @var Title |
81 | 80 | * @private |
82 | 81 | */ |
83 | 82 | var $ptitle; |
— | — | @@ -203,8 +202,8 @@ |
204 | 203 | |
205 | 204 | /** |
206 | 205 | * Constructor function of the class |
207 | | - * @param object $parser the parser object |
208 | | - * @global object $wgContLang |
| 206 | + * @param $parser Parser the parser object |
| 207 | + * @global $wgContLang |
209 | 208 | * @see SubpageList |
210 | 209 | * @private |
211 | 210 | */ |
— | — | @@ -231,7 +230,7 @@ |
232 | 231 | * @private |
233 | 232 | */ |
234 | 233 | function error( $message ) { |
235 | | - if ( $this->debug /*|| $this->debug == 1*/ ) { |
| 234 | + if ( $this->debug ) { |
236 | 235 | $this->errors[] = "<strong>Error [Subpage List 3]:</strong> $message"; |
237 | 236 | } |
238 | 237 | } |
— | — | @@ -280,17 +279,32 @@ |
281 | 280 | } |
282 | 281 | if( isset( $options['sortby'] ) ) { |
283 | 282 | switch( strtolower( $options['sortby'] ) ) { |
284 | | - case 'title': $this->ordermethod = 'title'; break; |
285 | | - case 'lastedit': $this->ordermethod = 'lastedit'; break; |
286 | | - default: $this->error( wfMsg('spl3_debug','sortby') ); |
| 283 | + case 'title': |
| 284 | + $this->ordermethod = 'title'; |
| 285 | + break; |
| 286 | + case 'lastedit': |
| 287 | + $this->ordermethod = 'lastedit'; |
| 288 | + break; |
| 289 | + default: |
| 290 | + $this->error( wfMsg('spl3_debug','sortby') ); |
287 | 291 | } |
288 | 292 | } |
289 | 293 | if( isset( $options['liststyle'] ) ) { |
290 | 294 | switch( strtolower( $options['liststyle'] ) ) { |
291 | | - case 'ordered': $this->mode = 'ordered'; $this->token = '#'; break; |
292 | | - case 'unordered': $this->mode = 'unordered'; $this->token = '*'; break; |
293 | | - case 'bar': $this->mode = 'bar'; $this->token = ' · '; break; |
294 | | - default: $this->error( wfMsg('spl3_debug','liststyle') ); |
| 295 | + case 'ordered': |
| 296 | + $this->mode = 'ordered'; |
| 297 | + $this->token = '#'; |
| 298 | + break; |
| 299 | + case 'unordered': |
| 300 | + $this->mode = 'unordered'; |
| 301 | + $this->token = '*'; |
| 302 | + break; |
| 303 | + case 'bar': |
| 304 | + $this->mode = 'bar'; |
| 305 | + $this->token = ' · '; |
| 306 | + break; |
| 307 | + default: |
| 308 | + $this->error( wfMsg('spl3_debug','liststyle') ); |
295 | 309 | } |
296 | 310 | } |
297 | 311 | if( isset( $options['parent'] ) ) { |
— | — | @@ -304,15 +318,32 @@ |
305 | 319 | } |
306 | 320 | if( isset( $options['showpath'] ) ) { |
307 | 321 | switch( strtolower( $options['showpath'] ) ) { |
308 | | - case 'no': $this->showpath = 'no'; break; |
309 | | - case '0': $this->showpath = 'no'; break; |
310 | | - case 'false': $this->showpath = 'no'; break; |
311 | | - case 'notparent': $this->showpath = 'notparent'; break; |
312 | | - case 'full': $this->showpath = 'full'; break; |
313 | | - case 'yes': $this->showpath = 'full'; break; |
314 | | - case '1': $this->showpath = 'full'; break; |
315 | | - case 'true': $this->showpath = 'full'; break; |
316 | | - default: $this->error( wfMsg('spl3_debug','showpath') ); |
| 322 | + case 'no': |
| 323 | + $this->showpath = 'no'; |
| 324 | + break; |
| 325 | + case '0': |
| 326 | + $this->showpath = 'no'; |
| 327 | + break; |
| 328 | + case 'false': |
| 329 | + $this->showpath = 'no'; |
| 330 | + break; |
| 331 | + case 'notparent': |
| 332 | + $this->showpath = 'notparent'; |
| 333 | + break; |
| 334 | + case 'full': |
| 335 | + $this->showpath = 'full'; |
| 336 | + break; |
| 337 | + case 'yes': |
| 338 | + $this->showpath = 'full'; |
| 339 | + break; |
| 340 | + case '1': |
| 341 | + $this->showpath = 'full'; |
| 342 | + break; |
| 343 | + case 'true': |
| 344 | + $this->showpath = 'full'; |
| 345 | + break; |
| 346 | + default: |
| 347 | + $this->error( wfMsg('spl3_debug','showpath') ); |
317 | 348 | } |
318 | 349 | } |
319 | 350 | if( isset( $options['kidsonly'] ) ) { |
— | — | @@ -369,7 +400,6 @@ |
370 | 401 | $conditions = array(); |
371 | 402 | $options = array(); |
372 | 403 | $order = strtoupper( $this->order ); |
373 | | - $parent = ''; |
374 | 404 | |
375 | 405 | if( $this->ordermethod == 'title' ) { |
376 | 406 | $options['ORDER BY'] = '`page_title`' . $order; |
— | — | @@ -397,7 +427,10 @@ |
398 | 428 | $nsi = $this->title->getNamespace(); |
399 | 429 | } |
400 | 430 | |
401 | | - if (strlen($nsi)>0) $conditions['page_namespace'] = $nsi; // don't let list cross namespaces |
| 431 | + // don't let list cross namespaces |
| 432 | + if (strlen($nsi)>0) { |
| 433 | + $conditions['page_namespace'] = $nsi; |
| 434 | + } |
402 | 435 | $conditions['page_is_redirect'] = 0; |
403 | 436 | $conditions[] = '`page_title` ' . $dbr->buildLike( $parent . '/', $dbr->anyString() ); |
404 | 437 | |
— | — | @@ -407,13 +440,12 @@ |
408 | 441 | $res = $dbr->select( 'page', $fields, $conditions, __METHOD__, $options ); |
409 | 442 | |
410 | 443 | $titles = array(); |
411 | | - while( $row = $dbr->fetchObject( $res ) ) { |
| 444 | + foreach ( $res as $row ) { |
412 | 445 | $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title ); |
413 | | - if( is_object( $title ) ) { |
| 446 | + if( $title ) { |
414 | 447 | $titles[] = $title; |
415 | 448 | } |
416 | 449 | } |
417 | | - $dbr->freeResult( $res ); |
418 | 450 | wfProfileOut( __METHOD__ ); |
419 | 451 | return $titles; |
420 | 452 | } |
— | — | @@ -424,23 +456,28 @@ |
425 | 457 | * - full: full, e.g. Mainpage/Entry/Sub |
426 | 458 | * - notparent: the path without the $parent item, e.g. Entry/Sub |
427 | 459 | * - no: no path, only the page title, e.g. Sub |
428 | | - * @param string $title the title of a page |
| 460 | + * @param $title Title the title of a page |
429 | 461 | * @return string the prepared string |
430 | 462 | * @see $showpath |
431 | 463 | */ |
432 | 464 | function makeListItem( $title ) { |
433 | 465 | switch( $this->showpath ) { |
434 | | - case 'no': $linktitle = substr( strrchr( $title->getText(), "/" ), 1 ); break; |
435 | | - case 'notparent': $linktitle = substr( strstr( $title->getText(), "/" ), 1 ); break; |
436 | | - case 'full': $linktitle = $title->getText(); |
| 466 | + case 'no': |
| 467 | + $linktitle = substr( strrchr( $title->getText(), "/" ), 1 ); |
| 468 | + break; |
| 469 | + case 'notparent': |
| 470 | + $linktitle = substr( strstr( $title->getText(), "/" ), 1 ); |
| 471 | + break; |
| 472 | + case 'full': |
| 473 | + $linktitle = $title->getText(); |
437 | 474 | } |
438 | 475 | return ' [[' . $title->getPrefixedText() . '|' . $linktitle . ']]'; |
439 | 476 | } |
440 | 477 | |
441 | 478 | /** |
442 | 479 | * create whole list using makeListItem |
443 | | - * @param string $titles all page titles |
444 | | - * @param string $token the token symbol: |
| 480 | + * @param $titles Array all page titles |
| 481 | + * @param $token string the token symbol: |
445 | 482 | * - * for ul, |
446 | 483 | * - # for ol |
447 | 484 | * - · for horizontal lists |
— | — | @@ -459,6 +496,7 @@ |
460 | 497 | } |
461 | 498 | # add descendents |
462 | 499 | $parlv = substr_count($this->ptitle->getPrefixedText(), '/'); |
| 500 | + $list = array(); |
463 | 501 | foreach( $titles as $title ) { |
464 | 502 | $lv = substr_count($title, '/') - $parlv; |
465 | 503 | if ($this->kidsonly!=1 || $lv<2) { |