Merge "Remove "report" link for logged-out users"

This commit is contained in:
jenkins-bot 2024-08-27 20:58:58 +00:00 committed by Gerrit Code Review
commit 66ca79e907

View file

@ -188,6 +188,39 @@ function appendRadioToggle( parent, featureName, value, currentValue, config, us
} ); } );
} }
/**
* @param {HTMLElement} betaMessageElement
*/
function makeFeedbackLink( betaMessageElement ) {
const pageWikiLink = `[https://${ window.location.hostname + mw.util.getUrl( mw.config.get( 'wgPageName' ) ) } ${ mw.config.get( 'wgTitle' ) }]`;
const preloadTitle = mw.message( 'vector-night-mode-issue-reporting-preload-title', pageWikiLink ).text();
const link = mw.msg( 'vector-night-mode-issue-reporting-notice-url', window.location.host, preloadTitle );
const linkLabel = mw.message( 'vector-night-mode-issue-reporting-link-label' ).text();
const anchor = document.createElement( 'a' );
anchor.setAttribute( 'href', link );
anchor.setAttribute( 'target', '_blank' );
anchor.textContent = linkLabel;
/**
* Shows the success message after clicking the beta feedback link.
* Note: event.stopPropagation(); is required to show the success message
* without closing the Appearance menu when it's in a dropdown.
*
* @param {Event} event
*/
const showSuccessFeedback = function ( event ) {
event.stopPropagation();
const icon = document.createElement( 'span' );
icon.classList.add( 'vector-icon', 'vector-icon--heart' );
anchor.textContent = mw.msg( 'vector-night-mode-issue-reporting-link-notification' );
anchor.classList.add( 'skin-theme-beta-notice-success' );
anchor.prepend( icon );
anchor.removeEventListener( 'click', showSuccessFeedback );
};
anchor.addEventListener( 'click', ( event ) => showSuccessFeedback( event ) );
betaMessageElement.appendChild( anchor );
}
/** /**
* @param {Element} form * @param {Element} form
* @param {string} featureName * @param {string} featureName
@ -350,39 +383,10 @@ function makeClientPreference( parent, featureName, config, userPreferences ) {
if ( config[ featureName ].betaMessage && !isFeatureExcluded( featureName ) ) { if ( config[ featureName ].betaMessage && !isFeatureExcluded( featureName ) ) {
const betaMessageElement = document.createElement( 'span' ); const betaMessageElement = document.createElement( 'span' );
betaMessageElement.id = `${ featureName }-beta-notice`; betaMessageElement.id = `${ featureName }-beta-notice`;
const pageWikiLink = `[https://${ window.location.hostname + mw.util.getUrl( mw.config.get( 'wgPageName' ) ) } ${ mw.config.get( 'wgTitle' ) }]`; // per requirements: only logged in users can report errors (T372754)
const preloadTitle = mw.message( 'vector-night-mode-issue-reporting-preload-title', pageWikiLink ).text();
const link = mw.msg( 'vector-night-mode-issue-reporting-notice-url', window.location.host, preloadTitle );
const linkLabel = mw.message( 'vector-night-mode-issue-reporting-link-label' ).text();
const anchor = document.createElement( 'a' );
// per requirements: only logged in users can report errors.
if ( !mw.user.isAnon() ) { if ( !mw.user.isAnon() ) {
anchor.setAttribute( 'href', link ); makeFeedbackLink( betaMessageElement );
anchor.setAttribute( 'target', '_blank' );
} else {
anchor.setAttribute( 'role', 'button' );
anchor.setAttribute( 'tabindex', '0' );
} }
anchor.textContent = linkLabel;
/**
* Shows the success message after clicking the beta feedback link.
* Note: event.stopPropagation(); is required to show the success message
* without closing the Appearance menu when it's in a dropdown.
*
* @param {Event} event
*/
const showSuccessFeedback = function ( event ) {
event.stopPropagation();
const icon = document.createElement( 'span' );
icon.classList.add( 'vector-icon', 'vector-icon--heart' );
anchor.textContent = mw.msg( 'vector-night-mode-issue-reporting-link-notification' );
anchor.classList.add( 'skin-theme-beta-notice-success' );
anchor.prepend( icon );
anchor.removeEventListener( 'click', showSuccessFeedback );
};
anchor.addEventListener( 'click', ( event ) => showSuccessFeedback( event ) );
betaMessageElement.appendChild( anchor );
row.appendChild( betaMessageElement ); row.appendChild( betaMessageElement );
} }
} }