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