Merge "DesktopArticleTarget.init: Allow veaction=edit to override namespace settings"

This commit is contained in:
jenkins-bot 2019-05-14 10:19:01 +00:00 committed by Gerrit Code Review
commit e5e17c3114
2 changed files with 18 additions and 8 deletions

View file

@ -213,22 +213,28 @@ class VisualEditorHooks {
}
if ( $req->getVal( 'wteswitched' ) ) {
return self::isVisualAvailable( $title );
return self::isVisualAvailable( $title, $req );
}
switch ( self::getPreferredEditor( $user, $req ) ) {
case 'visualeditor':
return self::isVisualAvailable( $title ) || self::isWikitextAvailable( $title, $user );
return self::isVisualAvailable( $title, $req ) || self::isWikitextAvailable( $title, $user );
case 'wikitext':
return self::isWikitextAvailable( $title, $user );
}
return false;
}
private static function isVisualAvailable( $title ) {
private static function isVisualAvailable( $title, $req ) {
$veConfig = MediaWikiServices::getInstance()->getConfigFactory()
->makeConfig( 'visualeditor' );
return ApiVisualEditor::isAllowedNamespace( $veConfig, $title->getNamespace() ) &&
return (
// Only in enabled namespaces
ApiVisualEditor::isAllowedNamespace( $veConfig, $title->getNamespace() ) ||
// Or if forced by the URL parameter (T221892)
$req->getVal( 'veaction' ) === 'edit'
) &&
// Only for pages with a supported content model
ApiVisualEditor::isAllowedContentType( $veConfig, $title->getContentModel() );
}
@ -415,7 +421,7 @@ class VisualEditorHooks {
$title = $skin->getRelevantTitle();
// Don't exit if this page isn't VE-enabled, since we should still
// change "Edit" to "Edit source".
$isAvailable = self::isVisualAvailable( $title );
$isAvailable = self::isVisualAvailable( $title, $skin->getRequest() );
$tabMessages = $config->get( 'VisualEditorTabMessages' );
// Rebuild the $links['views'] array and inject the VisualEditor tab before or after
@ -608,7 +614,7 @@ class VisualEditorHooks {
}
// add VE edit section in VE available namespaces
if ( self::isVisualAvailable( $title ) ) {
if ( self::isVisualAvailable( $title, $skin->getRequest() ) ) {
$veEditSection = $tabMessages['editsection'];
$veLink = [
'text' => $skin->msg( $veEditSection )->inLanguage( $lang )->text(),

View file

@ -998,8 +998,12 @@
init.isVisualAvailable = (
init.isAvailable &&
// Only in enabled namespaces
conf.namespaces.indexOf( new mw.Title( mw.config.get( 'wgRelevantPageName' ) ).getNamespaceId() ) !== -1 &&
(
// Only in enabled namespaces
conf.namespaces.indexOf( new mw.Title( mw.config.get( 'wgRelevantPageName' ) ).getNamespaceId() ) !== -1 ||
// Or if forced by the URL parameter (T221892)
uri.query.veaction === 'edit'
) &&
// Only for pages with a supported content model
Object.prototype.hasOwnProperty.call( conf.contentModels, mw.config.get( 'wgPageContentModel' ) )