Old log page -> logging table importer.
[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( NS_IMAGE, $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 case NS_CATEGORY:
108 if ( $wgUseCategoryMagic ) {
109 require_once( "includes/CategoryPage.php" );
110 $wgArticle = new CategoryPage( $wgTitle );
111 break;
112 }
113 # NO break if wgUseCategoryMagic is false, drop through to next (default).
114 # Don't insert other cases between NS_CATEGORY and default.
115 default:
116 $wgArticle = new Article( $wgTitle );
117 }
118
119 switch( $action ) {
120 case "view":
121 $wgOut->setSquidMaxage( $wgSquidMaxage );
122 $wgArticle->view();
123 break;
124 case "watch":
125 case "unwatch":
126 case "delete":
127 case "revert":
128 case "rollback":
129 case "protect":
130 case "unprotect":
131 case "validate":
132 case "info":
133 case "markpatrolled":
134 $wgArticle->$action();
135 break;
136 case "print":
137 $wgArticle->view();
138 break;
139 case "dublincore":
140 if( !$wgEnableDublinCoreRdf ) {
141 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
142 } else {
143 require_once( "includes/Metadata.php" );
144 wfDublinCoreRdf( $wgArticle );
145 }
146 break;
147 case "creativecommons":
148 if( !$wgEnableCreativeCommonsRdf ) {
149 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
150 } else {
151 require_once( "includes/Metadata.php" );
152 wfCreativeCommonsRdf( $wgArticle );
153 }
154 break;
155 case "credits":
156 require_once( "includes/Credits.php" );
157 showCreditsPage( $wgArticle );
158 break;
159 case "edit":
160 case "submit":
161 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
162 User::SetupSession();
163 }
164 require_once( "includes/EditPage.php" );
165 $editor = new EditPage( $wgArticle );
166 $editor->submit();
167 break;
168 case "history":
169 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
170 $wgOut->setSquidMaxage( $wgSquidMaxage );
171 }
172 require_once( "includes/PageHistory.php" );
173 $history = new PageHistory( $wgArticle );
174 $history->history();
175 break;
176 case "raw":
177 require_once( "includes/RawPage.php" );
178 $raw = new RawPage( $wgArticle );
179 $raw->view();
180 break;
181 case "purge":
182 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
183 $wgOut->setSquidMaxage( $wgSquidMaxage );
184 $wgTitle->invalidateCache();
185 $wgArticle->view();
186 break;
187 default:
188 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
189 }
190 }
191 wfProfileOut( "main-action" );
192
193 # Deferred updates aren't really deferred anymore. It's important to report errors to the
194 # user, and that means doing this before OutputPage::output(). Note that for page saves,
195 # the client will wait until the script exits anyway before following the redirect.
196 wfProfileIn( "main-updates" );
197 foreach ( $wgDeferredUpdateList as $up ) {
198 $up->doUpdate();
199 }
200 wfProfileOut( "main-updates" );
201
202 wfProfileIn( "main-cleanup" );
203 $wgLoadBalancer->saveMasterPos();
204
205 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
206 $wgLoadBalancer->commitAll();
207
208 $wgOut->output();
209 wfProfileOut( "main-cleanup" );
210
211 logProfilingData();
212 $wgLoadBalancer->closeAll();
213 wfDebug( "Request ended normally\n" );
214 ?>