(bug 18424) Clean up paging links on Special:allpages and special:prefixindex.
[lhc/web/wiklou.git] / includes / Setup.php
1 <?php
2 /**
3 * Include most things that's need to customize the site
4 *
5 * @file
6 */
7
8 /**
9 * This file is not a valid entry point, perform no further processing unless
10 * MEDIAWIKI is defined
11 */
12 if ( !defined( 'MEDIAWIKI' ) ) {
13 exit( 1 );
14 }
15
16 # The main wiki script and things like database
17 # conversion and maintenance scripts all share a
18 # common setup of including lots of classes and
19 # setting up a few globals.
20 #
21
22 $fname = 'Setup.php';
23 wfProfileIn( $fname );
24
25 // Check to see if we are at the file scope
26 if ( !isset( $wgVersion ) ) {
27 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
28 die( 1 );
29 }
30
31 // Set various default paths sensibly...
32 if ( $wgScript === false ) $wgScript = "$wgScriptPath/index$wgScriptExtension";
33 if ( $wgRedirectScript === false ) $wgRedirectScript = "$wgScriptPath/redirect$wgScriptExtension";
34 if ( $wgLoadScript === false ) $wgLoadScript = "$wgScriptPath/load$wgScriptExtension";
35
36 if ( $wgArticlePath === false ) {
37 if ( $wgUsePathInfo ) {
38 $wgArticlePath = "$wgScript/$1";
39 } else {
40 $wgArticlePath = "$wgScript?title=$1";
41 }
42 }
43
44 if ( !empty($wgActionPaths) && !isset($wgActionPaths['view']) ) {
45 # 'view' is assumed the default action path everywhere in the code
46 # but is rarely filled in $wgActionPaths
47 $wgActionPaths['view'] = $wgArticlePath;
48 }
49
50 if ( !empty($wgActionPaths) && !isset($wgActionPaths['view']) ) {
51 # 'view' is assumed the default action path everywhere in the code
52 # but is rarely filled in $wgActionPaths
53 $wgActionPaths['view'] = $wgArticlePath ;
54 }
55
56 if ( $wgStylePath === false ) $wgStylePath = "$wgScriptPath/skins";
57 if ( $wgLocalStylePath === false ) $wgLocalStylePath = "$wgScriptPath/skins";
58 if ( $wgStyleDirectory === false ) $wgStyleDirectory = "$IP/skins";
59 if ( $wgExtensionAssetsPath === false ) $wgExtensionAssetsPath = "$wgScriptPath/extensions";
60
61 if ( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png";
62
63 if ( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images";
64 if ( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images";
65
66 if ( $wgTmpDirectory === false ) $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
67
68 if ( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
69 if ( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
70 if ( $wgDeletedDirectory === false ) $wgDeletedDirectory = "{$wgUploadDirectory}/deleted";
71
72 if ( isset( $wgFileStore['deleted']['directory'] ) ) {
73 $wgDeletedDirectory = $wgFileStore['deleted']['directory'];
74 }
75
76 if ( isset( $wgFooterIcons['copyright'] ) &&
77 isset( $wgFooterIcons['copyright']['copyright'] ) &&
78 $wgFooterIcons['copyright']['copyright'] === array() )
79 {
80 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
81 $wgFooterIcons['copyright']['copyright'] = $wgCopyrightIcon;
82 } elseif ( $wgRightsIcon || $wgRightsText ) {
83 $wgFooterIcons['copyright']['copyright'] = array(
84 'url' => $wgRightsUrl,
85 'src' => $wgRightsIcon,
86 'alt' => $wgRightsText,
87 );
88 } else {
89 unset( $wgFooterIcons['copyright']['copyright'] );
90 }
91 }
92
93 if ( isset( $wgFooterIcons['poweredby'] ) &&
94 isset( $wgFooterIcons['poweredby']['mediawiki'] ) &&
95 $wgFooterIcons['poweredby']['mediawiki']['src'] === null )
96 {
97 $wgFooterIcons['poweredby']['mediawiki']['src'] = "$wgStylePath/common/images/poweredby_mediawiki_88x31.png";
98 }
99
100 /**
101 * Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
102 * sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
103 *
104 * Note that this is the definition of editinterface and it can be granted to
105 * all users if desired.
106 */
107 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
108
109 /**
110 * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
111 * and "File_talk". The old names "Image" and "Image_talk" are
112 * retained as aliases for backwards compatibility.
113 */
114 $wgNamespaceAliases['Image'] = NS_FILE;
115 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
116
117 /**
118 * Initialise $wgLocalFileRepo from backwards-compatible settings
119 */
120 if ( !$wgLocalFileRepo ) {
121 if ( isset( $wgFileStore['deleted']['hash'] ) ) {
122 $deletedHashLevel = $wgFileStore['deleted']['hash'];
123 } else {
124 $deletedHashLevel = $wgHashedUploadDirectory ? 3 : 0;
125 }
126 $wgLocalFileRepo = array(
127 'class' => 'LocalRepo',
128 'name' => 'local',
129 'directory' => $wgUploadDirectory,
130 'scriptDirUrl' => $wgScriptPath,
131 'scriptExtension' => $wgScriptExtension,
132 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
133 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
134 'thumbScriptUrl' => $wgThumbnailScriptPath,
135 'transformVia404' => !$wgGenerateThumbnailOnParse,
136 'deletedDir' => $wgDeletedDirectory,
137 'deletedHashLevels' => $deletedHashLevel
138 );
139 }
140 /**
141 * Initialise shared repo from backwards-compatible settings
142 */
143 if ( $wgUseSharedUploads ) {
144 if ( $wgSharedUploadDBname ) {
145 $wgForeignFileRepos[] = array(
146 'class' => 'ForeignDBRepo',
147 'name' => 'shared',
148 'directory' => $wgSharedUploadDirectory,
149 'url' => $wgSharedUploadPath,
150 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
151 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
152 'transformVia404' => !$wgGenerateThumbnailOnParse,
153 'dbType' => $wgDBtype,
154 'dbServer' => $wgDBserver,
155 'dbUser' => $wgDBuser,
156 'dbPassword' => $wgDBpassword,
157 'dbName' => $wgSharedUploadDBname,
158 'dbFlags' => ( $wgDebugDumpSql ? DBO_DEBUG : 0 ) | DBO_DEFAULT,
159 'tablePrefix' => $wgSharedUploadDBprefix,
160 'hasSharedCache' => $wgCacheSharedUploads,
161 'descBaseUrl' => $wgRepositoryBaseUrl,
162 'fetchDescription' => $wgFetchCommonsDescriptions,
163 );
164 } else {
165 $wgForeignFileRepos[] = array(
166 'class' => 'FSRepo',
167 'name' => 'shared',
168 'directory' => $wgSharedUploadDirectory,
169 'url' => $wgSharedUploadPath,
170 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
171 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
172 'transformVia404' => !$wgGenerateThumbnailOnParse,
173 'descBaseUrl' => $wgRepositoryBaseUrl,
174 'fetchDescription' => $wgFetchCommonsDescriptions,
175 );
176 }
177 }
178 if ( $wgUseInstantCommons ) {
179 $wgForeignFileRepos[] = array(
180 'class' => 'ForeignAPIRepo',
181 'name' => 'wikimediacommons',
182 'apibase' => 'http://commons.wikimedia.org/w/api.php',
183 'hashLevels' => 2,
184 'fetchDescription' => true,
185 'descriptionCacheExpiry' => 43200,
186 'apiThumbCacheExpiry' => 86400,
187 );
188 }
189
190 if ( $wgRCFilterByAge ) {
191 # # Trim down $wgRCLinkDays so that it only lists links which are valid
192 # # as determined by $wgRCMaxAge.
193 # # Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
194 sort( $wgRCLinkDays );
195 for ( $i = 0; $i < count( $wgRCLinkDays ); $i++ ) {
196 if ( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
197 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i + 1, false );
198 break;
199 }
200 }
201 }
202
203 if ( $wgSkipSkin ) {
204 $wgSkipSkins[] = $wgSkipSkin;
205 }
206
207 # Set default shared prefix
208 if ( $wgSharedPrefix === false ) {
209 $wgSharedPrefix = $wgDBprefix;
210 }
211
212 if ( !$wgCookiePrefix ) {
213 if ( $wgSharedDB && $wgSharedPrefix && in_array( 'user', $wgSharedTables ) ) {
214 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
215 } elseif ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
216 $wgCookiePrefix = $wgSharedDB;
217 } elseif ( $wgDBprefix ) {
218 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
219 } else {
220 $wgCookiePrefix = $wgDBname;
221 }
222 }
223 $wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' );
224
225 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
226
227 if ( $wgMetaNamespace === false ) {
228 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
229 }
230
231 /**
232 * Definitions of the NS_ constants are in Defines.php
233 * @private
234 */
235 $wgCanonicalNamespaceNames = array(
236 NS_MEDIA => 'Media',
237 NS_SPECIAL => 'Special',
238 NS_TALK => 'Talk',
239 NS_USER => 'User',
240 NS_USER_TALK => 'User_talk',
241 NS_PROJECT => 'Project',
242 NS_PROJECT_TALK => 'Project_talk',
243 NS_FILE => 'File',
244 NS_FILE_TALK => 'File_talk',
245 NS_MEDIAWIKI => 'MediaWiki',
246 NS_MEDIAWIKI_TALK => 'MediaWiki_talk',
247 NS_TEMPLATE => 'Template',
248 NS_TEMPLATE_TALK => 'Template_talk',
249 NS_HELP => 'Help',
250 NS_HELP_TALK => 'Help_talk',
251 NS_CATEGORY => 'Category',
252 NS_CATEGORY_TALK => 'Category_talk',
253 );
254
255 /// @todo UGLY UGLY
256 if( is_array( $wgExtraNamespaces ) ) {
257 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames + $wgExtraNamespaces;
258 }
259
260 # These are now the same, always
261 # To determine the user language, use $wgLang->getCode()
262 $wgContLanguageCode = $wgLanguageCode;
263
264 # Easy to forget to falsify $wgShowIPinHeader for static caches.
265 # If file cache or squid cache is on, just disable this (DWIMD).
266 if ( $wgUseFileCache || $wgUseSquid ) {
267 $wgShowIPinHeader = false;
268 }
269
270 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
271 # in favor of $wgHiddenPrefs, handle b/c here
272 if ( !$wgAllowRealName ) {
273 $wgHiddenPrefs[] = 'realname';
274 }
275
276 # Doesn't make sense to have if disabled.
277 if ( !$wgEnotifMinorEdits ) {
278 $wgHiddenPrefs[] = 'enotifminoredits';
279 }
280
281 # $wgDisabledActions is deprecated as of 1.18
282 foreach( $wgDisabledActions as $action ){
283 $wgActions[$action] = false;
284 }
285 if( !$wgAllowPageInfo ){
286 $wgActions['info'] = false;
287 }
288
289 if ( !$wgHtml5Version && $wgHtml5 && $wgAllowRdfaAttributes ) {
290 # see http://www.w3.org/TR/rdfa-in-html/#document-conformance
291 if ( $wgMimeType == 'application/xhtml+xml' ) {
292 $wgHtml5Version = 'XHTML+RDFa 1.0';
293 } else {
294 $wgHtml5Version = 'HTML+RDFa 1.0';
295 }
296 }
297
298 # Blacklisted file extensions shouldn't appear on the "allowed" list
299 $wgFileExtensions = array_diff ( $wgFileExtensions, $wgFileBlacklist );
300
301 if ( $wgArticleCountMethod === null ) {
302 $wgArticleCountMethod = $wgUseCommaCount ? 'comma' : 'link';
303 }
304
305 if ( $wgInvalidateCacheOnLocalSettingsChange ) {
306 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( "$IP/LocalSettings.php" ) ) );
307 }
308
309 if ( $wgAjaxUploadDestCheck ) {
310 $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
311 }
312
313 if ( $wgNewUserLog ) {
314 # Add a new log type
315 $wgLogTypes[] = 'newusers';
316 $wgLogNames['newusers'] = 'newuserlogpage';
317 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
318 $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
319 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
320 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
321 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
322 }
323
324 if ( $wgCookieSecure === 'detect' ) {
325 $wgCookieSecure = ( substr( $wgServer, 0, 6 ) === 'https:' );
326 }
327
328 if ( !defined( 'MW_COMPILED' ) ) {
329 if ( !MWInit::classExists( 'AutoLoader' ) ) {
330 require_once( "$IP/includes/AutoLoader.php" );
331 }
332
333 wfProfileIn( $fname . '-exception' );
334 MWExceptionHandler::installHandler();
335 wfProfileOut( $fname . '-exception' );
336
337 wfProfileIn( $fname . '-includes' );
338 require_once( "$IP/includes/normal/UtfNormalUtil.php" );
339 require_once( "$IP/includes/GlobalFunctions.php" );
340 require_once( "$IP/includes/ProxyTools.php" );
341 require_once( "$IP/includes/ImageFunctions.php" );
342 require_once( "$IP/includes/normal/UtfNormalDefines.php" );
343 wfProfileOut( $fname . '-includes' );
344 }
345
346 # Now that GlobalFunctions is loaded, set the default for $wgCanonicalServer
347 if ( $wgCanonicalServer === false ) {
348 $wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP );
349 }
350
351 wfProfileIn( $fname . '-misc1' );
352
353 # Raise the memory limit if it's too low
354 wfMemoryLimit();
355
356 /**
357 * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
358 * that happens whenever you use a date function without the timezone being
359 * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
360 */
361 if ( is_null( $wgLocaltimezone) ) {
362 wfSuppressWarnings();
363 $wgLocaltimezone = date_default_timezone_get();
364 wfRestoreWarnings();
365 }
366
367 date_default_timezone_set( $wgLocaltimezone );
368 if( is_null( $wgLocalTZoffset ) ) {
369 $wgLocalTZoffset = date( 'Z' ) / 60;
370 }
371
372 # Useful debug output
373 global $wgCommandLineMode;
374 if ( $wgCommandLineMode ) {
375 $wgRequest = new FauxRequest( array() );
376
377 wfDebug( "\n\nStart command line script $self\n" );
378 } else {
379 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
380 $wgRequest = new WebRequest;
381
382 $debug = "Start request\n\n{$_SERVER['REQUEST_METHOD']} {$wgRequest->getRequestURL()}";
383
384 if ( $wgDebugPrintHttpHeaders ) {
385 $debug .= "\nHTTP HEADERS:\n";
386
387 foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
388 $debug .= "$name: $value\n";
389 }
390 }
391 wfDebug( "$debug\n" );
392 }
393
394 wfProfileOut( $fname . '-misc1' );
395 wfProfileIn( $fname . '-memcached' );
396
397 $wgMemc = wfGetMainCache();
398 $messageMemc = wfGetMessageCacheStorage();
399 $parserMemc = wfGetParserCacheStorage();
400
401 wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
402 get_class( $messageMemc ) . '[message] ' .
403 get_class( $parserMemc ) . "[parser]\n" );
404
405 wfProfileOut( $fname . '-memcached' );
406
407 # # Most of the config is out, some might want to run hooks here.
408 wfRunHooks( 'SetupAfterCache' );
409
410 wfProfileIn( $fname . '-session' );
411
412 # If session.auto_start is there, we can't touch session name
413 if ( !wfIniGetBool( 'session.auto_start' ) ) {
414 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
415 }
416
417 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
418 if ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix . 'Token'] ) ) {
419 wfIncrStats( 'request_with_session' );
420 wfSetupSession();
421 $wgSessionStarted = true;
422 } else {
423 wfIncrStats( 'request_without_session' );
424 $wgSessionStarted = false;
425 }
426 }
427
428 wfProfileOut( $fname . '-session' );
429 wfProfileIn( $fname . '-globals' );
430
431 $wgContLang = Language::factory( $wgLanguageCode );
432 $wgContLang->initEncoding();
433 $wgContLang->initContLang();
434
435 // Now that variant lists may be available...
436 $wgRequest->interpolateTitle();
437 $wgUser = RequestContext::getMain()->getUser(); # BackCompat
438
439 /**
440 * @var Language
441 */
442 $wgLang = new StubUserLang;
443
444 /**
445 * @var OutputPage
446 */
447 $wgOut = RequestContext::getMain()->getOutput(); # BackCompat
448
449 /**
450 * @var Parser
451 */
452 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
453
454 if ( !is_object( $wgAuth ) ) {
455 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
456 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
457 }
458
459 # Placeholders in case of DB error
460 $wgTitle = null;
461
462 $wgDeferredUpdateList = array();
463
464 // We need to check for safe_mode, because mail() will throw an E_NOTICE
465 // on additional parameters
466 if( !is_null($wgAdditionalMailParams) && wfIniGetBool('safe_mode') ) {
467 $wgAdditionalMailParams = null;
468 }
469
470 wfProfileOut( $fname . '-globals' );
471 wfProfileIn( $fname . '-extensions' );
472
473 # Extension setup functions for extensions other than skins
474 # Entries should be added to this variable during the inclusion
475 # of the extension file. This allows the extension to perform
476 # any necessary initialisation in the fully initialised environment
477 foreach ( $wgExtensionFunctions as $func ) {
478 # Allow closures in PHP 5.3+
479 if ( is_object( $func ) && $func instanceof Closure ) {
480 $profName = $fname . '-extensions-closure';
481 } elseif ( is_array( $func ) ) {
482 if ( is_object( $func[0] ) )
483 $profName = $fname . '-extensions-' . get_class( $func[0] ) . '::' . $func[1];
484 else
485 $profName = $fname . '-extensions-' . implode( '::', $func );
486 } else {
487 $profName = $fname . '-extensions-' . strval( $func );
488 }
489
490 wfProfileIn( $profName );
491 call_user_func( $func );
492 wfProfileOut( $profName );
493 }
494
495 wfDebug( "Fully initialised\n" );
496 $wgFullyInitialised = true;
497
498 wfProfileOut( $fname . '-extensions' );
499 wfProfileOut( $fname );