jenkins-bot has submitted this change and it was merged.
Change subject: DesktopArticleTarget: Change tab text on server side when
possible
......................................................................
DesktopArticleTarget: Change tab text on server side when possible
Usually. Unless you load VE, because then you might be loading on
`action=edit` in remember-last mode and therefore the tab text needs to
be updated from "Edit source" to "Edit". Or "Create source" to "Create".
Or the equivalent with 'local description' in the case of pages from
foreign file repos, etc.
Bug: T120970
Change-Id: I8f07be6c8e415b40ad134ee82d0bda1d63cc4f96
---
M VisualEditor.hooks.php
M extension.json
M modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
3 files changed, 97 insertions(+), 51 deletions(-)
Approvals:
Esanders: Looks good to me, approved
jenkins-bot: Verified
diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php
index 2aa0c1c..03dfae1 100644
--- a/VisualEditor.hooks.php
+++ b/VisualEditor.hooks.php
@@ -86,18 +86,9 @@
$params = $req->getValueNames();
- if ( $user->isAnon() ) {
- $editor = $req->getCookie(
- 'VEE',
- '',
- User::getDefaultOption( 'visualeditor-editor' )
- );
- } else {
- $editor = $user->getOption( 'visualeditor-editor' );
- }
return $req->getVal( 'action' ) !== 'edit' ||
!$veConfig->get( 'VisualEditorUseSingleEditTab' ) ||
- $editor === 'wikitext' ||
+ self::getUserEditor( $user, $req ) === 'wikitext' ||
!$title->inNamespaces( array_keys( array_filter(
$availableNamespaces ) ) ) ||
$title->getContentModel() !== CONTENT_MODEL_WIKITEXT ||
// check for parameters that VE does not handle
@@ -109,6 +100,40 @@
in_array( 'preloadtitle', $params ) ||
in_array( 'preloadparams', $params );
// Known-good parameters: edit, veaction, section,
vesection, veswitched
+ }
+
+ private static function getUserEditor( User $user, WebRequest $req ) {
+ if ( $user->isAnon() ) {
+ return $req->getCookie(
+ 'VEE',
+ '',
+ User::getDefaultOption( 'visualeditor-editor' )
+ );
+ } else {
+ return $user->getOption( 'visualeditor-editor' );
+ }
+ }
+
+ /**
+ * Convert the content model of messages that are actually JSON to JSON.
+ * This only affects validation and UI when saving and editing, not
+ * loading the content.
+ *
+ * @param Title $title
+ * @param string $model
+ * @return bool
+ */
+ public static function onContentHandlerDefaultModelFor( Title $title,
&$model ) {
+ $messages = array(
+ 'Visualeditor-cite-tool-definition.json',
+ 'Visualeditor-quick-access-characters.json'
+ );
+
+ if ( $title->inNamespace( NS_MEDIAWIKI ) && in_array(
$title->getText(), $messages ) ) {
+ $model = CONTENT_MODEL_JSON;
+ }
+
+ return true;
}
/**
@@ -128,15 +153,20 @@
return true;
}
- // Exit if we're using the single edit tab.
+ $user = $skin->getUser();
if (
$config->get( 'VisualEditorUseSingleEditTab' ) &&
- $skin->getUser()->getOption( 'visualeditor-tabs' ) !==
'multi-tab'
+ $user->getOption( 'visualeditor-tabs' ) === 'prefer-wt'
+ ) {
+ return true;
+ }
+
+ if (
+ $config->get( 'VisualEditorUseSingleEditTab' ) &&
+ $user->getOption( 'visualeditor-tabs' ) !== 'multi-tab'
) {
$dbr = wfGetDB( DB_SLAVE );
- $user = RequestContext::getMain()->getUser();
if (
- $config->get( 'VisualEditorUseSingleEditTab' )
&&
!$user->isAnon() &&
!$user->getOption( 'visualeditor-autodisable' )
&&
!$user->getOption(
'visualeditor-betatempdisable' ) &&
@@ -155,18 +185,16 @@
array( 'LIMIT' => 1 )
)->numRows() === 1
) {
- wfDebugLog( 'debug', 'ok' );
$links['views']['edit']['class'] .= '
visualeditor-showtabdialog';
}
- return true;
}
// Exit if the user doesn't have VE enabled
if (
- !$skin->getUser()->getOption( 'visualeditor-enable' ) ||
- $skin->getUser()->getOption(
'visualeditor-betatempdisable' ) ||
- $skin->getUser()->getOption( 'visualeditor-autodisable'
) ||
- ( $config->get( 'VisualEditorDisableForAnons' ) &&
$skin->getUser()->isAnon() )
+ !$user->getOption( 'visualeditor-enable' ) ||
+ $user->getOption( 'visualeditor-betatempdisable' ) ||
+ $user->getOption( 'visualeditor-autodisable' ) ||
+ ( $config->get( 'VisualEditorDisableForAnons' ) &&
$user->isAnon() )
) {
return true;
}
@@ -228,7 +256,28 @@
if ( $editTabMessage !== null ) {
$editTab['text'] = $skin->msg(
$editTabMessage )->text();
}
- if ( $isAvailable ) {
+
+ $editor = self::getUserEditor( $user,
RequestContext::getMain()->getRequest() );
+ if (
+ $isAvailable &&
+ $config->get(
'VisualEditorUseSingleEditTab' ) &&
+ (
+ $user->getOption(
'visualeditor-tabs' ) === 'prefer-ve' ||
+ (
+ $user->getOption(
'visualeditor-tabs' ) === 'remember-last' &&
+ $editor ===
'visualeditor'
+ )
+ )
+ ) {
+ $editTab['text'] = $veTabText;
+ $newViews['edit'] = $editTab;
+ } elseif (
+ $isAvailable &&
+ (
+ !$config->get(
'VisualEditorUseSingleEditTab' ) ||
+ $user->getOption(
'visualeditor-tabs' ) === 'multi-tab'
+ )
+ ) {
// Inject the VE tab before or after
the edit tab
if ( $config->get(
'VisualEditorTabPosition' ) === 'before' ) {
$editTab['class'] .= '
collapsible';
@@ -239,9 +288,19 @@
$newViews['edit'] = $editTab;
$newViews['ve-edit'] = $veTab;
}
- } else {
+ } elseif (
+ !$config->get(
'VisualEditorUseSingleEditTab' ) ||
+ !$isAvailable ||
+ $user->getOption( 'visualeditor-tabs' )
=== 'multi-tab' ||
+ (
+ $user->getOption(
'visualeditor-tabs' ) === 'remember-last' &&
+ $editor === 'wikitext'
+ )
+ ) {
// Don't add ve-edit, but do update the
edit tab (e.g. "Edit source").
$newViews['edit'] = $editTab;
+ } else {
+ // This should not happen.
}
} else {
// Just pass through
diff --git a/extension.json b/extension.json
index 0b51478..7a38a38 100644
--- a/extension.json
+++ b/extension.json
@@ -287,7 +287,11 @@
"postedit-confirmation-created",
"postedit-confirmation-restored",
"postedit-confirmation-saved",
- "visualeditor-mweditmodeve-tool"
+ "visualeditor-mweditmodeve-tool",
+ "edit",
+ "create",
+ "edit-local",
+ "create-local"
],
"position": "top"
},
diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
index a9b455f..55cd5ff 100644
--- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
+++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
@@ -145,11 +145,20 @@
}
function activatePageTarget( modified ) {
+ var key;
trackActivateStart( { type: 'page', mechanism: 'click' } );
if ( !active ) {
- if ( $( '#ca-edit a' ).data( 'original-text' ) ) {
- $( '#ca-edit a' ).text( $( '#ca-edit a' ).data(
'original-text' ) );
+ if (
+ mw.config.get( 'wgVisualEditorConfig'
).singleEditTab &&
+ mw.user.options.get( 'visualeditor-tabs' ) ===
'remember-last'
+ ) {
+ key = pageExists ? 'edit' : 'create';
+ if ( $( '#ca-view-foreign' ).length ) {
+ key += '-local';
+ }
+
+ $( '#ca-edit a' ).text( mw.msg( key ) );
}
if ( uri.query.action !== 'edit' ) {
@@ -698,7 +707,6 @@
}
$( function () {
- var key;
if ( uri.query.action === 'edit' && $( '#wpTextbox1' ).length )
{
initialWikitext = $( '#wpTextbox1' ).val();
}
@@ -802,31 +810,6 @@
}
} else if ( userPrefEnabled ) {
init.setupSkin();
- }
- }
-
- if (
- conf.singleEditTab &&
- mw.user.options.get( 'visualeditor-tabs' ) ===
'multi-tab' &&
- userPrefEnabled &&
- (
- init.isAvailable &&
- !mw.user.isAnon() &&
- getLastEditor() === 'wikitext'
- ) || (
- !init.isAvailable &&
- mw.user.options.get( 'visualeditor-tabs' ) ===
'prefer-ve'
- )
- ) {
- key = pageExists ? 'edit' : 'create';
- if ( $( '#ca-view-foreign' ).length ) {
- key += 'localdescription';
- }
- key += 'source';
- if ( tabMessages[ key ] !== null ) {
- $( '#ca-edit a' )
- .data( 'original-text', $( '#ca-edit a'
).text() )
- .text( mw.msg( tabMessages[ key ] ) );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/258230
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8f07be6c8e415b40ad134ee82d0bda1d63cc4f96
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Alex Monk <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits