Merge "Add showing toast/drawer when visiting protected article with editor link"

This commit is contained in:
jenkins-bot 2018-11-03 18:04:58 +00:00 committed by Gerrit Code Review
commit 9bc962e075
1 changed files with 32 additions and 13 deletions

View File

@ -22,7 +22,8 @@
isNewFile = currentPage.inNamespace( 'file' ) && isNewPage, isNewFile = currentPage.inNamespace( 'file' ) && isNewPage,
veConfig = mw.config.get( 'wgVisualEditorConfig' ), veConfig = mw.config.get( 'wgVisualEditorConfig' ),
// FIXME: Should we consider default site options and user prefs? // FIXME: Should we consider default site options and user prefs?
isVisualEditorEnabled = veConfig; isVisualEditorEnabled = veConfig,
editorPath = /^\/editor\/(\d+|all)$/;
/** /**
* Event handler for edit link clicks. Will prevent default link * Event handler for edit link clicks. Will prevent default link
@ -72,7 +73,7 @@
leadSection = page.getLeadSectionElement(); leadSection = page.getLeadSectionElement();
$allEditLinks.on( 'click', onEditLinkClick ); $allEditLinks.on( 'click', onEditLinkClick );
overlayManager.add( /^\/editor\/(\d+|all)$/, function ( sectionId ) { overlayManager.add( editorPath, function ( sectionId ) {
var var
$content = $( '#mw-content-text' ), $content = $( '#mw-content-text' ),
preferredEditor = getPreferredEditor(), preferredEditor = getPreferredEditor(),
@ -214,13 +215,36 @@
currentPage.$( '.mw-editsection' ).hide(); currentPage.$( '.mw-editsection' ).hide();
} }
/**
* Show a drawer with log in / sign up buttons.
* @method
* @ignore
*/
function showLoginDrawer() {
var drawer = new CtaDrawer( {
content: mw.msg( 'mobile-frontend-editor-disabled-anon' ),
signupQueryParams: {
warning: 'mobile-frontend-watchlist-signup-action'
}
} );
$allEditLinks.on( 'click', function ( ev ) {
drawer.show();
ev.preventDefault();
return drawer;
} );
router.route( editorPath, function () {
drawer.show();
} );
router.checkRoute();
}
/** /**
* Setup the editor if the user can edit the page otherwise show a sorry toast. * Setup the editor if the user can edit the page otherwise show a sorry toast.
* @method * @method
* @ignore * @ignore
*/ */
function init() { function init() {
var isReadOnly, isEditable, editErrorMessage, drawer, editRestrictions; var isReadOnly, isEditable, editErrorMessage, editRestrictions;
// 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' );
@ -232,16 +256,7 @@
hideSectionEditIcons(); hideSectionEditIcons();
editRestrictions = mw.config.get( 'wgRestrictionEdit' ); editRestrictions = mw.config.get( 'wgRestrictionEdit' );
if ( mw.user.isAnon() && Array.isArray( editRestrictions ) && editRestrictions.indexOf( '*' ) !== -1 ) { if ( mw.user.isAnon() && Array.isArray( editRestrictions ) && editRestrictions.indexOf( '*' ) !== -1 ) {
drawer = new CtaDrawer( { showLoginDrawer();
content: mw.msg( 'mobile-frontend-editor-disabled-anon' ),
signupQueryParams: {
warning: 'mobile-frontend-watchlist-signup-action'
}
} );
$allEditLinks.on( 'click', function ( ev ) {
drawer.show();
ev.preventDefault();
} );
} else { } else {
editErrorMessage = isReadOnly ? mw.msg( 'apierror-readonly' ) : mw.msg( 'mobile-frontend-editor-disabled' ); editErrorMessage = isReadOnly ? mw.msg( 'apierror-readonly' ) : mw.msg( 'mobile-frontend-editor-disabled' );
showSorryToast( editErrorMessage ); showSorryToast( editErrorMessage );
@ -260,6 +275,10 @@
popup.show( msg ); popup.show( msg );
ev.preventDefault(); ev.preventDefault();
} ); } );
router.route( editorPath, function () {
popup.show( msg );
} );
router.checkRoute();
} }
if ( contentModel !== 'wikitext' ) { if ( contentModel !== 'wikitext' ) {