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