Made WikiPage::factory a bit more dummy proof
authorAaron Schulz <aaron@users.mediawiki.org>
Thu, 14 Jul 2011 17:39:04 +0000 (17:39 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Thu, 14 Jul 2011 17:39:04 +0000 (17:39 +0000)
includes/WikiPage.php

index 1d7f2fa..8804f83 100644 (file)
@@ -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;