# Please don't move this line to includes/Defines.php. This line essentially defines
[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 if ( $search = $wgRequest->getText( 'search' ) ) {
64 $wgTitle = Title::makeTitle( NS_SPECIAL, "Search" );
65 $searchEngine = new SearchEngine( $search );
66 if( $wgRequest->getVal( 'fulltext' ) ||
67 !is_null( $wgRequest->getVal( 'offset' ) ) ||
68 !is_null ($wgRequest->getVal( 'searchx' ) ) ) {
69 $searchEngine->showResults();
70 } else {
71 $searchEngine->goResult();
72 }
73 } else if( !$wgTitle or $wgTitle->getDBkey() == "" ) {
74 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
75 $wgOut->errorpage( "badtitle", "badtitletext" );
76 } else if ( $wgTitle->getInterwiki() != "" ) {
77 $url = $wgTitle->getFullURL();
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( wfMsg( "badtitle" ) );
83 $wgOut->errorpage( "badtitle", "badtitletext" );
84 }
85 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title &&
86 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
87 {
88 /* redirect to canonical url, make it a 301 to allow caching */
89 $wgOut->redirect( $wgTitle->getFullURL(), '301');
90 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
91 # actions that need to be made when we have a special pages
92 require_once( 'includes/SpecialPage.php' );
93 if ( !$wgAllowSysopQueries ) {SpecialPage::removePage( 'Asksql' ); }
94 SpecialPage::executePath( $wgTitle );
95 } else {
96 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
97 $wgTitle = Title::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
98 }
99
100 switch( $wgTitle->getNamespace() ) {
101 case NS_IMAGE:
102 require_once( "includes/ImagePage.php" );
103 $wgArticle = new ImagePage( $wgTitle );
104 break;
105 default:
106 $wgArticle = new Article( $wgTitle );
107 }
108
109 switch( $action ) {
110 case "view":
111 $wgOut->setSquidMaxage( $wgSquidMaxage );
112 $wgArticle->view();
113 break;
114 case "watch":
115 case "unwatch":
116 case "delete":
117 case "revert":
118 case "rollback":
119 case "protect":
120 case "unprotect":
121 case "validate":
122 case "info":
123 case "markpatrolled":
124 $wgArticle->$action();
125 break;
126 case "print":
127 $wgArticle->view();
128 break;
129 case "dublincore":
130 if( !$wgEnableDublinCoreRdf ) {
131 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
132 } else {
133 require_once( "includes/Metadata.php" );
134 wfDublinCoreRdf( $wgArticle );
135 }
136 break;
137 case "creativecommons":
138 if( !$wgEnableCreativeCommonsRdf ) {
139 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
140 } else {
141 require_once( "includes/Metadata.php" );
142 wfCreativeCommonsRdf( $wgArticle );
143 }
144 break;
145 case "credits":
146 require_once( "includes/Credits.php" );
147 showCreditsPage( $wgArticle );
148 break;
149 case "edit":
150 case "submit":
151 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
152 User::SetupSession();
153 }
154 require_once( "includes/EditPage.php" );
155 $editor = new EditPage( $wgArticle );
156 $editor->submit();
157 break;
158 case "history":
159 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
160 $wgOut->setSquidMaxage( $wgSquidMaxage );
161 }
162 require_once( "includes/PageHistory.php" );
163 $history = new PageHistory( $wgArticle );
164 $history->history();
165 break;
166 case "raw":
167 require_once( "includes/RawPage.php" );
168 $raw = new RawPage( $wgArticle );
169 $raw->view();
170 break;
171 case "purge":
172 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
173 $wgOut->setSquidMaxage( $wgSquidMaxage );
174 $wgTitle->invalidateCache();
175 $wgArticle->view();
176 break;
177 default:
178 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
179 }
180 }
181
182 # Deferred updates aren't really deferred anymore. It's important to report errors to the
183 # user, and that means doing this before OutputPage::output(). Note that for page saves,
184 # the client will wait until the script exits anyway before following the redirect.
185 foreach ( $wgDeferredUpdateList as $up ) {
186 $up->doUpdate();
187 }
188
189 $wgLoadBalancer->saveMasterPos();
190
191 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
192 $wgLoadBalancer->commitAll();
193
194 $wgOut->output();
195
196 logProfilingData();
197 $wgLoadBalancer->closeAll();
198 wfDebug( "Request ended normally\n" );
199 ?>