* (bug 23276) Add hook to Special:NewPages to modify query
[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 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 # Output the REQUEST_URI. This is not supported by IIS in rewrite mode,
186 # so use an alternative
187 $requestUri = isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] :
188 ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ? $_SERVER['HTTP_X_ORIGINAL_URL'] :
189 $_SERVER['PHP_SELF'] );
190 wfDebug( "{$_SERVER['REQUEST_METHOD']} {$requestUri}\n" );
191
192 if ( $wgDebugPrintHttpHeaders ) {
193 $headerOut = "HTTP HEADERS:\n";
194
195 if ( function_exists( 'getallheaders' ) ) {
196 $headers = getallheaders();
197 foreach ( $headers as $name => $value ) {
198 $headerOut .= "$name: $value\n";
199 }
200 } else {
201 $headers = $_SERVER;
202 foreach ( $headers as $name => $value ) {
203 if ( substr( $name, 0, 5 ) !== 'HTTP_' ) continue;
204 $name = substr( $name, 5 );
205 $headerOut .= "$name: $value\n";
206 }
207 }
208 wfDebug( "$headerOut\n" );
209 }
210 }
211
212 if( $wgRCFilterByAge ) {
213 ## Trim down $wgRCLinkDays so that it only lists links which are valid
214 ## as determined by $wgRCMaxAge.
215 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
216 sort($wgRCLinkDays);
217 for( $i = 0; $i < count($wgRCLinkDays); $i++ ) {
218 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
219 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+1, false );
220 break;
221 }
222 }
223 }
224
225 if ( $wgSkipSkin ) {
226 $wgSkipSkins[] = $wgSkipSkin;
227 }
228
229 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
230
231 if($wgMetaNamespace === FALSE) {
232 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
233 }
234
235 # These are now the same, always
236 # To determine the user language, use $wgLang->getCode()
237 $wgContLanguageCode = $wgLanguageCode;
238
239 # Easy to forget to falsify $wgShowIPinHeader for static caches.
240 # If file cache or squid cache is on, just disable this (DWIMD).
241 if( $wgUseFileCache || $wgUseSquid ) $wgShowIPinHeader = false;
242
243 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
244 # in favor of $wgHiddenPrefs, handle b/c here
245 if( !$wgAllowRealName ) {
246 $wgHiddenPrefs[] = 'realname';
247 }
248
249 if( !$wgAllowUserSkin ) {
250 $wgHiddenPrefs[] = 'skin';
251 }
252
253 if ( !$wgHtml5Version && $wgHtml5 && $wgAllowRdfaAttributes ) {
254 # see http://www.w3.org/TR/rdfa-in-html/#document-conformance
255 if ( $wgMimeType == 'application/xhtml+xml' ) $wgHtml5Version = 'XHTML+RDFa 1.0';
256 else $wgHtml5Version = 'HTML+RDFa 1.0';
257 }
258
259
260 wfProfileOut( $fname.'-misc1' );
261 wfProfileIn( $fname.'-memcached' );
262
263 $wgMemc =& wfGetMainCache();
264 $messageMemc =& wfGetMessageCacheStorage();
265 $parserMemc =& wfGetParserCacheStorage();
266
267 wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
268 get_class( $messageMemc ) . '[message] ' .
269 get_class( $parserMemc ) . "[parser]\n" );
270
271 wfProfileOut( $fname.'-memcached' );
272
273 ## Most of the config is out, some might want to run hooks here.
274 wfRunHooks( 'SetupAfterCache' );
275
276 wfProfileIn( $fname.'-SetupSession' );
277
278 # Set default shared prefix
279 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
280
281 if( !$wgCookiePrefix ) {
282 if ( $wgSharedDB && $wgSharedPrefix && in_array('user',$wgSharedTables) ) {
283 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
284 } elseif ( $wgSharedDB && in_array('user',$wgSharedTables) ) {
285 $wgCookiePrefix = $wgSharedDB;
286 } elseif ( $wgDBprefix ) {
287 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
288 } else {
289 $wgCookiePrefix = $wgDBname;
290 }
291 }
292 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
293
294 # If session.auto_start is there, we can't touch session name
295 #
296 if( !wfIniGetBool( 'session.auto_start' ) )
297 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
298
299 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
300 wfIncrStats( 'request_with_session' );
301 wfSetupSession();
302 $wgSessionStarted = true;
303 } else {
304 wfIncrStats( 'request_without_session' );
305 $wgSessionStarted = false;
306 }
307
308 wfProfileOut( $fname.'-SetupSession' );
309 wfProfileIn( $fname.'-globals' );
310
311 $wgContLang = new StubContLang;
312
313 // Now that variant lists may be available...
314 $wgRequest->interpolateTitle();
315
316 $wgUser = new StubUser;
317 $wgLang = new StubUserLang;
318 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
319 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
320
321 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
322 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
323
324 wfProfileOut( $fname.'-globals' );
325 wfProfileIn( $fname.'-User' );
326
327 # Skin setup functions
328 # Entries can be added to this variable during the inclusion
329 # of the extension file. Skins can then perform any necessary initialisation.
330 #
331 foreach ( $wgSkinExtensionFunctions as $func ) {
332 call_user_func( $func );
333 }
334
335 if( !is_object( $wgAuth ) ) {
336 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
337 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
338 }
339
340 wfProfileOut( $fname.'-User' );
341
342 wfProfileIn( $fname.'-misc2' );
343
344 $wgDeferredUpdateList = array();
345 $wgPostCommitUpdateList = array();
346
347 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
348 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
349
350 # Placeholders in case of DB error
351 $wgTitle = null;
352 $wgArticle = null;
353
354 wfProfileOut( $fname.'-misc2' );
355 wfProfileIn( $fname.'-extensions' );
356
357 # Extension setup functions for extensions other than skins
358 # Entries should be added to this variable during the inclusion
359 # of the extension file. This allows the extension to perform
360 # any necessary initialisation in the fully initialised environment
361 foreach ( $wgExtensionFunctions as $func ) {
362 # Allow closures in PHP 5.3+
363 if ( is_object( $func ) && $func instanceof Closure ) {
364 $profName = $fname.'-extensions-closure';
365 } elseif( is_array( $func ) ) {
366 if ( is_object( $func[0] ) )
367 $profName = $fname.'-extensions-'.get_class( $func[0] ).'::'.$func[1];
368 else
369 $profName = $fname.'-extensions-'.implode( '::', $func );
370 } else {
371 $profName = $fname.'-extensions-'.strval( $func );
372 }
373
374 wfProfileIn( $profName );
375 call_user_func( $func );
376 wfProfileOut( $profName );
377 }
378
379 // For compatibility
380 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
381 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
382 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
383 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
384
385 if( !empty($wgNewUserLog) ) {
386 # Add a new log type
387 $wgLogTypes[] = 'newusers';
388 $wgLogNames['newusers'] = 'newuserlogpage';
389 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
390 $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
391 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
392 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
393 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
394 }
395
396 wfDebug( "Fully initialised\n" );
397 $wgFullyInitialised = true;
398 wfProfileOut( $fname.'-extensions' );
399 wfProfileOut( $fname );