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