EditPage: Add capability of targeting editors of code in editor
Can also be used by projects for a policy/recommendations/ to advertise gadget community. Bug: T311891 Change-Id: Ieee508409843561481da246cf26e0f1d93fea6ed
This commit is contained in:
parent
2034de32ed
commit
37bd453af6
4 changed files with 21 additions and 8 deletions
|
|
@ -3739,6 +3739,10 @@ class EditPage implements IEditObject {
|
|||
$doesMessageContainDiv = $this->doesMessageContainDiv( $ctx, $warning );
|
||||
}
|
||||
}
|
||||
$codeMsg = $ctx->msg( 'editpage-code-message' );
|
||||
$codeMessageText = $codeMsg->isDisabled() ? '' : $codeMsg->parseAsBlock();
|
||||
$isJavaScript = $title->hasContentModel( CONTENT_MODEL_JAVASCRIPT );
|
||||
$isCSS = $title->hasContentModel( CONTENT_MODEL_CSS );
|
||||
|
||||
if ( $namespace === NS_MEDIAWIKI ) {
|
||||
$interfaceMsg = $ctx->msg( 'editinginterface' );
|
||||
|
|
@ -3752,9 +3756,9 @@ class EditPage implements IEditObject {
|
|||
# If this is a default message (but not css, json, or js),
|
||||
# show a hint that it is translatable on translatewiki.net
|
||||
if (
|
||||
!$title->hasContentModel( CONTENT_MODEL_CSS )
|
||||
!$isCSS
|
||||
&& !$title->hasContentModel( CONTENT_MODEL_JSON )
|
||||
&& !$title->hasContentModel( CONTENT_MODEL_JAVASCRIPT )
|
||||
&& !$isJavaScript
|
||||
) {
|
||||
$defaultMessageText = $title->getDefaultMessageText();
|
||||
if ( $defaultMessageText !== false ) {
|
||||
|
|
@ -3781,6 +3785,11 @@ class EditPage implements IEditObject {
|
|||
$this->doesMessageContainDiv( $ctx, 'userjsdangerous' );
|
||||
}
|
||||
|
||||
// If the wiki page contains JavaScript or CSS link add message specific to code.
|
||||
if ( $isJavaScript || $isCSS ) {
|
||||
$intro .= $codeMessageText;
|
||||
}
|
||||
|
||||
// If the message is plaintext, (which is the default for a MediaWiki
|
||||
// install) wrap it. If not, then local wiki customizations should be
|
||||
// respected.
|
||||
|
|
|
|||
|
|
@ -745,6 +745,7 @@
|
|||
"editpage-head-copy-warn": "-",
|
||||
"editpage-tos-summary": "-",
|
||||
"editpage-cannot-use-custom-model": "The content model of this page cannot be changed.",
|
||||
"editpage-code-message": "-",
|
||||
"longpage-hint": "-",
|
||||
"longpageerror": "<strong>Error: The text you have submitted is {{PLURAL:$1|one kilobyte|$1 kilobytes}} long, which is longer than the maximum of {{PLURAL:$2|one kilobyte|$2 kilobytes}}.</strong>\nIt cannot be published.",
|
||||
"readonlywarning": "<strong>Warning: The database has been locked for maintenance, so you will not be able to publish your edits right now.</strong>\nYou may wish to copy and paste your text into a text file and save it for later.\n\nThe system administrator who locked it offered this explanation: $1",
|
||||
|
|
|
|||
|
|
@ -995,6 +995,7 @@
|
|||
"editpage-head-copy-warn": "{{ignored}}Custom copyright warning in the header of an edit page.",
|
||||
"editpage-tos-summary": "{{notranslate}}",
|
||||
"editpage-cannot-use-custom-model": "Error message shown if the database does not support changing the content model of a page.",
|
||||
"editpage-code-message": "{{notranslate}} Message that shows when editing code (E.g. CSS, JS or JSON). Should be configured on a site-level.",
|
||||
"longpage-hint": "{{notranslate}}\n* <tt>$1</tt>: Size of the textbox formatted for output, using an appropriate unit ({{msg-mw|size-bytes}}, {{msg-mw|size-kilobytes}}, {{msg-mw|size-megabytes}}, {{msg-mw|size-gigabytes}})\n* <tt>$2</tt>: Size of the textbox in bytes, not formatnum",
|
||||
"longpageerror": "Warning displayed when trying to save a text larger than the maximum size allowed.\n\nParameters:\n* $1 - submitted size (in kilobytes)\n* $2 - maximum size (in kilobytes)",
|
||||
"readonlywarning": "Parameters:\n* $1 - reason",
|
||||
|
|
|
|||
|
|
@ -46,8 +46,9 @@ class EditPageTest extends MediaWikiLangTestCase {
|
|||
[
|
||||
NS_USER,
|
||||
'Bob/vector.js',
|
||||
'<div class="mw-message-box-error mw-message-box"><div class="mw-userconfigdangerous">(userjsdangerous)</div></div>',
|
||||
'JavaScript requires alert'
|
||||
'<div class="mw-message-box-error mw-message-box"><div class="mw-userconfigdangerous">(userjsdangerous)</div>'
|
||||
. '<p>(editpage-code-message)',
|
||||
'JavaScript requires alert as well as code-specific message'
|
||||
],
|
||||
[
|
||||
NS_MEDIAWIKI,
|
||||
|
|
@ -81,7 +82,7 @@ class EditPageTest extends MediaWikiLangTestCase {
|
|||
$title,
|
||||
$context
|
||||
);
|
||||
$this->assertEquals(
|
||||
$this->assertStringContainsString(
|
||||
$result,
|
||||
$intro,
|
||||
$reason
|
||||
|
|
@ -92,6 +93,7 @@ class EditPageTest extends MediaWikiLangTestCase {
|
|||
* @covers EditPage::getCodeEditingIntro
|
||||
*/
|
||||
public function testGetCodeEditingIntroForUser() {
|
||||
$guidelines = '<p>(editpage-code-message)';
|
||||
$editPageMock = $this->getMockBuilder( EditPage::class )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
|
@ -104,12 +106,12 @@ class EditPageTest extends MediaWikiLangTestCase {
|
|||
$title,
|
||||
$context
|
||||
);
|
||||
$this->assertEquals(
|
||||
$this->assertStringContainsString(
|
||||
'<div class="mw-message-box-error mw-message-box">'
|
||||
. '<div class="mw-userconfigpublic">(userjsispublic)</div>'
|
||||
. '<div class="mw-userconfigdangerous">(userjsdangerous)</div></div>',
|
||||
. '<div class="mw-userconfigdangerous">(userjsdangerous)</div>' . $guidelines,
|
||||
$intro,
|
||||
'Inform users that their JS is public'
|
||||
'Inform users that their JS is public and suggest guidelines'
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue