r85590 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85589‎ | r85590 | r85591 >
Date:23:43, 6 April 2011
Author:reedy
Status:ok
Tags:
Comment:
* (bug 13163) Activate SubPageList3 extension on English Wikiversity

Fixup some style and code issues

Also documentation and such
Modified paths:
  • /trunk/extensions/SubPageList3/SubPageList3.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SubPageList3/SubPageList3.php
@@ -35,6 +35,8 @@
3636
3737 /**
3838 * Hook in function
 39+ *
 40+ * @param $parser Parser
3941 */
4042 function efSubpageList3( &$parser ) {
4143 $parser->setHook( 'splist', 'efRenderSubpageList3' );
@@ -45,8 +47,6 @@
4648 * Function called by the Hook, returns the wiki text
4749 */
4850 function efRenderSubpageList3( $input, $args, $parser ) {
49 - global $wgVersion;
50 -
5151 $list = new SubpageList3( $parser );
5252 $list->options( $args );
5353
@@ -75,8 +75,7 @@
7676 var $title;
7777
7878 /**
79 - * ptitle object
80 - * @var object ptitle object
 79+ * @var Title
8180 * @private
8281 */
8382 var $ptitle;
@@ -203,8 +202,8 @@
204203
205204 /**
206205 * 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
209208 * @see SubpageList
210209 * @private
211210 */
@@ -231,7 +230,7 @@
232231 * @private
233232 */
234233 function error( $message ) {
235 - if ( $this->debug /*|| $this->debug == 1*/ ) {
 234+ if ( $this->debug ) {
236235 $this->errors[] = "<strong>Error [Subpage List 3]:</strong> $message";
237236 }
238237 }
@@ -280,17 +279,32 @@
281280 }
282281 if( isset( $options['sortby'] ) ) {
283282 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') );
287291 }
288292 }
289293 if( isset( $options['liststyle'] ) ) {
290294 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 = '&#160;· '; 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 = '&#160;· ';
 306+ break;
 307+ default:
 308+ $this->error( wfMsg('spl3_debug','liststyle') );
295309 }
296310 }
297311 if( isset( $options['parent'] ) ) {
@@ -304,15 +318,32 @@
305319 }
306320 if( isset( $options['showpath'] ) ) {
307321 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') );
317348 }
318349 }
319350 if( isset( $options['kidsonly'] ) ) {
@@ -369,7 +400,6 @@
370401 $conditions = array();
371402 $options = array();
372403 $order = strtoupper( $this->order );
373 - $parent = '';
374404
375405 if( $this->ordermethod == 'title' ) {
376406 $options['ORDER BY'] = '`page_title`' . $order;
@@ -397,7 +427,10 @@
398428 $nsi = $this->title->getNamespace();
399429 }
400430
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+ }
402435 $conditions['page_is_redirect'] = 0;
403436 $conditions[] = '`page_title` ' . $dbr->buildLike( $parent . '/', $dbr->anyString() );
404437
@@ -407,13 +440,12 @@
408441 $res = $dbr->select( 'page', $fields, $conditions, __METHOD__, $options );
409442
410443 $titles = array();
411 - while( $row = $dbr->fetchObject( $res ) ) {
 444+ foreach ( $res as $row ) {
412445 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
413 - if( is_object( $title ) ) {
 446+ if( $title ) {
414447 $titles[] = $title;
415448 }
416449 }
417 - $dbr->freeResult( $res );
418450 wfProfileOut( __METHOD__ );
419451 return $titles;
420452 }
@@ -424,23 +456,28 @@
425457 * - full: full, e.g. Mainpage/Entry/Sub
426458 * - notparent: the path without the $parent item, e.g. Entry/Sub
427459 * - 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
429461 * @return string the prepared string
430462 * @see $showpath
431463 */
432464 function makeListItem( $title ) {
433465 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();
437474 }
438475 return ' [[' . $title->getPrefixedText() . '|' . $linktitle . ']]';
439476 }
440477
441478 /**
442479 * 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:
445482 * - * for ul,
446483 * - # for ol
447484 * - · for horizontal lists
@@ -459,6 +496,7 @@
460497 }
461498 # add descendents
462499 $parlv = substr_count($this->ptitle->getPrefixedText(), '/');
 500+ $list = array();
463501 foreach( $titles as $title ) {
464502 $lv = substr_count($title, '/') - $parlv;
465503 if ($this->kidsonly!=1 || $lv<2) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r85596* (bug 13163) Activate SubPageList3 extension on English Wikiversity...reedy00:00, 7 April 2011
r90651Copying SubPageList3 from trunk to 1.17wmf1 per bug 13163.tstarling06:58, 23 June 2011

Status & tagging log