Reverting fix for 2585; some users report seeing error displays of some
[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 <style type='text/css' media='screen, projection'>
29 html, body {
30 color: #000;
31 background-color: #fff;
32 font-family: sans-serif;
33 text-align: center;
34 }
35
36 h1 {
37 font-size: 150%;
38 }
39 </style>
40 </head>
41 <body>
42 <img src='skins/common/images/mediawiki.png' alt='The MediaWiki logo' />
43
44 <h1>MediaWiki <?php echo $wgVersion ?></h1>
45 <div class='error'>
46 <?php
47 if ( file_exists( 'config/LocalSettings.php' ) ) {
48 echo( "To complete the installation, move <tt>config/LocalSettings.php</tt> to the parent directory." );
49 } else {
50 echo( "Please <a href='config/index.php' title='setup'>setup the wiki</a> first." );
51 }
52 ?>
53
54 </div>
55 </body>
56 </html>
57 <?php
58 die();
59 }
60
61 require_once( './LocalSettings.php' );
62 require_once( 'includes/Setup.php' );
63
64 wfProfileIn( 'main-misc-setup' );
65 OutputPage::setEncodings(); # Not really used yet
66
67 # Query string fields
68 $action = $wgRequest->getVal( 'action', 'view' );
69 $title = $wgRequest->getVal( 'title' );
70
71 if ($wgRequest->getVal( 'printable' ) == 'yes') {
72 $wgOut->setPrintable();
73 }
74
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 );
80 } else {
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
84 */
85 if( count($wgContLang->getVariants()) > 1 && !is_null($wgTitle) && $wgTitle->getArticleID() == 0 )
86 $wgContLang->findVariantLink( $title, $wgTitle );
87
88 }
89 wfProfileOut( 'main-misc-setup' );
90
91 # Debug statement for user levels
92 // print_r($wgUser);
93
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() ) {
98 $wgOut->loginToUse();
99 $wgOut->output();
100 exit;
101 }
102
103 wfProfileIn( 'main-action' );
104 $search = $wgRequest->getText( 'search' );
105 if( $wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
106 $wgTitle = Title::makeTitle( NS_SPECIAL, 'Search' );
107 }
108
109 if( !$wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
110 require_once( 'includes/SpecialSearch.php' );
111 $wgTitle = Title::makeTitle( NS_SPECIAL, 'Search' );
112 wfSpecialSearch();
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 ) );
119 } else {
120 $url = $wgTitle->getFullURL();
121 }
122 # Check for a redirect loop
123 if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $wgTitle->isLocal() ) {
124 $wgOut->redirect( $url );
125 } else {
126 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
127 $wgOut->errorpage( 'badtitle', 'badtitletext' );
128 }
129 } else if ( ( $action == 'view' ) &&
130 (!isset( $_GET['title'] ) || $wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
131 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
132 {
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 );
139 } else {
140 if ( NS_MEDIA == $wgTitle->getNamespace() ) {
141 $wgTitle = Title::makeTitle( NS_IMAGE, $wgTitle->getDBkey() );
142 }
143
144 $ns = $wgTitle->getNamespace();
145
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() );
150 if($rTitle) {
151 # Reload from the page pointed to later
152 $wgArticle->mContentLoaded = false;
153 $ns = $rTitle->getNamespace();
154 }
155 }
156
157 // Categories and images are handled by a different class
158 if ( $ns == NS_IMAGE ) {
159 unset($wgArticle);
160 require_once( 'includes/ImagePage.php' );
161 $wgArticle = new ImagePage( $wgTitle );
162 } elseif ( $wgUseCategoryMagic && $ns == NS_CATEGORY ) {
163 unset($wgArticle);
164 require_once( 'includes/CategoryPage.php' );
165 $wgArticle = new CategoryPage( $wgTitle );
166 }
167
168 if ( in_array( $action, $wgDisabledActions ) ) {
169 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
170 } else {
171 switch( $action ) {
172 case 'view':
173 $wgOut->setSquidMaxage( $wgSquidMaxage );
174 $wgArticle->view();
175 break;
176 case 'watch':
177 case 'unwatch':
178 case 'delete':
179 case 'revert':
180 case 'rollback':
181 case 'protect':
182 case 'unprotect':
183 case 'info':
184 case 'markpatrolled':
185 case 'validate':
186 case 'render':
187 case 'deletetrackback':
188 $wgArticle->$action();
189 break;
190 case 'print':
191 $wgArticle->view();
192 break;
193 case 'dublincore':
194 if( !$wgEnableDublinCoreRdf ) {
195 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
196 } else {
197 require_once( 'includes/Metadata.php' );
198 wfDublinCoreRdf( $wgArticle );
199 }
200 break;
201 case 'creativecommons':
202 if( !$wgEnableCreativeCommonsRdf ) {
203 wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
204 } else {
205 require_once( 'includes/Metadata.php' );
206 wfCreativeCommonsRdf( $wgArticle );
207 }
208 break;
209 case 'credits':
210 require_once( 'includes/Credits.php' );
211 showCreditsPage( $wgArticle );
212 break;
213 case 'submit':
214 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
215 # Send a cookie so anons get talk message notifications
216 User::SetupSession();
217 }
218 # Continue...
219 case 'edit':
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 );
228 $editor->submit();
229 } elseif($wgUseExternalEditor && ($external || $wgUser->getOption('externaleditor'))) {
230 require_once( 'includes/ExternalEdit.php' );
231 $mode = $wgRequest->getVal( 'mode' );
232 $extedit = new ExternalEdit( $wgArticle, $mode );
233 $extedit->edit();
234 }
235 break;
236 case 'history':
237 if ($_SERVER['REQUEST_URI'] == $wgTitle->getInternalURL('action=history')) {
238 $wgOut->setSquidMaxage( $wgSquidMaxage );
239 }
240 require_once( 'includes/PageHistory.php' );
241 $history = new PageHistory( $wgArticle );
242 $history->history();
243 break;
244 case 'raw':
245 require_once( 'includes/RawPage.php' );
246 $raw = new RawPage( $wgArticle );
247 $raw->view();
248 break;
249 case 'purge':
250 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
251 $wgOut->setSquidMaxage( $wgSquidMaxage );
252 $wgTitle->invalidateCache();
253 $wgArticle->view();
254 break;
255 default:
256 if (wfRunHooks('UnknownAction', array($action, $wgArticle))) {
257 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
258 }
259 }
260 }
261 }
262 wfProfileOut( 'main-action' );
263
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 ) {
269 $up->doUpdate();
270 }
271 wfProfileOut( 'main-updates' );
272
273 wfProfileIn( 'main-cleanup' );
274 $wgLoadBalancer->saveMasterPos();
275
276 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
277 $wgLoadBalancer->commitAll();
278
279 $wgOut->output();
280
281 foreach ( $wgPostCommitUpdateList as $up ) {
282 $up->doUpdate();
283 }
284
285 wfProfileOut( 'main-cleanup' );
286
287 logProfilingData();
288 $wgLoadBalancer->closeAll();
289 wfDebug( "Request ended normally\n" );
290 ?>