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