content: Add hidden preference to disable PST on CSS/JS content

Test Plan:
* Logged-in, preview a change adding {{subst:CURRENTYEAR}}
  to User:You/common.css, User:You/common.js and Main_Page.
* Observe that it expands to 2020 in all cases.
* Run `(new mw.Api).saveOption('pst-cssjs', '0')`
* Try again. Observe that the first two are now left unchanged.

Bug: T236828
Change-Id: Ic13e2ff3b90f0c3587cdb1e97fffcd96be650e0e
This commit is contained in:
C. Scott Ananian 2020-04-03 16:49:13 -04:00 committed by Krinkle
parent 9af266fd44
commit 770ace8723
4 changed files with 18 additions and 3 deletions

View file

@ -5284,6 +5284,7 @@ $wgDefaultUserOptions = [
'minordefault' => 0,
'newpageshidepatrolled' => 0,
'nickname' => '',
'pst-cssjs' => 1,
'norollbackdiff' => 0,
'numberheadings' => 0,
'previewonfirst' => 0,

View file

@ -62,7 +62,13 @@ class CssContent extends TextContent {
* @see TextContent::preSaveTransform
*/
public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) {
// @todo Make pre-save transformation optional for script pages
// @todo Make pre-save transformation optional for script pages (T34858)
if ( !$user->getBoolOption( 'pst-cssjs' ) ) {
// Allow bot users to disable the pre-save transform for CSS/JS (T236828).
$popts = clone $popts;
$popts->setPreSaveTransform( false );
}
$text = $this->getText();
$pst = MediaWikiServices::getInstance()->getParser()

View file

@ -60,8 +60,13 @@ class JavaScriptContent extends TextContent {
* @return JavaScriptContent
*/
public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) {
// @todo Make pre-save transformation optional for script pages
// See T34858
// @todo Make pre-save transformation optional for script pages (T34858)
if ( !$user->getBoolOption( 'pst-cssjs' ) ) {
// Allow bot users to disable the pre-save transform for CSS/JS (T236828).
$popts = clone $popts;
$popts->setPreSaveTransform( false );
}
$text = $this->getText();
$pst = MediaWikiServices::getInstance()->getParser()

View file

@ -1117,6 +1117,9 @@ class DefaultPreferencesFactory implements PreferencesFactory {
'label-message' => 'tog-hideminor',
'section' => 'rc/changesrc',
];
$defaultPreferences['pst-cssjs'] = [
'type' => 'api',
];
$defaultPreferences['rcfilters-rc-collapsed'] = [
'type' => 'api',
];