3 * Main wiki script; see docs/design.txt
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' />
28 <style type
='text/css' media
='screen, projection'>
31 background
-color
: #fff;
32 font
-family
: sans
-serif
;
42 <img src
='skins/common/images/mediawiki.png' alt
='The MediaWiki logo' />
44 <h1
>MediaWiki
<?php
echo $wgVersion ?
></h1
>
47 if ( file_exists( 'config/LocalSettings.php' ) ) {
48 echo( "To complete the installation, move <tt>config/LocalSettings.php</tt> to the parent directory." );
50 echo( "Please <a href='config/index.php' title='setup'>setup the wiki</a> first." );
61 require_once( './LocalSettings.php' );
62 require_once( 'includes/Setup.php' );
64 wfProfileIn( 'main-misc-setup' );
65 OutputPage
::setEncodings(); # Not really used yet
68 $action = $wgRequest->getVal( 'action', 'view' );
69 $title = $wgRequest->getVal( 'title' );
71 if ($wgRequest->getVal( 'printable' ) == 'yes') {
72 $wgOut->setPrintable();
75 if ( '' == $title && 'delete' != $action ) {
76 $wgTitle = Title
::newFromText( wfMsgForContent( 'mainpage' ) );
77 } elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
78 # URLs like this are generated by RC, because rc_title isn't always accurate
79 $wgTitle = Title
::newFromID( $curid );
81 $wgTitle = Title
::newFromURL( $title );
82 /* check variant links so that interwiki links don't have to worry about
83 the possible different language variants
85 if( !is_null($wgTitle) && $wgTitle->getArticleID() == 0 )
86 $wgContLang->findVariantLink( $title, $wgTitle );
89 wfProfileOut( 'main-misc-setup' );
91 # Debug statement for user levels
94 # If the user is not logged in, the Namespace:title of the article must be in
95 # the Read array in order for the user to see it. (We have to check here to
96 # catch special pages etc. We check again in Article::view())
97 if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
103 wfProfileIn( 'main-action' );
104 $search = $wgRequest->getText( 'search' );
105 if( $wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
106 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Search' );
109 if( !$wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
110 require_once( 'includes/SpecialSearch.php' );
111 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Search' );
113 } else if( !$wgTitle or $wgTitle->getDBkey() == '' ) {
114 $wgTitle = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
115 $wgOut->errorpage( 'badtitle', 'badtitletext' );
116 } else if ( $wgTitle->getInterwiki() != '' ) {
117 if( $rdfrom = $wgRequest->getVal( 'rdfrom' ) ) {
118 $url = $wgTitle->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
120 $url = $wgTitle->getFullURL();
122 # Check for a redirect loop
123 if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $wgTitle->isLocal() ) {
124 $wgOut->redirect( $url );
126 $wgTitle = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
127 $wgOut->errorpage( 'badtitle', 'badtitletext' );
129 } else if ( ( $action == 'view' ) &&
130 (!isset( $_GET['title'] ) ||
$wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
131 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
133 /* redirect to canonical url, make it a 301 to allow caching */
134 $wgOut->setSquidMaxage( 1200 );
135 $wgOut->redirect( $wgTitle->getFullURL(), '301');
136 } else if ( NS_SPECIAL
== $wgTitle->getNamespace() ) {
137 # actions that need to be made when we have a special pages
138 SpecialPage
::executePath( $wgTitle );
140 if ( NS_MEDIA
== $wgTitle->getNamespace() ) {
141 $wgTitle = Title
::makeTitle( NS_IMAGE
, $wgTitle->getDBkey() );
144 $ns = $wgTitle->getNamespace();
146 // Namespace might change when using redirects
147 if($action == 'view' && !$wgRequest->getVal( 'oldid' ) ) {
148 $wgArticle = new Article( $wgTitle );
149 $rTitle = Title
::newFromRedirect( $wgArticle->fetchContent() );
151 # Reload from the page pointed to later
152 $wgArticle->mContentLoaded
= false;
153 $ns = $rTitle->getNamespace();
157 // Categories and images are handled by a different class
158 if ( $ns == NS_IMAGE
) {
160 require_once( 'includes/ImagePage.php' );
161 $wgArticle = new ImagePage( $wgTitle );
162 } elseif ( $wgUseCategoryMagic && $ns == NS_CATEGORY
) {
164 require_once( 'includes/CategoryPage.php' );
165 $wgArticle = new CategoryPage( $wgTitle );
168 if ( in_array( $action, $wgDisabledActions ) ) {
169 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
173 $wgOut->setSquidMaxage( $wgSquidMaxage );
184 case 'markpatrolled':
187 case 'deletetrackback':
188 $wgArticle->$action();
194 if( !$wgEnableDublinCoreRdf ) {
195 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
197 require_once( 'includes/Metadata.php' );
198 wfDublinCoreRdf( $wgArticle );
201 case 'creativecommons':
202 if( !$wgEnableCreativeCommonsRdf ) {
203 wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
205 require_once( 'includes/Metadata.php' );
206 wfCreativeCommonsRdf( $wgArticle );
210 require_once( 'includes/Credits.php' );
211 showCreditsPage( $wgArticle );
214 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
215 # Send a cookie so anons get talk message notifications
216 User
::SetupSession();
220 $internal = $wgRequest->getVal( 'internaledit' );
221 $external = $wgRequest->getVal( 'externaledit' );
222 $section = $wgRequest->getVal( 'section' );
223 $oldid = $wgRequest->getVal( 'oldid' );
224 if(!$wgUseExternalEditor ||
$action=='submit' ||
$internal ||
225 $section ||
$oldid ||
(!$wgUser->getOption('externaleditor') && !$external)) {
226 require_once( 'includes/EditPage.php' );
227 $editor = new EditPage( $wgArticle );
229 } elseif($wgUseExternalEditor && ($external ||
$wgUser->getOption('externaleditor'))) {
230 require_once( 'includes/ExternalEdit.php' );
231 $mode = $wgRequest->getVal( 'mode' );
232 $extedit = new ExternalEdit( $wgArticle, $mode );
237 if ($_SERVER['REQUEST_URI'] == $wgTitle->getInternalURL('action=history')) {
238 $wgOut->setSquidMaxage( $wgSquidMaxage );
240 require_once( 'includes/PageHistory.php' );
241 $history = new PageHistory( $wgArticle );
245 require_once( 'includes/RawPage.php' );
246 $raw = new RawPage( $wgArticle );
250 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
251 $wgOut->setSquidMaxage( $wgSquidMaxage );
252 $wgTitle->invalidateCache();
256 if (wfRunHooks('UnknownAction', array($action, $wgArticle))) {
257 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
262 wfProfileOut( 'main-action' );
264 # Deferred updates aren't really deferred anymore. It's important to report errors to the
265 # user, and that means doing this before OutputPage::output(). Note that for page saves,
266 # the client will wait until the script exits anyway before following the redirect.
267 wfProfileIn( 'main-updates' );
268 foreach ( $wgDeferredUpdateList as $up ) {
271 wfProfileOut( 'main-updates' );
273 wfProfileIn( 'main-cleanup' );
274 $wgLoadBalancer->saveMasterPos();
276 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
277 $wgLoadBalancer->commitAll();
281 foreach ( $wgPostCommitUpdateList as $up ) {
285 wfProfileOut( 'main-cleanup' );
288 $wgLoadBalancer->closeAll();
289 wfDebug( "Request ended normally\n" );