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