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' />
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 if ($wgRequest->getVal( 'printable' ) == 'yes') {
73 $wgOut->setPrintable();
76 if ( '' == $title && 'delete' != $action ) {
77 $wgTitle = Title
::newFromText( wfMsgForContent( 'mainpage' ) );
78 } elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
79 # URLs like this are generated by RC, because rc_title isn't always accurate
80 $wgTitle = Title
::newFromID( $curid );
82 $wgTitle = Title
::newFromURL( $title );
83 /* check variant links so that interwiki links don't have to worry about
84 the possible different language variants
86 if( !is_null($wgTitle) && $wgTitle->getArticleID() == 0 )
87 $wgContLang->findVariantLink( $title, $wgTitle );
90 wfProfileOut( 'main-misc-setup' );
92 # Debug statement for user levels
95 # If the user is not logged in, the Namespace:title of the article must be in
96 # the Read array in order for the user to see it. (We have to check here to
97 # catch special pages etc. We check again in Article::view())
98 if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
104 wfProfileIn( 'main-action' );
105 $search = $wgRequest->getText( 'search' );
106 if( $wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
107 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Search' );
110 if( !$wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
111 require_once( 'includes/SpecialSearch.php' );
112 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Search' );
114 } else if( !$wgTitle or $wgTitle->getDBkey() == '' ) {
115 $wgTitle = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
116 $wgOut->errorpage( 'badtitle', 'badtitletext' );
117 } else if ( $wgTitle->getInterwiki() != '' ) {
118 if( $rdfrom = $wgRequest->getVal( 'rdfrom' ) ) {
119 $url = $wgTitle->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
121 $url = $wgTitle->getFullURL();
123 # Check for a redirect loop
124 if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $wgTitle->isLocal() ) {
125 $wgOut->redirect( $url );
127 $wgTitle = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
128 $wgOut->errorpage( 'badtitle', 'badtitletext' );
130 } else if ( ( $action == 'view' ) &&
131 (!isset( $_GET['title'] ) ||
$wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
132 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
134 /* redirect to canonical url, make it a 301 to allow caching */
135 $wgOut->setSquidMaxage( 1200 );
136 $wgOut->redirect( $wgTitle->getFullURL(), '301');
137 } else if ( NS_SPECIAL
== $wgTitle->getNamespace() ) {
138 # actions that need to be made when we have a special pages
139 SpecialPage
::executePath( $wgTitle );
141 if ( NS_MEDIA
== $wgTitle->getNamespace() ) {
142 $wgTitle = Title
::makeTitle( NS_IMAGE
, $wgTitle->getDBkey() );
145 $ns = $wgTitle->getNamespace();
147 // Namespace might change when using redirects
148 if($action == 'view' && !$wgRequest->getVal( 'oldid' ) ) {
149 $wgArticle = new Article( $wgTitle );
150 $rTitle = Title
::newFromRedirect( $wgArticle->fetchContent() );
152 if( $rTitle->getNamespace() == $ns ) {
153 $wgArticle->mContentLoaded
=false;
155 $ns = $rTitle->getNamespace();
159 // Categories and images are handled by a different class
160 if ( $ns == NS_IMAGE
) {
162 require_once( 'includes/ImagePage.php' );
163 $wgArticle = new ImagePage( $wgTitle );
164 } elseif ( $wgUseCategoryMagic && $ns == NS_CATEGORY
) {
166 require_once( 'includes/CategoryPage.php' );
167 $wgArticle = new CategoryPage( $wgTitle );
170 if ( in_array( $action, $wgDisabledActions ) ) {
171 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
175 $wgOut->setSquidMaxage( $wgSquidMaxage );
186 case 'markpatrolled':
189 case 'deletetrackback':
190 $wgArticle->$action();
196 if( !$wgEnableDublinCoreRdf ) {
197 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
199 require_once( 'includes/Metadata.php' );
200 wfDublinCoreRdf( $wgArticle );
203 case 'creativecommons':
204 if( !$wgEnableCreativeCommonsRdf ) {
205 wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
207 require_once( 'includes/Metadata.php' );
208 wfCreativeCommonsRdf( $wgArticle );
212 require_once( 'includes/Credits.php' );
213 showCreditsPage( $wgArticle );
216 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
217 # Send a cookie so anons get talk message notifications
218 User
::SetupSession();
222 $internal = $wgRequest->getVal( 'internaledit' );
223 $external = $wgRequest->getVal( 'externaledit' );
224 $section = $wgRequest->getVal( 'section' );
225 $oldid = $wgRequest->getVal( 'oldid' );
226 if(!$wgUseExternalEditor ||
$action=='submit' ||
$internal ||
227 $section ||
$oldid ||
(!$wgUser->getOption('externaleditor') && !$external)) {
228 require_once( 'includes/EditPage.php' );
229 $editor = new EditPage( $wgArticle );
231 } elseif($wgUseExternalEditor && ($external ||
$wgUser->getOption('externaleditor'))) {
232 require_once( 'includes/ExternalEdit.php' );
233 $mode = $wgRequest->getVal( 'mode' );
234 $extedit = new ExternalEdit( $wgArticle, $mode );
239 if ($_SERVER['REQUEST_URI'] == $wgTitle->getInternalURL('action=history')) {
240 $wgOut->setSquidMaxage( $wgSquidMaxage );
242 require_once( 'includes/PageHistory.php' );
243 $history = new PageHistory( $wgArticle );
247 require_once( 'includes/RawPage.php' );
248 $raw = new RawPage( $wgArticle );
252 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
253 $wgOut->setSquidMaxage( $wgSquidMaxage );
254 $wgTitle->invalidateCache();
258 if (wfRunHooks('UnknownAction', array($action, $wgArticle))) {
259 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
264 wfProfileOut( 'main-action' );
266 # Deferred updates aren't really deferred anymore. It's important to report errors to the
267 # user, and that means doing this before OutputPage::output(). Note that for page saves,
268 # the client will wait until the script exits anyway before following the redirect.
269 wfProfileIn( 'main-updates' );
270 foreach ( $wgDeferredUpdateList as $up ) {
273 wfProfileOut( 'main-updates' );
275 wfProfileIn( 'main-cleanup' );
276 $wgLoadBalancer->saveMasterPos();
278 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
279 $wgLoadBalancer->commitAll();
283 foreach ( $wgPostCommitUpdateList as $up ) {
287 wfProfileOut( 'main-cleanup' );
290 $wgLoadBalancer->closeAll();
291 wfDebug( "Request ended normally\n" );