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