include_once -> require_once
[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 require_once( "./LocalSettings.php" );
13
14 if( $wgSitename == "MediaWiki" ) {
15 die( "You must set the site name in \$wgSitename before installation.\n\n" );
16 }
17
18 # PATH_SEPARATOR avaialble only from 4.3.0
19 $sep = (DIRECTORY_SEPARATOR == "\\") ? ";" : ":";
20 ini_set( "include_path", $IP . $sep . ini_get( "include_path" ) );
21
22 require_once( "Setup.php" );
23
24 wfProfileIn( "main-misc-setup" );
25 OutputPage::setEncodings(); # Not really used yet
26
27 # Query string fields
28 $action = $wgRequest->getVal( "action", "view" );
29
30 if( isset( $_SERVER['PATH_INFO'] ) && $wgUsePathInfo ) {
31 $title = substr( $_SERVER['PATH_INFO'], 1 );
32 } else {
33 $title = $wgRequest->getVal( "title" );
34 }
35
36 # Placeholders in case of DB error
37 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
38 $wgArticle = new Article($wgTitle);
39
40 $action = strtolower( trim( $action ) );
41 if ( "" == $action ) { $action = "view"; }
42 if ($wgRequest->getVal( "printable" ) == "yes") {
43 $wgOut->setPrintable();
44 }
45
46 if ( "" == $title && "delete" != $action ) {
47 $wgTitle = Title::newFromText( wfMsg( "mainpage" ) );
48 } elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
49 # URLs like this are generated by RC, because rc_title isn't always accurate
50 $wgTitle = Title::newFromID( $curid );
51 } else {
52 $wgTitle = Title::newFromURL( $title );
53 }
54 wfProfileOut( "main-misc-setup" );
55
56 # If the user is not logged in, the Namespace:title of the article must be in the Read array in
57 # order for the user to see it.
58 if ( !$wgUser->getID() && is_array( $wgWhitelistRead ) && $wgTitle) {
59 if ( !in_array( $wgLang->getNsText( $wgTitle->getNamespace() ) . ":" . $wgTitle->getDBkey(), $wgWhitelistRead ) ) {
60 $wgOut->loginToUse();
61 $wgOut->output();
62 exit;
63 }
64 }
65
66 if ( $search = $wgRequest->getText( 'search' ) ) {
67 $wgTitle = Title::makeTitle( NS_SPECIAL, "Search" );
68 if( $wgRequest->getVal( 'fulltext' ) ) {
69 wfSearch( $search );
70 } else {
71 wfGo( $search );
72 }
73 } else if( !$wgTitle or $wgTitle->getDBkey() == "" ) {
74 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
75 $wgOut->errorpage( "badtitle", "badtitletext" );
76 } else if ( $wgTitle->getInterwiki() != "" ) {
77 $url = $wgTitle->getFullURL();
78 # Check for a redirect loop
79 if ( !preg_match( "/^" . preg_quote( $wgServer ) . "/", $url ) && $wgTitle->isLocal() ) {
80 $wgOut->redirect( $url );
81 } else {
82 $wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
83 $wgOut->errorpage( "badtitle", "badtitletext" );
84 }
85 } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title ) {
86 /* redirect to canonical url, make it a 301 to allow caching */
87 $wgOut->redirect( $wgTitle->getFullURL(), '301');
88 } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
89 wfSpecialPage();
90 } else {
91 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
92 $wgTitle = Title::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
93 }
94
95 switch( $wgTitle->getNamespace() ) {
96 case NS_IMAGE:
97 require_once( "ImagePage.php" );
98 $wgArticle = new ImagePage( $wgTitle );
99 break;
100 default:
101 $wgArticle = new Article( $wgTitle );
102 }
103
104 wfQuery("BEGIN", DB_WRITE);
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 $wgArticle->$action();
118 break;
119 case "print":
120 $wgArticle->view();
121 break;
122 case "dublincore":
123 if( !$wgEnableDublinCoreRdf ) {
124 wfHttpError( 403, "Forbidden", wfMsg( "nodublincore" ) );
125 } else {
126 require_once( "Metadata.php" );
127 wfDublinCoreRdf( $wgArticle );
128 }
129 break;
130 case "creativecommons":
131 if( !$wgEnableCreativeCommonsRdf ) {
132 wfHttpError( 403, "Forbidden", wfMsg("nocreativecommons") );
133 } else {
134 require_once( "Metadata.php" );
135 wfCreativeCommonsRdf( $wgArticle );
136 }
137 break;
138 case "edit":
139 case "submit":
140 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
141 User::SetupSession();
142 }
143 require_once( "EditPage.php" );
144 $editor = new EditPage( $wgArticle );
145 $editor->$action();
146 break;
147 case "history":
148 if ($_SERVER["REQUEST_URI"] == $wgTitle->getInternalURL('action=history')) {
149 $wgOut->setSquidMaxage( $wgSquidMaxage );
150 }
151 require_once( "PageHistory.php" );
152 $history = new PageHistory( $wgArticle );
153 $history->history();
154 break;
155 case "raw":
156 require_once( "RawPage.php" );
157 $raw = new RawPage( $wgArticle );
158 $raw->view();
159 break;
160 case "purge":
161 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
162 $wgOut->setSquidMaxage( $wgSquidMaxage );
163 $wgArticle->view();
164 break;
165 default:
166 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
167 }
168 wfQuery("COMMIT", DB_WRITE);
169 }
170
171 $wgOut->output();
172
173 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }
174 logProfilingData();
175 wfDebug( "Request ended normally\n" );
176 ?>