* (bug 10387) Detect and handle '.php5' extension environments at install time
[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 /**
58 * Initialise $wgLocalFileRepo from backwards-compatible settings
59 */
60 if ( !$wgLocalFileRepo ) {
61 $wgLocalFileRepo = array(
62 'class' => 'LocalRepo',
63 'name' => 'local',
64 'directory' => $wgUploadDirectory,
65 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
66 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
67 'thumbScriptUrl' => $wgThumbnailScriptPath,
68 'transformVia404' => !$wgGenerateThumbnailOnParse,
69 'initialCapital' => $wgCapitalLinks,
70 );
71 }
72 /**
73 * Initialise shared repo from backwards-compatible settings
74 */
75 if ( $wgUseSharedUploads ) {
76 if ( $wgSharedUploadDBname ) {
77 $wgForeignFileRepos[] = array(
78 'class' => 'ForeignDBRepo',
79 'name' => 'shared',
80 'directory' => $wgSharedUploadDirectory,
81 'url' => $wgSharedUploadPath,
82 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
83 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
84 'transformVia404' => !$wgGenerateThumbnailOnParse,
85 'dbType' => $wgDBtype,
86 'dbServer' => $wgDBserver,
87 'dbUser' => $wgDBuser,
88 'dbPassword' => $wgDBpassword,
89 'dbName' => $wgSharedUploadDBname,
90 'dbFlags' => DBO_DEFAULT,
91 'tablePrefix' => $wgSharedUploadDBprefix,
92 'hasSharedCache' => $wgCacheSharedUploads,
93 'descBaseUrl' => $wgRepositoryBaseUrl,
94 'fetchDescription' => $wgFetchCommonsDescriptions,
95 );
96 } else {
97 $wgForeignFileRepos[] = array(
98 'class' => 'FSRepo',
99 'name' => 'shared',
100 'directory' => $wgSharedUploadDirectory,
101 'url' => $wgSharedUploadPath,
102 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
103 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
104 'transformVia404' => !$wgGenerateThumbnailOnParse,
105 'descBaseUrl' => $wgRepositoryBaseUrl,
106 'fetchDescription' => $wgFetchCommonsDescriptions,
107 );
108 }
109 }
110
111 require_once( "$IP/includes/AutoLoader.php" );
112
113 wfProfileIn( $fname.'-exception' );
114 require_once( "$IP/includes/Exception.php" );
115 wfInstallExceptionHandler();
116 wfProfileOut( $fname.'-exception' );
117
118 wfProfileIn( $fname.'-includes' );
119 require_once( "$IP/includes/GlobalFunctions.php" );
120 require_once( "$IP/includes/Hooks.php" );
121 require_once( "$IP/includes/Namespace.php" );
122 require_once( "$IP/includes/ProxyTools.php" );
123 require_once( "$IP/includes/ObjectCache.php" );
124 require_once( "$IP/includes/ImageFunctions.php" );
125 require_once( "$IP/includes/StubObject.php" );
126 wfProfileOut( $fname.'-includes' );
127 wfProfileIn( $fname.'-misc1' );
128
129
130 $wgIP = false; # Load on demand
131 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
132 $wgRequest = new WebRequest;
133 if ( function_exists( 'posix_uname' ) ) {
134 $wguname = posix_uname();
135 $wgNodeName = $wguname['nodename'];
136 } else {
137 $wgNodeName = '';
138 }
139
140 # Useful debug output
141 if ( $wgCommandLineMode ) {
142 wfDebug( "\n\nStart command line script $self\n" );
143 } elseif ( function_exists( 'getallheaders' ) ) {
144 wfDebug( "\n\nStart request\n" );
145 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
146 $headers = getallheaders();
147 foreach ($headers as $name => $value) {
148 wfDebug( "$name: $value\n" );
149 }
150 wfDebug( "\n" );
151 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
152 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
153 }
154
155 if ( $wgSkipSkin ) {
156 $wgSkipSkins[] = $wgSkipSkin;
157 }
158
159 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
160
161 if($wgMetaNamespace === FALSE) {
162 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
163 }
164
165 # These are now the same, always
166 # To determine the user language, use $wgLang->getCode()
167 $wgContLanguageCode = $wgLanguageCode;
168
169 wfProfileOut( $fname.'-misc1' );
170 wfProfileIn( $fname.'-memcached' );
171
172 $wgMemc =& wfGetMainCache();
173 $messageMemc =& wfGetMessageCacheStorage();
174 $parserMemc =& wfGetParserCacheStorage();
175
176 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
177 "\nMessage cache: " . get_class( $messageMemc ) .
178 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
179
180 wfProfileOut( $fname.'-memcached' );
181 wfProfileIn( $fname.'-SetupSession' );
182
183 if ( $wgDBprefix ) {
184 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
185 } elseif ( $wgSharedDB ) {
186 $wgCookiePrefix = $wgSharedDB;
187 } else {
188 $wgCookiePrefix = $wgDBname;
189 }
190 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
191
192 # If session.auto_start is there, we can't touch session name
193 #
194 if( !ini_get( 'session.auto_start' ) )
195 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
196
197 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
198 wfIncrStats( 'request_with_session' );
199 wfSetupSession();
200 $wgSessionStarted = true;
201 } else {
202 wfIncrStats( 'request_without_session' );
203 $wgSessionStarted = false;
204 }
205
206 wfProfileOut( $fname.'-SetupSession' );
207 wfProfileIn( $fname.'-globals' );
208
209 if ( !$wgDBservers ) {
210 $wgDBservers = array(array(
211 'host' => $wgDBserver,
212 'user' => $wgDBuser,
213 'password' => $wgDBpassword,
214 'dbname' => $wgDBname,
215 'type' => $wgDBtype,
216 'load' => 1,
217 'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT
218 ));
219 }
220
221 $wgLoadBalancer = new StubObject( 'wgLoadBalancer', 'LoadBalancer',
222 array( $wgDBservers, false, $wgMasterWaitTimeout, true ) );
223 $wgContLang = new StubContLang;
224
225 // Now that variant lists may be available...
226 $wgRequest->interpolateTitle();
227
228 $wgUser = new StubUser;
229 $wgLang = new StubUserLang;
230 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
231 $wgParser = new StubObject( 'wgParser', 'Parser' );
232 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
233 array( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
234
235 wfProfileOut( $fname.'-globals' );
236 wfProfileIn( $fname.'-User' );
237
238 # Skin setup functions
239 # Entries can be added to this variable during the inclusion
240 # of the extension file. Skins can then perform any necessary initialisation.
241 #
242 foreach ( $wgSkinExtensionFunctions as $func ) {
243 call_user_func( $func );
244 }
245
246 if( !is_object( $wgAuth ) ) {
247 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
248 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
249 }
250
251 wfProfileOut( $fname.'-User' );
252
253 wfProfileIn( $fname.'-misc2' );
254
255 $wgDeferredUpdateList = array();
256 $wgPostCommitUpdateList = array();
257
258 if ( $wgAjaxSearch ) $wgAjaxExportList[] = 'wfSajaxSearch';
259 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
260
261 wfSeedRandom();
262
263 # Placeholders in case of DB error
264 $wgTitle = null;
265 $wgArticle = null;
266
267 wfProfileOut( $fname.'-misc2' );
268 wfProfileIn( $fname.'-extensions' );
269
270 # Extension setup functions for extensions other than skins
271 # Entries should be added to this variable during the inclusion
272 # of the extension file. This allows the extension to perform
273 # any necessary initialisation in the fully initialised environment
274 foreach ( $wgExtensionFunctions as $func ) {
275 $profName = $fname.'-extensions-'.strval( $func );
276 wfProfileIn( $profName );
277 call_user_func( $func );
278 wfProfileOut( $profName );
279 }
280
281 // For compatibility
282 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
283 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
284 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
285 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
286
287
288 wfDebug( "Fully initialised\n" );
289 $wgFullyInitialised = true;
290 wfProfileOut( $fname.'-extensions' );
291 wfProfileOut( $fname );
292
293 ?>