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