From 0b1eb48108274be6358a282b4d7f28948b77ddb6 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 14 Jul 2011 17:39:04 +0000 Subject: [PATCH] Made WikiPage::factory a bit more dummy proof --- includes/WikiPage.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/includes/WikiPage.php b/includes/WikiPage.php index 1d7f2fae70..8804f834f9 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -54,9 +54,15 @@ class WikiPage extends Page { * @return WikiPage object of the appropriate type */ public static function factory( Title $title ) { - switch( $title->getNamespace() ) { - case NS_MEDIA: - throw new MWException( "NS_MEDIA is a virtual namespace" ); + $ns = $title->getNamespace(); + + if ( $ns == NS_MEDIA ) { + throw new MWException( "NS_MEDIA is a virtual namespace; use NS_FILE." ); + } elseif ( $ns < 0 ) { + throw new MWException( "Invalid or virtual namespace $ns given." ); + } + + switch ( $ns ) { case NS_FILE: $page = new WikiFilePage( $title ); break; -- 2.20.1