API: Requesting a token you aren't allowed to request no longer dies with an error...
[lhc/web/wiklou.git] / includes / Setup.php
1 <?php
2 /**
3 * Include most things that's need to customize the site
4 */
5
6 /**
7 * This file is not a valid entry point, perform no further processing unless
8 * MEDIAWIKI is defined
9 */
10 if( !defined( 'MEDIAWIKI' ) ) {
11 echo "This file is part of MediaWiki, it is not a valid entry point.\n";
12 exit( 1 );
13 }
14
15 # The main wiki script and things like database
16 # conversion and maintenance scripts all share a
17 # common setup of including lots of classes and
18 # setting up a few globals.
19 #
20
21 $fname = 'Setup.php';
22 wfProfileIn( $fname );
23
24 // Check to see if we are at the file scope
25 if ( !isset( $wgVersion ) ) {
26 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
27 die( 1 );
28 }
29
30 // Set various default paths sensibly...
31 if( $wgScript === false ) $wgScript = "$wgScriptPath/index$wgScriptExtension";
32 if( $wgRedirectScript === false ) $wgRedirectScript = "$wgScriptPath/redirect$wgScriptExtension";
33
34 if( $wgArticlePath === false ) {
35 if( $wgUsePathInfo ) {
36 $wgArticlePath = "$wgScript/$1";
37 } else {
38 $wgArticlePath = "$wgScript?title=$1";
39 }
40 }
41
42 if( $wgStylePath === false ) $wgStylePath = "$wgScriptPath/skins";
43 if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins";
44
45 if( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png";
46
47 if( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images";
48 if( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images";
49
50 if( $wgMathPath === false ) $wgMathPath = "{$wgUploadPath}/math";
51 if( $wgMathDirectory === false ) $wgMathDirectory = "{$wgUploadDirectory}/math";
52 if( $wgTmpDirectory === false ) $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
53
54 if( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
55 if( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
56
57 if ( empty( $wgFileStore['deleted']['directory'] ) ) {
58 $wgFileStore['deleted']['directory'] = "{$wgUploadDirectory}/deleted";
59 }
60
61
62 /**
63 * Initialise $wgLocalFileRepo from backwards-compatible settings
64 */
65 if ( !$wgLocalFileRepo ) {
66 $wgLocalFileRepo = array(
67 'class' => 'LocalRepo',
68 'name' => 'local',
69 'directory' => $wgUploadDirectory,
70 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
71 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
72 'thumbScriptUrl' => $wgThumbnailScriptPath,
73 'transformVia404' => !$wgGenerateThumbnailOnParse,
74 'initialCapital' => $wgCapitalLinks,
75 'deletedDir' => $wgFileStore['deleted']['directory'],
76 'deletedHashLevels' => $wgFileStore['deleted']['hash']
77 );
78 }
79 /**
80 * Initialise shared repo from backwards-compatible settings
81 */
82 if ( $wgUseSharedUploads ) {
83 if ( $wgSharedUploadDBname ) {
84 $wgForeignFileRepos[] = array(
85 'class' => 'ForeignDBRepo',
86 'name' => 'shared',
87 'directory' => $wgSharedUploadDirectory,
88 'url' => $wgSharedUploadPath,
89 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
90 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
91 'transformVia404' => !$wgGenerateThumbnailOnParse,
92 'dbType' => $wgDBtype,
93 'dbServer' => $wgDBserver,
94 'dbUser' => $wgDBuser,
95 'dbPassword' => $wgDBpassword,
96 'dbName' => $wgSharedUploadDBname,
97 'dbFlags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT,
98 'tablePrefix' => $wgSharedUploadDBprefix,
99 'hasSharedCache' => $wgCacheSharedUploads,
100 'descBaseUrl' => $wgRepositoryBaseUrl,
101 'fetchDescription' => $wgFetchCommonsDescriptions,
102 );
103 } else {
104 $wgForeignFileRepos[] = array(
105 'class' => 'FSRepo',
106 'name' => 'shared',
107 'directory' => $wgSharedUploadDirectory,
108 'url' => $wgSharedUploadPath,
109 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
110 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
111 'transformVia404' => !$wgGenerateThumbnailOnParse,
112 'descBaseUrl' => $wgRepositoryBaseUrl,
113 'fetchDescription' => $wgFetchCommonsDescriptions,
114 );
115 }
116 }
117
118 require_once( "$IP/includes/AutoLoader.php" );
119
120 wfProfileIn( $fname.'-exception' );
121 require_once( "$IP/includes/Exception.php" );
122 wfInstallExceptionHandler();
123 wfProfileOut( $fname.'-exception' );
124
125 wfProfileIn( $fname.'-includes' );
126 require_once( "$IP/includes/GlobalFunctions.php" );
127 require_once( "$IP/includes/Hooks.php" );
128 require_once( "$IP/includes/Namespace.php" );
129 require_once( "$IP/includes/ProxyTools.php" );
130 require_once( "$IP/includes/ObjectCache.php" );
131 require_once( "$IP/includes/ImageFunctions.php" );
132 require_once( "$IP/includes/StubObject.php" );
133 wfProfileOut( $fname.'-includes' );
134 wfProfileIn( $fname.'-misc1' );
135
136
137 $wgIP = false; # Load on demand
138 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
139 $wgRequest = new WebRequest;
140 if ( function_exists( 'posix_uname' ) ) {
141 $wguname = posix_uname();
142 $wgNodeName = $wguname['nodename'];
143 } else {
144 $wgNodeName = '';
145 }
146
147 # Useful debug output
148 if ( $wgCommandLineMode ) {
149 wfDebug( "\n\nStart command line script $self\n" );
150 } elseif ( function_exists( 'getallheaders' ) ) {
151 wfDebug( "\n\nStart request\n" );
152 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
153 $headers = getallheaders();
154 foreach ($headers as $name => $value) {
155 wfDebug( "$name: $value\n" );
156 }
157 wfDebug( "\n" );
158 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
159 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
160 }
161
162 if( $wgRCFilterByAge ) {
163 ## Trim down $wgRCLinkDays so that it only lists links which are valid
164 ## as determined by $wgRCMaxAge.
165 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
166 sort($wgRCLinkDays);
167 for( $i = 0; $i < count($wgRCLinkDays); $i++ ) {
168 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
169 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+1, false );
170 break;
171 }
172 }
173 }
174
175 if ( $wgSkipSkin ) {
176 $wgSkipSkins[] = $wgSkipSkin;
177 }
178
179 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
180
181 if($wgMetaNamespace === FALSE) {
182 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
183 }
184
185 # These are now the same, always
186 # To determine the user language, use $wgLang->getCode()
187 $wgContLanguageCode = $wgLanguageCode;
188
189 wfProfileOut( $fname.'-misc1' );
190 wfProfileIn( $fname.'-memcached' );
191
192 $wgMemc =& wfGetMainCache();
193 $messageMemc =& wfGetMessageCacheStorage();
194 $parserMemc =& wfGetParserCacheStorage();
195
196 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
197 "\nMessage cache: " . get_class( $messageMemc ) .
198 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
199
200 wfProfileOut( $fname.'-memcached' );
201 wfProfileIn( $fname.'-SetupSession' );
202
203 # Set default shared prefix
204 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
205
206 if ( $wgDBprefix ) {
207 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
208 } elseif ( $wgSharedDB ) {
209 $wgCookiePrefix = $wgSharedDB;
210 } else {
211 $wgCookiePrefix = $wgDBname;
212 }
213 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
214
215 # If session.auto_start is there, we can't touch session name
216 #
217 if( !wfIniGetBool( 'session.auto_start' ) )
218 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
219
220 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
221 wfIncrStats( 'request_with_session' );
222 wfSetupSession();
223 $wgSessionStarted = true;
224 } else {
225 wfIncrStats( 'request_without_session' );
226 $wgSessionStarted = false;
227 }
228
229 wfProfileOut( $fname.'-SetupSession' );
230 wfProfileIn( $fname.'-globals' );
231
232 $wgContLang = new StubContLang;
233
234 // Now that variant lists may be available...
235 $wgRequest->interpolateTitle();
236
237 $wgUser = new StubUser;
238 $wgLang = new StubUserLang;
239 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
240 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
241
242 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
243 array( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
244
245 wfProfileOut( $fname.'-globals' );
246 wfProfileIn( $fname.'-User' );
247
248 # Skin setup functions
249 # Entries can be added to this variable during the inclusion
250 # of the extension file. Skins can then perform any necessary initialisation.
251 #
252 foreach ( $wgSkinExtensionFunctions as $func ) {
253 call_user_func( $func );
254 }
255
256 if( !is_object( $wgAuth ) ) {
257 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
258 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
259 }
260
261 wfProfileOut( $fname.'-User' );
262
263 wfProfileIn( $fname.'-misc2' );
264
265 $wgDeferredUpdateList = array();
266 $wgPostCommitUpdateList = array();
267
268 if ( $wgAjaxSearch ) $wgAjaxExportList[] = 'wfSajaxSearch';
269 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
270 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'UploadForm::ajaxGetExistsWarning';
271 if( $wgAjaxLicensePreview )
272 $wgAjaxExportList[] = 'UploadForm::ajaxGetLicensePreview';
273
274 wfSeedRandom();
275
276 # Placeholders in case of DB error
277 $wgTitle = null;
278 $wgArticle = null;
279
280 wfProfileOut( $fname.'-misc2' );
281 wfProfileIn( $fname.'-extensions' );
282
283 # Extension setup functions for extensions other than skins
284 # Entries should be added to this variable during the inclusion
285 # of the extension file. This allows the extension to perform
286 # any necessary initialisation in the fully initialised environment
287 foreach ( $wgExtensionFunctions as $func ) {
288 $profName = $fname.'-extensions-'.strval( $func );
289 wfProfileIn( $profName );
290 call_user_func( $func );
291 wfProfileOut( $profName );
292 }
293
294 // For compatibility
295 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
296 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
297 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
298 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
299
300
301 wfDebug( "Fully initialised\n" );
302 $wgFullyInitialised = true;
303 wfProfileOut( $fname.'-extensions' );
304 wfProfileOut( $fname );