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