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