* (bug 2262) Hide math preferences when TeX is not enabled
[lhc/web/wiklou.git] / index.php
1 <?php
2 /**
3 * Main wiki script; see docs/design.txt
4 * @package MediaWiki
5 */
6
7 $wgRequestTime = microtime();
8
9 unset( $IP );
10 @ini_set( 'allow_url_fopen', 0 ); # For security...
11
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' );
18
19 if( !file_exists( 'LocalSettings.php' ) ) {
20 $IP = "." ;
21 require_once( 'includes/DefaultSettings.php' ); # used for printing the version
22 ?>
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'>
25 <head>
26 <title>MediaWiki <?php echo $wgVersion ?></title>
27 <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
28
29 <style type='text/css' media='screen, projection'>
30 html, body {
31 color: #000;
32 background-color: #fff;
33 font-family: serif;
34 text-align:center;
35 }
36
37 h1 {
38 font-size: 150%;
39 }
40 </style>
41 </head>
42 <body>
43 <img src='skins/common/images/mediawiki.png' alt='The MediaWiki logo' />
44
45 <h1>MediaWiki <?php echo $wgVersion ?></h1>
46 <div class='error'>
47 <?php
48 if ( file_exists( 'config/LocalSettings.php' ) ) {
49 echo( "To complete the installation, move <tt>config/LocalSettings.php</tt> to the parent directory." );
50 } else {
51 echo( "You'll have to <a href='config/index.php' title='setup'>set the wiki up</a> first!" );
52 }
53 ?>
54
55 </div>
56 </body>
57 </html>
58 <?php
59 die();
60 }
61
62 require_once( './LocalSettings.php' );
63 require_once( 'includes/Setup.php' );
64
65 wfProfileIn( 'main-misc-setup' );
66 OutputPage::setEncodings(); # Not really used yet
67
68 # Query string fields
69 $action = $wgRequest->getVal( 'action', 'view' );
70 $title = $wgRequest->getVal( 'title' );
71
72 $action = rtrim( $action );
73 if ($wgRequest->getVal( 'printable' ) == 'yes') {
74 $wgOut->setPrintable();
75 }
76
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 );
82 } else {
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
86 */
87 if( !is_null($wgTitle) && $wgTitle->getArticleID() == 0 )
88 $wgContLang->findVariantLink( $title, $wgTitle );
89
90 }
91 wfProfileOut( 'main-misc-setup' );
92
93 # Debug statement for user levels
94 // print_r($wgUser);
95
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();
101 $wgOut->output();
102 exit;
103 }
104
105 wfProfileIn( 'main-action' );
106
107 $search = $wgRequest->getText( 'search' );
108 if( !$wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
109 require_once( 'includes/SpecialSearch.php' );
110 $wgTitle = Title::makeTitle( NS_SPECIAL, 'Search' );
111 wfSpecialSearch();
112 } else if( !$wgTitle or $wgTitle->getDBkey() == '' ) {
113 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
114 $wgOut->errorpage( 'badtitle', 'badtitletext' );
115 } else if ( $wgTitle->getInterwiki() != '' ) {
116 if( $rdfrom = $wgRequest->getVal( 'rdfrom' ) ) {
117 $url = $wgTitle->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
118 } else {
119 $url = $wgTitle->getFullURL();
120 }
121 # Check for a redirect loop
122 if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $wgTitle->isLocal() ) {
123 $wgOut->redirect( $url );
124 } else {
125 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
126 $wgOut->errorpage( 'badtitle', 'badtitletext' );
127 }
128 } else if ( ( $action == 'view' ) &&
129 (!isset( $_GET['title'] ) || $wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
130 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
131 {
132 /* redirect to canonical url, make it a 301 to allow caching */
133 $wgOut->setSquidMaxage( 1200 );
134 $wgOut->redirect( $wgTitle->getFullURL(), '301');
135 } else if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
136 # actions that need to be made when we have a special pages
137 SpecialPage::executePath( $wgTitle );
138 } else {
139 if ( NS_MEDIA == $wgTitle->getNamespace() ) {
140 $wgTitle = Title::makeTitle( NS_IMAGE, $wgTitle->getDBkey() );
141 }
142
143 $ns = $wgTitle->getNamespace();
144 if ( $ns == NS_IMAGE ) {
145 require_once( 'includes/ImagePage.php' );
146 $wgArticle = new ImagePage( $wgTitle );
147 } elseif ( $wgUseCategoryMagic && $ns == NS_CATEGORY ) {
148 require_once( 'includes/CategoryPage.php' );
149 $wgArticle = new CategoryPage( $wgTitle );
150 } else {
151 $wgArticle = new Article( $wgTitle );
152 }
153
154 if ( in_array( $action, $wgDisabledActions ) ) {
155 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
156 } else {
157 switch( $action ) {
158 case 'view':
159 $wgOut->setSquidMaxage( $wgSquidMaxage );
160 $wgArticle->view();
161 break;
162 case 'watch':
163 case 'unwatch':
164 case 'delete':
165 case 'revert':
166 case 'rollback':
167 case 'protect':
168 case 'unprotect':
169 case 'info':
170 case 'markpatrolled':
171 case 'validate':
172 $wgArticle->$action();
173 break;
174 case 'print':
175 $wgArticle->view();
176 break;
177 case 'dublincore':
178 if( !$wgEnableDublinCoreRdf ) {
179 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
180 } else {
181 require_once( 'includes/Metadata.php' );
182 wfDublinCoreRdf( $wgArticle );
183 }
184 break;
185 case 'creativecommons':
186 if( !$wgEnableCreativeCommonsRdf ) {
187 wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
188 } else {
189 require_once( 'includes/Metadata.php' );
190 wfCreativeCommonsRdf( $wgArticle );
191 }
192 break;
193 case 'credits':
194 require_once( 'includes/Credits.php' );
195 showCreditsPage( $wgArticle );
196 break;
197 case 'submit':
198 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
199 # Send a cookie so anons get talk message notifications
200 User::SetupSession();
201 }
202 # Continue...
203 case 'edit':
204 $internal = $wgRequest->getVal( 'internaledit' );
205 $external = $wgRequest->getVal( 'externaledit' );
206 $section = $wgRequest->getVal( 'section' );
207 $oldid = $wgRequest->getVal( 'oldid' );
208 if(!$wgUseExternalEditor || $action=='submit' || $internal ||
209 $section || $oldid || (!$wgUser->getOption('externaleditor') && !$external)) {
210 require_once( 'includes/EditPage.php' );
211 $editor = new EditPage( $wgArticle );
212 $editor->submit();
213 } elseif($wgUseExternalEditor && ($external || $wgUser->getOption('externaleditor'))) {
214 require_once( 'includes/ExternalEdit.php' );
215 $mode = $wgRequest->getVal( 'mode' );
216 $extedit = new ExternalEdit( $wgArticle, $mode );
217 $extedit->edit();
218 }
219 break;
220 case 'history':
221 if ($_SERVER['REQUEST_URI'] == $wgTitle->getInternalURL('action=history')) {
222 $wgOut->setSquidMaxage( $wgSquidMaxage );
223 }
224 require_once( 'includes/PageHistory.php' );
225 $history = new PageHistory( $wgArticle );
226 $history->history();
227 break;
228 case 'raw':
229 require_once( 'includes/RawPage.php' );
230 $raw = new RawPage( $wgArticle );
231 $raw->view();
232 break;
233 case 'purge':
234 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
235 $wgOut->setSquidMaxage( $wgSquidMaxage );
236 $wgTitle->invalidateCache();
237 $wgArticle->view();
238 break;
239 default:
240 if (wfRunHooks('UnknownAction', $action, $wgArticle)) {
241 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
242 }
243 }
244 }
245 }
246 wfProfileOut( 'main-action' );
247
248 # Deferred updates aren't really deferred anymore. It's important to report errors to the
249 # user, and that means doing this before OutputPage::output(). Note that for page saves,
250 # the client will wait until the script exits anyway before following the redirect.
251 wfProfileIn( 'main-updates' );
252 foreach ( $wgDeferredUpdateList as $up ) {
253 $up->doUpdate();
254 }
255 wfProfileOut( 'main-updates' );
256
257 wfProfileIn( 'main-cleanup' );
258 $wgLoadBalancer->saveMasterPos();
259
260 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
261 $wgLoadBalancer->commitAll();
262
263 $wgOut->output();
264
265 foreach ( $wgPostCommitUpdateList as $up ) {
266 $up->doUpdate();
267 }
268
269 wfProfileOut( 'main-cleanup' );
270
271 logProfilingData();
272 $wgLoadBalancer->closeAll();
273 wfDebug( "Request ended normally\n" );
274 ?>