Merge "Make Minerva use new PageHTMLParser.js and refactored Page.js"

This commit is contained in:
jenkins-bot 2019-07-15 23:12:58 +00:00 committed by Gerrit Code Review
commit 4e2458aeba
10 changed files with 66 additions and 73 deletions

View File

@ -25,7 +25,7 @@ module.exports = function () {
return categoryOverlay( { return categoryOverlay( {
api: new mw.Api(), api: new mw.Api(),
isAnon: isAnon, isAnon: isAnon,
title: M.getCurrentPage().title, title: mobile.currentPage().title,
eventBus: eventBus eventBus: eventBus
} ); } );
} ); } );
@ -40,7 +40,7 @@ module.exports = function () {
return new CategoryAddOverlay( { return new CategoryAddOverlay( {
api: new mw.Api(), api: new mw.Api(),
isAnon: isAnon, isAnon: isAnon,
title: M.getCurrentPage().title, title: mobile.currentPage().title,
eventBus: eventBus eventBus: eventBus
} ); } );
} ); } );

View File

@ -12,8 +12,9 @@
errorSamplingRate = config.get( 'wgMinervaErrorLogSamplingRate', 0 ), errorSamplingRate = config.get( 'wgMinervaErrorLogSamplingRate', 0 ),
sessionToken = user.sessionId(), sessionToken = user.sessionId(),
EVENT_CLIENT_ERROR_LOG = 'wikimedia.event.WebClientError', EVENT_CLIENT_ERROR_LOG = 'wikimedia.event.WebClientError',
page = M.getCurrentPage(), mobile = M.require( 'mobile.startup' ),
util = M.require( 'mobile.startup' ).util, currentPage = mobile.currentPage(),
util = mobile.util,
errorExperiment = { errorExperiment = {
name: 'WebClientError', name: 'WebClientError',
enabled: errorSamplingRate > 0, enabled: errorSamplingRate > 0,
@ -29,7 +30,7 @@
wgVersion: config.get( 'wgVersion' ), wgVersion: config.get( 'wgVersion' ),
mobileMode: config.get( 'wgMFMode', 'desktop' ), mobileMode: config.get( 'wgMFMode', 'desktop' ),
isAnon: user.isAnon(), isAnon: user.isAnon(),
revision: page.getRevisionId() revision: currentPage.getRevisionId()
}; };
if ( isErrorLoggingEnabled ) { if ( isErrorLoggingEnabled ) {

View File

@ -13,8 +13,9 @@
Button = mobile.Button, Button = mobile.Button,
Anchor = mobile.Anchor, Anchor = mobile.Anchor,
overlayManager = OverlayManager.getSingleton(), overlayManager = OverlayManager.getSingleton(),
page = M.getCurrentPage(), currentPage = mobile.currentPage(),
$redLinks = page.getRedLinks(), currentPageHTMLParser = mobile.currentPageHTMLParser(),
$redLinks = currentPageHTMLParser.getRedLinks(),
api = new mw.Api(), api = new mw.Api(),
eventBus = mobile.eventBusSingleton, eventBus = mobile.eventBusSingleton,
namespaceIDs = mw.config.get( 'wgNamespaceIds' ); namespaceIDs = mw.config.get( 'wgNamespaceIds' );
@ -50,7 +51,7 @@
* @param {JQuery.Object} [$container] Optional container to search within * @param {JQuery.Object} [$container] Optional container to search within
*/ */
function initMediaViewer( $container ) { function initMediaViewer( $container ) {
page.getThumbnails( $container ).forEach( function ( thumb ) { currentPageHTMLParser.getThumbnails( $container ).forEach( function ( thumb ) {
thumb.$el.off().data( 'thumb', thumb ).on( 'click', onClickImage ); thumb.$el.off().data( 'thumb', thumb ).on( 'click', onClickImage );
} ); } );
} }
@ -96,7 +97,7 @@
return mobile.mediaViewer.overlay( { return mobile.mediaViewer.overlay( {
api: api, api: api,
thumbnails: page.getThumbnails(), thumbnails: currentPageHTMLParser.getThumbnails(),
title: decodeURIComponent( title ), title: decodeURIComponent( title ),
eventBus: eventBus eventBus: eventBus
} ); } );
@ -347,8 +348,8 @@
initTabsScrollPosition(); initTabsScrollPosition();
// 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 ( !currentPage.isMissing ) {
issues.init( overlayManager, page ); issues.init( overlayManager, currentPageHTMLParser );
} }
} ); } );

