Start cracking down on illegal titles: in UTF-8 mode reject titles which have had...
[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 $title = $wgRequest->getVal( "title" );
29
30 # Placeholders in case of DB error
31 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
32 $wgArticle = new Article($wgTitle);
33
34 $action = strtolower( trim( $action ) );
35 if ($wgRequest->getVal( "printable" ) == "yes") {
36 $wgOut->setPrintable();
37 }
38
39 if ( "" == $title && "delete" != $action ) {
40 $wgTitle = Title::newFromText( wfMsg( "mainpage" ) );
41 } elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
42 # URLs like this are generated by RC, because rc_title isn't always accurate
43 $wgTitle = Title::newFromID( $curid );
44 } else {
45 $wgTitle = Title::newFromURL( $title );
46 }
47 wfProfileOut( "main-misc-setup" );
48
49 # If the user is not logged in, the Namespace:title of the article must be in
50 # the Read array in order for the user to see it. (We have to check here to
51 # catch special pages etc. We check again in Article::view())
52 if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
53 $wgOut->loginToUse();
54 $wgOut->output();
55 exit;
56 }
57
58 wfProfileIn( "main-action" );
59 $search = $wgRequest->getText( 'search' );
60 if( !is_null( $search ) && $search !== '' ) {
61 require_once( 'SearchEngine.php' );
62 $wgTitle = Title::makeTitle( NS_SPECIAL, "Search" );
63 $searchEngine = new SearchEngine( $search );
64 if( $wgRequest->getVal( 'fulltext' ) ||
65 !is_null( $wgRequest->getVal( 'offset' ) ) ||
66 !is_null ($wgRequest->getVal( 'searchx' ) ) ) {
67 $searchEngine->showResults();
68 } else {
69 $searchEngine->goResult();
70 }
71 } else if( !$wgTitle or $wgTitle->getDBkey() == "" ) {
72 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
73 $wgOut->errorpage( "badtitle", "badtitletext" );
74 } else if ( $wgTitle->getInterwiki() != "" ) {
75 $url = $wgTitle->getFullURL();
76 # Check for a redirect loop
77 if ( !preg_match( "/^" . preg_quote( $wgServer, "/" ) . "/", $url ) && $wgTitle->isLocal() ) {
78 $wgOut->redirect( $url );
79 } else {
80 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
81 $wgOut->errorpage( "badtitle", "badtitletext" );
82 }
83 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title &&
84 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
85 {
86 /* redirect to canonical url, make it a 301 to allow caching */
87 $wgOut->redirect( $wgTitle->getFullURL(), '301');
88 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
89 # actions that need to be made when we have a special pages
90 require_once( 'includes/SpecialPage.php' );
91 if ( !$wgAllowSysopQueries ) {SpecialPage::removePage( 'Asksql' ); }
92 SpecialPage::executePath( $wgTitle );
93 } else {
94 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
95 $wgTitle = Title::makeTitle( NS_IMAGE, $wgTitle->getDBkey() );
96 }
97
98 switch( $wgTitle->getNamespace() ) {
99 case NS_IMAGE:
100 require_once( "includes/ImagePage.php" );
101 $wgArticle = new ImagePage( $wgTitle );
102 break;
103 case NS_CATEGORY:
104 if ( $wgUseCategoryMagic ) {
105 require_once( "includes/CategoryPage.php" );
106 $wgArticle = new CategoryPage( $wgTitle );
107 break;
108 }
109 # NO break if wgUseCategoryMagic is false, drop through to next (default).
110 # Don't insert other cases between NS_CATEGORY and default.
111 default:
112 $wgArticle = new Article( $wgTitle );
113 }
114
115 switch( $action ) {
116 case "view":
117 $wgOut->setSquidMaxage( $wgSquidMaxage );
118 $wgArticle->view();
119 break;
120 case "watch":
121 case "unwatch":
122 case "delete":
123 case "revert":
124 case "rollback":
125 case "protect":
126 case "unprotect":
127 case "validate":
128 case "info":
129 case "markpatrolled":
130 $wgArticle->$action();
131 break;
132 case "print":
133 $wgArticle->view();
134 break;
135 case "dublincore":
136 if( !$wgEnableDublinCoreRdf ) {
137 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
138 } else {
139 require_once( "includes/Metadata.php" );
140 wfDublinCoreRdf( $wgArticle );
141 }
142 break;
143 case "creativecommons":
144 if( !$wgEnableCreativeCommonsRdf ) {
145 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
146 } else {
147 require_once( "includes/Metadata.php" );
148 wfCreativeCommonsRdf( $wgArticle );
149 }
150 break;
151 case "credits":
152 require_once( "includes/Credits.php" );
153 showCreditsPage( $wgArticle );
154 break;
155 case "edit":
156 case "submit":
157 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
158 User::SetupSession();
159 }
160 require_once( "includes/EditPage.php" );
161 $editor = new EditPage( $wgArticle );
162 $editor->submit();
163 break;
164 case "history":
165 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
166 $wgOut->setSquidMaxage( $wgSquidMaxage );
167 }
168 require_once( "includes/PageHistory.php" );
169 $history = new PageHistory( $wgArticle );
170 $history->history();
171 break;
172 case "raw":
173 require_once( "includes/RawPage.php" );
174 $raw = new RawPage( $wgArticle );
175 $raw->view();
176 break;
177 case "purge":
178 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
179 $wgOut->setSquidMaxage( $wgSquidMaxage );
180 $wgTitle->invalidateCache();
181 $wgArticle->view();
182 break;
183 default:
184 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
185 }
186 }
187 wfProfileOut( "main-action" );
188
189 # Deferred updates aren't really deferred anymore. It's important to report errors to the
190 # user, and that means doing this before OutputPage::output(). Note that for page saves,
191 # the client will wait until the script exits anyway before following the redirect.
192 wfProfileIn( "main-updates" );
193 foreach ( $wgDeferredUpdateList as $up ) {
194 $up->doUpdate();
195 }
196 wfProfileOut( "main-updates" );
197
198 wfProfileIn( "main-cleanup" );
199 $wgLoadBalancer->saveMasterPos();
200
201 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
202 $wgLoadBalancer->commitAll();
203
204 $wgOut->output();
205 wfProfileOut( "main-cleanup" );
206
207 logProfilingData();
208 $wgLoadBalancer->closeAll();
209 wfDebug( "Request ended normally\n" );
210 ?>