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