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