Image redirect fix back in
[lhc/web/wiklou.git] / index.php
index 026f31f..c535ae7 100644 (file)
--- a/index.php
+++ b/index.php
@@ -3,12 +3,22 @@
  * Main wiki script; see docs/design.txt
  * @package MediaWiki
  */
-
 $wgRequestTime = microtime();
 
+# getrusage() does not exist on the Window$ platform, catching this
+if ( function_exists ( 'getrusage' ) ) {
+       $wgRUstart = getrusage();
+} else {
+       $wgRUstart = array() ;
+}
+
 unset( $IP );
 @ini_set( 'allow_url_fopen', 0 ); # For security...
 
+if ( isset( $_REQUEST['GLOBALS'] ) ) {
+       die( '<a href="http://www.hardened-php.net/index.76.html">$GLOBALS overwrite vulnerability</a>');
+}
+
 # Valid web server entry point, enable includes.
 # Please don't move this line to includes/Defines.php. This line essentially defines
 # a valid entry point. If you put it in includes/Defines.php, then any script that includes
@@ -82,7 +92,7 @@ if ( '' == $title && 'delete' != $action ) {
        /* check variant links so that interwiki links don't have to worry about
           the possible different language variants
        */
-       if( !is_null($wgTitle) && $wgTitle->getArticleID() == 0 )
+       if( count($wgContLang->getVariants()) > 1 && !is_null($wgTitle) && $wgTitle->getArticleID() == 0 )
                $wgContLang->findVariantLink( $title, $wgTitle );
 
 }
@@ -91,6 +101,13 @@ wfProfileOut( 'main-misc-setup' );
 # Debug statement for user levels
 // print_r($wgUser);
 
+$search = $wgRequest->getText( 'search' );
+if( !is_null( $search ) && $search !== '' ) {
+       // Compatibility with old search URLs which didn't use Special:Search
+       // Do this above the read whitelist check for security...
+       $wgTitle = Title::makeTitle( NS_SPECIAL, 'Search' );
+}
+
 # If the user is not logged in, the Namespace:title of the article must be in
 # the Read array in order for the user to see it. (We have to check here to
 # catch special pages etc. We check again in Article::view())
@@ -101,10 +118,6 @@ if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
 }
 
 wfProfileIn( 'main-action' );
