typo
[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 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 /* check variant links so that interwiki links don't have to worry about
84 the possible different language variants
85 */
86 if( !is_null($wgTitle) && $wgTitle->getArticleID() == 0 )
87 $wgContLang->findVariantLink( $title, $wgTitle );
88
89 }
90 wfProfileOut( 'main-misc-setup' );
91
92 # Debug statement for user levels
93 // print_r($wgUser);
94
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() ) {
99 $wgOut->loginToUse();
100 $wgOut->output();
101 exit;
102 }
103
104 wfProfileIn( 'main-action' );
105 $search = $wgRequest->getText( 'search' );
106 if( $wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
107 $wgTitle = Title::makeTitle( NS_SPECIAL, 'Search' );
108 }
109
110 if( !$wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
111 require_once( 'includes/SpecialSearch.php' );
112 $wgTitle = Title::makeTitle( NS_SPECIAL, 'Search' );
113 wfSpecialSearch();
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 ) );
120 } else {
121 $url = $wgTitle->getFullURL();
122 }
123 # Check for a redirect loop
124 if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $wgTitle->isLocal() ) {
125 $wgOut->redirect( $url );
126 } else {
127 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
128 $wgOut->errorpage( 'badtitle', 'badtitletext' );
129 }
130 } else if ( ( $action == 'view' ) &&
131 (!isset( $_GET['title'] ) || $wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
132 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
133 {
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 );
140 } else {
141 if ( NS_MEDIA == $wgTitle->getNamespace() ) {
142 $wgTitle = Title::makeTitle( NS_IMAGE, $wgTitle->getDBkey() );
143 }
144
145 $ns = $wgTitle->getNamespace();
146
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() );
151 if($rTitle) {
152 # Reload from the page pointed to later
153 $wgArticle->mContentLoaded = false;
154 $ns = $rTitle->getNamespace();
155 }
156 }
157
158 // Categories and images are handled by a different class
159 if ( $ns == NS_IMAGE ) {
160 unset($wgArticle);
161 require_once( 'includes/ImagePage.php' );
162 $wgArticle = new ImagePage( $wgTitle );
163 } elseif ( $wgUseCategoryMagic && $ns == NS_CATEGORY ) {
164 unset($wgArticle);
165 require_once( 'includes/CategoryPage.php' );
166 $wgArticle = new CategoryPage( $wgTitle );
167 }
168
169 if ( in_array( $action, $wgDisabledActions ) ) {
170 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
171 } else {
172 switch( $action ) {
173 case 'view':
174 $wgOut->setSquidMaxage( $wgSquidMaxage );
175 $wgArticle->view();
176 break;
177 case 'watch':
178 case 'unwatch':
179 case 'delete':
180 case 'revert':
181 case 'rollback':
182 case 'protect':
183 case 'unprotect':
184 case 'info':
185 case 'markpatrolled':
186 case 'validate':
187 case 'render':
188 case 'deletetrackback':
189 $wgArticle->$action();
190 break;
191 case 'print':
192 $wgArticle->view();
193 break;
194 case 'dublincore':
195 if( !$wgEnableDublinCoreRdf ) {
196 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
197 } else {
198 require_once( 'includes/Metadata.php' );
199 wfDublinCoreRdf( $wgArticle );
200 }
201 break;
202 case 'creativecommons':
203 if( !$wgEnableCreativeCommonsRdf ) {
204 wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
205 } else {
206 require_once( 'includes/Metadata.php' );
207 wfCreativeCommonsRdf( $wgArticle );
208 }
209 break;
210 case 'credits':
211 require_once( 'includes/Credits.php' );
212 showCreditsPage( $wgArticle );
213 break;
214 case 'submit':
215 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
216 # Send a cookie so anons get talk message notifications
217 User::SetupSession();
218 }
219 # Continue...
220 case 'edit':
221 $internal = $wgRequest->getVal( 'internaledit' );
222 $external = $wgRequest->getVal( 'externaledit' );
223 $section = $wgRequest->getVal( 'section' );
224 $oldid = $wgRequest->getVal( 'oldid' );
225 if(!$wgUseExternalEditor || $action=='submit' || $internal ||
226 $section || $oldid || (!$wgUser->getOption('externaleditor') && !$external)) {
227 require_once( 'includes/EditPage.php' );
228 $editor = new EditPage( $wgArticle );
229 $editor->submit();
230 } elseif($wgUseExternalEditor && ($external || $wgUser->getOption('externaleditor'))) {
231 require_once( 'includes/ExternalEdit.php' );
232 $mode = $wgRequest->getVal( 'mode' );
233 $extedit = new ExternalEdit( $wgArticle, $mode );
234 $extedit->edit();
235 }
236 break;
237 case 'history':
238 if ($_SERVER['REQUEST_URI'] == $wgTitle->getInternalURL('action=history')) {
239 $wgOut->setSquidMaxage( $wgSquidMaxage );
240 }
241 require_once( 'includes/PageHistory.php' );
242 $history = new PageHistory( $wgArticle );
243 $history->history();
244 break;
245 case 'raw':
246 require_once( 'includes/RawPage.php' );
247 $raw = new RawPage( $wgArticle );
248 $raw->view();
249 break;
250 case 'purge':
251 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
252 $wgOut->setSquidMaxage( $wgSquidMaxage );
253 $wgTitle->invalidateCache();
254 $wgArticle->view();
255 break;
256 default:
257 if (wfRunHooks('UnknownAction', array($action, $wgArticle))) {
258 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
259 }
260 }
261 }
262 }
263 wfProfileOut( 'main-action' );
264
265 # Deferred updates aren't really deferred anymore. It's important to report errors to the
266 # user, and that means doing this before OutputPage::output(). Note that for page saves,
267 # the client will wait until the script exits anyway before following the redirect.
268 wfProfileIn( 'main-updates' );
269 foreach ( $wgDeferredUpdateList as $up ) {
270 $up->doUpdate();
271 }
272 wfProfileOut( 'main-updates' );
273
274 wfProfileIn( 'main-cleanup' );
275 $wgLoadBalancer->saveMasterPos();
276
277 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
278 $wgLoadBalancer->commitAll();
279
280 $wgOut->output();
281
282 foreach ( $wgPostCommitUpdateList as $up ) {
283 $up->doUpdate();
284 }
285
286 wfProfileOut( 'main-cleanup' );
287
288 logProfilingData();
289 $wgLoadBalancer->closeAll();
290 wfDebug( "Request ended normally\n" );
291 ?>