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