From: Happy-melon Date: Tue, 12 Apr 2011 23:00:49 +0000 (+0000) Subject: Implement a $context and getContext/setContext methods for Article (and its subclasses). X-Git-Tag: 1.31.0-rc.0~30883 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/password.php?a=commitdiff_plain;h=66e176b15336cc57d22126433b18cf6a49445ded;p=lhc%2Fweb%2Fwiklou.git Implement a $context and getContext/setContext methods for Article (and its subclasses). --- diff --git a/includes/Article.php b/includes/Article.php index 1babd579a7..8ad3eb0ad6 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -17,6 +17,8 @@ class Article { /**@{{ * @private */ + protected $mContext; // !< RequestContext + var $mContent; // !< var $mContentLoaded = false; // !< var $mCounter = -1; // !< Not loaded @@ -4531,6 +4533,31 @@ class Article { return $this->getOutputFromWikitext( $text, $useParserCache ); } + /** + * Sets the context this Article is executed in + * + * @param $context RequestContext + * @since 1.18 + */ + public function setContext( $context ) { + $this->mContext = $context; + } + + /** + * Gets the context this Article is executed in + * + * @return RequestContext + * @since 1.18 + */ + public function getContext() { + if ( $this->mContext instanceof RequestContext ) { + return $this->mContext; + } else { + wfDebug( __METHOD__ . " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" ); + return RequestContext::getMain(); + } + } + } class PoolWorkArticleView extends PoolCounterWork { diff --git a/includes/Wiki.php b/includes/Wiki.php index 3bf94d24a6..2a1c6d26f7 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -266,7 +266,7 @@ class MediaWiki { * @param $title Title * @return Article object */ - public static function articleFromTitle( &$title ) { + public static function articleFromTitle( &$title, RequestContext &$context ) { if ( NS_MEDIA == $title->getNamespace() ) { // FIXME: where should this go? $title = Title::makeTitle( NS_FILE, $title->getDBkey() ); @@ -280,12 +280,14 @@ class MediaWiki { switch( $title->getNamespace() ) { case NS_FILE: - return new ImagePage( $title ); + $page = new ImagePage( $title ); case NS_CATEGORY: - return new CategoryPage( $title ); + $page = new CategoryPage( $title ); default: - return new Article( $title ); + $page = new Article( $title ); } + $page->setContext( $context ); + return $page; } /** @@ -332,7 +334,7 @@ class MediaWiki { wfProfileIn( __METHOD__ ); $action = $this->context->request->getVal( 'action', 'view' ); - $article = self::articleFromTitle( $this->context->title ); + $article = self::articleFromTitle( $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 ) { @@ -369,7 +371,7 @@ class MediaWiki { } if ( is_object( $target ) ) { // Rewrite environment to redirected article - $rarticle = self::articleFromTitle( $target ); + $rarticle = self::articleFromTitle( $target, $this->context ); $rarticle->loadPageData(); if ( $rarticle->exists() || ( is_object( $file ) && !$file->isLocal() ) ) { $rarticle->setRedirectedFrom( $this->context->title ); @@ -467,9 +469,16 @@ class MediaWiki { return; } - $action = $this->getAction(); + $act = $this->getAction(); - switch( $action ) { + $action = Action::factory( $this->getAction(), $article ); + if( $action instanceof Action ){ + $action->execute(); + wfProfileOut( __METHOD__ ); + return; + } + + switch( $act ) { case 'view': $this->context->output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) ); $article->view(); @@ -492,7 +501,7 @@ class MediaWiki { case 'render': case 'deletetrackback': case 'purge': - $article->$action(); + $article->$act(); break; case 'print': $article->view(); @@ -513,9 +522,6 @@ class MediaWiki { $rdf->show(); } break; - case 'credits': - Credits::showPage( $article ); - break; case 'submit': if ( session_id() == '' ) { // Send a cookie so anons get talk message notifications @@ -528,7 +534,7 @@ class MediaWiki { $external = $this->context->request->getVal( 'externaledit' ); $section = $this->context->request->getVal( 'section' ); $oldid = $this->context->request->getVal( 'oldid' ); - if ( !$this->getVal( 'UseExternalEditor' ) || $action == 'submit' || $internal || + if ( !$this->getVal( 'UseExternalEditor' ) || $act == 'submit' || $internal || $section || $oldid || ( !$this->context->user->getOption( 'externaleditor' ) && !$external ) ) { $editor = new EditPage( $article ); $editor->submit(); @@ -557,7 +563,7 @@ class MediaWiki { $special->execute( '' ); break; default: - if ( wfRunHooks( 'UnknownAction', array( $action, $article ) ) ) { + if ( wfRunHooks( 'UnknownAction', array( $act, $article ) ) ) { $this->context->output->showErrorPage( 'nosuchaction', 'nosuchactiontext' ); } }