From 076fe2de0dde8c4b8ae680efe8f6754801c60a45 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sun, 22 May 2011 18:38:04 +0000 Subject: [PATCH] Moved MediaWiki::articleFromTitle() to Article::newFromTitle(), this has nothing to do in the MediaWiki class --- includes/Article.php | 34 ++++++++++++++++++++++++++++++++ includes/Wiki.php | 29 ++++----------------------- includes/api/ApiPurge.php | 2 +- includes/search/SearchEngine.php | 2 +- index.php | 2 +- 5 files changed, 41 insertions(+), 28 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 1b23a67923..807a029366 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -85,6 +85,40 @@ class Article { $this->mOldId = $oldId; } + /** + * Create an Article object of the appropriate class for the given page. + * + * @param $title Title + * @param $context RequestContext + * @return Article object + */ + public static function newFromTitle( $title, RequestContext $context ) { + if ( NS_MEDIA == $title->getNamespace() ) { + // FIXME: where should this go? + $title = Title::makeTitle( NS_FILE, $title->getDBkey() ); + } + + $article = null; + wfRunHooks( 'ArticleFromTitle', array( &$title, &$article ) ); + if ( $article ) { + $article->setContext( $context ); + return $article; + } + + switch( $title->getNamespace() ) { + case NS_FILE: + $page = new ImagePage( $title ); + break; + case NS_CATEGORY: + $page = new CategoryPage( $title ); + break; + default: + $page = new Article( $title ); + } + $page->setContext( $context ); + return $page; + } + /** * Constructor from an page id * @param $id Int article ID to load diff --git a/includes/Wiki.php b/includes/Wiki.php index fe9b0e3097..cf5856f016 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -228,34 +228,13 @@ class MediaWiki { /** * Create an Article object of the appropriate class for the given page. * + * @deprecated in 1.19; use Article::newFromTitle() instead * @param $title Title * @param $context RequestContext * @return Article object */ public static function articleFromTitle( $title, RequestContext $context ) { - if ( NS_MEDIA == $title->getNamespace() ) { - // @todo FIXME: Where should this go? - $title = Title::makeTitle( NS_FILE, $title->getDBkey() ); - } - - $article = null; - wfRunHooks( 'ArticleFromTitle', array( &$title, &$article ) ); - if ( $article ) { - return $article; - } - - switch( $title->getNamespace() ) { - case NS_FILE: - $page = new ImagePage( $title ); - break; - case NS_CATEGORY: - $page = new CategoryPage( $title ); - break; - default: - $page = new Article( $title ); - } - $page->setContext( $context ); - return $page; + return Article::newFromTitle( $title, $context ); } /** @@ -302,7 +281,7 @@ class MediaWiki { wfProfileIn( __METHOD__ ); $action = $this->context->request->getVal( 'action', 'view' ); - $article = self::articleFromTitle( $this->context->title, $this->context ); + $article = Article::newFromTitle( $this->context->title, $this->context ); // NS_MEDIAWIKI has no redirects. // It is also used for CSS/JS, so performance matters here... if ( $this->context->title->getNamespace() == NS_MEDIAWIKI ) { @@ -339,7 +318,7 @@ class MediaWiki { } if ( is_object( $target ) ) { // Rewrite environment to redirected article - $rarticle = self::articleFromTitle( $target, $this->context ); + $rarticle = Article::newFromTitle( $target, $this->context ); $rarticle->loadPageData(); if ( $rarticle->exists() || ( is_object( $file ) && !$file->isLocal() ) ) { $rarticle->setRedirectedFrom( $this->context->title ); diff --git a/includes/api/ApiPurge.php b/includes/api/ApiPurge.php index 6f2635f658..5757b0a367 100644 --- a/includes/api/ApiPurge.php +++ b/includes/api/ApiPurge.php @@ -69,7 +69,7 @@ class ApiPurge extends ApiBase { continue; } $context = RequestContext::getMain(); - $article = MediaWiki::articleFromTitle( $title, $context ); + $article = Article::newFromTitle( $title, $context ); $article->doPurge(); // Directly purge and skip the UI part of purge(). $r['purged'] = ''; diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php index 1d82190495..2941d7d7d4 100644 --- a/includes/search/SearchEngine.php +++ b/includes/search/SearchEngine.php @@ -177,7 +177,7 @@ class SearchEngine { # See if it still otherwise has content is some sane sense $context->setTitle( $title ); - $article = MediaWiki::articleFromTitle( $title, $context ); + $article = Article::newFromTitle( $title, $context ); if ( $article->hasViewableContent() ) { return $title; } diff --git a/index.php b/index.php index ba325e0dae..309e3ad4d5 100644 --- a/index.php +++ b/index.php @@ -124,7 +124,7 @@ function wfIndexMain() { $cache->loadFromFileCache(); } # Do any stats increment/watchlist stuff - $article = MediaWiki::articleFromTitle( $wgTitle, $context ); + $article = Article::newFromTitle( $wgTitle, $context ); $article->viewUpdates(); # Tell OutputPage that output is taken care of $context->output->disable(); -- 2.20.1