Fix PHP 5.2 compatibility for r77144
[lhc/web/wiklou.git] / includes / Setup.php
1 <?php
2 /**
3 * Include most things that's need to customize the site
4 *
5 * @file
6 */
7
8 /**
9 * This file is not a valid entry point, perform no further processing unless
10 * MEDIAWIKI is defined
11 */
12 if( !defined( 'MEDIAWIKI' ) ) {
13 exit( 1 );
14 }
15
16 # The main wiki script and things like database
17 # conversion and maintenance scripts all share a
18 # common setup of including lots of classes and
19 # setting up a few globals.
20 #
21
22 $fname = 'Setup.php';
23 wfProfileIn( $fname );
24
25 // Check to see if we are at the file scope
26 if ( !isset( $wgVersion ) ) {
27 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
28 die( 1 );
29 }
30
31 // Set various default paths sensibly...
32 if( $wgScript === false ) $wgScript = "$wgScriptPath/index$wgScriptExtension";
33 if( $wgRedirectScript === false ) $wgRedirectScript = "$wgScriptPath/redirect$wgScriptExtension";
34 if( $wgLoadScript === false ) $wgLoadScript = "$wgScriptPath/load$wgScriptExtension";
35
36 if( $wgArticlePath === false ) {
37 if( $wgUsePathInfo ) {
38 $wgArticlePath = "$wgScript/$1";
39 } else {
40 $wgArticlePath = "$wgScript?title=$1";
41 }
42 }
43
44 if( $wgStylePath === false ) $wgStylePath = "$wgScriptPath/skins";
45 if( $wgLocalStylePath === false ) $wgLocalStylePath = "$wgScriptPath/skins";
46 if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins";
47 if( $wgExtensionAssetsPath === false ) $wgExtensionAssetsPath = "$wgScriptPath/extensions";
48
49 if( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png";
50
51 if( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images";
52 if( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images";
53
54 if( $wgMathPath === false ) $wgMathPath = "{$wgUploadPath}/math";
55 if( $wgMathDirectory === false ) $wgMathDirectory = "{$wgUploadDirectory}/math";
56 if( $wgTmpDirectory === false ) $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
57
58 if( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
59 if( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
60 if( $wgDeletedDirectory === false ) $wgDeletedDirectory = "{$wgUploadDirectory}/deleted";
61
62 if( isset( $wgFileStore['deleted']['directory'] ) ) {
63 $wgDeletedDirectory = $wgFileStore['deleted']['directory'];
64 }
65
66 /**
67 * Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
68 * sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
69 *
70 * Note that this is the definition of editinterface and it can be granted to
71 * all users if desired.
72 */
73 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
74
75 /**
76 * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
77 * and "File_talk". The old names "Image" and "Image_talk" are
78 * retained as aliases for backwards compatibility.
79 */
80 $wgNamespaceAliases['Image'] = NS_FILE;
81 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
82
83 /**
84 * Initialise $wgLocalFileRepo from backwards-compatible settings
85 */
86 if ( !$wgLocalFileRepo ) {
87 if( isset( $wgFileStore['deleted']['hash'] ) ) {
88 $deletedHashLevel = $wgFileStore['deleted']['hash'];
89 } else {
90 $deletedHashLevel = $wgHashedUploadDirectory ? 3 : 0;
91 }
92 $wgLocalFileRepo = array(
93 'class' => 'LocalRepo',
94 'name' => 'local',
95 'directory' => $wgUploadDirectory,
96 'scriptDirUrl' => $wgScriptPath,
97 'scriptExtension' => $wgScriptExtension,
98 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
99 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
100 'thumbScriptUrl' => $wgThumbnailScriptPath,
101 'transformVia404' => !$wgGenerateThumbnailOnParse,
102 'deletedDir' => $wgDeletedDirectory,
103 'deletedHashLevels' => $deletedHashLevel
104 );
105 }
106 /**
107 * Initialise shared repo from backwards-compatible settings
108 */
109 if ( $wgUseSharedUploads ) {
110 if ( $wgSharedUploadDBname ) {
111 $wgForeignFileRepos[] = array(
112 'class' => 'ForeignDBRepo',
113 'name' => 'shared',
114 'directory' => $wgSharedUploadDirectory,
115 'url' => $wgSharedUploadPath,
116 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
117 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
118 'transformVia404' => !$wgGenerateThumbnailOnParse,
119 'dbType' => $wgDBtype,
120 'dbServer' => $wgDBserver,
121 'dbUser' => $wgDBuser,
122 'dbPassword' => $wgDBpassword,
123 'dbName' => $wgSharedUploadDBname,
124 'dbFlags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT,
125 'tablePrefix' => $wgSharedUploadDBprefix,
126 'hasSharedCache' => $wgCacheSharedUploads,
127 'descBaseUrl' => $wgRepositoryBaseUrl,
128 'fetchDescription' => $wgFetchCommonsDescriptions,
129 );
130 } else {
131 $wgForeignFileRepos[] = array(
132 'class' => 'FSRepo',
133 'name' => 'shared',
134 'directory' => $wgSharedUploadDirectory,
135 'url' => $wgSharedUploadPath,
136 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
137 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
138 'transformVia404' => !$wgGenerateThumbnailOnParse,
139 'descBaseUrl' => $wgRepositoryBaseUrl,
140 'fetchDescription' => $wgFetchCommonsDescriptions,
141 );
142 }
143 }
144 if( $wgUseInstantCommons ) {
145 $wgForeignFileRepos[] = array(
146 'class' => 'ForeignAPIRepo',
147 'name' => 'wikimediacommons',
148 'apibase' => 'http://commons.wikimedia.org/w/api.php',
149 'hashLevels' => 2,
150 'fetchDescription' => true,
151 'descriptionCacheExpiry' => 43200,
152 'apiThumbCacheExpiry' => 86400,
153 );
154 }
155
156 if ( !class_exists( 'AutoLoader' ) ) {
157 require_once( "$IP/includes/AutoLoader.php" );
158 }
159
160 wfProfileIn( $fname.'-exception' );
161 require_once( "$IP/includes/Exception.php" );
162 wfInstallExceptionHandler();
163 wfProfileOut( $fname.'-exception' );
164
165 wfProfileIn( $fname.'-includes' );
166 require_once( "$IP/includes/GlobalFunctions.php" );
167 require_once( "$IP/includes/Hooks.php" );
168 require_once( "$IP/includes/Namespace.php" );
169 require_once( "$IP/includes/ProxyTools.php" );
170 require_once( "$IP/includes/ObjectCache.php" );
171 require_once( "$IP/includes/ImageFunctions.php" );
172 wfProfileOut( $fname.'-includes' );
173 wfProfileIn( $fname.'-misc1' );
174
175 # Raise the memory limit if it's too low
176 wfMemoryLimit();
177
178 /**
179 * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
180 * that happens whenever you use a date function without the timezone being
181 * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
182 */
183 wfSuppressWarnings();
184 date_default_timezone_set( date_default_timezone_get() );
185 wfRestoreWarnings();
186
187 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
188 $wgRequest = new WebRequest;
189
190 # Useful debug output
191 global $wgCommandLineMode;
192 if ( $wgCommandLineMode ) {
193 wfDebug( "\n\nStart command line script $self\n" );
194 } else {
195 wfDebug( "Start request\n\n" );
196 # Output the REQUEST_URI. This is not supported by IIS in rewrite mode,
197 # so use an alternative
198 $requestUri = isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] :
199 ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ? $_SERVER['HTTP_X_ORIGINAL_URL'] :
200 $_SERVER['PHP_SELF'] );
201 wfDebug( "{$_SERVER['REQUEST_METHOD']} {$requestUri}\n" );
202
203 if ( $wgDebugPrintHttpHeaders ) {
204 $headerOut = "HTTP HEADERS:\n";
205
206 if ( function_exists( 'getallheaders' ) ) {
207 $headers = getallheaders();
208 foreach ( $headers as $name => $value ) {
209 $headerOut .= "$name: $value\n";
210 }
211 } else {
212 $headers = $_SERVER;
213 foreach ( $headers as $name => $value ) {
214 if ( substr( $name, 0, 5 ) !== 'HTTP_' ) continue;
215 $name = substr( $name, 5 );
216 $headerOut .= "$name: $value\n";
217 }
218 }
219 wfDebug( "$headerOut\n" );
220 }
221 }
222
223 if( $wgRCFilterByAge ) {
224 ## Trim down $wgRCLinkDays so that it only lists links which are valid
225 ## as determined by $wgRCMaxAge.
226 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
227 sort($wgRCLinkDays);
228 for( $i = 0; $i < count($wgRCLinkDays); $i++ ) {
229 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
230 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+1, false );
231 break;
232 }
233 }
234 }
235
236 if ( $wgSkipSkin ) {
237 $wgSkipSkins[] = $wgSkipSkin;
238 }
239
240 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
241
242 if($wgMetaNamespace === FALSE) {
243 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
244 }
245
246 # These are now the same, always
247 # To determine the user language, use $wgLang->getCode()
248 $wgContLanguageCode = $wgLanguageCode;
249
250 # Easy to forget to falsify $wgShowIPinHeader for static caches.
251 # If file cache or squid cache is on, just disable this (DWIMD).
252 if( $wgUseFileCache || $wgUseSquid ) $wgShowIPinHeader = false;
253
254 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
255 # in favor of $wgHiddenPrefs, handle b/c here
256 if( !$wgAllowRealName ) {
257 $wgHiddenPrefs[] = 'realname';
258 }
259
260 if( !$wgAllowUserSkin ) {
261 $wgHiddenPrefs[] = 'skin';
262 }
263
264 if ( !$wgHtml5Version && $wgHtml5 && $wgAllowRdfaAttributes ) {
265 # see http://www.w3.org/TR/rdfa-in-html/#document-conformance
266 if ( $wgMimeType == 'application/xhtml+xml' ) $wgHtml5Version = 'XHTML+RDFa 1.0';
267 else $wgHtml5Version = 'HTML+RDFa 1.0';
268 }
269
270
271 wfProfileOut( $fname.'-misc1' );
272 wfProfileIn( $fname.'-memcached' );
273
274 $wgMemc =& wfGetMainCache();
275 $messageMemc =& wfGetMessageCacheStorage();
276 $parserMemc =& wfGetParserCacheStorage();
277
278 wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
279 get_class( $messageMemc ) . '[message] ' .
280 get_class( $parserMemc ) . "[parser]\n" );
281
282 wfProfileOut( $fname.'-memcached' );
283
284 ## Most of the config is out, some might want to run hooks here.
285 wfRunHooks( 'SetupAfterCache' );
286
287 wfProfileIn( $fname.'-SetupSession' );
288
289 # Set default shared prefix
290 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
291
292 if( !$wgCookiePrefix ) {
293 if ( $wgSharedDB && $wgSharedPrefix && in_array('user',$wgSharedTables) ) {
294 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
295 } elseif ( $wgSharedDB && in_array('user',$wgSharedTables) ) {
296 $wgCookiePrefix = $wgSharedDB;
297 } elseif ( $wgDBprefix ) {
298 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
299 } else {
300 $wgCookiePrefix = $wgDBname;
301 }
302 }
303 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
304
305 # If session.auto_start is there, we can't touch session name
306 #
307 if( !wfIniGetBool( 'session.auto_start' ) )
308 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
309
310 if( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
311 if( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) {
312 wfIncrStats( 'request_with_session' );
313 wfSetupSession();
314 $wgSessionStarted = true;
315 } else {
316 wfIncrStats( 'request_without_session' );
317 $wgSessionStarted = false;
318 }
319 }
320
321 wfProfileOut( $fname.'-SetupSession' );
322 wfProfileIn( $fname.'-globals' );
323
324 $wgContLang = new StubContLang;
325
326 // Now that variant lists may be available...
327 $wgRequest->interpolateTitle();
328 $wgUser = $wgCommandLineMode ? new User : User::newFromSession();
329 $wgLang = new StubUserLang;
330 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
331 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
332
333 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
334 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry ) );
335
336 wfProfileOut( $fname.'-globals' );
337 wfProfileIn( $fname.'-User' );
338
339 # Skin setup functions
340 # Entries can be added to this variable during the inclusion
341 # of the extension file. Skins can then perform any necessary initialisation.
342 #
343 foreach ( $wgSkinExtensionFunctions as $func ) {
344 call_user_func( $func );
345 }
346
347 if( !is_object( $wgAuth ) ) {
348 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
349 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
350 }
351
352 wfProfileOut( $fname.'-User' );
353
354 wfProfileIn( $fname.'-misc2' );
355
356 $wgDeferredUpdateList = array();
357 $wgPostCommitUpdateList = array();
358
359 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
360
361 # Placeholders in case of DB error
362 $wgTitle = null;
363 $wgArticle = null;
364
365 wfProfileOut( $fname.'-misc2' );
366 wfProfileIn( $fname.'-extensions' );
367
368 # Extension setup functions for extensions other than skins
369 # Entries should be added to this variable during the inclusion
370 # of the extension file. This allows the extension to perform
371 # any necessary initialisation in the fully initialised environment
372 foreach ( $wgExtensionFunctions as $func ) {
373 # Allow closures in PHP 5.3+
374 if ( is_object( $func ) && $func instanceof Closure ) {
375 $profName = $fname.'-extensions-closure';
376 } elseif( is_array( $func ) ) {
377 if ( is_object( $func[0] ) )
378 $profName = $fname.'-extensions-'.get_class( $func[0] ).'::'.$func[1];
379 else
380 $profName = $fname.'-extensions-'.implode( '::', $func );
381 } else {
382 $profName = $fname.'-extensions-'.strval( $func );
383 }
384
385 wfProfileIn( $profName );
386 call_user_func( $func );
387 wfProfileOut( $profName );
388 }
389
390 // For compatibility
391 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
392 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
393 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
394 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
395
396 if( !empty($wgNewUserLog) ) {
397 # Add a new log type
398 $wgLogTypes[] = 'newusers';
399 $wgLogNames['newusers'] = 'newuserlogpage';
400 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
401 $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
402 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
403 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
404 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
405 }
406
407 wfDebug( "Fully initialised\n" );
408 $wgFullyInitialised = true;
409 wfProfileOut( $fname.'-extensions' );
410 wfProfileOut( $fname );