Merge "rest: Return a 400 for invalid render IDs"
[mediawiki.git] / includes / DevelopmentSettings.php
blob20561ed31fe40eb7c14ff62e1a9d73a9f2bd47f6
1 <?php
2 /**
3 * Extra settings useful for MediaWiki development.
5 * To enable built-in debug and development settings, add the
6 * following to your LocalSettings.php file.
8 * require "$IP/includes/DevelopmentSettings.php";
10 * @file
13 use Wikimedia\FileBackend\FSFile\TempFSFile;
15 /**
16 * Ad-hoc debugging
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.
23 * See https://www.mediawiki.org/wiki/How_to_debug
26 // $wgDebugDumpSql = true;
27 // $wgDebugRawPage = true;
28 // $wgDebugToolbar = true;
30 /**
31 * Debugging for PHP
34 // Enable logging of all errors
35 error_reporting( -1 );
37 // Enable showing of errors, but avoid breaking non-HTML responses
38 if ( MW_ENTRY_POINT === 'index' ) {
39 ini_set( 'display_errors', '1' );
42 /**
43 * Debugging for MediaWiki
46 global $wgDevelopmentWarnings, $wgShowExceptionDetails, $wgShowHostnames,
47 $wgDebugLogFile,
48 $wgDBerrorLog, $wgDebugLogGroups;
50 // Use of wfWarn() should cause tests to fail
51 $wgDevelopmentWarnings = true;
53 // Enable showing of errors
54 $wgShowExceptionDetails = true;
55 $wgShowHostnames = true;
57 // Enable log files
58 $logDir = getenv( 'MW_LOG_DIR' );
59 if ( $logDir ) {
60 if ( !file_exists( $logDir ) ) {
61 mkdir( $logDir );
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',
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' );
76 foreach ( $logFileNames as $key => $logFileName ) {
77 if ( $splitGroupLogId ) {
78 $logFileNames[$key] = "$logDir/$logFileName.split-group-$splitGroupLogId.log";
79 } else {
80 $logFileNames[$key] = "$logDir/$logFileName.log";
84 if ( MW_ENTRY_POINT === 'cli' ) {
85 $wgDebugLogFile = $logFileNames['debug-cli'];
86 } else {
87 $wgDebugLogFile = $logFileNames['debug-web'];
89 $wgDBerrorLog = $logFileNames['db'];
90 $wgDebugLogGroups['ratelimit'] = $logFileNames['ratelimit'];
91 $wgDebugLogGroups['error'] = $logFileNames['error'];
92 $wgDebugLogGroups['exception'] = $logFileNames['error'];
94 unset( $logDir );
96 /**
97 * Make testing possible (or easier)
100 global $wgRateLimits, $wgEnableJavaScriptTest, $wgRestAPIAdditionalRouteFiles,
101 $wgPasswordAttemptThrottle, $wgForceDeferredUpdatesPreSend,
102 $wgParsoidSettings, $wgMaxArticleSize;
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)
107 foreach ( $wgRateLimits as $right => &$limit ) {
108 foreach ( $limit as $group => &$groupLimit ) {
109 $groupLimit[0] = PHP_INT_MAX;
113 // Enable Special:JavaScriptTest and allow `npm run qunit` to work
114 // https://www.mediawiki.org/wiki/Manual:JavaScript_unit_testing
115 $wgEnableJavaScriptTest = true;
117 // Enable development/experimental endpoints
118 $wgRestAPIAdditionalRouteFiles[] = 'includes/Rest/coreDevelopmentRoutes.json';
119 $wgRestAPIAdditionalRouteFiles[] = 'includes/Rest/content.v1.json';
120 $wgRestAPIAdditionalRouteFiles[] = 'includes/Rest/specs.v0.json';
122 // Greatly raise the limits on short/long term login attempts,
123 // so that automated tests run in parallel don't error.
124 $wgPasswordAttemptThrottle = [
125 [ 'count' => 1000, 'seconds' => 300 ],
126 [ 'count' => 100000, 'seconds' => 60 * 60 * 48 ],
129 // Run deferred updates before sending a response to the client.
130 // This ensures that in end-to-end tests, a GET request will see the
131 // effect of all previous POST requests (T230211).
132 // Caveat: this does not wait for jobs to be executed, and it does
133 // not wait for database replication to complete.
134 $wgForceDeferredUpdatesPreSend = true;
136 // Set size limits for parsing small enough so we can test them,
137 // but not so small that they interfere with other tests.
138 $wgMaxArticleSize = 20; // in Kilobyte
139 $wgParsoidSettings['wt2htmlLimits']['wikitextSize'] = 20 * 1024; // $wgMaxArticleSize, in byte
140 $wgParsoidSettings['html2wtLimits']['htmlSize'] = 100 * 1024; // in characters!
142 // Enable Vue dev mode by default, so that Vue devtools are functional.
143 $wgVueDevelopmentMode = true;
145 // Disable rate limiting of temp account creation and temp account name
146 // acquisition, to facilitate local development and testing
147 $wgTempAccountCreationThrottle = [];
148 $wgTempAccountNameAcquisitionThrottle = [];
151 * Experimental changes that may later become the default.
152 * (Must reference a Phabricator ticket)
155 global $wgSQLMode, $wgDBStrictWarnings, $wgLocalisationCacheConf, $wgCiteBookReferencing,
156 $wgCacheDirectory, $wgEnableUploads, $wgUsePigLatinVariant,
157 $wgVisualEditorEnableWikitext, $wgDefaultUserOptions, $wgAutoCreateTempUser;
159 // Enable MariaDB/MySQL strict mode (T108255)
160 $wgSQLMode = 'STRICT_ALL_TABLES,ONLY_FULL_GROUP_BY';
161 $wgDBStrictWarnings = true;
163 // Localisation Cache to StaticArray (T218207)
164 $wgLocalisationCacheConf['store'] = 'array';
166 // Experimental Book Referencing feature (T236255)
167 $wgCiteBookReferencing = true;
169 // The default value is false, but for development it is useful to set this to the system temp
170 // directory by default (T218207)
171 $wgCacheDirectory = TempFSFile::getUsableTempDirectory() .
172 DIRECTORY_SEPARATOR .
173 rawurlencode( MediaWiki\WikiMap\WikiMap::getCurrentWikiId() );
175 // Enable uploads for FileImporter browser tests (T190829)
176 $wgEnableUploads = true;
178 // Enable en-x-piglatin variant conversion for testing
179 $wgUsePigLatinVariant = true;
180 // Enable x-xss language code for testing correct message escaping
181 $wgUseXssLanguage = true;
183 // Enable the new wikitext mode for browser testing (T270240)
184 $wgVisualEditorEnableWikitext = true;
185 // Currently the default, but repeated here for safety since it would break many source editor tests.
186 $wgDefaultUserOptions['visualeditor-newwikitext'] = 0;
188 // Enable creation of temp user accounts on edit (T355880, T359043)
189 $wgAutoCreateTempUser['enabled'] = true;
191 // Make sure Mocha tests can create language links by defining an interwiki
192 // prefix that matches a known language code.
193 $wgHooks['InterwikiLoadPrefix'][] = static function ( $prefix, &$iwData ) {
194 if ( $prefix === 'en-x-piglatin' ) {
195 $iwData['iw_url'] = 'https://piggy.wikipedia.org/wiki/$1';
196 return false;
198 return true;