ec627961cbf816c55f466f6d0963ff3472da8722
[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( $wgUseLatin1 ) {
74 # Conversion from UTF-8 may truncate or corrupt non-Latin links.
75 # Grab a fresh copy without doing the automated conversion checks.
76 $interwiki = Title::newFromUrl( $_REQUEST['title'] );
77 if( !is_null( $interwiki ) ) $wgTitle = $interwiki;
78 }
79 $url = $wgTitle->getFullURL();
80 # Check for a redirect loop
81 if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $wgTitle->isLocal() ) {
82 $wgOut->redirect( $url );
83 } else {
84 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
85 $wgOut->errorpage( 'badtitle', 'badtitletext' );
86 }
87 } else if ( ( $action == 'view' ) &&
88 (!isset( $_GET['title'] ) || $wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
89 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
90 {
91 /* redirect to canonical url, make it a 301 to allow caching */
92 $wgOut->setSquidMaxage( 1200 );
93 $wgOut->redirect( $wgTitle->getFullURL(), '301');
94 } else if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
95 # actions that need to be made when we have a special pages
96 require_once( 'includes/SpecialPage.php' );
97 SpecialPage::executePath( $wgTitle );
98 } else {
99 if ( NS_MEDIA == $wgTitle->getNamespace() ) {
100 $wgTitle = Title::makeTitle( NS_IMAGE, $wgTitle->getDBkey() );
101 }
102
103 switch( $wgTitle->getNamespace() ) {
104 case NS_IMAGE:
105 require_once( 'includes/ImagePage.php' );
106 $wgArticle = new ImagePage( $wgTitle );
107 break;
108 case NS_CATEGORY:
109 if ( $wgUseCategoryMagic ) {
110 require_once( 'includes/CategoryPage.php' );
111 $wgArticle = new CategoryPage( $wgTitle );
112 break;
113 }
114 # NO break if wgUseCategoryMagic is false, drop through to next (default).
115 # Don't insert other cases between NS_CATEGORY and default.
116 default:
117 $wgArticle = new Article( $wgTitle );
118 }
119
120 switch( $action ) {
121 case 'view':
122 $wgOut->setSquidMaxage( $wgSquidMaxage );
123 $wgArticle->view();
124 break;
125 case 'watch':
126 case 'unwatch':
127 case 'delete':
128 case 'revert':
129 case 'rollback':
130 case 'protect':
131 case 'unprotect':
132 case 'info':
133 case 'markpatrolled':
134 $wgArticle->$action();
135 break;
136 case 'print':
137 $wgArticle->view();
138 break;
139 case 'dublincore':
140 if( !$wgEnableDublinCoreRdf ) {
141 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
142 } else {
143 require_once( 'includes/Metadata.php' );
144 wfDublinCoreRdf( $wgArticle );
145 }
146 break;
147 case 'creativecommons':
148 if( !$wgEnableCreativeCommonsRdf ) {
149 wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
150 } else {
151 require_once( 'includes/Metadata.php' );
152 wfCreativeCommonsRdf( $wgArticle );
153 }
154 break;
155 case 'credits':
156 require_once( 'includes/Credits.php' );
157 showCreditsPage( $wgArticle );
158 break;
159 case 'submit':
160 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
161 # Send a cookie so anons get talk message notifications
162 User::SetupSession();
163 }
164 # Continue...
165 case 'edit':
166 require_once( 'includes/EditPage.php' );
167 $editor = new EditPage( $wgArticle );
168 $editor->submit();
169 break;
170 case 'history':
171 if ($_SERVER['REQUEST_URI'] == $wgTitle->getInternalURL('action=history')) {
172 $wgOut->setSquidMaxage( $wgSquidMaxage );
173 }
174 require_once( 'includes/PageHistory.php' );
175 $history = new PageHistory( $wgArticle );
176 $history->history();
177 break;
178 case 'raw':
179 require_once( 'includes/RawPage.php' );
180 $raw = new RawPage( $wgArticle );
181 $raw->view();
182 break;
183 case 'purge':
184 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
185 $wgOut->setSquidMaxage( $wgSquidMaxage );
186 $wgTitle->invalidateCache();
187 $wgArticle->view();
188 break;
189 default:
190 if (wfRunHooks('UnknownAction', $action, $wgArticle)) {
191 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
192 }
193 }
194 }
195 wfProfileOut( 'main-action' );
196
197 # Deferred updates aren't really deferred anymore. It's important to report errors to the
198 # user, and that means doing this before OutputPage::output(). Note that for page saves,
199 # the client will wait until the script exits anyway before following the redirect.
200 wfProfileIn( 'main-updates' );
201 foreach ( $wgDeferredUpdateList as $up ) {
202 $up->doUpdate();
203 }
204 wfProfileOut( 'main-updates' );
205
206 wfProfileIn( 'main-cleanup' );
207 $wgLoadBalancer->saveMasterPos();
208
209 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
210 $wgLoadBalancer->commitAll();
211
212 $wgOut->output();
213
214 foreach ( $wgPostCommitUpdateList as $up ) {
215 $up->doUpdate();
216 }
217
218 wfProfileOut( 'main-cleanup' );
219
220 logProfilingData();
221 $wgLoadBalancer->closeAll();
222 wfDebug( "Request ended normally\n" );
223 ?>