<? => <?php
[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 require_once( 'includes/DefaultSettings.php' ); # used for printing the version
12 ?>
13 <!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
14 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
15 <head>
16 <title>MediaWiki <?php echo $wgVersion ?></title>
17 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
18
19 <style type='text/css' media='screen, projection'>
20 html, body {
21 color: #000;
22 background-color: #fff;
23 font-family: serif;
24 text-align:center;
25 }
26
27 h1 {
28 font-size: 150%;
29 }
30 </style>
31 </head>
32 <body>
33 <img src='skins/common/images/wiki.png' alt='The MediaWiki logo' />
34
35 <h1>MediaWiki <?php echo $wgVersion ?></h1>
36 <div class='error'>
37 <?php
38 if ( file_exists( 'config/LocalSettings.php' ) ) {
39 echo( "To complete the installation, move <tt>config/LocalSettings.php</tt> to the parent directory." );
40 } else {
41 echo( "You'll have to <a href='config/index.php' title='setup'>set the wiki up</a> first!" );
42 }
43 ?>
44
45 </div>
46 </body>
47 </html>
48 <?php
49 die();
50 }
51
52 # Valid web server entry point, enable includes.
53 # Please don't move this line to includes/Defines.php. This line essentially defines
54 # a valid entry point. If you put it in includes/Defines.php, then any script that includes
55 # it becomes an entry point, thereby defeating its purpose.
56 define( 'MEDIAWIKI', true );
57
58 require_once( './includes/Defines.php' );
59 require_once( './LocalSettings.php' );
60 require_once( 'includes/Setup.php' );
61
62 wfProfileIn( 'main-misc-setup' );
63 OutputPage::setEncodings(); # Not really used yet
64
65 # Query string fields
66 $action = $wgRequest->getVal( 'action', 'view' );
67 $title = $wgRequest->getVal( 'title' );
68
69 $action = strtolower( trim( $action ) );
70 if ($wgRequest->getVal( 'printable' ) == 'yes') {
71 $wgOut->setPrintable();
72 }
73
74 if ( '' == $title && 'delete' != $action ) {
75 $wgTitle = Title::newFromText( wfMsgForContent( 'mainpage' ) );
76 } elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
77 # URLs like this are generated by RC, because rc_title isn't always accurate
78 $wgTitle = Title::newFromID( $curid );
79 } else {
80 $wgTitle = Title::newFromURL( $title );
81 }
82 wfProfileOut( 'main-misc-setup' );
83
84 # Debug statement for user levels
85 // print_r($wgUser);
86
87 # If the user is not logged in, the Namespace:title of the article must be in
88 # the Read array in order for the user to see it. (We have to check here to
89 # catch special pages etc. We check again in Article::view())
90 if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
91 $wgOut->loginToUse();
92 $wgOut->output();
93 exit;
94 }
95
96 wfProfileIn( 'main-action' );
97
98 $search = $wgRequest->getText( 'search' );
99 if( !$wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
100 require_once( 'includes/SpecialSearch.php' );
101 $wgTitle = Title::makeTitle( NS_SPECIAL, 'Search' );
102 wfSpecialSearch();
103 } else if( !$wgTitle or $wgTitle->getDBkey() == '' ) {
104 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
105 $wgOut->errorpage( 'badtitle', 'badtitletext' );
106 } else if ( $wgTitle->getInterwiki() != '' ) {
107 if( $rdfrom = $wgRequest->getVal( 'rdfrom' ) ) {
108 $url = $wgTitle->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
109 } else {
110 $url = $wgTitle->getFullURL();
111 }
112 # Check for a redirect loop
113 if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $wgTitle->isLocal() ) {
114 $wgOut->redirect( $url );
115 } else {
116 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
117 $wgOut->errorpage( 'badtitle', 'badtitletext' );
118 }
119 } else if ( ( $action == 'view' ) &&
120 (!isset( $_GET['title'] ) || $wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
121 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
122 {
123 /* redirect to canonical url, make it a 301 to allow caching */
124 $wgOut->setSquidMaxage( 1200 );
125 $wgOut->redirect( $wgTitle->getFullURL(), '301');
126 } else if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
127 # actions that need to be made when we have a special pages
128 require_once( 'includes/SpecialPage.php' );
129 SpecialPage::executePath( $wgTitle );
130 } else {
131 if ( NS_MEDIA == $wgTitle->getNamespace() ) {
132 $wgTitle = Title::makeTitle( NS_IMAGE, $wgTitle->getDBkey() );
133 }
134
135 switch( $wgTitle->getNamespace() ) {
136 case NS_IMAGE:
137 require_once( 'includes/ImagePage.php' );
138 $wgArticle = new ImagePage( $wgTitle );
139 break;
140 case NS_CATEGORY:
141 if ( $wgUseCategoryMagic ) {
142 require_once( 'includes/CategoryPage.php' );
143 $wgArticle = new CategoryPage( $wgTitle );
144 break;
145 }
146 # NO break if wgUseCategoryMagic is false, drop through to next (default).
147 # Don't insert other cases between NS_CATEGORY and default.
148 default:
149 $wgArticle = new Article( $wgTitle );
150 }
151
152 if ( in_array( $action, $wgDisabledActions ) ) {
153 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
154 } else {
155 switch( $action ) {
156 case 'view':
157 $wgOut->setSquidMaxage( $wgSquidMaxage );
158 $wgArticle->view();
159 break;
160 case 'watch':
161 case 'unwatch':
162 case 'delete':
163 case 'revert':
164 case 'rollback':
165 case 'protect':
166 case 'unprotect':
167 case 'info':
168 case 'markpatrolled':
169 case 'validate':
170 $wgArticle->$action();
171 break;
172 case 'print':
173 $wgArticle->view();
174 break;
175 case 'dublincore':
176 if( !$wgEnableDublinCoreRdf ) {
177 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
178 } else {
179 require_once( 'includes/Metadata.php' );
180 wfDublinCoreRdf( $wgArticle );
181 }
182 break;
183 case 'creativecommons':
184 if( !$wgEnableCreativeCommonsRdf ) {
185 wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
186 } else {
187 require_once( 'includes/Metadata.php' );
188 wfCreativeCommonsRdf( $wgArticle );
189 }
190 break;
191 case 'credits':
192 require_once( 'includes/Credits.php' );
193 showCreditsPage( $wgArticle );
194 break;
195 case 'submit':
196 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
197 # Send a cookie so anons get talk message notifications
198 User::SetupSession();
199 }
200 # Continue...
201 case 'edit':
202 $internal = $wgRequest->getVal( 'internaledit' );
203 $external = $wgRequest->getVal( 'externaledit' );
204 $section = $wgRequest->getVal( 'section' );
205 $oldid = $wgRequest->getVal( 'oldid' );
206 if(!$wgUseExternalEditor || $action=='submit' || $internal ||
207 $section || $oldid || (!$wgUser->getOption('externaleditor') && !$external)) {
208 require_once( 'includes/EditPage.php' );
209 $editor = new EditPage( $wgArticle );
210 $editor->submit();
211 } elseif($wgUseExternalEditor && ($external || $wgUser->getOption('externaleditor'))) {
212 require_once( 'includes/ExternalEdit.php' );
213 $mode = $wgRequest->getVal( 'mode' );
214 $extedit = new ExternalEdit( $wgArticle, $mode );
215 $extedit->edit();
216 }
217 break;
218 case 'history':
219 if ($_SERVER['REQUEST_URI'] == $wgTitle->getInternalURL('action=history')) {
220 $wgOut->setSquidMaxage( $wgSquidMaxage );
221 }
222 require_once( 'includes/PageHistory.php' );
223 $history = new PageHistory( $wgArticle );
224 $history->history();
225 break;
226 case 'raw':
227 require_once( 'includes/RawPage.php' );
228 $raw = new RawPage( $wgArticle );
229 $raw->view();
230 break;
231 case 'purge':
232 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
233 $wgOut->setSquidMaxage( $wgSquidMaxage );
234 $wgTitle->invalidateCache();
235 $wgArticle->view();
236 break;
237 default:
238 if (wfRunHooks('UnknownAction', $action, $wgArticle)) {
239 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
240 }
241 }
242 }
243 }
244 wfProfileOut( 'main-action' );
245
246 # Deferred updates aren't really deferred anymore. It's important to report errors to the
247 # user, and that means doing this before OutputPage::output(). Note that for page saves,
248 # the client will wait until the script exits anyway before following the redirect.
249 wfProfileIn( 'main-updates' );
250 foreach ( $wgDeferredUpdateList as $up ) {
251 $up->doUpdate();
252 }
253 wfProfileOut( 'main-updates' );
254
255 wfProfileIn( 'main-cleanup' );
256 $wgLoadBalancer->saveMasterPos();
257
258 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
259 $wgLoadBalancer->commitAll();
260
261 $wgOut->output();
262
263 foreach ( $wgPostCommitUpdateList as $up ) {
264 $up->doUpdate();
265 }
266
267 wfProfileOut( 'main-cleanup' );
268
269 logProfilingData();
270 $wgLoadBalancer->closeAll();
271 wfDebug( "Request ended normally\n" );
272 ?>