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