Start removing the Latin-1 hacks. We're going pure UTF-8 for 1.5...
[lhc/web/wiklou.git] / index.php
1 <?php
2
3 #apd_set_pprof_trace();
4 # Main wiki script; see design.doc
5 #
6 $wgRequestTime = microtime();
7
8 unset( $IP );
9 @ini_set( 'allow_url_fopen', 0 ); # For security...
10 if( !file_exists( 'LocalSettings.php' ) ) {
11 if ( file_exists( 'config/LocalSettings.php' ) ) {
12 die( "To complete the installation, move <tt>config/LocalSettings.php</tt> to the parent directory.\n" );
13 } else {
14 die( "You'll have to <a href='config/index.php'>set the wiki up</a> first!" );
15 }
16 }
17
18 # Valid web server entry point, enable includes.
19 # Please don't move this line to includes/Defines.php. This line essentially defines
20 # a valid entry point. If you put it in includes/Defines.php, then any script that includes
21 # it becomes an entry point, thereby defeating its purpose.
22 define( 'MEDIAWIKI', true );
23
24 require_once( './includes/Defines.php' );
25 require_once( './LocalSettings.php' );
26 require_once( 'includes/Setup.php' );
27
28 wfProfileIn( 'main-misc-setup' );
29 OutputPage::setEncodings(); # Not really used yet
30
31 # Query string fields
32 $action = $wgRequest->getVal( 'action', 'view' );
33 $title = $wgRequest->getVal( 'title' );
34
35 $action = strtolower( trim( $action ) );
36 if ($wgRequest->getVal( 'printable' ) == 'yes') {
37 $wgOut->setPrintable();
38 }
39
40 if ( '' == $title && 'delete' != $action ) {
41 $wgTitle = Title::newFromText( wfMsgForContent( 'mainpage' ) );
42 } elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
43 # URLs like this are generated by RC, because rc_title isn't always accurate
44 $wgTitle = Title::newFromID( $curid );
45 } else {
46 $wgTitle = Title::newFromURL( $title );
47 }
48 wfProfileOut( 'main-misc-setup' );
49
50 # Debug statement for user levels
51 // print_r($wgUser);
52
53 # If the user is not logged in, the Namespace:title of the article must be in
54 # the Read array in order for the user to see it. (We have to check here to
55 # catch special pages etc. We check again in Article::view())
56 if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
57 $wgOut->loginToUse();
58 $wgOut->output();
59 exit;
60 }
61
62 wfProfileIn( 'main-action' );
63
64 $search = $wgRequest->getText( 'search' );
65 if( !$wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
66 require_once( 'includes/SpecialSearch.php' );
67 $wgTitle = Title::makeTitle( NS_SPECIAL, 'Search' );
68 wfSpecialSearch();
69 } else if( !$wgTitle or $wgTitle->getDBkey() == '' ) {
70 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
71 $wgOut->errorpage( 'badtitle', 'badtitletext' );
72 } else if ( $wgTitle->getInterwiki() != '' ) {
73 if( $rdfrom = $wgRequest->getVal( 'rdfrom' ) ) {
74 $url = $wgTitle->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
75 } else {
76 $url = $wgTitle->getFullURL();
77 }
78 # Check for a redirect loop
79 if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $wgTitle->isLocal() ) {
80 $wgOut->redirect( $url );
81 } else {
82 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
83 $wgOut->errorpage( 'badtitle', 'badtitletext' );
84 }
85 } else if ( ( $action == 'view' ) &&
86 (!isset( $_GET['title'] ) || $wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
87 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
88 {
89 /* redirect to canonical url, make it a 301 to allow caching */
90 $wgOut->setSquidMaxage( 1200 );
91 $wgOut->redirect( $wgTitle->getFullURL(), '301');
92 } else if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
93 # actions that need to be made when we have a special pages
94 require_once( 'includes/SpecialPage.php' );
95 SpecialPage::executePath( $wgTitle );
96 } else {
97 if ( NS_MEDIA == $wgTitle->getNamespace() ) {
98 $wgTitle = Title::makeTitle( NS_IMAGE, $wgTitle->getDBkey() );
99 }
100
101 switch( $wgTitle->getNamespace() ) {
102 case NS_IMAGE:
103 require_once( 'includes/ImagePage.php' );
104 $wgArticle = new ImagePage( $wgTitle );
105 break;
106 case NS_CATEGORY:
107 if ( $wgUseCategoryMagic ) {
108 require_once( 'includes/CategoryPage.php' );
109 $wgArticle = new CategoryPage( $wgTitle );
110 break;
111 }
112 # NO break if wgUseCategoryMagic is false, drop through to next (default).
113 # Don't insert other cases between NS_CATEGORY and default.
114 default:
115 $wgArticle = new Article( $wgTitle );
116 }
117
118 switch( $action ) {
119 case 'view':
120 $wgOut->setSquidMaxage( $wgSquidMaxage );
121 $wgArticle->view();
122 break;
123 case 'watch':
124 case 'unwatch':
125 case 'delete':
126 case 'revert':
127 case 'rollback':
128 case 'protect':
129 case 'unprotect':
130 case 'info':
131 case 'markpatrolled':
132 case 'validate':
133 $wgArticle->$action();
134 break;
135 case 'print':
136 $wgArticle->view();
137 break;
138 case 'dublincore':
139 if( !$wgEnableDublinCoreRdf ) {
140 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
141 } else {
142 require_once( 'includes/Metadata.php' );
143 wfDublinCoreRdf( $wgArticle );
144 }
145 break;
146 case 'creativecommons':
147 if( !$wgEnableCreativeCommonsRdf ) {
148 wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
149 } else {
150 require_once( 'includes/Metadata.php' );
151 wfCreativeCommonsRdf( $wgArticle );
152 }
153 break;
154 case 'credits':
155 require_once( 'includes/Credits.php' );
156 showCreditsPage( $wgArticle );
157 break;
158 case 'submit':
159 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
160 # Send a cookie so anons get talk message notifications
161 User::SetupSession();
162 }
163 # Continue...
164 case 'edit':
165 $internal = $wgRequest->getVal( 'internaledit' );
166 $external = $wgRequest->getVal( 'externaledit' );
167 $section = $wgRequest->getVal( 'section' );
168 $oldid = $wgRequest->getVal( 'oldid' );
169 if(!$wgUseExternalEditor || $action=='submit' || $internal ||
170 $section || $oldid || (!$wgUser->getOption('externaleditor') && !$external)) {
171 require_once( 'includes/EditPage.php' );
172 $editor = new EditPage( $wgArticle );
173 $editor->submit();
174 } elseif($wgUseExternalEditor && ($external || $wgUser->getOption('externaleditor'))) {
175 require_once( 'includes/ExternalEdit.php' );
176 $mode = $wgRequest->getVal( 'mode' );
177 $extedit = new ExternalEdit( $wgArticle, $mode );
178 $extedit->edit();
179 }
180 break;
181 case 'history':
182 if ($_SERVER['REQUEST_URI'] == $wgTitle->getInternalURL('action=history')) {
183 $wgOut->setSquidMaxage( $wgSquidMaxage );
184 }
185 require_once( 'includes/PageHistory.php' );
186 $history = new PageHistory( $wgArticle );
187 $history->history();
188 break;
189 case 'raw':
190 require_once( 'includes/RawPage.php' );
191 $raw = new RawPage( $wgArticle );
192 $raw->view();
193 break;
194 case 'purge':
195 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
196 $wgOut->setSquidMaxage( $wgSquidMaxage );
197 $wgTitle->invalidateCache();
198 $wgArticle->view();
199 break;
200 default:
201 if (wfRunHooks('UnknownAction', $action, $wgArticle)) {
202 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
203 }
204 }
205 }
206 wfProfileOut( 'main-action' );
207
208 # Deferred updates aren't really deferred anymore. It's important to report errors to the
209 # user, and that means doing this before OutputPage::output(). Note that for page saves,
210 # the client will wait until the script exits anyway before following the redirect.
211 wfProfileIn( 'main-updates' );
212 foreach ( $wgDeferredUpdateList as $up ) {
213 $up->doUpdate();
214 }
215 wfProfileOut( 'main-updates' );
216
217 wfProfileIn( 'main-cleanup' );
218 $wgLoadBalancer->saveMasterPos();
219
220 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
221 $wgLoadBalancer->commitAll();
222
223 $wgOut->output();
224
225 foreach ( $wgPostCommitUpdateList as $up ) {
226 $up->doUpdate();
227 }
228
229 wfProfileOut( 'main-cleanup' );
230
231 logProfilingData();
232 $wgLoadBalancer->closeAll();
233 wfDebug( "Request ended normally\n" );
234 ?>