Index: trunk/phase3/tests/phpunit/includes/ArticleTest.php |
— | — | @@ -63,4 +63,17 @@ |
64 | 64 | "Article static functions" ); |
65 | 65 | } |
66 | 66 | |
| 67 | + function testWikiPageFactory() { |
| 68 | + $title = Title::makeTitle( NS_FILE, 'Someimage.png' ); |
| 69 | + $page = WikiPageFactory::newFromTitle( $title ); |
| 70 | + $this->assertEquals( 'WikiFilePage', get_class( $page ) ); |
| 71 | + |
| 72 | + $title = Title::makeTitle( NS_CATEGORY, 'SomeCategory' ); |
| 73 | + $page = WikiPageFactory::newFromTitle( $title ); |
| 74 | + $this->assertEquals( 'WikiCategoryPage', get_class( $page ) ); |
| 75 | + |
| 76 | + $title = Title::makeTitle( NS_MAIN, 'SomePage' ); |
| 77 | + $page = WikiPageFactory::newFromTitle( $title ); |
| 78 | + $this->assertEquals( 'WikiPage', get_class( $page ) ); |
| 79 | + } |
67 | 80 | } |
Index: trunk/phase3/includes/WikiPageFactory.php |
— | — | @@ -0,0 +1,28 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Factory class for classes representing a MediaWiki article and history. |
| 5 | + */ |
| 6 | +class WikiPageFactory { |
| 7 | + /** |
| 8 | + * Create an WikiPage object of the appropriate class for the given title. |
| 9 | + * |
| 10 | + * @param $title Title |
| 11 | + * @return WikiPage object |
| 12 | + */ |
| 13 | + public static function newFromTitle( Title $title ) { |
| 14 | + switch( $title->getNamespace() ) { |
| 15 | + case NS_MEDIA: |
| 16 | + throw new MWException( "NS_MEDIA is a virtual namespace" ); |
| 17 | + case NS_FILE: |
| 18 | + $page = new WikiFilePage( $title ); |
| 19 | + break; |
| 20 | + case NS_CATEGORY: |
| 21 | + $page = new WikiCategoryPage( $title ); |
| 22 | + break; |
| 23 | + default: |
| 24 | + $page = new WikiPage( $title ); |
| 25 | + } |
| 26 | + |
| 27 | + return $page; |
| 28 | + } |
| 29 | +} |
Property changes on: trunk/phase3/includes/WikiPageFactory.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 30 | + native |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -243,6 +243,7 @@ |
244 | 244 | 'WikiFilePage' => 'includes/WikiFilePage.php', |
245 | 245 | 'WikiImporter' => 'includes/Import.php', |
246 | 246 | 'WikiPage' => 'includes/WikiPage.php', |
| 247 | + 'WikiPageFactory' => 'includes/WikiPageFactory.php', |
247 | 248 | 'WikiRevision' => 'includes/Import.php', |
248 | 249 | 'WikiMap' => 'includes/WikiMap.php', |
249 | 250 | 'WikiReference' => 'includes/WikiMap.php', |