From fe623a323b21720074e1ac4ca6c9a8a7dd38e725 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 12 Jul 2011 18:01:16 +0000 Subject: [PATCH] Added WikiPageFactory class with newFromTitle() function --- includes/AutoLoader.php | 1 + includes/WikiPageFactory.php | 28 ++++++++++++++++++++++++++ tests/phpunit/includes/ArticleTest.php | 13 ++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 includes/WikiPageFactory.php diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index af97abf693..41daa7bb75 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -243,6 +243,7 @@ $wgAutoloadLocalClasses = array( 'WikiFilePage' => 'includes/WikiFilePage.php', 'WikiImporter' => 'includes/Import.php', 'WikiPage' => 'includes/WikiPage.php', + 'WikiPageFactory' => 'includes/WikiPageFactory.php', 'WikiRevision' => 'includes/Import.php', 'WikiMap' => 'includes/WikiMap.php', 'WikiReference' => 'includes/WikiMap.php', diff --git a/includes/WikiPageFactory.php b/includes/WikiPageFactory.php new file mode 100644 index 0000000000..4310c387de --- /dev/null +++ b/includes/WikiPageFactory.php @@ -0,0 +1,28 @@ +getNamespace() ) { + case NS_MEDIA: + throw new MWException( "NS_MEDIA is a virtual namespace" ); + case NS_FILE: + $page = new WikiFilePage( $title ); + break; + case NS_CATEGORY: + $page = new WikiCategoryPage( $title ); + break; + default: + $page = new WikiPage( $title ); + } + + return $page; + } +} diff --git a/tests/phpunit/includes/ArticleTest.php b/tests/phpunit/includes/ArticleTest.php index 1814b86128..449851c56b 100644 --- a/tests/phpunit/includes/ArticleTest.php +++ b/tests/phpunit/includes/ArticleTest.php @@ -63,4 +63,17 @@ class ArticleTest extends MediaWikiTestCase { "Article static functions" ); } + function testWikiPageFactory() { + $title = Title::makeTitle( NS_FILE, 'Someimage.png' ); + $page = WikiPageFactory::newFromTitle( $title ); + $this->assertEquals( 'WikiFilePage', get_class( $page ) ); + + $title = Title::makeTitle( NS_CATEGORY, 'SomeCategory' ); + $page = WikiPageFactory::newFromTitle( $title ); + $this->assertEquals( 'WikiCategoryPage', get_class( $page ) ); + + $title = Title::makeTitle( NS_MAIN, 'SomePage' ); + $page = WikiPageFactory::newFromTitle( $title ); + $this->assertEquals( 'WikiPage', get_class( $page ) ); + } } -- 2.20.1