2019-04-04 21:20:39 +00:00
|
|
|
( function ( M ) {
|
2017-10-27 17:09:46 +00:00
|
|
|
var
|
2019-02-07 16:34:18 +00:00
|
|
|
mobile = M.require( 'mobile.startup' ),
|
2019-02-08 19:29:14 +00:00
|
|
|
PageGateway = mobile.PageGateway,
|
2019-09-18 23:07:21 +00:00
|
|
|
permissions = mw.config.get( 'wgMinervaPermissions' ) || {},
|
2019-02-07 16:34:18 +00:00
|
|
|
toast = mobile.toast,
|
2019-08-30 00:02:35 +00:00
|
|
|
Icon = mobile.Icon,
|
2019-02-07 16:34:18 +00:00
|
|
|
time = mobile.time,
|
2019-07-16 21:41:37 +00:00
|
|
|
errorLogging = require( './errorLogging.js' ),
|
2019-07-02 21:10:10 +00:00
|
|
|
preInit = require( './preInit.js' ),
|
|
|
|
mobileRedirect = require( './mobileRedirect.js' ),
|
|
|
|
search = require( './search.js' ),
|
|
|
|
references = require( './references.js' ),
|
|
|
|
TitleUtil = require( './TitleUtil.js' ),
|
|
|
|
issues = require( './page-issues/index.js' ),
|
|
|
|
Toolbar = require( './Toolbar.js' ),
|
[UI] [new] add user menu
Add new user menu. The changes required include:
- Break up AuthMenuEntry into reusable components. They're now simple,
independent, static functions in AuthUtil that are easy to reason
about and compose.
There's lots of verbose code because of the builder and director
patterns. That is, most of the code is for building the thing we
actually want to build instead of just building it. It's easy to write
but no fun to read--even simple configurations are extremely verbose
expressions that must be threaded through the system.
These builders are also single purpose and unlikely to be reusable
unlike a URI builder, for example. As objects, they're not especially
composable either.
- Similarly, break up Menu/DefaultBuilder into BuilderUtil and ban
inheritance. Inheritance has not worked well on the frontend of
MobileFrontend. I don't think it's going to work well here. E.g., I
could have made changes to the base class' getPersonalTools() method
such that the client passes a parameter for the advanced config or
maybe I just override it in the subclass. In either case, I think it
makes the whole hierarchy nuanced and harder to reason about for
something that should be simple.
- Add ProfileMenuEntry and LogOutMenuEntry for the user menu.
- Rename insertLogInOutMenuItem() to insertAuthMenuItem() which matches
the entry name, AuthMenuEntry.
- Extension:SandboxLink is needed to display the sandbox link in the
user menu.
- Performance note: the toolbar is now processed in MinervaTemplate,
which corresponds to removing the buildPersonalUrls() override.
- To mimic the design of main menu, the following steps would be
necessary:
1. Create a user/Default and user/Advanced user menu builder and also
a user/IBuilder interface.
2. Create a user/Director.
3. Create a service entry for Minerva.Menu.UserDirector in
ServiceWiring. The Director is actually powerless and doesn't get
to make any decisions--the appropriate builder is passed in from
ServiceWiring which checks the mode.
4. Access the service in SkinMinerva to set a userMenuHTML data member
on the Minerva QuickTemplate.
5. In MinervaTemplate, access the userMenuHTML QuickTemplate member
and do the usual song and dance of inflating a Mustache template.
This patch does everything except add a service, which was agreed to
be unnecessary, so that logic is now in SkinMinerva.
- Wrap the existing echo user notifications button and new user menu
button in a nav element. This seems like a semantic improvement.
- The existing styling and logic for the search bar and search overlay
are pretty messy and delicate. Changes made to that LESS endeavored to
be surgical. There's lots of room for improvement in the toolbar but
it's out of scope.
- Rename logout icon to logOut.
Bug: T214540
Change-Id: Ib517864fcf4e4d611e05525a6358ee6662fe4e05
2019-06-25 20:12:58 +00:00
|
|
|
ToggleList = require( '../../components/ToggleList/ToggleList.js' ),
|
2019-06-25 01:10:51 +00:00
|
|
|
TabScroll = require( './TabScroll.js' ),
|
2017-07-12 15:12:40 +00:00
|
|
|
router = require( 'mediawiki.router' ),
|
2019-09-19 21:19:07 +00:00
|
|
|
ctaDrawers = require( './ctaDrawers.js' ),
|
2019-07-19 19:13:57 +00:00
|
|
|
desktopMMV = mw.loader.getState( 'mmv.bootstrap' ),
|
2019-09-06 20:32:01 +00:00
|
|
|
overlayManager = mobile.OverlayManager.getSingleton(),
|
2019-07-11 00:56:04 +00:00
|
|
|
currentPage = mobile.currentPage(),
|
|
|
|
currentPageHTMLParser = mobile.currentPageHTMLParser(),
|
|
|
|
$redLinks = currentPageHTMLParser.getRedLinks(),
|
2018-07-26 10:47:05 +00:00
|
|
|
api = new mw.Api(),
|
2019-03-04 22:19:33 +00:00
|
|
|
eventBus = mobile.eventBusSingleton,
|
|
|
|
namespaceIDs = mw.config.get( 'wgNamespaceIds' );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler for clicking on an image thumbnail
|
2018-07-03 14:50:09 +00:00
|
|
|
* @param {JQuery.Event} ev
|
2017-07-12 15:12:40 +00:00
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
function onClickImage( ev ) {
|
2018-11-19 20:00:47 +00:00
|
|
|
// Do not interfere with non-left clicks or if modifier keys are pressed.
|
|
|
|
if ( ( ev.button !== 0 && ev.which !== 1 ) ||
|
|
|
|
ev.altKey || ev.ctrlKey || ev.shiftKey || ev.metaKey ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
ev.preventDefault();
|
2018-03-05 20:42:00 +00:00
|
|
|
routeThumbnail( $( this ).data( 'thumb' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-03 14:50:09 +00:00
|
|
|
* @param {JQuery.Element} thumbnail
|
2018-03-05 20:42:00 +00:00
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
function routeThumbnail( thumbnail ) {
|
|
|
|
router.navigate( '#/media/' + encodeURIComponent( thumbnail.getFileName() ) );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add routes to images and handle clicks
|
|
|
|
* @method
|
|
|
|
* @ignore
|
2019-04-19 17:36:50 +00:00
|
|
|
* @param {JQuery.Object} [$container] Optional container to search within
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
2019-04-19 17:36:50 +00:00
|
|
|
function initMediaViewer( $container ) {
|
2019-07-11 00:56:04 +00:00
|
|
|
currentPageHTMLParser.getThumbnails( $container ).forEach( function ( thumb ) {
|
2017-07-12 15:12:40 +00:00
|
|
|
thumb.$el.off().data( 'thumb', thumb ).on( 'click', onClickImage );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-22 17:59:56 +00:00
|
|
|
* Hijack the Special:Languages link and replace it with a trigger to a languageOverlay
|
2017-07-12 15:12:40 +00:00
|
|
|
* that displays the same data
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
function initButton() {
|
|
|
|
// This catches language selectors in page actions and in secondary actions (e.g. Main Page)
|
2019-04-03 23:32:18 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2017-07-12 15:12:40 +00:00
|
|
|
var $primaryBtn = $( '.language-selector' );
|
|
|
|
|
|
|
|
if ( $primaryBtn.length ) {
|
|
|
|
// We only bind the click event to the first language switcher in page
|
|
|
|
$primaryBtn.on( 'click', function ( ev ) {
|
|
|
|
ev.preventDefault();
|
|
|
|
|
|
|
|
if ( $primaryBtn.attr( 'href' ) || $primaryBtn.find( 'a' ).length ) {
|
|
|
|
router.navigate( '/languages' );
|
|
|
|
} else {
|
|
|
|
toast.show( mw.msg( 'mobile-frontend-languages-not-available' ) );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-26 10:47:05 +00:00
|
|
|
/**
|
2019-03-25 20:08:54 +00:00
|
|
|
* Returns a rejected promise if MultimediaViewer is available. Otherwise
|
|
|
|
* returns the mediaViewerOverlay
|
2018-07-26 10:47:05 +00:00
|
|
|
* @method
|
|
|
|
* @ignore
|
2019-03-25 20:08:54 +00:00
|
|
|
* @param {string} title the title of the image
|
|
|
|
* @return {JQuery.Deferred|Overlay}
|
2018-07-26 10:47:05 +00:00
|
|
|
*/
|
2019-03-25 20:08:54 +00:00
|
|
|
function makeMediaViewerOverlayIfNeeded( title ) {
|
2017-07-19 23:08:24 +00:00
|
|
|
if ( mw.loader.getState( 'mmv.bootstrap' ) === 'ready' ) {
|
|
|
|
// This means MultimediaViewer has been installed and is loaded.
|
|
|
|
// Avoid loading it (T169622)
|
|
|
|
return $.Deferred().reject();
|
2018-08-31 22:48:34 +00:00
|
|
|
}
|
2019-03-25 20:08:54 +00:00
|
|
|
|
|
|
|
return mobile.mediaViewer.overlay( {
|
|
|
|
api: api,
|
2019-07-11 00:56:04 +00:00
|
|
|
thumbnails: currentPageHTMLParser.getThumbnails(),
|
2019-03-25 20:08:54 +00:00
|
|
|
title: decodeURIComponent( title ),
|
|
|
|
eventBus: eventBus
|
2018-08-31 22:48:34 +00:00
|
|
|
} );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Routes
|
2019-03-25 20:08:54 +00:00
|
|
|
overlayManager.add( /^\/media\/(.+)$/, makeMediaViewerOverlayIfNeeded );
|
2017-07-12 15:12:40 +00:00
|
|
|
overlayManager.add( /^\/languages$/, function () {
|
2019-02-14 16:39:37 +00:00
|
|
|
return mobile.languageOverlay( new PageGateway( api ) );
|
2017-07-12 15:12:40 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
// Setup
|
|
|
|
$( function () {
|
|
|
|
initButton();
|
|
|
|
} );
|
|
|
|
|
2019-07-19 19:13:57 +00:00
|
|
|
// If the MMV module is missing or disabled from the page, initialise our version
|
|
|
|
if ( desktopMMV === null || desktopMMV === 'registered' ) {
|
|
|
|
mw.hook( 'wikipage.content' ).add( initMediaViewer );
|
|
|
|
}
|
2019-04-19 17:36:50 +00:00
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
/**
|
|
|
|
* Initialisation function for last modified module.
|
|
|
|
*
|
|
|
|
* Enhances an element representing a time
|
|
|
|
* to show a human friendly date in seconds, minutes, hours, days
|
|
|
|
* months or years
|
|
|
|
* @ignore
|
2019-09-18 03:07:48 +00:00
|
|
|
* @param {JQuery.Object} $lastModifiedLink
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
function initHistoryLink( $lastModifiedLink ) {
|
2019-10-31 21:36:43 +00:00
|
|
|
var delta, historyUrl, $msg, $bar,
|
2017-07-12 15:12:40 +00:00
|
|
|
ts, username, gender;
|
|
|
|
|
|
|
|
historyUrl = $lastModifiedLink.attr( 'href' );
|
|
|
|
ts = $lastModifiedLink.data( 'timestamp' );
|
|
|
|
username = $lastModifiedLink.data( 'user-name' ) || false;
|
|
|
|
gender = $lastModifiedLink.data( 'user-gender' );
|
|
|
|
|
|
|
|
if ( ts ) {
|
|
|
|
delta = time.getTimeAgoDelta( parseInt( ts, 10 ) );
|
|
|
|
if ( time.isRecent( delta ) ) {
|
|
|
|
$bar = $lastModifiedLink.closest( '.last-modified-bar' );
|
|
|
|
$bar.addClass( 'active' );
|
2019-03-21 14:50:23 +00:00
|
|
|
$bar.find( '.mw-ui-icon-minerva-clock' ).addClass( 'mw-ui-icon-minerva-clock-invert' );
|
2019-09-06 19:13:20 +00:00
|
|
|
$bar.find( '.mw-ui-icon-mf-expand-gray' ).addClass( 'mw-ui-icon-mf-expand-invert' );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
2019-10-31 21:36:43 +00:00
|
|
|
$msg = $( '<span>' ).addClass( 'last-modified-bar__text' ).html(
|
2019-08-30 17:23:55 +00:00
|
|
|
time.getLastModifiedMessage( ts, username, gender, historyUrl )
|
|
|
|
);
|
2019-10-31 21:36:43 +00:00
|
|
|
$lastModifiedLink.replaceWith( $msg );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-18 03:07:48 +00:00
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
* @param {JQuery.Event} ev
|
|
|
|
*/
|
|
|
|
function amcHistoryClickHandler( ev ) {
|
|
|
|
var
|
|
|
|
self = this,
|
|
|
|
amcOutreach = mobile.amcOutreach,
|
|
|
|
amcCampaign = amcOutreach.loadCampaign(),
|
|
|
|
onDismiss = function () {
|
|
|
|
toast.showOnPageReload( mw.message( 'mobile-frontend-amc-outreach-dismissed-message' ).text() );
|
|
|
|
window.location = self.href;
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( amcCampaign.showIfEligible( amcOutreach.ACTIONS.onHistoryLink, onDismiss, currentPage.title, 'action=history' ) ) {
|
|
|
|
ev.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
* @param {JQuery.Object} $lastModifiedLink
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
function initAmcHistoryLink( $lastModifiedLink ) {
|
|
|
|
$lastModifiedLink.one( 'click', amcHistoryClickHandler );
|
|
|
|
}
|
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
/**
|
|
|
|
* Initialisation function for last modified times
|
|
|
|
*
|
|
|
|
* Enhances .modified-enhancement element
|
|
|
|
* to show a human friendly date in seconds, minutes, hours, days
|
|
|
|
* months or years
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
function initModifiedInfo() {
|
2019-04-03 23:32:18 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2017-07-12 15:12:40 +00:00
|
|
|
$( '.modified-enhancement' ).each( function () {
|
|
|
|
initHistoryLink( $( this ) );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialisation function for user creation module.
|
|
|
|
*
|
|
|
|
* Enhances an element representing a time
|
|
|
|
+ to show a human friendly date in seconds, minutes, hours, days
|
|
|
|
* months or years
|
|
|
|
* @ignore
|
|
|
|
* @param {JQuery.Object} [$tagline]
|
|
|
|
*/
|
|
|
|
function initRegistrationDate( $tagline ) {
|
|
|
|
var msg, ts;
|
|
|
|
|
|
|
|
ts = $tagline.data( 'userpage-registration-date' );
|
|
|
|
|
|
|
|
if ( ts ) {
|
|
|
|
msg = time.getRegistrationMessage( ts, $tagline.data( 'userpage-gender' ) );
|
|
|
|
$tagline.text( msg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialisation function for registration date on user page
|
|
|
|
*
|
|
|
|
* Enhances .tagline-userpage element
|
|
|
|
* to show human friendly date in seconds, minutes, hours, days
|
|
|
|
* months or years
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
function initRegistrationInfo() {
|
2019-04-03 23:32:18 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2017-07-12 15:12:40 +00:00
|
|
|
$( '#tagline-userpage' ).each( function () {
|
|
|
|
initRegistrationDate( $( this ) );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2019-03-04 22:19:33 +00:00
|
|
|
/**
|
|
|
|
* Tests a URL to determine if it links to a local User namespace page or not.
|
|
|
|
*
|
|
|
|
* Assuming the current page visited is hosted on metawiki, the following examples would return
|
|
|
|
* true:
|
|
|
|
*
|
|
|
|
* https://meta.wikimedia.org/wiki/User:Foo
|
|
|
|
* /wiki/User:Foo
|
|
|
|
* /wiki/User:Nonexistent_user_page
|
|
|
|
*
|
|
|
|
* The following examples return false:
|
|
|
|
*
|
|
|
|
* https://en.wikipedia.org/wiki/User:Foo
|
|
|
|
* /wiki/Foo
|
|
|
|
* /wiki/User_talk:Foo
|
|
|
|
*
|
|
|
|
* @param {string} url
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
function isUserUri( url ) {
|
|
|
|
var
|
|
|
|
title = TitleUtil.newFromUri( url ),
|
|
|
|
namespace = title ? title.getNamespaceId() : undefined;
|
|
|
|
return namespace === namespaceIDs.user;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Strip the edit action from red links to nonexistent User namespace pages.
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
function initUserRedLinks() {
|
2019-06-12 20:29:49 +00:00
|
|
|
$redLinks.filter( function ( _, element ) {
|
2019-03-04 22:19:33 +00:00
|
|
|
// Filter out non-User namespace pages.
|
|
|
|
return isUserUri( element.href );
|
|
|
|
} ).each( function ( _, element ) {
|
|
|
|
var uri = new mw.Uri( element.href );
|
|
|
|
if ( uri.query.action !== 'edit' ) {
|
|
|
|
// Nothing to strip.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Strip the action.
|
|
|
|
delete uri.query.action;
|
|
|
|
|
|
|
|
// Update the element with the new link.
|
|
|
|
element.href = uri.toString();
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2018-01-12 17:45:39 +00:00
|
|
|
$( function () {
|
2019-08-30 00:02:35 +00:00
|
|
|
var
|
2019-09-19 21:19:07 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
|
|
|
$watch = $( '#page-actions-watch' ),
|
[UI] [new] add user menu
Add new user menu. The changes required include:
- Break up AuthMenuEntry into reusable components. They're now simple,
independent, static functions in AuthUtil that are easy to reason
about and compose.
There's lots of verbose code because of the builder and director
patterns. That is, most of the code is for building the thing we
actually want to build instead of just building it. It's easy to write
but no fun to read--even simple configurations are extremely verbose
expressions that must be threaded through the system.
These builders are also single purpose and unlikely to be reusable
unlike a URI builder, for example. As objects, they're not especially
composable either.
- Similarly, break up Menu/DefaultBuilder into BuilderUtil and ban
inheritance. Inheritance has not worked well on the frontend of
MobileFrontend. I don't think it's going to work well here. E.g., I
could have made changes to the base class' getPersonalTools() method
such that the client passes a parameter for the advanced config or
maybe I just override it in the subclass. In either case, I think it
makes the whole hierarchy nuanced and harder to reason about for
something that should be simple.
- Add ProfileMenuEntry and LogOutMenuEntry for the user menu.
- Rename insertLogInOutMenuItem() to insertAuthMenuItem() which matches
the entry name, AuthMenuEntry.
- Extension:SandboxLink is needed to display the sandbox link in the
user menu.
- Performance note: the toolbar is now processed in MinervaTemplate,
which corresponds to removing the buildPersonalUrls() override.
- To mimic the design of main menu, the following steps would be
necessary:
1. Create a user/Default and user/Advanced user menu builder and also
a user/IBuilder interface.
2. Create a user/Director.
3. Create a service entry for Minerva.Menu.UserDirector in
ServiceWiring. The Director is actually powerless and doesn't get
to make any decisions--the appropriate builder is passed in from
ServiceWiring which checks the mode.
4. Access the service in SkinMinerva to set a userMenuHTML data member
on the Minerva QuickTemplate.
5. In MinervaTemplate, access the userMenuHTML QuickTemplate member
and do the usual song and dance of inflating a Mustache template.
This patch does everything except add a service, which was agreed to
be unnecessary, so that logic is now in SkinMinerva.
- Wrap the existing echo user notifications button and new user menu
button in a nav element. This seems like a semantic improvement.
- The existing styling and logic for the search bar and search overlay
are pretty messy and delicate. Changes made to that LESS endeavored to
be surgical. There's lots of room for improvement in the toolbar but
it's out of scope.
- Rename logout icon to logOut.
Bug: T214540
Change-Id: Ib517864fcf4e4d611e05525a6358ee6662fe4e05
2019-06-25 20:12:58 +00:00
|
|
|
toolbarElement = document.querySelector( Toolbar.selector ),
|
|
|
|
userMenu = document.querySelector( '.minerva-user-menu' ); // See UserMenuDirector.
|
2019-07-02 21:10:10 +00:00
|
|
|
// Init:
|
|
|
|
// - main menu closes when you click outside of it
|
|
|
|
// - redirects show a toast.
|
|
|
|
preInit();
|
|
|
|
// - references
|
|
|
|
references();
|
|
|
|
// - search
|
|
|
|
search();
|
|
|
|
// - mobile redirect
|
2019-09-18 03:07:48 +00:00
|
|
|
mobileRedirect( mobile.amcOutreach, currentPage );
|
2018-01-12 17:45:39 +00:00
|
|
|
// Update anything else that needs enhancing (e.g. watchlist)
|
|
|
|
initModifiedInfo();
|
|
|
|
initRegistrationInfo();
|
2019-04-03 23:32:18 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2019-09-26 11:27:39 +00:00
|
|
|
initHistoryLink( $( 'a.last-modified-bar__text' ) );
|
2019-09-18 03:07:48 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
|
|
|
initAmcHistoryLink( $( '.last-modified-bar__text a' ) );
|
2019-04-04 21:20:39 +00:00
|
|
|
if ( toolbarElement ) {
|
2019-07-31 17:36:19 +00:00
|
|
|
Toolbar.bind( window, toolbarElement );
|
2019-04-04 21:20:39 +00:00
|
|
|
Toolbar.render( window, toolbarElement );
|
|
|
|
}
|
[UI] [new] add user menu
Add new user menu. The changes required include:
- Break up AuthMenuEntry into reusable components. They're now simple,
independent, static functions in AuthUtil that are easy to reason
about and compose.
There's lots of verbose code because of the builder and director
patterns. That is, most of the code is for building the thing we
actually want to build instead of just building it. It's easy to write
but no fun to read--even simple configurations are extremely verbose
expressions that must be threaded through the system.
These builders are also single purpose and unlikely to be reusable
unlike a URI builder, for example. As objects, they're not especially
composable either.
- Similarly, break up Menu/DefaultBuilder into BuilderUtil and ban
inheritance. Inheritance has not worked well on the frontend of
MobileFrontend. I don't think it's going to work well here. E.g., I
could have made changes to the base class' getPersonalTools() method
such that the client passes a parameter for the advanced config or
maybe I just override it in the subclass. In either case, I think it
makes the whole hierarchy nuanced and harder to reason about for
something that should be simple.
- Add ProfileMenuEntry and LogOutMenuEntry for the user menu.
- Rename insertLogInOutMenuItem() to insertAuthMenuItem() which matches
the entry name, AuthMenuEntry.
- Extension:SandboxLink is needed to display the sandbox link in the
user menu.
- Performance note: the toolbar is now processed in MinervaTemplate,
which corresponds to removing the buildPersonalUrls() override.
- To mimic the design of main menu, the following steps would be
necessary:
1. Create a user/Default and user/Advanced user menu builder and also
a user/IBuilder interface.
2. Create a user/Director.
3. Create a service entry for Minerva.Menu.UserDirector in
ServiceWiring. The Director is actually powerless and doesn't get
to make any decisions--the appropriate builder is passed in from
ServiceWiring which checks the mode.
4. Access the service in SkinMinerva to set a userMenuHTML data member
on the Minerva QuickTemplate.
5. In MinervaTemplate, access the userMenuHTML QuickTemplate member
and do the usual song and dance of inflating a Mustache template.
This patch does everything except add a service, which was agreed to
be unnecessary, so that logic is now in SkinMinerva.
- Wrap the existing echo user notifications button and new user menu
button in a nav element. This seems like a semantic improvement.
- The existing styling and logic for the search bar and search overlay
are pretty messy and delicate. Changes made to that LESS endeavored to
be surgical. There's lots of room for improvement in the toolbar but
it's out of scope.
- Rename logout icon to logOut.
Bug: T214540
Change-Id: Ib517864fcf4e4d611e05525a6358ee6662fe4e05
2019-06-25 20:12:58 +00:00
|
|
|
if ( userMenu ) {
|
2019-07-31 17:36:19 +00:00
|
|
|
ToggleList.bind( window, userMenu );
|
[UI] [new] add user menu
Add new user menu. The changes required include:
- Break up AuthMenuEntry into reusable components. They're now simple,
independent, static functions in AuthUtil that are easy to reason
about and compose.
There's lots of verbose code because of the builder and director
patterns. That is, most of the code is for building the thing we
actually want to build instead of just building it. It's easy to write
but no fun to read--even simple configurations are extremely verbose
expressions that must be threaded through the system.
These builders are also single purpose and unlikely to be reusable
unlike a URI builder, for example. As objects, they're not especially
composable either.
- Similarly, break up Menu/DefaultBuilder into BuilderUtil and ban
inheritance. Inheritance has not worked well on the frontend of
MobileFrontend. I don't think it's going to work well here. E.g., I
could have made changes to the base class' getPersonalTools() method
such that the client passes a parameter for the advanced config or
maybe I just override it in the subclass. In either case, I think it
makes the whole hierarchy nuanced and harder to reason about for
something that should be simple.
- Add ProfileMenuEntry and LogOutMenuEntry for the user menu.
- Rename insertLogInOutMenuItem() to insertAuthMenuItem() which matches
the entry name, AuthMenuEntry.
- Extension:SandboxLink is needed to display the sandbox link in the
user menu.
- Performance note: the toolbar is now processed in MinervaTemplate,
which corresponds to removing the buildPersonalUrls() override.
- To mimic the design of main menu, the following steps would be
necessary:
1. Create a user/Default and user/Advanced user menu builder and also
a user/IBuilder interface.
2. Create a user/Director.
3. Create a service entry for Minerva.Menu.UserDirector in
ServiceWiring. The Director is actually powerless and doesn't get
to make any decisions--the appropriate builder is passed in from
ServiceWiring which checks the mode.
4. Access the service in SkinMinerva to set a userMenuHTML data member
on the Minerva QuickTemplate.
5. In MinervaTemplate, access the userMenuHTML QuickTemplate member
and do the usual song and dance of inflating a Mustache template.
This patch does everything except add a service, which was agreed to
be unnecessary, so that logic is now in SkinMinerva.
- Wrap the existing echo user notifications button and new user menu
button in a nav element. This seems like a semantic improvement.
- The existing styling and logic for the search bar and search overlay
are pretty messy and delicate. Changes made to that LESS endeavored to
be surgical. There's lots of room for improvement in the toolbar but
it's out of scope.
- Rename logout icon to logOut.
Bug: T214540
Change-Id: Ib517864fcf4e4d611e05525a6358ee6662fe4e05
2019-06-25 20:12:58 +00:00
|
|
|
}
|
2019-06-25 01:10:51 +00:00
|
|
|
TabScroll.initTabsScrollPosition();
|
2018-07-30 14:45:44 +00:00
|
|
|
// Setup the issues banner on the page
|
|
|
|
// Pages which dont exist (id 0) cannot have issues
|
2019-07-11 00:56:04 +00:00
|
|
|
if ( !currentPage.isMissing ) {
|
|
|
|
issues.init( overlayManager, currentPageHTMLParser );
|
2018-07-30 14:45:44 +00:00
|
|
|
}
|
2019-07-16 21:41:37 +00:00
|
|
|
|
|
|
|
mw.requestIdleCallback( errorLogging );
|
2019-07-16 23:19:07 +00:00
|
|
|
// deprecation notices
|
|
|
|
mw.log.deprecate( router, 'navigate', router.navigate, 'use navigateTo instead' );
|
2019-08-30 00:02:35 +00:00
|
|
|
|
|
|
|
// setup toc icons
|
|
|
|
new Icon( {
|
2019-09-06 19:13:20 +00:00
|
|
|
glyphPrefix: 'minerva',
|
2019-08-30 00:02:35 +00:00
|
|
|
name: 'toc'
|
|
|
|
} ).$el.prependTo( '.toctitle' );
|
|
|
|
new Icon( {
|
|
|
|
glyphPrefix: 'mf',
|
2019-09-06 19:13:20 +00:00
|
|
|
name: 'expand',
|
|
|
|
// FIXME: `additionalClassNames` for backwards compatibility.
|
|
|
|
// Can be removed when Ibbc706146710a9e31a72b3c2cd4e247d7a227488 lands.
|
|
|
|
additionalClassNames: 'mw-ui-icon-mf-arrow',
|
2019-08-30 00:02:35 +00:00
|
|
|
isSmall: true
|
|
|
|
} ).$el.appendTo( '.toctitle' );
|
2019-09-18 23:07:21 +00:00
|
|
|
|
|
|
|
// wire up talk icon if necessary
|
|
|
|
if ( permissions.talk ) {
|
|
|
|
require( './talk.js' )( mobile );
|
|
|
|
}
|
|
|
|
|
|
|
|
// wire up watch icon if necessary
|
|
|
|
if ( permissions.watch ) {
|
2019-09-19 21:19:07 +00:00
|
|
|
if ( mw.user.isAnon() ) {
|
|
|
|
ctaDrawers.initWatchstarCta( $watch );
|
|
|
|
} else {
|
|
|
|
require( './watchstar.js' )( $watch );
|
|
|
|
}
|
2019-09-18 23:07:21 +00:00
|
|
|
}
|
2019-09-19 21:19:07 +00:00
|
|
|
ctaDrawers.initRedlinksCta(
|
|
|
|
$redLinks.filter( function ( _, element ) {
|
|
|
|
// Filter out local User namespace pages.
|
|
|
|
return !isUserUri( element.href );
|
|
|
|
} )
|
|
|
|
);
|
|
|
|
initUserRedLinks();
|
2017-07-12 15:12:40 +00:00
|
|
|
} );
|
2019-09-27 18:53:01 +00:00
|
|
|
|
|
|
|
// eslint-disable-next-line no-restricted-properties
|
2019-04-04 21:20:39 +00:00
|
|
|
}( mw.mobileFrontend ) );
|
2019-10-01 21:40:49 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
// Version number allows breaking changes to be detected by other extensions
|
|
|
|
VERSION: 1
|
|
|
|
};
|