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