View File

@ -1,7 +1,7 @@
( function ( M ) { ( function ( M ) {
/** @typedef {Object.<number | 'all', IssueSummary[]>} IssueSummaryMap */ /** @typedef {Object.<number | 'all', IssueSummary[]>} IssueSummaryMap */
var Page = M.require( 'mobile.startup' ).Page, var PageHTMLParser = M.require( 'mobile.startup' ).PageHTMLParser,
KEYWORD_ALL_SECTIONS = 'all', KEYWORD_ALL_SECTIONS = 'all',
config = mw.config, config = mw.config,
NS_MAIN = 0, NS_MAIN = 0,
@ -24,7 +24,7 @@
* will be rendered above the heading. * will be rendered above the heading.
* This function comes with side effects. It will populate a global "allIssues" object which * This function comes with side effects. It will populate a global "allIssues" object which
* will link section numbers to issues. * will link section numbers to issues.
* @param {Page} page to search for page issues inside * @param {PageHTMLParser} pageHTMLParser parser to search for page issues
* @param {string} labelText what the label of the page issues banner should say * @param {string} labelText what the label of the page issues banner should say
* @param {string} section that the banner and its issues belong to. * @param {string} section that the banner and its issues belong to.
* If string KEYWORD_ALL_SECTIONS banner should apply to entire page. * If string KEYWORD_ALL_SECTIONS banner should apply to entire page.
@ -36,7 +36,7 @@
* *
* @return {{ambox: JQuery.Object, issueSummaries: IssueSummary[]}} * @return {{ambox: JQuery.Object, issueSummaries: IssueSummary[]}}
*/ */
function insertBannersOrNotice( page, labelText, section, inline, overlayManager ) { function insertBannersOrNotice( pageHTMLParser, labelText, section, inline, overlayManager ) {
var var
$metadata, $metadata,
issueUrl = section === KEYWORD_ALL_SECTIONS ? '#/issues/' + KEYWORD_ALL_SECTIONS : '#/issues/' + section, issueUrl = section === KEYWORD_ALL_SECTIONS ? '#/issues/' + KEYWORD_ALL_SECTIONS : '#/issues/' + section,
@ -44,10 +44,10 @@
issueSummaries = []; issueSummaries = [];
if ( section === KEYWORD_ALL_SECTIONS ) { if ( section === KEYWORD_ALL_SECTIONS ) {
$metadata = page.$el.find( selector ); $metadata = pageHTMLParser.$el.find( selector );
} else { } else {
// find heading associated with the section // find heading associated with the section
$metadata = page.findChildInSectionLead( parseInt( section, 10 ), selector ); $metadata = pageHTMLParser.findChildInSectionLead( parseInt( section, 10 ), selector );
} }
// clean it up a little // clean it up a little
$metadata.find( '.NavFrame' ).remove(); $metadata.find( '.NavFrame' ).remove();
@ -118,9 +118,9 @@
* that opens them in a mobile friendly overlay. * that opens them in a mobile friendly overlay.
* @ignore * @ignore
* @param {OverlayManager} overlayManager * @param {OverlayManager} overlayManager
* @param {Page} page * @param {PageHTMLParser} pageHTMLParser
*/ */
function initPageIssues( overlayManager, page ) { function initPageIssues( overlayManager, pageHTMLParser ) {
var var
section, section,
/** @type {IssueSummary[]} */ /** @type {IssueSummary[]} */
@ -128,7 +128,7 @@
/** @type {IssueSummaryMap} */ /** @type {IssueSummaryMap} */
allIssues = {}, allIssues = {},
label, label,
$lead = page.getLeadSectionElement(), $lead = pageHTMLParser.getLeadSectionElement(),
issueOverlayShowAll = CURRENT_NS === NS_CATEGORY || CURRENT_NS === NS_TALK || !$lead, issueOverlayShowAll = CURRENT_NS === NS_CATEGORY || CURRENT_NS === NS_TALK || !$lead,
inline = newTreatmentEnabled && CURRENT_NS === 0; inline = newTreatmentEnabled && CURRENT_NS === 0;
@ -142,7 +142,7 @@
if ( CURRENT_NS === NS_TALK || CURRENT_NS === NS_CATEGORY ) { if ( CURRENT_NS === NS_TALK || CURRENT_NS === NS_CATEGORY ) {
section = KEYWORD_ALL_SECTIONS; section = KEYWORD_ALL_SECTIONS;
// e.g. Template:English variant category; Template:WikiProject // e.g. Template:English variant category; Template:WikiProject
issueSummaries = insertBannersOrNotice( page, mw.msg( 'mobile-frontend-meta-data-issues-header-talk' ), issueSummaries = insertBannersOrNotice( pageHTMLParser, mw.msg( 'mobile-frontend-meta-data-issues-header-talk' ),
section, inline, overlayManager ).issueSummaries; section, inline, overlayManager ).issueSummaries;
allIssues[ section ] = issueSummaries; allIssues[ section ] = issueSummaries;
} else if ( CURRENT_NS === NS_MAIN ) { } else if ( CURRENT_NS === NS_MAIN ) {
@ -150,35 +150,38 @@
if ( issueOverlayShowAll ) { if ( issueOverlayShowAll ) {
section = KEYWORD_ALL_SECTIONS; section = KEYWORD_ALL_SECTIONS;
issueSummaries = insertBannersOrNotice( issueSummaries = insertBannersOrNotice(
page, label, section, inline, overlayManager pageHTMLParser, label, section, inline, overlayManager
).issueSummaries; ).issueSummaries;
allIssues[ section ] = issueSummaries; allIssues[ section ] = issueSummaries;
} else { } else {
// parse lead // parse lead
section = '0'; section = '0';
issueSummaries = insertBannersOrNotice( issueSummaries = insertBannersOrNotice(
page, label, section, inline, overlayManager pageHTMLParser, label, section, inline, overlayManager
).issueSummaries; ).issueSummaries;
allIssues[ section ] = issueSummaries; allIssues[ section ] = issueSummaries;
if ( newTreatmentEnabled ) { if ( newTreatmentEnabled ) {
// parse other sections but only in group B. In treatment A no issues are shown // parse other sections but only in group B. In treatment A no issues are shown
// for sections. // for sections.
page.$el.find( Page.HEADING_SELECTOR ).each( function ( i, headingEl ) { pageHTMLParser.$el.find( PageHTMLParser.HEADING_SELECTOR ).each(
var $headingEl = $( headingEl ), function ( i, headingEl ) {
sectionNum = $headingEl.find( '.edit-page' ).data( 'section' ); var $headingEl = $( headingEl ),
sectionNum = $headingEl.find( '.edit-page' ).data( 'section' );
// Note certain headings matched using Page.HEADING_SELECTOR may not be // Note certain headings matched using
// headings and will not have a edit link. E.g. table of contents. // PageHTMLParser.HEADING_SELECTOR may not be headings and will
if ( sectionNum ) { // not have a edit link. E.g. table of contents.
// Render banner for sectionNum associated with headingEl inside if ( sectionNum ) {
// Page // Render banner for sectionNum associated with headingEl inside
section = sectionNum.toString(); // Page
issueSummaries = insertBannersOrNotice( section = sectionNum.toString();
page, label, section, inline, overlayManager issueSummaries = insertBannersOrNotice(
).issueSummaries; pageHTMLParser, label, section, inline, overlayManager
allIssues[ section ] = issueSummaries; ).issueSummaries;
allIssues[ section ] = issueSummaries;
}
} }
} ); );
} }
} }
} }

View File

@ -1,9 +1,9 @@
( function ( M ) { ( function ( M ) {
var drawer, var drawer,
skin = M.require( 'skins.minerva.scripts/skin' ),
page = M.getCurrentPage(),
router = require( 'mediawiki.router' ), router = require( 'mediawiki.router' ),
mobile = M.require( 'mobile.startup' ), mobile = M.require( 'mobile.startup' ),
currentPage = mobile.currentPage(),
currentPageHTMLParser = mobile.currentPageHTMLParser(),
ReferencesGateway = mobile.ReferencesGateway, ReferencesGateway = mobile.ReferencesGateway,
ReferencesMobileViewGateway = mobile.ReferencesMobileViewGateway, ReferencesMobileViewGateway = mobile.ReferencesMobileViewGateway,
referencesMobileViewGateway = ReferencesMobileViewGateway.getSingleton(), referencesMobileViewGateway = ReferencesMobileViewGateway.getSingleton(),
@ -36,9 +36,8 @@
* @ignore * @ignore
* @param {JQuery.Event} ev Click event of the reference element * @param {JQuery.Event} ev Click event of the reference element
* @param {ReferencesDrawer} drawer to show the reference in * @param {ReferencesDrawer} drawer to show the reference in
* @param {Page} page
*/ */
function showReference( ev, drawer, page ) { function showReference( ev, drawer ) {
var urlComponents, result, var urlComponents, result,
$dest = $( ev.currentTarget ), $dest = $( ev.currentTarget ),
href = $dest.attr( 'href' ); href = $dest.attr( 'href' );
@ -51,7 +50,7 @@
if ( urlComponents.length > 1 ) { if ( urlComponents.length > 1 ) {
href = '#' + urlComponents[ 1 ]; href = '#' + urlComponents[ 1 ];
} }
result = drawer.showReference( href, page, $dest.text() ); result = drawer.showReference( href, currentPage, $dest.text(), currentPageHTMLParser );
// Previously showReference method returns nothing so we check its truthy // Previously showReference method returns nothing so we check its truthy
// Can be removed when I5a7b23f60722eb5017a85c68f38844dd460f8b63 is merged. // Can be removed when I5a7b23f60722eb5017a85c68f38844dd460f8b63 is merged.
if ( result ) { if ( result ) {
@ -85,29 +84,13 @@
if ( !drawer ) { if ( !drawer ) {
drawer = referenceDrawerFactory(); drawer = referenceDrawerFactory();
} }
showReference( ev, drawer, ev.data.page ); showReference( ev, drawer );
} }
/** function init() {
* Make references clickable and show a drawer when clicked on. // Make references clickable and show a drawer when clicked on.
* @ignore mobile.util.getDocument().on( 'click', 'sup.reference a', onClickReference );
* @param {Page} page
*/
function setup( page ) {
var $refs = page.$el.find( 'sup.reference a' );
if ( $refs.length ) {
$refs
.off( 'click.references' )
.on( 'click.references', {
page: page
}, onClickReference );
}
} }
setup( page ); init();
// When references are lazy loaded you'll want to take care of nested references
skin.on( 'references-loaded', function ( page ) {
setup( page );
} );
}( mw.mobileFrontend ) ); }( mw.mobileFrontend ) );

View File

@ -1,5 +1,6 @@
( function ( M ) { ( function ( M ) {
var mobile = M.require( 'mobile.startup' ), var mobile = M.require( 'mobile.startup' ),
currentPage = mobile.currentPage(),
Toggler = mobile.Toggler, Toggler = mobile.Toggler,
TableOfContents = mobile.toc.TableOfContents, TableOfContents = mobile.toc.TableOfContents,
eventBus = mobile.eventBusSingleton, eventBus = mobile.eventBusSingleton,
@ -40,7 +41,7 @@
// add a ToC only for "view" action (user is reading a page) // add a ToC only for "view" action (user is reading a page)
// provided a table of contents placeholder has been rendered // provided a table of contents placeholder has been rendered
if ( mw.config.get( 'wgAction' ) === 'view' && $toc.length > 0 ) { if ( mw.config.get( 'wgAction' ) === 'view' && $toc.length > 0 ) {
init( M.getCurrentPage() ); init( currentPage );
} }
}( mw.mobileFrontend ) ); }( mw.mobileFrontend ) );

View File

@ -49,9 +49,9 @@
talkOptions = { talkOptions = {
api: api, api: api,
title: title, title: title,
// T184273 using `getCurrentPage` because 'wgPageName' // T184273 using `currentPage` because 'wgPageName'
// contains underscores instead of spaces. // contains underscores instead of spaces.
currentPageTitle: M.getCurrentPage().title, currentPageTitle: mobile.currentPage().title,
licenseMsg: skin.getLicenseMsg(), licenseMsg: skin.getLicenseMsg(),
eventBus: eventBus, eventBus: eventBus,
id: id id: id

View File

@ -1,13 +1,14 @@
( function ( M ) { ( function ( M ) {
var var
page = M.getCurrentPage(),
// eslint-disable-next-line no-jquery/no-global-selector // eslint-disable-next-line no-jquery/no-global-selector
$contentContainer = $( '#mw-content-text > .mw-parser-output' ), $contentContainer = $( '#mw-content-text > .mw-parser-output' ),
mobile = M.require( 'mobile.startup' ), mobile = M.require( 'mobile.startup' ),
currentPage = mobile.currentPage(),
currentPageHTMLParser = mobile.currentPageHTMLParser(),
Toggler = mobile.Toggler, Toggler = mobile.Toggler,
eventBus = mobile.eventBusSingleton; eventBus = mobile.eventBusSingleton;
if ( !page.getLeadSectionElement() ) { if ( !currentPageHTMLParser.getLeadSectionElement() ) {
// Operating in desktop Minerva mode. Stop execution. (T172948) // Operating in desktop Minerva mode. Stop execution. (T172948)
return; return;
} }
@ -46,9 +47,9 @@
// avoid this running on Watchlist // avoid this running on Watchlist
if ( if (
!page.inNamespace( 'special' ) && !currentPage.inNamespace( 'special' ) &&
mw.config.get( 'wgAction' ) === 'view' mw.config.get( 'wgAction' ) === 'view'
) { ) {
init( $contentContainer, 'content-', page ); init( $contentContainer, 'content-', currentPage );
} }
}( mw.mobileFrontend ) ); }( mw.mobileFrontend ) );

View File

@ -1,6 +1,9 @@
( function ( M ) { ( function ( M ) {
var Watchstar = M.require( 'mobile.startup' ).Watchstar, var
mobile = M.require( 'mobile.startup' ),
currentPage = mobile.currentPage(),
Watchstar = mobile.Watchstar,
user = mw.user; user = mw.user;
/** /**
@ -24,6 +27,6 @@
} ); } );
} }
} }
init( M.getCurrentPage() ); init( currentPage );
}( mw.mobileFrontend ) ); }( mw.mobileFrontend ) );

View File

@ -4,7 +4,7 @@
pageIssues = M.require( 'skins.minerva.scripts/pageIssues' ), pageIssues = M.require( 'skins.minerva.scripts/pageIssues' ),
insertBannersOrNotice = pageIssues.test.insertBannersOrNotice, insertBannersOrNotice = pageIssues.test.insertBannersOrNotice,
OverlayManager = mobile.OverlayManager, OverlayManager = mobile.OverlayManager,
Page = mobile.Page, PageHTMLParser = mobile.PageHTMLParser,
overlayManager = OverlayManager.getSingleton(), overlayManager = OverlayManager.getSingleton(),
$mockContainer = $( $mockContainer = $(
'<div id=\'bodyContent\'>' + '<div id=\'bodyContent\'>' +
@ -19,7 +19,7 @@
inline = true, inline = true,
SECTION = '0', SECTION = '0',
processedAmbox = insertBannersOrNotice( processedAmbox = insertBannersOrNotice(
new Page( { el: $mockContainer } ), new PageHTMLParser( $mockContainer ),
labelText, SECTION, inline, overlayManager labelText, SECTION, inline, overlayManager
).ambox; ).ambox;