-$search = $wgRequest->getText( 'search' );
-if( $wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
-       $wgTitle = Title::makeTitle( NS_SPECIAL, 'Search' );
-}
 
 if( !$wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
        require_once( 'includes/SpecialSearch.php' );
@@ -112,7 +125,6 @@ if( !$wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
        wfSpecialSearch();
 } else if( !$wgTitle or $wgTitle->getDBkey() == '' ) {
        $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
-       $wgOut->setStatusCode( 404 );
        $wgOut->errorpage( 'badtitle', 'badtitletext' );
 } else if ( $wgTitle->getInterwiki() != '' ) {
        if( $rdfrom = $wgRequest->getVal( 'rdfrom' ) ) {
@@ -125,7 +137,6 @@ if( !$wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
                $wgOut->redirect( $url );
        } else {
                $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
-               $wgOut->setStatusCode( 404 );
                $wgOut->errorpage( 'badtitle', 'badtitletext' );
        }
 } else if ( ( $action == 'view' ) &&
@@ -139,133 +150,24 @@ if( !$wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
        # actions that need to be made when we have a special pages
        SpecialPage::executePath( $wgTitle );
 } else {
-       if ( NS_MEDIA == $wgTitle->getNamespace() ) {
-               $wgTitle = Title::makeTitle( NS_IMAGE, $wgTitle->getDBkey() );
-       }
-
-       if ( !$wgTitle->exists() ) {
-               $wgOut->setStatusCode( 404 );
-       }
 
-       $ns = $wgTitle->getNamespace();
+       require_once( "includes/Wiki.php" ) ;
+       $mediaWiki = new MediaWiki() ;
 
-       // Namespace might change when using redirects
-       if($action == 'view' && !$wgRequest->getVal( 'oldid' ) ) {
-               $wgArticle = new Article( $wgTitle );
-               $rTitle = Title::newFromRedirect( $wgArticle->fetchContent() );
-               if($rTitle) {
-                       # Reload from the page pointed to later
-                       $wgArticle->mContentLoaded = false;
-                       $ns = $rTitle->getNamespace();
-               }
-       }
+       $wgArticle =& $mediaWiki->initializeArticle( $wgTitle, $wgRequest, $action );
 
-       // Categories and images are handled by a different class
-       if ( $ns == NS_IMAGE ) {
-               unset($wgArticle);
-               require_once( 'includes/ImagePage.php' );
-               $wgArticle = new ImagePage( $wgTitle );
-       } elseif ( $wgUseCategoryMagic && $ns == NS_CATEGORY ) {
-               unset($wgArticle);
-               require_once( 'includes/CategoryPage.php' );
-               $wgArticle = new CategoryPage( $wgTitle );
-       }
-
-       if ( in_array( $action, $wgDisabledActions ) ) {
-               $wgOut->setStatusCode( 404 );
+       if( in_array( $action, $wgDisabledActions ) ) {
                $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
        } else {
-               switch( $action ) {
-                       case 'view':
-                               $wgOut->setSquidMaxage( $wgSquidMaxage );
-                               $wgArticle->view();
-                               break;
-                       case 'watch':
-                       case 'unwatch':
-                       case 'delete':
-                       case 'revert':
-                       case 'rollback':
-                       case 'protect':
-                       case 'unprotect':
-                       case 'info':
-                       case 'markpatrolled':
-                       case 'validate':
-                       case 'render':
-                       case 'deletetrackback':
-                               $wgArticle->$action();
-                               break;
-                       case 'print':
-                               $wgArticle->view();
-                               break;
-                       case 'dublincore':
-                               if( !$wgEnableDublinCoreRdf ) {
-                                       wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
-                               } else {
-                                       require_once( 'includes/Metadata.php' );
-                                       wfDublinCoreRdf( $wgArticle );
-                               }
-                               break;
-                       case 'creativecommons':
-                               if( !$wgEnableCreativeCommonsRdf ) {
-                                       wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
-                               } else {
-                                       require_once( 'includes/Metadata.php' );
-                                       wfCreativeCommonsRdf( $wgArticle );
-                               }
-                               break;
-                       case 'credits':
-                               require_once( 'includes/Credits.php' );
-                               showCreditsPage( $wgArticle );
-                               break;
-                       case 'submit':
-                               if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
-                                       # Send a cookie so anons get talk message notifications
-                                       User::SetupSession();
-                               }
-                               # Continue...
-                       case 'edit':
-                               $internal = $wgRequest->getVal( 'internaledit' );
-                               $external = $wgRequest->getVal( 'externaledit' );
-                               $section = $wgRequest->getVal( 'section' );
-                               $oldid = $wgRequest->getVal( 'oldid' );
-                               if(!$wgUseExternalEditor || $action=='submit' || $internal ||
-                                  $section || $oldid || (!$wgUser->getOption('externaleditor') && !$external)) {
-                                       require_once( 'includes/EditPage.php' );
-                                       $editor = new EditPage( $wgArticle );
-                                       $editor->submit();
-                               } elseif($wgUseExternalEditor && ($external || $wgUser->getOption('externaleditor'))) {
-                                       require_once( 'includes/ExternalEdit.php' );
-                                       $mode = $wgRequest->getVal( 'mode' );
-                                       $extedit = new ExternalEdit( $wgArticle, $mode );
-                                       $extedit->edit();
-                               }
-                               break;
-                       case 'history':
-                               if ($_SERVER['REQUEST_URI'] == $wgTitle->getInternalURL('action=history')) {
-                                       $wgOut->setSquidMaxage( $wgSquidMaxage );
-                               }
-                               require_once( 'includes/PageHistory.php' );
-                               $history = new PageHistory( $wgArticle );
-                               $history->history();
-                               break;
-                       case 'raw':
-                               require_once( 'includes/RawPage.php' );
-                               $raw = new RawPage( $wgArticle );
-                               $raw->view();
-                               break;
-                       case 'purge':
-                               wfPurgeSquidServers(array($wgTitle->getInternalURL()));
-                               $wgOut->setSquidMaxage( $wgSquidMaxage );
-                               $wgTitle->invalidateCache();
-                               $wgArticle->view();
-                               break;
-                       default:
-                               if (wfRunHooks('UnknownAction', array($action, $wgArticle))) {
-                                       $wgOut->setStatusCode( 404 );
-                                       $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
-                               }
-               }
+               $mediaWiki->setVal( "SquidMaxage", $wgSquidMaxage );
+               $mediaWiki->setVal( "EnableDublinCoreRdf", $wgEnableDublinCoreRdf );
+               $mediaWiki->setVal( "EnableCreativeCommonsRdf", $wgEnableCreativeCommonsRdf );
+               $mediaWiki->setVal( "CommandLineMode", $wgCommandLineMode );
+               $mediaWiki->setVal( "UseExternalEditor", $wgUseExternalEditor );
+               $mediaWiki->performAction( $action, $wgOut, $wgArticle, $wgTitle, $wgUser, $wgRequest );
        }
+
+
 }
 wfProfileOut( 'main-action' );
 
@@ -273,7 +175,7 @@ wfProfileOut( 'main-action' );
 # user, and that means doing this before OutputPage::output(). Note that for page saves,
 # the client will wait until the script exits anyway before following the redirect.
 wfProfileIn( 'main-updates' );
-foreach ( $wgDeferredUpdateList as $up ) {
+foreach( $wgDeferredUpdateList as $up ) {
        $up->doUpdate();
 }
 wfProfileOut( 'main-updates' );
@@ -286,12 +188,13 @@ $wgLoadBalancer->commitAll();
 
 $wgOut->output();
 
-foreach ( $wgPostCommitUpdateList as $up ) {
+foreach( $wgPostCommitUpdateList as $up ) {
        $up->doUpdate();
 }
 
 wfProfileOut( 'main-cleanup' );
 
+wfProfileClose();
 logProfilingData();
 $wgLoadBalancer->closeAll();
 wfDebug( "Request ended normally\n" );