r88594 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88593‎ | r88594 | r88595 >
Date:18:38, 22 May 2011
Author:ialex
Status:ok
Tags:
Comment:
Moved MediaWiki::articleFromTitle() to Article::newFromTitle(), this has nothing to do in the MediaWiki class
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Wiki.php (modified) (history)
  • /trunk/phase3/includes/api/ApiPurge.php (modified) (history)
  • /trunk/phase3/includes/search/SearchEngine.php (modified) (history)
  • /trunk/phase3/index.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/search/SearchEngine.php
@@ -177,7 +177,7 @@
178178
179179 # See if it still otherwise has content is some sane sense
180180 $context->setTitle( $title );
181 - $article = MediaWiki::articleFromTitle( $title, $context );
 181+ $article = Article::newFromTitle( $title, $context );
182182 if ( $article->hasViewableContent() ) {
183183 return $title;
184184 }
Index: trunk/phase3/includes/Article.php
@@ -86,6 +86,40 @@
8787 }
8888
8989 /**
 90+ * Create an Article object of the appropriate class for the given page.
 91+ *
 92+ * @param $title Title
 93+ * @param $context RequestContext
 94+ * @return Article object
 95+ */
 96+ public static function newFromTitle( $title, RequestContext $context ) {
 97+ if ( NS_MEDIA == $title->getNamespace() ) {
 98+ // FIXME: where should this go?
 99+ $title = Title::makeTitle( NS_FILE, $title->getDBkey() );
 100+ }
 101+
 102+ $article = null;
 103+ wfRunHooks( 'ArticleFromTitle', array( &$title, &$article ) );
 104+ if ( $article ) {
 105+ $article->setContext( $context );
 106+ return $article;
 107+ }
 108+
 109+ switch( $title->getNamespace() ) {
 110+ case NS_FILE:
 111+ $page = new ImagePage( $title );
 112+ break;
 113+ case NS_CATEGORY:
 114+ $page = new CategoryPage( $title );
 115+ break;
 116+ default:
 117+ $page = new Article( $title );
 118+ }
 119+ $page->setContext( $context );
 120+ return $page;
 121+ }
 122+
 123+ /**
90124 * Constructor from an page id
91125 * @param $id Int article ID to load
92126 */
Index: trunk/phase3/includes/api/ApiPurge.php
@@ -69,7 +69,7 @@
7070 continue;
7171 }
7272 $context = RequestContext::getMain();
73 - $article = MediaWiki::articleFromTitle( $title, $context );
 73+ $article = Article::newFromTitle( $title, $context );
7474 $article->doPurge(); // Directly purge and skip the UI part of purge().
7575 $r['purged'] = '';
7676
Index: trunk/phase3/includes/Wiki.php
@@ -228,34 +228,13 @@
229229 /**
230230 * Create an Article object of the appropriate class for the given page.
231231 *
 232+ * @deprecated in 1.19; use Article::newFromTitle() instead
232233 * @param $title Title
233234 * @param $context RequestContext
234235 * @return Article object
235236 */
236237 public static function articleFromTitle( $title, RequestContext $context ) {
237 - if ( NS_MEDIA == $title->getNamespace() ) {
238 - // @todo FIXME: Where should this go?
239 - $title = Title::makeTitle( NS_FILE, $title->getDBkey() );
240 - }
241 -
242 - $article = null;
243 - wfRunHooks( 'ArticleFromTitle', array( &$title, &$article ) );
244 - if ( $article ) {
245 - return $article;
246 - }
247 -
248 - switch( $title->getNamespace() ) {
249 - case NS_FILE:
250 - $page = new ImagePage( $title );
251 - break;
252 - case NS_CATEGORY:
253 - $page = new CategoryPage( $title );
254 - break;
255 - default:
256 - $page = new Article( $title );
257 - }
258 - $page->setContext( $context );
259 - return $page;
 238+ return Article::newFromTitle( $title, $context );
260239 }
261240
262241 /**
@@ -302,7 +281,7 @@
303282 wfProfileIn( __METHOD__ );
304283
305284 $action = $this->context->request->getVal( 'action', 'view' );
306 - $article = self::articleFromTitle( $this->context->title, $this->context );
 285+ $article = Article::newFromTitle( $this->context->title, $this->context );
307286 // NS_MEDIAWIKI has no redirects.
308287 // It is also used for CSS/JS, so performance matters here...
309288 if ( $this->context->title->getNamespace() == NS_MEDIAWIKI ) {
@@ -339,7 +318,7 @@
340319 }
341320 if ( is_object( $target ) ) {
342321 // Rewrite environment to redirected article
343 - $rarticle = self::articleFromTitle( $target, $this->context );
 322+ $rarticle = Article::newFromTitle( $target, $this->context );
344323 $rarticle->loadPageData();
345324 if ( $rarticle->exists() || ( is_object( $file ) && !$file->isLocal() ) ) {
346325 $rarticle->setRedirectedFrom( $this->context->title );
Index: trunk/phase3/index.php
@@ -124,7 +124,7 @@
125125 $cache->loadFromFileCache();
126126 }
127127 # Do any stats increment/watchlist stuff
128 - $article = MediaWiki::articleFromTitle( $wgTitle, $context );
 128+ $article = Article::newFromTitle( $wgTitle, $context );
129129 $article->viewUpdates();
130130 # Tell OutputPage that output is taken care of
131131 $context->output->disable();

Status & tagging log