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