Removed configuration storage in the MediaWiki class:
[lhc/web/wiklou.git] / includes / Wiki.php
index ba498f8..d0e2eac 100644 (file)
@@ -6,60 +6,22 @@
  */
 class MediaWiki {
 
-       /**
-        * Array of options which may or may not be used
-        * FIXME: this seems currently to be a messy halfway-house between globals
-        *     and a config object.  Pick one and run with it
-        * @var array
-        */
-       private $params = array();
-
        /**
         * TODO: fold $output, etc, into this
         * @var RequestContext
         */
        private $context;
 
-       /**
-        * Stores key/value pairs to circumvent global variables
-        * Note that keys are case-insensitive!
-        *
-        * @param $key String: key to store
-        * @param $value Mixed: value to put for the key
-        */
-       public function setVal( $key, &$value ) {
-               $key = strtolower( $key );
-               $this->params[$key] =& $value;
-       }
-
-       /**
-        * Retrieves key/value pairs to circumvent global variables
-        * Note that keys are case-insensitive!
-        *
-        * @param $key String: key to get
-        * @param $default string default value, defaults to empty string
-        * @return $default Mixed: default value if if the key doesn't exist
-        */
-       public function getVal( $key, $default = '' ) {
-               $key = strtolower( $key );
-               if ( isset( $this->params[$key] ) ) {
-                       return $this->params[$key];
-               }
-               return $default;
-       }
-
-       public function request( WebRequest &$x = null ){
+       public function request( WebRequest $x = null ){
                return wfSetVar( $this->context->request, $x );
        }
 
-       public function output( OutputPage &$x = null ){
+       public function output( OutputPage $x = null ){
                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 +30,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 +42,7 @@ class MediaWiki {
                        &$this->context->title,
                        &$article,
                        &$this->context->output,
-                       &$user,
+                       &$this->context->user,
                        $this->context->request,
                        $this
                ) );
@@ -105,7 +65,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 +101,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 +116,10 @@ class MediaWiki {
                                $ret = $rev ? $rev->getTitle() : $ret;
                        }
                }
+
+               if( $ret === null || ( $ret->getDBkey() == '' && $ret->getInterwiki() == '' ) ){
+                       $ret = new BadTitle;
+               }
                return $ret;
        }
 
@@ -179,12 +144,12 @@ class MediaWiki {
         * @return bool true if the request is already executed
         */
        private function handleSpecialCases() {
+               global $wgServer, $wgUsePathInfo;
+
                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 +163,12 @@ class MediaWiki {
                                unset( $query['title'] );
                                $url = $this->context->title->getFullURL( $query );
                        }
-                       /* Check for a redirect loop */
-                       if ( !preg_match( '/^' . preg_quote( $this->getVal( 'Server' ), '/' ) . '/', $url ) && $this->context->title->isLocal() ) {
+                       // Check for a redirect loop
+                       if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $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' );
                        }
@@ -214,7 +178,7 @@ class MediaWiki {
                        && !count( array_diff( array_keys( $this->context->request->getValues() ), array( 'action', 'title' ) ) ) )
                {
                        if ( $this->context->title->getNamespace() == NS_SPECIAL ) {
-                               list( $name, $subpage ) = SpecialPage::resolveAliasWithSubpage( $this->context->title->getDBkey() );
+                               list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $this->context->title->getDBkey() );
                                if ( $name ) {
                                        $this->context->title = SpecialPage::getTitleFor( $name, $subpage );
                                }
@@ -227,7 +191,7 @@ class MediaWiki {
                                        "requested; this sometimes happens when moving a wiki " .
                                        "to a new server or changing the server configuration.\n\n";
 
-                               if ( $this->getVal( 'UsePathInfo' ) ) {
+                               if ( $wgUsePathInfo ) {
                                        $message .= "The wiki is trying to interpret the page " .
                                                "title from the URL path portion (PATH_INFO), which " .
                                                "sometimes fails depending on the web server. Try " .
@@ -250,14 +214,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 */
-                       SpecialPage::executePath( $this->context->title, $this->context );
+                       // actions that need to be made when we have a special pages
+                       SpecialPageFactory::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;
        }
@@ -266,9 +230,10 @@ class MediaWiki {
         * Create an Article object of the appropriate class for the given page.
         *
         * @param $title Title
+        * @param $context RequestContext
         * @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 +247,16 @@ class MediaWiki {
 
                switch( $title->getNamespace() ) {
                        case NS_FILE:
-                               return new ImagePage( $title );
+                               $page = new ImagePage( $title );
+                               break;
                        case NS_CATEGORY:
-                               return new CategoryPage( $title );
+                               $page = new CategoryPage( $title );
+                               break;
                        default:
-                               return new Article( $title );
+                               $page = new Article( $title );
                }
+               $page->setContext( $context );
+               return $page;
        }
 
        /**
@@ -312,8 +281,6 @@ class MediaWiki {
                if ( $action === 'historysubmit' ) {
                        if ( $this->context->request->getBool( 'revisiondelete' ) ) {
                                return 'revisiondelete';
-                       } elseif ( $this->context->request->getBool( 'revisionmove' ) ) {
-                               return 'revisionmove';
                        } else {
                                return 'view';
                        }
@@ -331,10 +298,12 @@ class MediaWiki {
         * @return mixed an Article, or a string to redirect to another URL
         */
        private function initializeArticle() {
+               global $wgDisableHardRedirects;
+
                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 ) {
@@ -363,7 +332,7 @@ class MediaWiki {
                                // Is the target already set by an extension?
                                $target = $target ? $target : $article->followRedirect();
                                if ( is_string( $target ) ) {
-                                       if ( !$this->getVal( 'DisableHardRedirects' ) ) {
+                                       if ( !$wgDisableHardRedirects ) {
                                                // we'll need to redirect
                                                wfProfileOut( __METHOD__ );
                                                return $target;
@@ -371,13 +340,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,24 +426,33 @@ class MediaWiki {
         * Perform one of the "standard" actions
         *
         * @param $article Article
-        * @param $user User
         */
-       private function performAction( &$article, &$user ) {
+       private function performAction( $article ) {
+               global $wgSquidMaxage, $wgUseExternalEditor,
+                       $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
+
                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;
                }
 
-               $action = $this->getAction();
+               $act = $this->getAction();
 
-               switch( $action ) {
+               $action = Action::factory( $this->getAction(), $article );
+               if( $action instanceof Action ){
+                       $action->show();
+                       wfProfileOut( __METHOD__ );
+                       return;
+               }
+
+               switch( $act ) {
                        case 'view':
-                               $this->context->output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) );
+                               $this->context->output->setSquidMaxage( $wgSquidMaxage );
                                $article->view();
                                break;
                        case 'raw': // includes JS/CSS
@@ -484,8 +461,6 @@ class MediaWiki {
                                $raw->view();
                                wfProfileOut( __METHOD__ . '-raw' );
                                break;
-                       case 'watch':
-                       case 'unwatch':
                        case 'delete':
                        case 'revert':
                        case 'rollback':
@@ -495,14 +470,10 @@ class MediaWiki {
                        case 'markpatrolled':
                        case 'render':
                        case 'deletetrackback':
-                       case 'purge':
-                               $article->$action();
-                               break;
-                       case 'print':
-                               $article->view();
+                               $article->$act();
                                break;
                        case 'dublincore':
-                               if ( !$this->getVal( 'EnableDublinCoreRdf' ) ) {
+                               if ( !$wgEnableDublinCoreRdf ) {
                                        wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
                                } else {
                                        $rdf = new DublinCoreRdf( $article );
@@ -510,33 +481,30 @@ class MediaWiki {
                                }
                                break;
                        case 'creativecommons':
-                               if ( !$this->getVal( 'EnableCreativeCommonsRdf' ) ) {
+                               if ( !$wgEnableCreativeCommonsRdf ) {
                                        wfHttpError( 403, 'Forbidden', wfMsg( 'nocreativecommons' ) );
                                } else {
                                        $rdf = new CreativeCommonsRdf( $article );
                                        $rdf->show();
                                }
                                break;
-                       case 'credits':
-                               Credits::showPage( $article );
-                               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 ) ) {
+                                       if ( !$wgUseExternalEditor || $act == 'submit' || $internal ||
+                                          $section || $oldid || ( !$this->context->user->getOption( 'externaleditor' ) && !$external ) ) {
                                                $editor = new EditPage( $article );
                                                $editor->submit();
-                                       } elseif ( $this->getVal( 'UseExternalEditor' ) && ( $external || $user->getOption( 'externaleditor' ) ) ) {
+                                       } elseif ( $wgUseExternalEditor && ( $external || $this->context->user->getOption( 'externaleditor' ) ) ) {
                                                $mode = $this->context->request->getVal( 'mode' );
                                                $extedit = new ExternalEdit( $article, $mode );
                                                $extedit->edit();
@@ -545,23 +513,18 @@ class MediaWiki {
                                break;
                        case 'history':
                                if ( $this->context->request->getFullRequestURL() == $this->context->title->getInternalURL( 'action=history' ) ) {
-                                       $this->context->output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) );
+                                       $this->context->output->setSquidMaxage( $wgSquidMaxage );
                                }
                                $history = new HistoryPage( $article );
                                $history->history();
                                break;
                        case 'revisiondelete':
                                // For show/hide submission from history page
-                               $special = SpecialPage::getPage( 'Revisiondelete' );
-                               $special->execute( '' );
-                               break;
-                       case 'revisionmove':
-                               // For revision move submission from history page
-                               $special = SpecialPage::getPage( 'RevisionMove' );
+                               $special = SpecialPageFactory::getPage( 'Revisiondelete' );
                                $special->execute( '' );
                                break;
                        default:
-                               if ( wfRunHooks( 'UnknownAction', array( $action, $article ) ) ) {
+                               if ( wfRunHooks( 'UnknownAction', array( $act, $article ) ) ) {
                                        $this->context->output->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
                                }
                }