Refactor contribs to use the newer class extension method (about to do bug 6955)
[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 * 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 * Initialise $wgLocalFileRepo from backwards-compatible settings
72 */
73 if ( !$wgLocalFileRepo ) {
74 $wgLocalFileRepo = array(
75 'class' => 'LocalRepo',
76 'name' => 'local',
77 'directory' => $wgUploadDirectory,
78 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
79 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
80 'thumbScriptUrl' => $wgThumbnailScriptPath,
81 'transformVia404' => !$wgGenerateThumbnailOnParse,
82 'initialCapital' => $wgCapitalLinks,
83 'deletedDir' => $wgFileStore['deleted']['directory'],
84 'deletedHashLevels' => $wgFileStore['deleted']['hash']
85 );
86 }
87 /**
88 * Initialise shared repo from backwards-compatible settings
89 */
90 if ( $wgUseSharedUploads ) {
91 if ( $wgSharedUploadDBname ) {
92 $wgForeignFileRepos[] = array(
93 'class' => 'ForeignDBRepo',
94 'name' => 'shared',
95 'directory' => $wgSharedUploadDirectory,
96 'url' => $wgSharedUploadPath,
97 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
98 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
99 'transformVia404' => !$wgGenerateThumbnailOnParse,
100 'dbType' => $wgDBtype,
101 'dbServer' => $wgDBserver,
102 'dbUser' => $wgDBuser,
103 'dbPassword' => $wgDBpassword,
104 'dbName' => $wgSharedUploadDBname,
105 'dbFlags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT,
106 'tablePrefix' => $wgSharedUploadDBprefix,
107 'hasSharedCache' => $wgCacheSharedUploads,
108 'descBaseUrl' => $wgRepositoryBaseUrl,
109 'fetchDescription' => $wgFetchCommonsDescriptions,
110 );
111 } else {
112 $wgForeignFileRepos[] = array(
113 'class' => 'FSRepo',
114 'name' => 'shared',
115 'directory' => $wgSharedUploadDirectory,
116 'url' => $wgSharedUploadPath,
117 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
118 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
119 'transformVia404' => !$wgGenerateThumbnailOnParse,
120 'descBaseUrl' => $wgRepositoryBaseUrl,
121 'fetchDescription' => $wgFetchCommonsDescriptions,
122 );
123 }
124 }
125 if ( !class_exists( 'AutoLoader' ) ) {
126 require_once( "$IP/includes/AutoLoader.php" );
127 }
128
129 wfProfileIn( $fname.'-exception' );
130 require_once( "$IP/includes/Exception.php" );
131 wfInstallExceptionHandler();
132 wfProfileOut( $fname.'-exception' );
133
134 wfProfileIn( $fname.'-includes' );
135 require_once( "$IP/includes/GlobalFunctions.php" );
136 require_once( "$IP/includes/Hooks.php" );
137 require_once( "$IP/includes/Namespace.php" );
138 require_once( "$IP/includes/ProxyTools.php" );
139 require_once( "$IP/includes/ObjectCache.php" );
140 require_once( "$IP/includes/ImageFunctions.php" );
141 require_once( "$IP/includes/StubObject.php" );
142 wfProfileOut( $fname.'-includes' );
143 wfProfileIn( $fname.'-misc1' );
144
145
146 $wgIP = false; # Load on demand
147 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
148 $wgRequest = new WebRequest;
149
150 # Useful debug output
151 if ( $wgCommandLineMode ) {
152 wfDebug( "\n\nStart command line script $self\n" );
153 } elseif ( function_exists( 'getallheaders' ) ) {
154 wfDebug( "\n\nStart request\n" );
155 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
156 $headers = getallheaders();
157 foreach ($headers as $name => $value) {
158 wfDebug( "$name: $value\n" );
159 }
160 wfDebug( "\n" );
161 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
162 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
163 }
164
165 if( $wgRCFilterByAge ) {
166 ## Trim down $wgRCLinkDays so that it only lists links which are valid
167 ## as determined by $wgRCMaxAge.
168 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
169 sort($wgRCLinkDays);
170 for( $i = 0; $i < count($wgRCLinkDays); $i++ ) {
171 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
172 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+1, false );
173 break;
174 }
175 }
176 }
177
178 if ( $wgSkipSkin ) {
179 $wgSkipSkins[] = $wgSkipSkin;
180 }
181
182 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
183
184 if($wgMetaNamespace === FALSE) {
185 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
186 }
187
188 # These are now the same, always
189 # To determine the user language, use $wgLang->getCode()
190 $wgContLanguageCode = $wgLanguageCode;
191
192 wfProfileOut( $fname.'-misc1' );
193 wfProfileIn( $fname.'-memcached' );
194
195 $wgMemc =& wfGetMainCache();
196 $messageMemc =& wfGetMessageCacheStorage();
197 $parserMemc =& wfGetParserCacheStorage();
198
199 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
200 "\nMessage cache: " . get_class( $messageMemc ) .
201 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
202
203 wfProfileOut( $fname.'-memcached' );
204 wfProfileIn( $fname.'-SetupSession' );
205
206 # Set default shared prefix
207 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
208
209 if( !$wgCookiePrefix ) {
210 if ( in_array('user', $wgSharedTables) && $wgSharedDB && $wgSharedPrefix ) {
211 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
212 } elseif ( in_array('user', $wgSharedTables) && $wgSharedDB ) {
213 $wgCookiePrefix = $wgSharedDB;
214 } elseif ( $wgDBprefix ) {
215 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
216 } else {
217 $wgCookiePrefix = $wgDBname;
218 }
219 }
220 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
221
222 # If session.auto_start is there, we can't touch session name
223 #
224 if( !wfIniGetBool( 'session.auto_start' ) )
225 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
226
227 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
228 wfIncrStats( 'request_with_session' );
229 wfSetupSession();
230 $wgSessionStarted = true;
231 } else {
232 wfIncrStats( 'request_without_session' );
233 $wgSessionStarted = false;
234 }
235
236 wfProfileOut( $fname.'-SetupSession' );
237 wfProfileIn( $fname.'-globals' );
238
239 $wgContLang = new StubContLang;
240
241 // Now that variant lists may be available...
242 $wgRequest->interpolateTitle();
243
244 $wgUser = new StubUser;
245 $wgLang = new StubUserLang;
246 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
247 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
248
249 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
250 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
251
252 wfProfileOut( $fname.'-globals' );
253 wfProfileIn( $fname.'-User' );
254
255 # Skin setup functions
256 # Entries can be added to this variable during the inclusion
257 # of the extension file. Skins can then perform any necessary initialisation.
258 #
259 foreach ( $wgSkinExtensionFunctions as $func ) {
260 call_user_func( $func );
261 }
262
263 if( !is_object( $wgAuth ) ) {
264 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
265 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
266 }
267
268 wfProfileOut( $fname.'-User' );
269
270 wfProfileIn( $fname.'-misc2' );
271
272 $wgDeferredUpdateList = array();
273 $wgPostCommitUpdateList = array();
274
275 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
276 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'UploadForm::ajaxGetExistsWarning';
277 if( $wgAjaxLicensePreview )
278 $wgAjaxExportList[] = 'UploadForm::ajaxGetLicensePreview';
279
280 # Placeholders in case of DB error
281 $wgTitle = null;
282 $wgArticle = null;
283
284 wfProfileOut( $fname.'-misc2' );
285 wfProfileIn( $fname.'-extensions' );
286
287 # Extension setup functions for extensions other than skins
288 # Entries should be added to this variable during the inclusion
289 # of the extension file. This allows the extension to perform
290 # any necessary initialisation in the fully initialised environment
291 foreach ( $wgExtensionFunctions as $func ) {
292 $profName = $fname.'-extensions-'.strval( $func );
293 wfProfileIn( $profName );
294 call_user_func( $func );
295 wfProfileOut( $profName );
296 }
297
298 // For compatibility
299 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
300 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
301 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
302 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
303
304 if( !empty($wgNewUserLog) ) {
305 # Add a new log type
306 $wgLogTypes[] = 'newusers';
307 $wgLogNames['newusers'] = 'newuserlogpage';
308 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
309 $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
310 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
311 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
312 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
313 }
314
315 wfDebug( "Fully initialised\n" );
316 $wgFullyInitialised = true;
317 wfProfileOut( $fname.'-extensions' );
318 wfProfileOut( $fname );