* Removed getSelectOptions, which did nothing other than send FOR UPDATE on some...
[lhc/web/wiklou.git] / includes / Wiki.php
index ba498f8..015ef2b 100644 (file)
@@ -56,10 +56,8 @@ class MediaWiki {
                return wfSetVar( $this->context->output, $x );
        }
 
-       public function __construct( WebRequest &$request, /*OutputPage*/ &$output ){
-               $this->context = new RequestContext();
-               $this->context->setRequest( $request );
-               $this->context->setOutput( $output );
+       public function __construct( RequestContext $context ){
+               $this->context = $context;
                $this->context->setTitle( $this->parseTitle() );
        }
 
@@ -68,12 +66,10 @@ class MediaWiki {
         * Performs the request too
         *
         * @param $article Article
-        * @param $user User
         */
-       public function performRequestForTitle( &$article, &$user ) {
+       public function performRequestForTitle( &$article ) {
                wfProfileIn( __METHOD__ );
 
-               $this->context->output->setTitle( $this->context->title );
                if ( $this->context->request->getVal( 'printable' ) === 'yes' ) {
                        $this->context->output->setPrintable();
                }
@@ -82,7 +78,7 @@ class MediaWiki {
                        &$this->context->title,
                        &$article,
                        &$this->context->output,
-                       &$user,
+                       &$this->context->user,
                        $this->context->request,
                        $this
                ) );
@@ -105,7 +101,7 @@ class MediaWiki {
                        $new_article = $this->initializeArticle();
                        if ( is_object( $new_article ) ) {
                                $article = $new_article;
-                               $this->performAction( $article, $user );
+                               $this->performAction( $article );
                        } elseif ( is_string( $new_article ) ) {
                                $this->context->output->redirect( $new_article );
                        } else {
@@ -141,8 +137,9 @@ class MediaWiki {
                        $ret = Title::newFromURL( $title );
                        // check variant links so that interwiki links don't have to worry
                        // about the possible different language variants
-                       if ( count( $wgContLang->getVariants() ) > 1 && !is_null( $ret ) && $ret->getArticleID() == 0 )
+                       if ( count( $wgContLang->getVariants() ) > 1 && !is_null( $ret ) && $ret->getArticleID() == 0 ){
                                $wgContLang->findVariantLink( $title, $ret );
+                       }
                }
                // For non-special titles, check for implicit titles
                if ( is_null( $ret ) || $ret->getNamespace() != NS_SPECIAL ) {
@@ -155,6 +152,10 @@ class MediaWiki {
                                $ret = $rev ? $rev->getTitle() : $ret;
                        }
                }
+
+               if( $ret === null || ( $ret->getDBkey() == '' && $ret->getInterwiki() == '' ) ){
+                       $ret = new BadTitle;
+               }
                return $ret;
        }
 
@@ -182,9 +183,7 @@ class MediaWiki {
                wfProfileIn( __METHOD__ );
 
                // Invalid titles. Bug 21776: The interwikis must redirect even if the page name is empty.
-               if ( is_null( $this->context->title ) || ( ( $this->context->title->getDBkey() == '' ) && ( $this->context->title->getInterwiki() == '' ) ) ) {
-                       $this->context->title = SpecialPage::getTitleFor( 'Badtitle' );
-                       $this->context->output->setTitle( $this->context->title ); // bug 21456
+               if ( $this->context->title instanceof BadTitle ) {
                        // Die now before we mess up $wgArticle and the skin stops working
                        throw new ErrorPageError( 'badtitle', 'badtitletext' );
 
@@ -198,13 +197,12 @@ class MediaWiki {
                                unset( $query['title'] );
                                $url = $this->context->title->getFullURL( $query );
                        }
-                       /* Check for a redirect loop */
+                       // Check for a redirect loop
                        if ( !preg_match( '/^' . preg_quote( $this->getVal( 'Server' ), '/' ) . '/', $url ) && $this->context->title->isLocal() ) {
                                // 301 so google et al report the target as the actual url.
                                $this->context->output->redirect( $url, 301 );
                        } else {
-                               $this->context->title = SpecialPage::getTitleFor( 'Badtitle' );
-                               $this->context->output->setTitle( $this->context->title ); // bug 21456
+                               $this->context->title = new BadTitle;
                                wfProfileOut( __METHOD__ );
                                throw new ErrorPageError( 'badtitle', 'badtitletext' );
                        }
@@ -250,14 +248,14 @@ class MediaWiki {
                        }
                // Special pages
                } else if ( NS_SPECIAL == $this->context->title->getNamespace() ) {
-                       /* actions that need to be made when we have a special pages */
+                       // actions that need to be made when we have a special pages
                        SpecialPage::executePath( $this->context->title, $this->context );
                } else {
-                       /* No match to special cases */
+                       // No match to special cases
                        wfProfileOut( __METHOD__ );
                        return false;
                }
-               /* Did match a special case */
+               // Did match a special case
                wfProfileOut( __METHOD__ );
                return true;
        }
@@ -268,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() );
@@ -282,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;
        }
 
        /**
@@ -334,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 ) {
@@ -371,13 +371,12 @@ 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 );
                                                $article = $rarticle;
                                                $this->context->title = $target;
-                                               $this->context->output->setTitle( $this->context->title );
                                        }
                                }
                        } else {
@@ -458,14 +457,13 @@ class MediaWiki {
         * Perform one of the "standard" actions
         *
         * @param $article Article
-        * @param $user User
         */
-       private function performAction( &$article, &$user ) {
+       private function performAction( &$article ) {
                wfProfileIn( __METHOD__ );
 
                if ( !wfRunHooks( 'MediaWikiPerformAction', array(
                                $this->context->output, $article, $this->context->title,
-                               $user, $this->context->request, $this ) ) )
+                               $this->context->user, $this->context->request, $this ) ) )
                {
                        wfProfileOut( __METHOD__ );
                        return;
@@ -522,21 +520,21 @@ class MediaWiki {
                                break;
                        case 'submit':
                                if ( session_id() == '' ) {
-                                       /* Send a cookie so anons get talk message notifications */
+                                       // Send a cookie so anons get talk message notifications
                                        wfSetupSession();
                                }
-                               /* Continue... */
+                               // Continue...
                        case 'edit':
-                               if ( wfRunHooks( 'CustomEditor', array( $article, $user ) ) ) {
+                               if ( wfRunHooks( 'CustomEditor', array( $article, $this->context->user ) ) ) {
                                        $internal = $this->context->request->getVal( 'internaledit' );
                                        $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 ||
-                                          $section || $oldid || ( !$user->getOption( 'externaleditor' ) && !$external ) ) {
+                                          $section || $oldid || ( !$this->context->user->getOption( 'externaleditor' ) && !$external ) ) {
                                                $editor = new EditPage( $article );
                                                $editor->submit();
-                                       } elseif ( $this->getVal( 'UseExternalEditor' ) && ( $external || $user->getOption( 'externaleditor' ) ) ) {
+                                       } elseif ( $this->getVal( 'UseExternalEditor' ) && ( $external || $this->context->user->getOption( 'externaleditor' ) ) ) {
                                                $mode = $this->context->request->getVal( 'mode' );
                                                $extedit = new ExternalEdit( $article, $mode );
                                                $extedit->edit();