dc9780a9561a2b0dd46ae565af6e3d482e5ae4d0
[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 if( $wgRequest->getVal( 'fulltext' ) ||
63 !is_null( $wgRequest->getVal( 'offset' ) ) ||
64 !is_null ($wgRequest->getVal( 'searchx' ) ) ) {
65 wfSearch( $search );
66 } else {
67 wfGo( $search );
68 }
69 } else if( !$wgTitle or $wgTitle->getDBkey() == "" ) {
70 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
71 $wgOut->errorpage( "badtitle", "badtitletext" );
72 } else if ( $wgTitle->getInterwiki() != "" ) {
73 $url = $wgTitle->getFullURL();
74 # Check for a redirect loop
75 if ( !preg_match( "/^" . preg_quote( $wgServer, "/" ) . "/", $url ) && $wgTitle->isLocal() ) {
76 $wgOut->redirect( $url );
77 } else {
78 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
79 $wgOut->errorpage( "badtitle", "badtitletext" );
80 }
81 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title &&
82 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
83 {
84 /* redirect to canonical url, make it a 301 to allow caching */
85 $wgOut->redirect( $wgTitle->getFullURL(), '301');
86 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
87 # actions that need to be made when we have a special pages
88 require_once( 'includes/SpecialPage.php' );
89 if ( !$wgAllowSysopQueries ) {SpecialPage::removePage( 'Asksql' ); }
90 SpecialPage::executePath( $wgTitle );
91 } else {
92 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
93 $wgTitle = Title::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
94 }
95
96 switch( $wgTitle->getNamespace() ) {
97 case NS_IMAGE:
98 require_once( "includes/ImagePage.php" );
99 $wgArticle = new ImagePage( $wgTitle );
100 break;
101 default:
102 $wgArticle = new Article( $wgTitle );
103 }
104
105 switch( $action ) {
106 case "view":
107 $wgOut->setSquidMaxage( $wgSquidMaxage );
108 $wgArticle->view();
109 break;
110 case "watch":
111 case "unwatch":
112 case "delete":
113 case "revert":
114 case "rollback":
115 case "protect":
116 case "unprotect":
117 case "validate":
118 case "info":
119 case "markpatrolled":
120 $wgArticle->$action();
121 break;
122 case "print":
123 $wgArticle->view();
124 break;
125 case "dublincore":
126 if( !$wgEnableDublinCoreRdf ) {
127 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
128 } else {
129 require_once( "includes/Metadata.php" );
130 wfDublinCoreRdf( $wgArticle );
131 }
132 break;
133 case "creativecommons":
134 if( !$wgEnableCreativeCommonsRdf ) {
135 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
136 } else {
137 require_once( "includes/Metadata.php" );
138 wfCreativeCommonsRdf( $wgArticle );
139 }
140 break;
141 case "credits":
142 require_once( "includes/Credits.php" );
143 showCreditsPage( $wgArticle );
144 break;
145 case "edit":
146 case "submit":
147 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
148 User::SetupSession();
149 }
150 require_once( "includes/EditPage.php" );
151 $editor = new EditPage( $wgArticle );
152 $editor->submit();
153 break;
154 case "history":
155 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
156 $wgOut->setSquidMaxage( $wgSquidMaxage );
157 }
158 require_once( "includes/PageHistory.php" );
159 $history = new PageHistory( $wgArticle );
160 $history->history();
161 break;
162 case "raw":
163 require_once( "includes/RawPage.php" );
164 $raw = new RawPage( $wgArticle );
165 $raw->view();
166 break;
167 case "purge":
168 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
169 $wgOut->setSquidMaxage( $wgSquidMaxage );
170 $wgTitle->invalidateCache();
171 $wgArticle->view();
172 break;
173 default:
174 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
175 }
176 }
177
178 # Deferred updates aren't really deferred anymore. It's important to report errors to the
179 # user, and that means doing this before OutputPage::output(). Note that for page saves,
180 # the client will wait until the script exits anyway before following the redirect.
181 foreach ( $wgDeferredUpdateList as $up ) {
182 $up->doUpdate();
183 }
184
185 $wgLoadBalancer->saveMasterPos();
186
187 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
188 $wgLoadBalancer->commitAll();
189
190 $wgOut->output();
191
192 logProfilingData();
193 $wgLoadBalancer->closeAll();
194 wfDebug( "Request ended normally\n" );
195 ?>