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