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 $action = rtrim( $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 );
84 /* check variant links so that interwiki links don't have to worry about
85 the possible different language variants
87 if( !is_null($wgTitle) && $wgTitle->getArticleID() == 0 )
88 $wgContLang->findVariantLink( $title, $wgTitle );
91 wfProfileOut( 'main-misc-setup' );
93 # Debug statement for user levels
96 # If the user is not logged in, the Namespace:title of the article must be in
97 # the Read array in order for the user to see it. (We have to check here to
98 # catch special pages etc. We check again in Article::view())
99 if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
100 $wgOut->loginToUse();
105 wfProfileIn( 'main-action' );
106 $search = $wgRequest->getText( 'search' );
107 if( $wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
108 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Search' );
111 if( !$wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
112 require_once( 'includes/SpecialSearch.php' );
113 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Search' );
115 } else if( !$wgTitle or $wgTitle->getDBkey() == '' ) {
116 $wgTitle = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
117 $wgOut->errorpage( 'badtitle', 'badtitletext' );
118 } else if ( $wgTitle->getInterwiki() != '' ) {
119 if( $rdfrom = $wgRequest->getVal( 'rdfrom' ) ) {
120 $url = $wgTitle->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
122 $url = $wgTitle->getFullURL();
124 # Check for a redirect loop
125 if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $wgTitle->isLocal() ) {
126 $wgOut->redirect( $url );
128 $wgTitle = Title
::newFromText( wfMsgForContent( 'badtitle' ) );
129 $wgOut->errorpage( 'badtitle', 'badtitletext' );
131 } else if ( ( $action == 'view' ) &&
132 (!isset( $_GET['title'] ) ||
$wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
133 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
135 /* redirect to canonical url, make it a 301 to allow caching */
136 $wgOut->setSquidMaxage( 1200 );
137 $wgOut->redirect( $wgTitle->getFullURL(), '301');
138 } else if ( NS_SPECIAL
== $wgTitle->getNamespace() ) {
139 # actions that need to be made when we have a special pages
140 SpecialPage
::executePath( $wgTitle );
142 if ( NS_MEDIA
== $wgTitle->getNamespace() ) {
143 $wgTitle = Title
::makeTitle( NS_IMAGE
, $wgTitle->getDBkey() );
146 $ns = $wgTitle->getNamespace();
147 if ( $ns == NS_IMAGE
) {
148 require_once( 'includes/ImagePage.php' );
149 $wgArticle = new ImagePage( $wgTitle );
150 } elseif ( $wgUseCategoryMagic && $ns == NS_CATEGORY
) {
151 require_once( 'includes/CategoryPage.php' );
152 $wgArticle = new CategoryPage( $wgTitle );
154 $wgArticle = new Article( $wgTitle );
157 if ( in_array( $action, $wgDisabledActions ) ) {
158 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
162 $wgOut->setSquidMaxage( $wgSquidMaxage );
173 case 'markpatrolled':
175 $wgArticle->$action();
181 if( !$wgEnableDublinCoreRdf ) {
182 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
184 require_once( 'includes/Metadata.php' );
185 wfDublinCoreRdf( $wgArticle );
188 case 'creativecommons':
189 if( !$wgEnableCreativeCommonsRdf ) {
190 wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
192 require_once( 'includes/Metadata.php' );
193 wfCreativeCommonsRdf( $wgArticle );
197 require_once( 'includes/Credits.php' );
198 showCreditsPage( $wgArticle );
201 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
202 # Send a cookie so anons get talk message notifications
203 User
::SetupSession();
207 $internal = $wgRequest->getVal( 'internaledit' );
208 $external = $wgRequest->getVal( 'externaledit' );
209 $section = $wgRequest->getVal( 'section' );
210 $oldid = $wgRequest->getVal( 'oldid' );
211 if(!$wgUseExternalEditor ||
$action=='submit' ||
$internal ||
212 $section ||
$oldid ||
(!$wgUser->getOption('externaleditor') && !$external)) {
213 require_once( 'includes/EditPage.php' );
214 $editor = new EditPage( $wgArticle );
216 } elseif($wgUseExternalEditor && ($external ||
$wgUser->getOption('externaleditor'))) {
217 require_once( 'includes/ExternalEdit.php' );
218 $mode = $wgRequest->getVal( 'mode' );
219 $extedit = new ExternalEdit( $wgArticle, $mode );
224 if ($_SERVER['REQUEST_URI'] == $wgTitle->getInternalURL('action=history')) {
225 $wgOut->setSquidMaxage( $wgSquidMaxage );
227 require_once( 'includes/PageHistory.php' );
228 $history = new PageHistory( $wgArticle );
232 require_once( 'includes/RawPage.php' );
233 $raw = new RawPage( $wgArticle );
237 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
238 $wgOut->setSquidMaxage( $wgSquidMaxage );
239 $wgTitle->invalidateCache();
243 if (wfRunHooks('UnknownAction', $action, $wgArticle)) {
244 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
249 wfProfileOut( 'main-action' );
251 # Deferred updates aren't really deferred anymore. It's important to report errors to the
252 # user, and that means doing this before OutputPage::output(). Note that for page saves,
253 # the client will wait until the script exits anyway before following the redirect.
254 wfProfileIn( 'main-updates' );
255 foreach ( $wgDeferredUpdateList as $up ) {
258 wfProfileOut( 'main-updates' );
260 wfProfileIn( 'main-cleanup' );
261 $wgLoadBalancer->saveMasterPos();
263 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
264 $wgLoadBalancer->commitAll();
268 foreach ( $wgPostCommitUpdateList as $up ) {
272 wfProfileOut( 'main-cleanup' );
275 $wgLoadBalancer->closeAll();
276 wfDebug( "Request ended normally\n" );