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