2018-08-17 19:00:57 +00:00
|
|
|
( function ( M, mwMsg ) {
|
|
|
|
var
|
|
|
|
Overlay = M.require( 'mobile.startup/Overlay' ),
|
|
|
|
util = M.require( 'mobile.startup/util' ),
|
|
|
|
KEYWORD_ALL_SECTIONS = 'all',
|
|
|
|
NS_MAIN = 0,
|
|
|
|
NS_TALK = 1,
|
|
|
|
NS_CATEGORY = 14;
|
2018-08-16 19:00:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Overlay for displaying page issues
|
|
|
|
* @class PageIssuesOverlay
|
|
|
|
* @extends Overlay
|
|
|
|
*
|
2018-08-17 19:00:57 +00:00
|
|
|
* @param {IssueSummary[]} issues list of page issue summaries for display.
|
|
|
|
* @param {PageIssuesLogger} logger E.g., { log: console.log }.
|
|
|
|
* @param {string} section
|
|
|
|
* @param {number} namespaceID
|
2018-08-16 19:00:38 +00:00
|
|
|
*/
|
2018-08-17 19:00:57 +00:00
|
|
|
function PageIssuesOverlay( issues, logger, section, namespaceID ) {
|
|
|
|
var
|
|
|
|
options,
|
|
|
|
// Note only the main namespace is expected to make use of section issues, so the heading will
|
|
|
|
// always be minerva-meta-data-issues-section-header regardless of namespace.
|
|
|
|
headingText = section === '0' || section === KEYWORD_ALL_SECTIONS ?
|
|
|
|
getNamespaceHeadingText( namespaceID ) :
|
|
|
|
mwMsg( 'minerva-meta-data-issues-section-header' );
|
|
|
|
|
|
|
|
this.issues = issues;
|
|
|
|
this.logger = logger;
|
2018-08-23 20:57:47 +00:00
|
|
|
this.section = section;
|
2018-08-17 19:00:57 +00:00
|
|
|
|
|
|
|
options = {};
|
|
|
|
options.issues = issues;
|
2018-08-27 21:39:33 +00:00
|
|
|
|
|
|
|
// Set default logging data
|
|
|
|
this.defaultLoggerData = {};
|
|
|
|
// In the case of KEYWORD_ALL_SECTIONS all issues are in the overlay and the sectionNumbers
|
|
|
|
// field should be no different from the default behaviour.
|
|
|
|
if ( this.section !== KEYWORD_ALL_SECTIONS ) {
|
|
|
|
this.defaultLoggerData.sectionNumbers = [ this.section ];
|
|
|
|
}
|
2018-08-17 19:00:57 +00:00
|
|
|
options.heading = '<strong>' + headingText + '</strong>';
|
2018-08-16 19:00:38 +00:00
|
|
|
Overlay.call( this, options );
|
2018-08-17 19:00:57 +00:00
|
|
|
|
|
|
|
this.on( Overlay.EVENT_EXIT, this.onExit.bind( this ) );
|
2018-08-16 19:00:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OO.mfExtend( PageIssuesOverlay, Overlay, {
|
|
|
|
/**
|
|
|
|
* @memberof PageIssuesOverlay
|
|
|
|
* @instance
|
|
|
|
*/
|
|
|
|
className: 'overlay overlay-issues',
|
2018-08-17 19:00:57 +00:00
|
|
|
|
2018-08-16 19:00:38 +00:00
|
|
|
/**
|
|
|
|
* @memberof PageIssuesOverlay
|
|
|
|
* @instance
|
|
|
|
*/
|
|
|
|
events: util.extend( {}, Overlay.prototype.events, {
|
|
|
|
'click a:not(.external):not([href*=edit])': 'onInternalClick',
|
|
|
|
'click a[href*="edit"]': 'onEditClick'
|
|
|
|
} ),
|
2018-08-17 19:00:57 +00:00
|
|
|
|
2018-08-16 19:00:38 +00:00
|
|
|
/**
|
|
|
|
* @memberof PageIssuesOverlay
|
|
|
|
* @instance
|
|
|
|
*/
|
|
|
|
templatePartials: util.extend( {}, Overlay.prototype.templatePartials, {
|
|
|
|
content: mw.template.get( 'skins.minerva.scripts', 'PageIssuesOverlayContent.hogan' )
|
|
|
|
} ),
|
2018-08-17 19:00:57 +00:00
|
|
|
|
2018-08-27 21:39:33 +00:00
|
|
|
/**
|
|
|
|
* Log data via the associated logger, adding sectionNumbers to override the event default
|
|
|
|
* if applicable.
|
|
|
|
* @param {Object} data
|
|
|
|
* @instance
|
|
|
|
*/
|
|
|
|
log: function ( data ) {
|
|
|
|
this.logger.log( util.extend( {}, this.defaultLoggerData, data ) );
|
|
|
|
},
|
|
|
|
|
2018-08-17 19:00:57 +00:00
|
|
|
/**
|
|
|
|
* Note: an "on enter" state is tracked by the issueClicked log event.
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
onExit: function () {
|
2018-08-31 22:54:21 +00:00
|
|
|
var logData = {
|
|
|
|
action: 'modalClose',
|
|
|
|
issuesSeverity: this.issues.map( issueSummaryToSeverity )
|
|
|
|
},
|
|
|
|
currentSection = this.section;
|
|
|
|
// When users close the modal, `sectionNumbers` should correlate to each visible issue in
|
|
|
|
// the modal, provided that this.section is a valid number and not `KEYWORD_ALL_SECTIONS`.
|
|
|
|
if ( this.section !== KEYWORD_ALL_SECTIONS ) {
|
|
|
|
logData.sectionNumbers = this.issues.map( function () {
|
|
|
|
return currentSection;
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
this.log( logData );
|
2018-08-17 19:00:57 +00:00
|
|
|
},
|
|
|
|
|
2018-08-16 19:00:38 +00:00
|
|
|
/**
|
2018-08-17 19:00:57 +00:00
|
|
|
* Event that is triggered when an internal link inside the overlay is clicked. This event will
|
|
|
|
* not be triggered if the link contains the edit keyword, in which case onEditClick will be
|
|
|
|
* fired. This is primarily used for instrumenting page issues (see
|
|
|
|
* https://meta.wikimedia.org/wiki/Schema:PageIssues).
|
|
|
|
* @param {JQuery.Event} ev
|
2018-08-16 19:00:38 +00:00
|
|
|
* @memberof PageIssuesOverlay
|
|
|
|
* @instance
|
|
|
|
*/
|
|
|
|
onInternalClick: function ( ev ) {
|
2018-08-17 19:00:57 +00:00
|
|
|
var severity = parseSeverity( this.$( ev.target ) );
|
2018-08-27 21:39:33 +00:00
|
|
|
this.log( {
|
2018-08-17 19:00:57 +00:00
|
|
|
action: 'modalInternalClicked',
|
2018-08-27 21:39:33 +00:00
|
|
|
issuesSeverity: [ severity ]
|
2018-08-17 19:00:57 +00:00
|
|
|
} );
|
2018-08-16 19:00:38 +00:00
|
|
|
},
|
2018-08-17 19:00:57 +00:00
|
|
|
|
2018-08-16 19:00:38 +00:00
|
|
|
/**
|
2018-08-17 19:00:57 +00:00
|
|
|
* Event that is triggered when an edit link inside the overlay is clicked. This is primarily
|
|
|
|
* used for instrumenting page issues (see https://meta.wikimedia.org/wiki/Schema:PageIssues).
|
|
|
|
* @param {JQuery.Event} ev
|
2018-08-16 19:00:38 +00:00
|
|
|
* @memberof PageIssuesOverlay
|
|
|
|
* @instance
|
|
|
|
*/
|
|
|
|
onEditClick: function ( ev ) {
|
2018-08-17 19:00:57 +00:00
|
|
|
var severity = parseSeverity( this.$( ev.target ) );
|
2018-08-27 21:39:33 +00:00
|
|
|
this.log( {
|
2018-08-17 19:00:57 +00:00
|
|
|
action: 'modalEditClicked',
|
2018-08-27 21:39:33 +00:00
|
|
|
issuesSeverity: [ severity ]
|
2018-08-17 19:00:57 +00:00
|
|
|
} );
|
2018-08-16 19:00:38 +00:00
|
|
|
}
|
|
|
|
} );
|
2018-08-17 19:00:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtain severity associated with a given $target node by looking at associated parent node
|
|
|
|
* (defined by templatePartials, PageIssuesOverlayContent.hogan).
|
|
|
|
*
|
|
|
|
* @param {JQuery.Object} $target
|
|
|
|
* @return {string[]} severity as defined in associated PageIssue
|
|
|
|
*/
|
|
|
|
function parseSeverity( $target ) {
|
|
|
|
return $target.parents( '.issue-notice' ).data( 'severity' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {IssueSummary} issue
|
|
|
|
* @return {string} A PageIssue.severity.
|
|
|
|
*/
|
|
|
|
function issueSummaryToSeverity( issue ) {
|
|
|
|
return issue.severity;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtain a suitable heading for the issues overlay based on the namespace
|
|
|
|
* @param {number} namespaceID is the namespace to generate heading for
|
|
|
|
* @return {string} heading for overlay
|
|
|
|
*/
|
|
|
|
function getNamespaceHeadingText( namespaceID ) {
|
|
|
|
switch ( namespaceID ) {
|
|
|
|
case NS_CATEGORY:
|
|
|
|
return mw.msg( 'mobile-frontend-meta-data-issues-categories' );
|
|
|
|
case NS_TALK:
|
|
|
|
return mw.msg( 'mobile-frontend-meta-data-issues-talk' );
|
|
|
|
case NS_MAIN:
|
|
|
|
return mw.msg( 'mobile-frontend-meta-data-issues' );
|
|
|
|
default:
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 19:00:38 +00:00
|
|
|
M.define( 'skins.minerva.scripts/PageIssuesOverlay', PageIssuesOverlay );
|
2018-08-17 19:00:57 +00:00
|
|
|
}( mw.mobileFrontend, mw.msg ) );
|