3 * Main wiki script; see docs/design.doc
7 $wgRequestTime = microtime();
10 @ini_set
( 'allow_url_fopen', 0 ); # For security...
12 # Valid web server entry point, enable includes.
13 # Please don't move this line to includes/Defines.php. This line essentially defines
14 # a valid entry point. If you put it in includes/Defines.php, then any script that includes
15 # it becomes an entry point, thereby defeating its purpose.
16 define( 'MEDIAWIKI', true );
17 require_once( './includes/Defines.php' );
19 if( !file_exists( 'LocalSettings.php' ) ) {
21 require_once( 'includes/DefaultSettings.php' ); # used for printing the version
23 <!DOCTYPE html
PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
24 <html xmlns
='http://www.w3.org/1999/xhtml' xml
:lang
='en' lang
='en'>
26 <title
>MediaWiki
<?php
echo $wgVersion ?
></title
>
27 <meta http
-equiv
='Content-Type' content
='text/html; charset=utf-8' />
29 <style type
='text/css' media
='screen, projection'>
32 background
-color
: #fff;
43 <img src
='skins/common/images/mediawiki.png' alt
='The MediaWiki logo' />
45 <h1
>MediaWiki
<?php
echo $wgVersion ?
></h1
>
48 if ( file_exists( 'config/LocalSettings.php' ) ) {
49 echo( "To complete the installation, move <tt>config/LocalSettings.php</tt> to the parent directory." );
51 echo( "You'll have to <a href='config/index.php' title='setup'>set the wiki up</a> first!" );
62 require_once( './LocalSettings.php' );
63 require_once( 'includes/Setup.php' );
65 wfProfileIn( 'main-misc-setup' );
66 OutputPage
::setEncodings(); # Not really used yet
69 $action = $wgRequest->getVal( 'action', 'view' );
70 $title = $wgRequest->getVal( 'title' );
72 $action = strtolower( trim( $action ) );
73 if ($wgRequest->getVal( 'printable' ) == 'yes') {
74 $wgOut->setPrintable();
77 if ( '' == $title && 'delete' != $action ) {
78 $wgTitle = Title
::newFromText( wfMsgForContent( 'mainpage' ) );
79 } elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
80 # URLs like this are generated by RC, because rc_title isn't always accurate
81 $wgTitle = Title
::newFromID( $curid );
83 $wgTitle = Title
::newFromURL( $title );
85 wfProfileOut( 'main-misc-setup' );
87 # Debug statement for user levels
90 # If the user is not logged in, the Namespace:title of the article must be in
91 # the Read array in order for the user to see it. (We have to check here to
92 # catch special pages etc. We check again in Article::view())
93 if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
99 wfProfileIn( 'main-action' );
101 $search = $wgRequest->getText( 'search' );
102 if( !$wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
103 require_once( 'includes/SpecialSearch.php' );
104 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Search' );
106 } else if( !$wgTitle or $wgTitle->getDBkey() == '' ) {
107 $wgTitle = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
108 $wgOut->errorpage( 'badtitle', 'badtitletext' );
109 } else if ( $wgTitle->getInterwiki() != '' ) {
110 if( $rdfrom = $wgRequest->getVal( 'rdfrom' ) ) {
111 $url = $wgTitle->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
113 $url = $wgTitle->getFullURL();
115 # Check for a redirect loop
116 if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $wgTitle->isLocal() ) {
117 $wgOut->redirect( $url );
119 $wgTitle = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
120 $wgOut->errorpage( 'badtitle', 'badtitletext' );
122 } else if ( ( $action == 'view' ) &&
123 (!isset( $_GET['title'] ) ||
$wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
124 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
126 /* redirect to canonical url, make it a 301 to allow caching */
127 $wgOut->setSquidMaxage( 1200 );
128 $wgOut->redirect( $wgTitle->getFullURL(), '301');
129 } else if ( NS_SPECIAL
== $wgTitle->getNamespace() ) {
130 # actions that need to be made when we have a special pages
131 require_once( 'includes/SpecialPage.php' );
132 SpecialPage
::executePath( $wgTitle );
134 if ( NS_MEDIA
== $wgTitle->getNamespace() ) {
135 $wgTitle = Title
::makeTitle( NS_IMAGE
, $wgTitle->getDBkey() );
138 switch( $wgTitle->getNamespace() ) {
140 require_once( 'includes/ImagePage.php' );
141 $wgArticle = new ImagePage( $wgTitle );
144 if ( $wgUseCategoryMagic ) {
145 require_once( 'includes/CategoryPage.php' );
146 $wgArticle = new CategoryPage( $wgTitle );
149 # NO break if wgUseCategoryMagic is false, drop through to next (default).
150 # Don't insert other cases between NS_CATEGORY and default.
152 $wgArticle = new Article( $wgTitle );
155 if ( in_array( $action, $wgDisabledActions ) ) {
156 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
160 $wgOut->setSquidMaxage( $wgSquidMaxage );
171 case 'markpatrolled':
173 $wgArticle->$action();
179 if( !$wgEnableDublinCoreRdf ) {
180 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
182 require_once( 'includes/Metadata.php' );
183 wfDublinCoreRdf( $wgArticle );
186 case 'creativecommons':
187 if( !$wgEnableCreativeCommonsRdf ) {
188 wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
190 require_once( 'includes/Metadata.php' );
191 wfCreativeCommonsRdf( $wgArticle );
195 require_once( 'includes/Credits.php' );
196 showCreditsPage( $wgArticle );
199 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
200 # Send a cookie so anons get talk message notifications
201 User
::SetupSession();
205 $internal = $wgRequest->getVal( 'internaledit' );
206 $external = $wgRequest->getVal( 'externaledit' );
207 $section = $wgRequest->getVal( 'section' );
208 $oldid = $wgRequest->getVal( 'oldid' );
209 if(!$wgUseExternalEditor ||
$action=='submit' ||
$internal ||
210 $section ||
$oldid ||
(!$wgUser->getOption('externaleditor') && !$external)) {
211 require_once( 'includes/EditPage.php' );
212 $editor = new EditPage( $wgArticle );
214 } elseif($wgUseExternalEditor && ($external ||
$wgUser->getOption('externaleditor'))) {
215 require_once( 'includes/ExternalEdit.php' );
216 $mode = $wgRequest->getVal( 'mode' );
217 $extedit = new ExternalEdit( $wgArticle, $mode );
222 if ($_SERVER['REQUEST_URI'] == $wgTitle->getInternalURL('action=history')) {
223 $wgOut->setSquidMaxage( $wgSquidMaxage );
225 require_once( 'includes/PageHistory.php' );
226 $history = new PageHistory( $wgArticle );
230 require_once( 'includes/RawPage.php' );
231 $raw = new RawPage( $wgArticle );
235 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
236 $wgOut->setSquidMaxage( $wgSquidMaxage );
237 $wgTitle->invalidateCache();
241 if (wfRunHooks('UnknownAction', $action, $wgArticle)) {
242 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
247 wfProfileOut( 'main-action' );
249 # Deferred updates aren't really deferred anymore. It's important to report errors to the
250 # user, and that means doing this before OutputPage::output(). Note that for page saves,
251 # the client will wait until the script exits anyway before following the redirect.
252 wfProfileIn( 'main-updates' );
253 foreach ( $wgDeferredUpdateList as $up ) {
256 wfProfileOut( 'main-updates' );
258 wfProfileIn( 'main-cleanup' );
259 $wgLoadBalancer->saveMasterPos();
261 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
262 $wgLoadBalancer->commitAll();
266 foreach ( $wgPostCommitUpdateList as $up ) {
270 wfProfileOut( 'main-cleanup' );
273 $wgLoadBalancer->closeAll();
274 wfDebug( "Request ended normally\n" );