Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 69
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2/**
3 * Extra settings useful for MediaWiki development.
4 *
5 * To enable built-in debug and development settings, add the
6 * following to your LocalSettings.php file.
7 *
8 *     require "$IP/includes/DevelopmentSettings.php";
9 *
10 * @file
11 */
12
13use Wikimedia\FileBackend\FSFile\TempFSFile;
14
15/**
16 * Ad-hoc debugging
17 *
18 * To keep your Git copy clean and easier to work with, it is recommended
19 * to copy this to your LocalSettings.php and enable them as-needed.
20 * These are not enabled by default as they make the wiki considerably
21 * slower and/or significantly alter how things work or look.
22 *
23 * See https://www.mediawiki.org/wiki/How_to_debug
24 */
25
26// $wgDebugDumpSql = true;
27// $wgDebugRawPage = true;
28// $wgDebugToolbar = true;
29
30/**
31 * Debugging for PHP
32 */
33
34// Enable logging of all errors
35error_reporting( -1 );
36
37// Enable showing of errors, but avoid breaking non-HTML responses
38if ( MW_ENTRY_POINT === 'index' ) {
39    ini_set( 'display_errors', '1' );
40}
41
42/**
43 * Debugging for MediaWiki
44 */
45
46global $wgDevelopmentWarnings, $wgShowExceptionDetails, $wgShowHostnames,
47    $wgDebugLogFile,
48    $wgDBerrorLog, $wgDebugLogGroups;
49
50// Use of wfWarn() should cause tests to fail
51$wgDevelopmentWarnings = true;
52
53// Enable showing of errors
54$wgShowExceptionDetails = true;
55$wgShowHostnames = true;
56
57// Enable log files
58$logDir = getenv( 'MW_LOG_DIR' );
59if ( $logDir ) {
60    if ( !file_exists( $logDir ) ) {
61        mkdir( $logDir );
62    }
63    $logFileNames = [
64        'debug-cli' => 'mw-debug-cli',
65        'debug-web' => 'mw-debug-web',
66        'db' => 'mw-dberror',
67        'ratelimit' => 'mw-ratelimit',
68        'error' => 'mw-error',
69    ];
70    // For PHPUnit tests run in parallel via ComposerLaunchParallel,
71    // there will be an environment variable containing the group ID
72    // of the batch of tests being run in a process. Use this to group
73    // those logs together.
74    $splitGroupLogId = getenv( 'MW_PHPUNIT_SPLIT_GROUP_ID' );
75
76    foreach ( $logFileNames as $key => $logFileName ) {
77        if ( $splitGroupLogId !== false ) {
78            $logFileNames[$key] = "$logDir/$logFileName.split-group-$splitGroupLogId.log";
79        } else {
80            $logFileNames[$key] = "$logDir/$logFileName.log";
81        }
82    }
83
84    if ( MW_ENTRY_POINT === 'cli' ) {
85        $wgDebugLogFile = $logFileNames['debug-cli'];
86    } else {
87        $wgDebugLogFile = $logFileNames['debug-web'];
88    }
89    $wgDBerrorLog = $logFileNames['db'];
90    $wgDebugLogGroups['ratelimit'] = $logFileNames['ratelimit'];
91    $wgDebugLogGroups['error'] = $logFileNames['error'];
92    $wgDebugLogGroups['exception'] = $logFileNames['error'];
93}
94unset( $logDir );
95
96/**
97 * Make testing possible (or easier)
98 */
99
100global $wgRateLimits, $wgEnableJavaScriptTest, $wgRestAPIAdditionalRouteFiles,
101    $wgPasswordAttemptThrottle, $wgForceDeferredUpdatesPreSend,
102    $wgParsoidSettings, $wgMaxArticleSize;
103
104// Set almost infinite rate limits. This allows integration tests to run unthrottled
105// in CI and for devs locally (T225796), but doesn't turn a large chunk of production
106// code completely off during testing (T284804)
107foreach ( $wgRateLimits as $right => &$limit ) {
108    foreach ( $limit as $group => &$groupLimit ) {
109        $groupLimit[0] = PHP_INT_MAX;
110    }
111}
112
113// Enable Special:JavaScriptTest and allow `npm run qunit` to work
114// https://www.mediawiki.org/wiki/Manual:JavaScript_unit_testing
115$wgEnableJavaScriptTest = true;
116
117// Enable development/experimental endpoints
118$wgRestAPIAdditionalRouteFiles[] = 'includes/Rest/coreDevelopmentRoutes.json';
119$wgRestAPIAdditionalRouteFiles[] = 'includes/Rest/content.v1.json';
120$wgRestAPIAdditionalRouteFiles[] = 'includes/Rest/site.v1.json';
121$wgRestAPIAdditionalRouteFiles[] = 'includes/Rest/specs.v0.json';
122
123// Greatly raise the limits on short/long term login attempts,
124// so that automated tests run in parallel don't error.
125$wgPasswordAttemptThrottle = [
126    [ 'count' => 1000, 'seconds' => 300 ],
127    [ 'count' => 100000, 'seconds' => 60 * 60 * 48 ],
128];
129
130// Run deferred updates before sending a response to the client.
131// This ensures that in end-to-end tests, a GET request will see the
132// effect of all previous POST requests (T230211).
133// Caveat: this does not wait for jobs to be executed, and it does
134// not wait for database replication to complete.
135$wgForceDeferredUpdatesPreSend = true;
136
137// Set size limits for parsing small enough so we can test them,
138// but not so small that they interfere with other tests.
139$wgMaxArticleSize = 20; // in Kilobyte
140$wgParsoidSettings['wt2htmlLimits']['wikitextSize'] = 20 * 1024; // $wgMaxArticleSize, in byte
141$wgParsoidSettings['html2wtLimits']['htmlSize'] = 100 * 1024; // in characters!
142
143// Enable linting, so we can test it.
144$wgParsoidSettings['linting'] = true;
145
146// Enable Vue dev mode by default, so that Vue devtools are functional.
147$wgVueDevelopmentMode = true;
148
149// Disable rate limiting of temp account creation and temp account name
150// acquisition, to facilitate local development and testing
151$wgTempAccountCreationThrottle = [];
152$wgTempAccountNameAcquisitionThrottle = [];
153
154/**
155 * Experimental changes that may later become the default.
156 * (Must reference a Phabricator ticket)
157 */
158
159global $wgSQLMode, $wgDBStrictWarnings, $wgLocalisationCacheConf, $wgCiteSubReferencing,
160    $wgCacheDirectory, $wgEnableUploads, $wgUsePigLatinVariant,
161    $wgVisualEditorEnableWikitext, $wgDefaultUserOptions, $wgAutoCreateTempUser;
162
163// Enable MariaDB/MySQL strict mode (T108255)
164$wgSQLMode = 'STRICT_ALL_TABLES,ONLY_FULL_GROUP_BY';
165$wgDBStrictWarnings = true;
166
167// Localisation Cache to StaticArray (T218207)
168$wgLocalisationCacheConf['store'] = 'array';
169
170// Experimental sub-referencing feature in Cite (T236255)
171$wgCiteSubReferencing = true;
172
173// The default value is false, but for development it is useful to set this to the system temp
174// directory by default (T218207)
175$wgCacheDirectory = TempFSFile::getUsableTempDirectory() .
176    DIRECTORY_SEPARATOR .
177    rawurlencode( MediaWiki\WikiMap\WikiMap::getCurrentWikiId() );
178
179// Enable uploads for FileImporter browser tests (T190829)
180$wgEnableUploads = true;
181
182// Enable en-x-piglatin variant conversion for testing
183$wgUsePigLatinVariant = true;
184// Enable x-xss language code for testing correct message escaping
185$wgUseXssLanguage = true;
186
187// Enable the new wikitext mode for browser testing (T270240)
188$wgVisualEditorEnableWikitext = true;
189// Currently the default, but repeated here for safety since it would break many source editor tests.
190$wgDefaultUserOptions['visualeditor-newwikitext'] = 0;
191
192// Enable creation of temp user accounts on edit (T355880, T359043)
193$wgAutoCreateTempUser['enabled'] = true;
194
195// Make sure Mocha tests can create language links by defining an interwiki
196// prefix that matches a known language code.
197$wgHooks['InterwikiLoadPrefix'][] = static function ( $prefix, &$iwData ) {
198    if ( $prefix === 'en-x-piglatin' ) {
199        $iwData['iw_url'] = 'https://piggy.wikipedia.org/wiki/$1';
200        return false;
201    }
202    return true;
203};