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