r92169 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92168‎ | r92169 | r92170 >
Date:17:39, 14 July 2011
Author:aaron
Status:ok
Tags:
Comment:
Made WikiPage::factory a bit more dummy proof
Modified paths:
  • /trunk/phase3/includes/WikiPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/WikiPage.php
@@ -54,9 +54,15 @@
5555 * @return WikiPage object of the appropriate type
5656 */
5757 public static function factory( Title $title ) {
58 - switch( $title->getNamespace() ) {
59 - case NS_MEDIA:
60 - throw new MWException( "NS_MEDIA is a virtual namespace" );
 58+ $ns = $title->getNamespace();
 59+
 60+ if ( $ns == NS_MEDIA ) {
 61+ throw new MWException( "NS_MEDIA is a virtual namespace; use NS_FILE." );
 62+ } elseif ( $ns < 0 ) {
 63+ throw new MWException( "Invalid or virtual namespace $ns given." );
 64+ }
 65+
 66+ switch ( $ns ) {
6167 case NS_FILE:
6268 $page = new WikiFilePage( $title );
6369 break;

Status & tagging log