3 * Main wiki script; see docs/design.txt
6 $wgRequestTime = microtime();
8 # getrusage() does not exist on the Window$ platform, catching this
9 if ( function_exists ( 'getrusage' ) ) {
10 $wgRUstart = getrusage();
12 $wgRUstart = array() ;
16 @ini_set
( 'allow_url_fopen', 0 ); # For security...
18 if ( isset( $_REQUEST['GLOBALS'] ) ) {
19 die( '<a href="http://www.hardened-php.net/index.76.html">$GLOBALS overwrite vulnerability</a>');
22 # Valid web server entry point, enable includes.
23 # Please don't move this line to includes/Defines.php. This line essentially defines
24 # a valid entry point. If you put it in includes/Defines.php, then any script that includes
25 # it becomes an entry point, thereby defeating its purpose.
26 define( 'MEDIAWIKI', true );
27 require_once( './includes/Defines.php' );
29 if( !file_exists( 'LocalSettings.php' ) ) {
31 require_once( 'includes/DefaultSettings.php' ); # used for printing the version
33 <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
34 <html xmlns
='http://www.w3.org/1999/xhtml' xml
:lang
='en' lang
='en'>
36 <title
>MediaWiki
<?php
echo $wgVersion ?
></title
>
37 <meta http
-equiv
='Content-Type' content
='text/html; charset=utf-8' />
38 <style type
='text/css' media
='screen, projection'>
41 background
-color
: #fff;
42 font
-family
: sans
-serif
;
52 <img src
='skins/common/images/mediawiki.png' alt
='The MediaWiki logo' />
54 <h1
>MediaWiki
<?php
echo $wgVersion ?
></h1
>
57 if ( file_exists( 'config/LocalSettings.php' ) ) {
58 echo( "To complete the installation, move <tt>config/LocalSettings.php</tt> to the parent directory." );
60 echo( "Please <a href='config/index.php' title='setup'>setup the wiki</a> first." );
71 require_once( './LocalSettings.php' );
72 require_once( 'includes/Setup.php' );
74 wfProfileIn( 'main-misc-setup' );
75 OutputPage
::setEncodings(); # Not really used yet
78 $action = $wgRequest->getVal( 'action', 'view' );
79 $title = $wgRequest->getVal( 'title' );
81 if ($wgRequest->getVal( 'printable' ) == 'yes') {
82 $wgOut->setPrintable();
85 if ( '' == $title && 'delete' != $action ) {
86 $wgTitle = Title
::newFromText( wfMsgForContent( 'mainpage' ) );
87 } elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
88 # URLs like this are generated by RC, because rc_title isn't always accurate
89 $wgTitle = Title
::newFromID( $curid );
91 $wgTitle = Title
::newFromURL( $title );
92 /* check variant links so that interwiki links don't have to worry about
93 the possible different language variants
95 if( count($wgContLang->getVariants()) > 1 && !is_null($wgTitle) && $wgTitle->getArticleID() == 0 )
96 $wgContLang->findVariantLink( $title, $wgTitle );
99 wfProfileOut( 'main-misc-setup' );
101 # Debug statement for user levels
104 $search = $wgRequest->getText( 'search' );
105 if( !is_null( $search ) && $search !== '' ) {
106 // Compatibility with old search URLs which didn't use Special:Search
107 // Do this above the read whitelist check for security...
108 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Search' );
111 # If the user is not logged in, the Namespace:title of the article must be in
112 # the Read array in order for the user to see it. (We have to check here to
113 # catch special pages etc. We check again in Article::view())
114 if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
115 $wgOut->loginToUse();
120 wfProfileIn( 'main-action' );
122 if( !$wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
123 require_once( 'includes/SpecialSearch.php' );
124 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Search' );
126 } else if( !$wgTitle or $wgTitle->getDBkey() == '' ) {
127 $wgTitle = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
128 $wgOut->errorpage( 'badtitle', 'badtitletext' );
129 } else if ( $wgTitle->getInterwiki() != '' ) {
130 if( $rdfrom = $wgRequest->getVal( 'rdfrom' ) ) {
131 $url = $wgTitle->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
133 $url = $wgTitle->getFullURL();
135 # Check for a redirect loop
136 if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $wgTitle->isLocal() ) {
137 $wgOut->redirect( $url );
139 $wgTitle = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
140 $wgOut->errorpage( 'badtitle', 'badtitletext' );
142 } else if ( ( $action == 'view' ) &&
143 (!isset( $_GET['title'] ) ||
$wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
144 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
146 /* redirect to canonical url, make it a 301 to allow caching */
147 $wgOut->setSquidMaxage( 1200 );
148 $wgOut->redirect( $wgTitle->getFullURL(), '301');
149 } else if ( NS_SPECIAL
== $wgTitle->getNamespace() ) {
150 # actions that need to be made when we have a special pages
151 SpecialPage
::executePath( $wgTitle );
153 if ( NS_MEDIA
== $wgTitle->getNamespace() ) {
154 $wgTitle = Title
::makeTitle( NS_IMAGE
, $wgTitle->getDBkey() );
157 $ns = $wgTitle->getNamespace();
159 // Namespace might change when using redirects
160 if($action == 'view' && !$wgRequest->getVal( 'oldid' ) ) {
161 $wgArticle = new Article( $wgTitle );
162 $rTitle = Title
::newFromRedirect( $wgArticle->fetchContent() );
164 # Reload from the page pointed to later
165 $wgArticle->mContentLoaded
= false;
166 $ns = $rTitle->getNamespace();
171 require_once ( "includes/Wiki.php" ) ;
172 $mediaWiki = new MediaWiki() ;
174 $wgArticle =& $mediaWiki->setCorrectArticleClass ( $wgArticle , $wgTitle , $ns ) ;
176 if ( in_array( $action, $wgDisabledActions ) ) {
177 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
179 $mediaWiki->setVal ( "SquidMaxage" , $wgSquidMaxage ) ;
180 $mediaWiki->setVal ( "EnableDublinCoreRdf" , $wgEnableDublinCoreRdf ) ;
181 $mediaWiki->setVal ( "EnableCreativeCommonsRdf" , $wgEnableCreativeCommonsRdf ) ;
182 $mediaWiki->setVal ( "CommandLineMode" , $wgCommandLineMode ) ;
183 $mediaWiki->setVal ( "UseExternalEditor" , $wgUseExternalEditor ) ;
184 $mediaWiki->performAction ( $action , $wgOut , $wgArticle , $wgTitle , $wgUser , $wgRequest ) ;
189 wfProfileOut( 'main-action' );
191 # Deferred updates aren't really deferred anymore. It's important to report errors to the
192 # user, and that means doing this before OutputPage::output(). Note that for page saves,
193 # the client will wait until the script exits anyway before following the redirect.
194 wfProfileIn( 'main-updates' );
195 foreach ( $wgDeferredUpdateList as $up ) {
198 wfProfileOut( 'main-updates' );
200 wfProfileIn( 'main-cleanup' );
201 $wgLoadBalancer->saveMasterPos();
203 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
204 $wgLoadBalancer->commitAll();
208 foreach ( $wgPostCommitUpdateList as $up ) {
212 wfProfileOut( 'main-cleanup' );
216 $wgLoadBalancer->closeAll();
217 wfDebug( "Request ended normally\n" );