Disable wikitext editor on non-wikitext content models

Do not allow editing via JavaScript on non-wikitext content models
For these pages ?action=edit will be used

Bug: T173800
Change-Id: Ic62a0c1397ab8a6a59e5382c2999b63b3c60a19f
This commit is contained in:
jdlrobson 2017-08-22 09:12:32 -05:00 committed by Jdlrobson
parent cd22f736d7
commit ac7fcfc9e1
2 changed files with 18 additions and 3 deletions

View File

@ -19,6 +19,9 @@ class SkinMinerva extends SkinTemplate implements ICustomizableSkin {
const OPTION_BACK_TO_TOP = 'backToTop';
const OPTION_TOGGLING = 'toggling';
const OPTIONS_MOBILE_BETA = 'beta';
/** @const LEAD_SECTION_NUMBER integer which corresponds to the lead section
in editing mode */
const LEAD_SECTION_NUMBER = 0;
/** @var string $skinname Name of this skin */
public $skinname = 'minerva';
@ -1063,6 +1066,13 @@ class SkinMinerva extends SkinTemplate implements ICustomizableSkin {
* @return array A map compatible with BaseTemplate#makeListItem
*/
protected function createEditPageAction() {
$title = $this->getTitle();
$editArgs = [ 'action' => 'edit' ];
if ( $title->isWikitextPage() ) {
// If the content model is wikitext we'll default to editing the lead section.
// Full wikitext editing is not possible via the api and hard on mobile devices.
$editArgs['section'] = self::LEAD_SECTION_NUMBER;
}
return [
'id' => 'ca-edit',
'text' => '',
@ -1070,7 +1080,7 @@ class SkinMinerva extends SkinTemplate implements ICustomizableSkin {
'class' => MobileUI::iconClass( 'edit-enabled', 'element' ),
'links' => [
'edit' => [
'href' => $this->getTitle()->getLocalURL( [ 'action' => 'edit', 'section' => 0 ] )
'href' => $title->getLocalURL( $editArgs )
],
],
'is_js_only' => false
@ -1240,7 +1250,7 @@ class SkinMinerva extends SkinTemplate implements ICustomizableSkin {
if ( !$title->isTalkPage() ) {
$title = $title->getTalkPage();
}
return $title->getContentModel() === CONTENT_MODEL_WIKITEXT;
return $title->isWikitextPage();
}
/**

View File

@ -24,6 +24,7 @@
popup = M.require( 'mobile.startup/toast' ),
// FIXME: Disable on IE < 10 for time being
blacklisted = /MSIE \d\./.test( navigator.userAgent ),
contentModel = mw.config.get( 'wgPageContentModel' ),
isEditingSupported = router.isSupported() && !blacklisted,
// FIXME: Use currentPage.getId()
isNewPage = currentPage.options.id === 0,
@ -345,7 +346,11 @@
} );
}
if ( !isEditingSupported ) {
if ( contentModel !== 'wikitext' ) {
// Only load the wikitext editor on wikitext. Otherwise we'll rely on the fallback behaviour
// (You can test this on MediaWiki:Common.css) ?action=edit url (T173800)
return;
} else if ( !isEditingSupported ) {
// Editing is disabled (or browser is blacklisted)
$caEdit.removeClass( 'hidden' );
showSorryToast( mw.msg( 'mobile-frontend-editor-unavailable' ) );