Allow installing and running the wiki on a server where ini_set has been
[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 ( "" == $action ) { $action = "view"; }
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 the Read array in
50 # order for the user to see it.
51 if ( !$wgUser->getID() && is_array( $wgWhitelistRead ) && $wgTitle) {
52 if ( !in_array( $wgLang->getNsText( $wgTitle->getNamespace() ) . ":" . $wgTitle->getDBkey(), $wgWhitelistRead ) ) {
53 $wgOut->loginToUse();
54 $wgOut->output();
55 exit;
56 }
57 }
58
59 if ( $search = $wgRequest->getText( 'search' ) ) {
60 $wgTitle = Title::makeTitle( NS_SPECIAL, "Search" );
61 if( $wgRequest->getVal( 'fulltext' ) ) {
62 wfSearch( $search );
63 } else {
64 wfGo( $search );
65 }
66 } else if( !$wgTitle or $wgTitle->getDBkey() == "" ) {
67 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
68 $wgOut->errorpage( "badtitle", "badtitletext" );
69 } else if ( $wgTitle->getInterwiki() != "" ) {
70 $url = $wgTitle->getFullURL();
71 # Check for a redirect loop
72 if ( !preg_match( "/^" . preg_quote( $wgServer ) . "/", $url ) && $wgTitle->isLocal() ) {
73 $wgOut->redirect( $url );
74 } else {
75 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
76 $wgOut->errorpage( "badtitle", "badtitletext" );
77 }
78 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title ) {
79 /* redirect to canonical url, make it a 301 to allow caching */
80 $wgOut->redirect( $wgTitle->getFullURL(), '301');
81 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
82 wfSpecialPage();
83 } else {
84 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
85 $wgTitle = Title::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
86 }
87
88 switch( $wgTitle->getNamespace() ) {
89 case NS_IMAGE:
90 require_once( "includes/ImagePage.php" );
91 $wgArticle = new ImagePage( $wgTitle );
92 break;
93 default:
94 $wgArticle = new Article( $wgTitle );
95 }
96
97 wfQuery("BEGIN", DB_WRITE);
98 switch( $action ) {
99 case "view":
100 $wgOut->setSquidMaxage( $wgSquidMaxage );
101 $wgArticle->view();
102 break;
103 case "watch":
104 case "unwatch":
105 case "delete":
106 case "revert":
107 case "rollback":
108 case "protect":
109 case "unprotect":
110 $wgArticle->$action();
111 break;
112 case "print":
113 $wgArticle->view();
114 break;
115 case "dublincore":
116 if( !$wgEnableDublinCoreRdf ) {
117 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
118 } else {
119 require_once( "includes/Metadata.php" );
120 wfDublinCoreRdf( $wgArticle );
121 }
122 break;
123 case "creativecommons":
124 if( !$wgEnableCreativeCommonsRdf ) {
125 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
126 } else {
127 require_once( "includes/Metadata.php" );
128 wfCreativeCommonsRdf( $wgArticle );
129 }
130 break;
131 case "edit":
132 case "submit":
133 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
134 User::SetupSession();
135 }
136 require_once( "includes/EditPage.php" );
137 $editor = new EditPage( $wgArticle );
138 $editor->$action();
139 break;
140 case "history":
141 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
142 $wgOut->setSquidMaxage( $wgSquidMaxage );
143 }
144 require_once( "includes/PageHistory.php" );
145 $history = new PageHistory( $wgArticle );
146 $history->history();
147 break;
148 case "raw":
149 require_once( "includes/RawPage.php" );
150 $raw = new RawPage( $wgArticle );
151 $raw->view();
152 break;
153 case "purge":
154 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
155 $wgOut->setSquidMaxage( $wgSquidMaxage );
156 $wgArticle->view();
157 break;
158 default:
159 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
160 }
161 wfQuery("COMMIT", DB_WRITE);
162 }
163
164 $wgOut->output();
165
166 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }
167 logProfilingData();
168 wfDebug( "Request ended normally\n" );
169 ?>