Ability to disable actions from LocalSettings.php
[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 if ( in_array( $action, $wgDisabledActions ) ) {
119 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
120 } else {
121 switch( $action ) {
122 case 'view':
123 $wgOut->setSquidMaxage( $wgSquidMaxage );
124 $wgArticle->view();
125 break;
126 case 'watch':
127 case 'unwatch':
128 case 'delete':
129 case 'revert':
130 case 'rollback':
131 case 'protect':
132 case 'unprotect':
133 case 'info':
134 case 'markpatrolled':
135 case 'validate':
136 $wgArticle->$action();
137 break;
138 case 'print':
139 $wgArticle->view();
140 break;
141 case 'dublincore':
142 if( !$wgEnableDublinCoreRdf ) {
143 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
144 } else {
145 require_once( 'includes/Metadata.php' );
146 wfDublinCoreRdf( $wgArticle );
147 }
148 break;
149 case 'creativecommons':
150 if( !$wgEnableCreativeCommonsRdf ) {
151 wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
152 } else {
153 require_once( 'includes/Metadata.php' );
154 wfCreativeCommonsRdf( $wgArticle );
155 }
156 break;
157 case 'credits':
158 require_once( 'includes/Credits.php' );
159 showCreditsPage( $wgArticle );
160 break;
161 case 'submit':
162 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
163 # Send a cookie so anons get talk message notifications
164 User::SetupSession();
165 }
166 # Continue...
167 case 'edit':
168 $internal = $wgRequest->getVal( 'internaledit' );
169 $external = $wgRequest->getVal( 'externaledit' );
170 $section = $wgRequest->getVal( 'section' );
171 $oldid = $wgRequest->getVal( 'oldid' );
172 if(!$wgUseExternalEditor || $action=='submit' || $internal ||
173 $section || $oldid || (!$wgUser->getOption('externaleditor') && !$external)) {
174 require_once( 'includes/EditPage.php' );
175 $editor = new EditPage( $wgArticle );
176 $editor->submit();
177 } elseif($wgUseExternalEditor && ($external || $wgUser->getOption('externaleditor'))) {
178 require_once( 'includes/ExternalEdit.php' );
179 $mode = $wgRequest->getVal( 'mode' );
180 $extedit = new ExternalEdit( $wgArticle, $mode );
181 $extedit->edit();
182 }
183 break;
184 case 'history':
185 if ($_SERVER['REQUEST_URI'] == $wgTitle->getInternalURL('action=history')) {
186 $wgOut->setSquidMaxage( $wgSquidMaxage );
187 }
188 require_once( 'includes/PageHistory.php' );
189 $history = new PageHistory( $wgArticle );
190 $history->history();
191 break;
192 case 'raw':
193 require_once( 'includes/RawPage.php' );
194 $raw = new RawPage( $wgArticle );
195 $raw->view();
196 break;
197 case 'purge':
198 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
199 $wgOut->setSquidMaxage( $wgSquidMaxage );
200 $wgTitle->invalidateCache();
201 $wgArticle->view();
202 break;
203 default:
204 if (wfRunHooks('UnknownAction', $action, $wgArticle)) {
205 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
206 }
207 }
208 }
209 }
210 wfProfileOut( 'main-action' );
211
212 # Deferred updates aren't really deferred anymore. It's important to report errors to the
213 # user, and that means doing this before OutputPage::output(). Note that for page saves,
214 # the client will wait until the script exits anyway before following the redirect.
215 wfProfileIn( 'main-updates' );
216 foreach ( $wgDeferredUpdateList as $up ) {
217 $up->doUpdate();
218 }
219 wfProfileOut( 'main-updates' );
220
221 wfProfileIn( 'main-cleanup' );
222 $wgLoadBalancer->saveMasterPos();
223
224 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
225 $wgLoadBalancer->commitAll();
226
227 $wgOut->output();
228
229 foreach ( $wgPostCommitUpdateList as $up ) {
230 $up->doUpdate();
231 }
232
233 wfProfileOut( 'main-cleanup' );
234
235 logProfilingData();
236 $wgLoadBalancer->closeAll();
237 wfDebug( "Request ended normally\n" );
238 ?>