Merge "Move edit link enabling/disabling out of skins.minerva.editor"

This commit is contained in:
jenkins-bot 2018-10-04 21:22:56 +00:00 committed by Gerrit Code Review
commit 5d4e3e01aa
2 changed files with 45 additions and 44 deletions

View file

@ -4,32 +4,14 @@
// see: https://www.mediawiki.org/wiki/Manual:Interface/JavaScript#Page-specific // see: https://www.mediawiki.org/wiki/Manual:Interface/JavaScript#Page-specific
isReadOnly = mw.config.get( 'wgMinervaReadOnly' ), isReadOnly = mw.config.get( 'wgMinervaReadOnly' ),
isEditable = !isReadOnly && mw.config.get( 'wgIsProbablyEditable' ), isEditable = !isReadOnly && mw.config.get( 'wgIsProbablyEditable' ),
blockInfo = mw.config.get( 'wgMinervaUserBlockInfo', false ),
router = require( 'mediawiki.router' ), router = require( 'mediawiki.router' ),
issues = M.require( 'skins.minerva.scripts/pageIssues' ), issues = M.require( 'skins.minerva.scripts/pageIssues' ),
overlayManager = M.require( 'skins.minerva.scripts/overlayManager' ), overlayManager = M.require( 'skins.minerva.scripts/overlayManager' ),
loader = M.require( 'mobile.startup/rlModuleLoader' ), loader = M.require( 'mobile.startup/rlModuleLoader' ),
Icon = M.require( 'mobile.startup/Icon' ),
skin = M.require( 'skins.minerva.scripts/skin' ), skin = M.require( 'skins.minerva.scripts/skin' ),
currentPage = M.getCurrentPage(), currentPage = M.getCurrentPage(),
// TODO: create a utility method to generate class names instead of
// constructing temporary objects. This affects disabledEditIcon,
// enabledEditIcon, enabledEditIcon, and disabledClass and
// a number of other places in the code base.
disabledEditIcon = new Icon( {
name: 'edit',
glyphPrefix: 'minerva'
} ),
enabledEditIcon = new Icon( {
name: 'edit-enabled',
glyphPrefix: 'minerva'
} ),
editErrorMessage = isReadOnly ? mw.msg( 'apierror-readonly' ) : mw.msg( 'mobile-frontend-editor-disabled' ), editErrorMessage = isReadOnly ? mw.msg( 'apierror-readonly' ) : mw.msg( 'mobile-frontend-editor-disabled' ),
// TODO: move enabledClass, $caEdit, and disabledClass to locals within // FIXME: rename to editPageButton.
// updateEditPageButton().
enabledClass = enabledEditIcon.getGlyphClassName(),
disabledClass = disabledEditIcon.getGlyphClassName(),
// TODO: rename to editPageButton.
$caEdit = $( '#ca-edit' ), $caEdit = $( '#ca-edit' ),
user = M.require( 'mobile.startup/user' ), user = M.require( 'mobile.startup/user' ),
popup = M.require( 'mobile.startup/toast' ), popup = M.require( 'mobile.startup/toast' ),
@ -46,10 +28,6 @@
CtaDrawer = M.require( 'mobile.startup/CtaDrawer' ), CtaDrawer = M.require( 'mobile.startup/CtaDrawer' ),
drawer; drawer;
if ( user.isAnon() ) {
blockInfo = false;
}
/** /**
* Event handler for edit link clicks. Will prevent default link * Event handler for edit link clicks. Will prevent default link
* behaviour and will not allow propagation * behaviour and will not allow propagation
@ -65,7 +43,7 @@
return false; return false;
} }
// TODO: rename addEditSectionButton and evaluate whether the page edit button // FIXME: rename addEditSectionButton and evaluate whether the page edit button
// can leverage the same code. Also: change the CSS class name to use // can leverage the same code. Also: change the CSS class name to use
// the word "section" instead of "page". // the word "section" instead of "page".
/** /**
@ -86,16 +64,6 @@
.prependTo( container ); .prependTo( container );
} }
/**
* @param {boolean} enabled
* @return {void}
*/
function updateEditPageButton( enabled ) {
$caEdit
.addClass( enabled ? enabledClass : disabledClass )
.removeClass( enabled ? disabledClass : enabledClass );
}
/** /**
* Make an element render a CTA when clicked * Make an element render a CTA when clicked
* @method * @method
@ -164,7 +132,7 @@
isNewPage = page.options.id === 0, isNewPage = page.options.id === 0,
leadSection = page.getLeadSectionElement(); leadSection = page.getLeadSectionElement();
page.$( '.edit-page, .edit-link' ).removeClass( disabledClass ) page.$( '.edit-page, .edit-link' )
.on( 'click', onEditLinkClick ); .on( 'click', onEditLinkClick );
overlayManager.add( /^\/editor\/(\d+|all)$/, function ( sectionId ) { overlayManager.add( /^\/editor\/(\d+|all)$/, function ( sectionId ) {
var var
@ -260,7 +228,6 @@
return loadSourceEditor(); return loadSourceEditor();
} }
} ); } );
updateEditPageButton( true );
// Make sure we never create two edit links by accident // Make sure we never create two edit links by accident
// FIXME: split the selector and cache it // FIXME: split the selector and cache it
@ -300,10 +267,6 @@
router.navigate( fragment ); router.navigate( fragment );
} }
} }
if ( blockInfo ) {
updateEditPageButton( false );
}
} }
/** /**
@ -326,7 +289,6 @@
// Edit button updated in setupEditor. // Edit button updated in setupEditor.
setupEditor( currentPage ); setupEditor( currentPage );
} else { } else {
updateEditPageButton( false );
hideSectionEditIcons(); hideSectionEditIcons();
showSorryToast( editErrorMessage ); showSorryToast( editErrorMessage );
} }
@ -341,7 +303,6 @@
// Initialize edit button links (to show Cta) only, if page is editable, // Initialize edit button links (to show Cta) only, if page is editable,
// otherwise show an error toast // otherwise show an error toast
if ( isEditable ) { if ( isEditable ) {
updateEditPageButton( true );
// Init lead section edit button // Init lead section edit button
makeCta( $caEdit, 0 ); makeCta( $caEdit, 0 );
@ -356,7 +317,6 @@
makeCta( $a, section ); makeCta( $a, section );
} ); } );
} else { } else {
updateEditPageButton( false );
showSorryToast( editErrorMessage ); showSorryToast( editErrorMessage );
} }
} }
@ -391,7 +351,6 @@
} }
if ( isNewFile ) { if ( isNewFile ) {
updateEditPageButton( true );
// Is a new file page (enable upload image only) Bug 58311 // Is a new file page (enable upload image only) Bug 58311
showSorryToast( mw.msg( 'mobile-frontend-editor-uploadenable' ) ); showSorryToast( mw.msg( 'mobile-frontend-editor-uploadenable' ) );
} else { } else {

View file

@ -2,6 +2,7 @@
var var
toast = M.require( 'mobile.startup/toast' ), toast = M.require( 'mobile.startup/toast' ),
time = M.require( 'mobile.startup/time' ), time = M.require( 'mobile.startup/time' ),
user = M.require( 'mobile.startup/user' ),
skin = M.require( 'mobile.init/skin' ), skin = M.require( 'mobile.init/skin' ),
issues = M.require( 'skins.minerva.scripts/pageIssues' ), issues = M.require( 'skins.minerva.scripts/pageIssues' ),
DownloadIcon = M.require( 'skins.minerva.scripts/DownloadIcon' ), DownloadIcon = M.require( 'skins.minerva.scripts/DownloadIcon' ),
@ -10,6 +11,7 @@
router = require( 'mediawiki.router' ), router = require( 'mediawiki.router' ),
OverlayManager = M.require( 'mobile.startup/OverlayManager' ), OverlayManager = M.require( 'mobile.startup/OverlayManager' ),
CtaDrawer = M.require( 'mobile.startup/CtaDrawer' ), CtaDrawer = M.require( 'mobile.startup/CtaDrawer' ),
Icon = M.require( 'mobile.startup/Icon' ),
Button = M.require( 'mobile.startup/Button' ), Button = M.require( 'mobile.startup/Button' ),
Anchor = M.require( 'mobile.startup/Anchor' ), Anchor = M.require( 'mobile.startup/Anchor' ),
overlayManager = new OverlayManager( require( 'mediawiki.router' ) ), overlayManager = new OverlayManager( require( 'mediawiki.router' ) ),
@ -312,6 +314,45 @@
} ); } );
} }
/**
* Initialize page edit action link (#ca-edit)
*
* Mark the edit link as disabled if the user is not actually able to edit the page for some
* reason (e.g. page is protected or user is blocked).
*
* Note that the link is still clickable, but clicking it will probably open a view-source
* form or display an error message, rather than open an edit form.
*
* FIXME: Review this code as part of T206262
*
* @ignore
*/
function initEditLink() {
var
// FIXME: create a utility method to generate class names instead of
// constructing temporary objects. This affects disabledEditIcon,
// enabledEditIcon, enabledEditIcon, and disabledClass and
// a number of other places in the code base.
disabledEditIcon = new Icon( {
name: 'edit',
glyphPrefix: 'minerva'
} ),
enabledEditIcon = new Icon( {
name: 'edit-enabled',
glyphPrefix: 'minerva'
} ),
enabledClass = enabledEditIcon.getGlyphClassName(),
disabledClass = disabledEditIcon.getGlyphClassName(),
isReadOnly = mw.config.get( 'wgMinervaReadOnly' ),
isEditable = mw.config.get( 'wgIsProbablyEditable' ),
blockInfo = user.isAnon() ? false : mw.config.get( 'wgMinervaUserBlockInfo', false ),
canEdit = !isReadOnly && isEditable && !blockInfo;
$( '#ca-edit' )
.addClass( canEdit ? enabledClass : disabledClass )
.removeClass( canEdit ? disabledClass : enabledClass );
}
$( function () { $( function () {
// Update anything else that needs enhancing (e.g. watchlist) // Update anything else that needs enhancing (e.g. watchlist)
initModifiedInfo(); initModifiedInfo();
@ -321,6 +362,7 @@
loadTabletModules(); loadTabletModules();
appendDownloadButton(); appendDownloadButton();
initRedlinksCta(); initRedlinksCta();
initEditLink();
// Setup the issues banner on the page // Setup the issues banner on the page
// Pages which dont exist (id 0) cannot have issues // Pages which dont exist (id 0) cannot have issues
if ( !page.isMissing ) { if ( !page.isMissing ) {