Partial fix for installation bug
[lhc/web/wiklou.git] / index.php
1 <?php
2 #apd_set_pprof_trace();
3 # Main wiki script; see design.doc
4 #
5 $wgRequestTime = microtime();
6
7 unset( $IP );
8 @ini_set( 'allow_url_fopen', 0 ); # For security...
9 if( !file_exists( 'LocalSettings.php' ) ) {
10 define( 'MEDIAWIKI', true );
11 $IP = "127.0.0.1" ;
12 require_once( './includes/Defines.php' );
13 require_once( 'includes/DefaultSettings.php' ); # used for printing the version
14 ?>
15 <!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
16 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
17 <head>
18 <title>MediaWiki <?php echo $wgVersion ?></title>
19 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
20
21 <style type='text/css' media='screen, projection'>
22 html, body {
23 color: #000;
24 background-color: #fff;
25 font-family: serif;
26 text-align:center;
27 }
28
29 h1 {
30 font-size: 150%;
31 }
32 </style>
33 </head>
34 <body>
35 <img src='skins/common/images/wiki.png' alt='The MediaWiki logo' />
36
37 <h1>MediaWiki <?php echo $wgVersion ?></h1>
38 <div class='error'>
39 <?php
40 if ( file_exists( 'config/LocalSettings.php' ) ) {
41 echo( "To complete the installation, move <tt>config/LocalSettings.php</tt> to the parent directory." );
42 } else {
43 echo( "You'll have to <a href='config/index.php' title='setup'>set the wiki up</a> first!" );
44 }
45 ?>
46
47 </div>
48 </body>
49 </html>
50 <?php
51 die();
52 }
53
54 # Valid web server entry point, enable includes.
55 # Please don't move this line to includes/Defines.php. This line essentially defines
56 # a valid entry point. If you put it in includes/Defines.php, then any script that includes
57 # it becomes an entry point, thereby defeating its purpose.
58 define( 'MEDIAWIKI', true );
59
60 require_once( './includes/Defines.php' );
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 $action = strtolower( trim( $action ) );
72 if ($wgRequest->getVal( 'printable' ) == 'yes') {
73 $wgOut->setPrintable();
74 }
75
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 );
81 } else {
82 $wgTitle = Title::newFromURL( $title );
83 }
84 wfProfileOut( 'main-misc-setup' );
85
86 # Debug statement for user levels
87 // print_r($wgUser);
88
89 # If the user is not logged in, the Namespace:title of the article must be in
90 # the Read array in order for the user to see it. (We have to check here to
91 # catch special pages etc. We check again in Article::view())
92 if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
93 $wgOut->loginToUse();
94 $wgOut->output();
95 exit;
96 }
97
98 wfProfileIn( 'main-action' );
99
100 $search = $wgRequest->getText( 'search' );
101 if( !$wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
102 require_once( 'includes/SpecialSearch.php' );
103 $wgTitle = Title::makeTitle( NS_SPECIAL, 'Search' );
104 wfSpecialSearch();
105 } else if( !$wgTitle or $wgTitle->getDBkey() == '' ) {
106 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
107 $wgOut->errorpage( 'badtitle', 'badtitletext' );
108 } else if ( $wgTitle->getInterwiki() != '' ) {
109 if( $rdfrom = $wgRequest->getVal( 'rdfrom' ) ) {
110 $url = $wgTitle->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
111 } else {
112 $url = $wgTitle->getFullURL();
113 }
114 # Check for a redirect loop
115 if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $wgTitle->isLocal() ) {
116 $wgOut->redirect( $url );
117 } else {
118 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
119 $wgOut->errorpage( 'badtitle', 'badtitletext' );
120 }
121 } else if ( ( $action == 'view' ) &&
122 (!isset( $_GET['title'] ) || $wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
123 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
124 {
125 /* redirect to canonical url, make it a 301 to allow caching */
126 $wgOut->setSquidMaxage( 1200 );
127 $wgOut->redirect( $wgTitle->getFullURL(), '301');
128 } else if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
129 # actions that need to be made when we have a special pages
130 require_once( 'includes/SpecialPage.php' );
131 SpecialPage::executePath( $wgTitle );
132 } else {
133 if ( NS_MEDIA == $wgTitle->getNamespace() ) {
134 $wgTitle = Title::makeTitle( NS_IMAGE, $wgTitle->getDBkey() );
135 }
136
137 switch( $wgTitle->getNamespace() ) {
138 case NS_IMAGE:
139 require_once( 'includes/ImagePage.php' );
140 $wgArticle = new ImagePage( $wgTitle );
141 break;
142 case NS_CATEGORY:
143 if ( $wgUseCategoryMagic ) {
144 require_once( 'includes/CategoryPage.php' );
145 $wgArticle = new CategoryPage( $wgTitle );
146 break;
147 }
148 # NO break if wgUseCategoryMagic is false, drop through to next (default).
149 # Don't insert other cases between NS_CATEGORY and default.
150 default:
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 ?>