2021-05-26 23:23:53 +00:00
/ * *
* @ external MenuDefinition
2021-06-21 19:30:11 +00:00
* @ external UserLinksDefinition
2021-05-26 23:23:53 +00:00
* /
2021-08-25 20:16:33 +00:00
import msgs from '../i18n/en.json' ;
2021-06-02 22:57:43 +00:00
import mustache from 'mustache' ;
2021-05-26 23:23:53 +00:00
import { menuTemplate } from './Menu.stories.data' ;
import userLinksTemplateLegacy from '!!raw-loader!../includes/templates/legacy/UserLinks.mustache' ;
import userLinksTemplate from '!!raw-loader!../includes/templates/UserLinks.mustache' ;
2021-06-02 22:57:43 +00:00
import userLinksMoreTemplate from '!!raw-loader!../includes/templates/UserLinks__more.mustache' ;
2021-07-22 17:27:33 +00:00
import userLinksLogoutTemplate from '!!raw-loader!../includes/templates/UserLinks__logout.mustache' ;
import userLinksLoginTemplate from '!!raw-loader!../includes/templates/UserLinks__login.mustache' ;
2021-05-27 21:47:55 +00:00
import { helperClassName , helperMakeMenuData } from './utils' ;
2021-05-26 23:23:53 +00:00
/ * *
2021-07-22 17:27:33 +00:00
* Legacy User Links
2021-05-26 23:23:53 +00:00
* /
const ECHO _ITEMS = ` <li id="pt-notifications-alert"><a href="/wiki/Special:Notifications" class="mw-echo-notifications-badge mw-echo-notification-badge-nojs oo-ui-icon-bell mw-echo-notifications-badge-all-read" data-counter-num="0" data-counter-text="0" title="Your alerts">Alerts (0)</a></li><li id="pt-notifications-notice"><a href="/wiki/Special:Notifications" class="mw-echo-notifications-badge mw-echo-notification-badge-nojs oo-ui-icon-tray" data-counter-num="3" data-counter-text="3" title="Your notices">Notices (3)</a></li> ` ;
const USERNAME _ITEM = ` <li id="pt-userpage"><a href="/wiki/User:WikiUser" dir="auto" title="Your user page [⌃⌥.]" accesskey=".">WikiUser</a></li> ` ;
const REST _ITEMS = ` <li id="pt-mytalk"><a href="/wiki/User_talk:WikiUser" title="Your talk page [⌃⌥n]" accesskey="n">Talk</a></li><li id="pt-sandbox"><a href="/wiki/User:WikiUser/sandbox" title="Your sandbox">Sandbox</a></li><li id="pt-preferences"><a href="/wiki/Special:Preferences" title="Your preferences">Preferences</a></li><li id="pt-betafeatures"><a href="/wiki/Special:Preferences#mw-prefsection-betafeatures" title="Beta features">Beta</a></li><li id="pt-watchlist"><a href="/wiki/Special:Watchlist" title="A list of pages you are monitoring for changes [⌃⌥l]" accesskey="l">Watchlist</a></li><li id="pt-mycontris"><a href="/wiki/Special:Contributions/WikiUser" title="A list of your contributions [⌃⌥y]" accesskey="y">Contributions</a></li> ` ;
const LOGOUT _ITEM = ` <li id="pt-logout"><a href="/w/index.php?title=Special:UserLogout&returnto=Main+Page&returntoquery=useskin%3Dvector" title="Log out">Log out</a></li> ` ;
const ULS _LANGUAGE _SELECTOR = '<li class="uls-trigger active"><a href="#">English</a></li>' ;
2021-07-22 17:27:33 +00:00
/ * *
* @ type { MenuDefinition }
* /
const loggedOut = helperMakeMenuData (
'personal' ,
` <li id="pt-anonuserpage">Not logged in</li><li id="pt-anontalk"><a href="/wiki/Special:MyTalk" title="Discussion about edits from this IP address [⌃⌥n]" accesskey="n">Talk</a></li><li id="pt-anoncontribs"><a href="/wiki/Special:MyContributions" title="A list of edits made from this IP address [⌃⌥y]" accesskey="y">Contributions</a></li><li id="pt-createaccount"><a href="/w/index.php?title=Special:CreateAccount&returnto=Main+Page" title="You are encouraged to create an account and log in; however, it is not mandatory">Create account</a></li><li id="pt-login"><a href="/w/index.php?title=Special:UserLogin&returnto=Main+Page" title="You're encouraged to log in; however, it's not mandatory. [⌃⌥o]" accesskey="o">Log in</a></li> ` ,
helperClassName ( 'vector-user-menu-legacy' )
) ;
2021-06-22 16:12:50 +00:00
2021-05-26 23:23:53 +00:00
/ * *
* @ type { MenuDefinition }
* /
const loggedInWithEcho = helperMakeMenuData (
'personal' ,
` ${ USERNAME _ITEM } ${ ECHO _ITEMS } ${ REST _ITEMS } ${ LOGOUT _ITEM } ` ,
2021-05-27 21:47:55 +00:00
helperClassName ( 'vector-user-menu-legacy' )
2021-05-26 23:23:53 +00:00
) ;
/ * *
* @ type { MenuDefinition }
* /
const loggedInWithULS = helperMakeMenuData (
'personal' ,
` ${ ULS _LANGUAGE _SELECTOR } ${ USERNAME _ITEM } ${ ECHO _ITEMS } ${ REST _ITEMS } ${ LOGOUT _ITEM } ` ,
2021-05-27 21:47:55 +00:00
helperClassName ( 'vector-user-menu-legacy' )
2021-05-26 23:23:53 +00:00
) ;
/ * *
* @ type { Object . < string , MenuDefinition > }
* /
const PERSONAL _MENU _TEMPLATE _DATA = {
loggedOut ,
loggedInWithEcho ,
loggedInWithULS
} ;
2021-07-22 17:27:33 +00:00
/ * *
* Modern User Links
* /
const LOGGED _IN _ITEMS = `
< li id = "pt-userpage" class = "user-links-collapsible-item" > < a class = "mw-ui-icon mw-ui-icon-before mw-ui-icon-wikimedia-userAvatar" href = "/wiki/User:Test" dir = "auto" title = "Your user page [ctrl-option-.]" accesskey = "." > < span > Test < / s p a n > < / a > < / l i >
< li id = "pt-mytalk" > < a class = "mw-ui-icon mw-ui-icon-before mw-ui-icon-wikimedia-userTalk" href = "/wiki/User_talk:WikiUser" title = "Your talk page [⌃⌥n]" accesskey = "n" > < span > Talk < / s p a n > < / a > < / l i >
< li id = "pt-sandbox" > < a class = "mw-ui-icon mw-ui-icon-before mw-ui-icon-wikimedia-markup" href = "/wiki/User:WikiUser/sandbox" title = "Your sandbox" > < span > Sandbox < / s p a n > < / a > < / l i >
< li id = "pt-preferences" > < a class = "mw-ui-icon mw-ui-icon-before mw-ui-icon-wikimedia-settings" href = "/wiki/Special:Preferences" title = "Your preferences" > < span > Preferences < / s p a n > < / a > < / l i >
< li id = "pt-watchlist" > < a class = "mw-ui-icon mw-ui-icon-before mw-ui-icon-wikimedia-unStar" href = "/wiki/Special:Watchlist" title = "A list of pages you are monitoring for changes [⌃⌥l]" accesskey = "l" > < span > Watchlist < / s p a n > < / a > < / l i >
< li id = "pt-mycontris" > < a class = "mw-ui-icon mw-ui-icon-before mw-ui-icon-wikimedia-userContributions" href = "/wiki/Special:Contributions/WikiUser" title = "A list of your contributions [⌃⌥y]" accesskey = "y" > < span > Contributions < / s p a n > < / a > < / l i >
` ;
const LOGGED _OUT _ITEMS = `
< li id = "pt-anontalk" > < a href = "/wiki/Special:MyTalk" title = "Discussion about edits from this IP address [ctrl-option-n]" accesskey = "n" > < span > Talk < / s p a n > < / a > < / l i >
< li id = "pt-anoncontribs" > < a href = "/wiki/Special:MyContributions" title = "A list of edits made from this IP address [ctrl-option-y]" accesskey = "y" > < span > Contributions < / s p a n > < / a > < / l i >
` ;
2021-06-02 22:57:43 +00:00
const additionalUserMoreData = {
class : 'vector-menu vector-user-menu-more' ,
2021-07-22 17:27:33 +00:00
'heading-class' : 'vector-menu-heading' ,
'is-dropdown' : false
2021-06-02 22:57:43 +00:00
} ;
const userMoreHtmlItems = ( isAnon = true ) => mustache . render ( userLinksMoreTemplate , {
'is-anon' : isAnon ,
2021-09-01 22:58:54 +00:00
'is-create-account-allowed' : isAnon ,
2021-06-02 22:57:43 +00:00
'html-create-account' : ` <a href="/w/index.php?title=Special:CreateAccount&returnto=Main+Page" class="mw-ui-button mw-ui-quiet" title="You are encouraged to create an account and log in; however, it is not mandatory">Create account</a> ` ,
2021-07-22 17:27:33 +00:00
'data-user-page' : helperMakeMenuData ( 'user-page' , `
< li id = "pt-userpage-2" class = "user-links-collapsible-item" >
< a href = "/wiki/User:WikiUser" dir = "auto" title = "Your user page [⌃⌥.]" accesskey = "." class = "mw-ui-button mw-ui-quiet" > < span > WikiUser < / s p a n > < / a >
< / l i >
` ),
2021-06-02 22:57:43 +00:00
'data-notifications' : helperMakeMenuData ( 'notifications' , ECHO _ITEMS )
} ) ;
2021-06-03 21:37:01 +00:00
const loggedInData = {
2021-06-24 19:13:20 +00:00
class : 'vector-user-menu vector-menu-dropdown vector-user-menu-logged-in' ,
2021-07-22 17:27:33 +00:00
'is-dropdown' : true ,
2021-09-01 22:58:54 +00:00
'heading-class' : 'mw-ui-button mw-ui-quiet mw-ui-icon mw-ui-icon-element mw-ui-icon-wikimedia-userAvatar' ,
2021-06-24 19:13:20 +00:00
'is-anon' : false ,
2021-07-22 17:27:33 +00:00
'html-after-portal' : mustache . render ( userLinksLogoutTemplate , {
htmlLogout : ` <a class="vector-menu-content-item vector-menu-content-item-logout mw-ui-icon mw-ui-icon-before mw-ui-icon-wikimedia-logOut" data-mw="interface" href="/w/index.php?title=Special:UserLogout&returnto=Main+Page"><span>Log out</span></a> `
} )
2021-06-03 21:37:01 +00:00
} ;
const loggedOutData = {
2021-06-24 19:13:20 +00:00
class : 'vector-user-menu vector-menu-dropdown vector-user-menu-logged-out' ,
2021-07-22 17:27:33 +00:00
'is-dropdown' : true ,
2021-09-01 22:58:54 +00:00
'heading-class' : 'mw-ui-button mw-ui-quiet mw-ui-icon mw-ui-icon-element mw-ui-icon-wikimedia-ellipsis' ,
2021-06-03 21:37:01 +00:00
'is-anon' : true ,
2021-07-22 17:27:33 +00:00
'html-before-portal' : mustache . render ( userLinksLoginTemplate , {
htmlCreateAccount : ` <a href="/w/index.php?title=Special:CreateAccount&returnto=Special%3AUserLogout" icon="userAvatar" class="user-links-collapsible-item vector-menu-content-item mw-ui-icon mw-ui-icon-before mw-ui-icon-wikimedia-userAvatar" title="You are encouraged to create an account and log in; however, it is not mandatory"><span>Create account</span></a> ` ,
htmlLogin : ` <a class="vector-menu-content-item vector-menu-content-item-login mw-ui-icon mw-ui-icon-before mw-ui-icon-wikimedia-logIn" href="/w/index.php?title=Special:UserLogin&returnto=Main+Page" title="You are encouraged to log in; however, it is not mandatory [ctrl-option-o]" accesskey="o"><span>Log in</span></a> ` ,
2021-08-25 20:16:33 +00:00
msgLearnMore : msgs [ 'vector-anon-user-menu-pages' ] ,
htmlLearnMoreLink : ` <a href="/wiki/Help:Introduction"><span> ${ msgs [ 'vector-anon-user-menu-pages-learn' ] } </span></a>: `
2021-07-22 17:27:33 +00:00
} )
2021-06-03 21:37:01 +00:00
} ;
2021-05-27 21:47:55 +00:00
/ * *
* @ type { UserLinksDefinition }
2021-05-26 23:23:53 +00:00
* /
const USER _LINKS _LOGGED _IN _TEMPLATE _DATA = {
2021-06-02 22:57:43 +00:00
'data-user-more' : helperMakeMenuData ( 'personal-more' , userMoreHtmlItems ( false ) , additionalUserMoreData ) ,
2021-07-22 17:27:33 +00:00
'data-user-menu' : helperMakeMenuData ( 'new-personal' , LOGGED _IN _ITEMS , loggedInData )
2021-05-26 23:23:53 +00:00
} ;
2021-05-27 21:47:55 +00:00
/ * *
* @ type { UserLinksDefinition }
* /
const USER _LINKS _LOGGED _OUT _TEMPLATE _DATA = {
2021-06-02 22:57:43 +00:00
'data-user-more' : helperMakeMenuData ( 'personal-more' , userMoreHtmlItems ( true ) , additionalUserMoreData ) ,
2021-07-22 17:27:33 +00:00
'data-user-menu' : helperMakeMenuData ( 'new-personal' , LOGGED _OUT _ITEMS , loggedOutData )
2021-05-27 21:47:55 +00:00
} ;
2021-09-13 21:19:58 +00:00
const USER _LINK _PARTIALS = {
Menu : menuTemplate
} ;
2021-05-27 21:47:55 +00:00
export {
PERSONAL _MENU _TEMPLATE _DATA ,
2021-05-26 23:23:53 +00:00
USER _LINKS _LOGGED _IN _TEMPLATE _DATA ,
2021-05-27 21:47:55 +00:00
USER _LINKS _LOGGED _OUT _TEMPLATE _DATA ,
2021-09-13 21:19:58 +00:00
USER _LINK _PARTIALS ,
2021-05-27 21:47:55 +00:00
userLinksTemplateLegacy ,
2021-06-03 21:37:01 +00:00
userLinksTemplate
2021-05-27 21:47:55 +00:00
} ;