r92002 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92001‎ | r92002 | r92003 >
Date:20:32, 12 July 2011
Author:aaron
Status:ok (Comments)
Tags:
Comment:
Follow-up r91997, moved newFromTitle() function to WikiPage.php and renamed to factory(). This avoids an extra class.
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/WikiPage.php (modified) (history)
  • /trunk/phase3/includes/WikiPageFactory.php (deleted) (history)
  • /trunk/phase3/tests/phpunit/includes/ArticleTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/ArticleTest.php
@@ -65,15 +65,15 @@
6666
6767 function testWikiPageFactory() {
6868 $title = Title::makeTitle( NS_FILE, 'Someimage.png' );
69 - $page = WikiPageFactory::newFromTitle( $title );
 69+ $page = WikiPage::factory( $title );
7070 $this->assertEquals( 'WikiFilePage', get_class( $page ) );
7171
7272 $title = Title::makeTitle( NS_CATEGORY, 'SomeCategory' );
73 - $page = WikiPageFactory::newFromTitle( $title );
 73+ $page = WikiPage::factory( $title );
7474 $this->assertEquals( 'WikiCategoryPage', get_class( $page ) );
7575
7676 $title = Title::makeTitle( NS_MAIN, 'SomePage' );
77 - $page = WikiPageFactory::newFromTitle( $title );
 77+ $page = WikiPage::factory( $title );
7878 $this->assertEquals( 'WikiPage', get_class( $page ) );
7979 }
8080 }
Index: trunk/phase3/includes/WikiPageFactory.php
@@ -1,28 +0,0 @@
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 -}
Index: trunk/phase3/includes/AutoLoader.php
@@ -243,7 +243,6 @@
244244 'WikiFilePage' => 'includes/WikiFilePage.php',
245245 'WikiImporter' => 'includes/Import.php',
246246 'WikiPage' => 'includes/WikiPage.php',
247 - 'WikiPageFactory' => 'includes/WikiPageFactory.php',
248247 'WikiRevision' => 'includes/Import.php',
249248 'WikiMap' => 'includes/WikiMap.php',
250249 'WikiReference' => 'includes/WikiMap.php',
Index: trunk/phase3/includes/WikiPage.php
@@ -48,6 +48,29 @@
4949 }
5050
5151 /**
 52+ * Create a WikiPage object of the appropriate class for the given title.
 53+ *
 54+ * @param $title Title
 55+ * @return WikiPage object of the appropriate type
 56+ */
 57+ public static function factory( Title $title ) {
 58+ switch( $title->getNamespace() ) {
 59+ case NS_MEDIA:
 60+ throw new MWException( "NS_MEDIA is a virtual namespace" );
 61+ case NS_FILE:
 62+ $page = new WikiFilePage( $title );
 63+ break;
 64+ case NS_CATEGORY:
 65+ $page = new WikiCategoryPage( $title );
 66+ break;
 67+ default:
 68+ $page = new WikiPage( $title );
 69+ }
 70+
 71+ return $page;
 72+ }
 73+
 74+ /**
5275 * Constructor from a page id
5376 *
5477 * Always override this for all subclasses (until we use PHP with LSB)

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r91980Added WikiPageFactory class with newFromTitle() functionaaron18:01, 12 July 2011

Comments

#Comment by Siebrand (talk | contribs)   23:02, 12 July 2011

Incorrect follow-up revision r91997. Please add correct one.

#Comment by Aaron Schulz (talk | contribs)   23:05, 12 July 2011
#Comment by Siebrand (talk | contribs)   23:08, 12 July 2011

That is THIS rev :).

#Comment by Aaron Schulz (talk | contribs)   23:13, 12 July 2011

Status & tagging log