1 const AuthPopup = require( './AuthPopup.js' );
2 const config = require( './config.json' );
4 function checkLoggedIn() {
5 return ( new mw.Api() ).get( {
7 } ).then( ( resp ) => {
8 const userinfo = resp.query.userinfo;
9 if ( userinfo.anon !== undefined || userinfo.temp !== undefined ) {
16 const loginTitle = mw.Title.makeTitle( -1, config.specialPageNames.UserLogin );
17 const successTitle = mw.Title.makeTitle( -1, config.specialPageNames.AuthenticationPopupSuccess );
19 const loginPopupUrl = loginTitle.getUrl( {
21 returnto: successTitle.getPrefixedText(),
22 returntoquery: 'display=popup'
24 const loginFallbackUrl = loginTitle.getUrl( {
25 returnto: successTitle.getPrefixedText()
29 * `userinfo` object as returned by the
30 * {@link https://www.mediawiki.org/wiki/API:Userinfo action=query&meta=userinfo API module}.
32 * @typedef {Object} module:mediawiki.authenticationPopup~userinfo
33 * @property {string} name
34 * @property {number} id
38 * Exposes an instance of {@link AuthPopup} configured to display a login dialog for the local
39 * instance of MediaWiki.
41 * The promises returned by `AuthPopup` methods will be resolved with a {@link userinfo} object.
43 * **This library is not stable yet (as of May 2024). We're still testing which of the
44 * methods work from the technical side, and which methods are understandable for users.
45 * Some methods or the whole library may be removed in the future.**
48 * const authPopup = require( 'mediawiki.authenticationPopup' );
49 * authPopup.startPopupWindow()
50 * // or: authPopup.startNewTabOrWindow()
51 * // or: authPopup.startIframe()
52 * .then( function ( userinfo ) {
55 * console.log( userinfo.name );
57 * // Cancelled by the user
59 * }, function ( error ) {
60 * // Unexpected error stopped the login process
63 * @example <caption>Example using `await` syntax</caption>
64 * const userinfo = await authPopup.startPopupWindow(); // etc.
68 * // Cancelled by the user
71 * @module mediawiki.authenticationPopup
74 module.exports = new AuthPopup( {
75 loginPopupUrl: loginPopupUrl,
76 loginFallbackUrl: loginFallbackUrl,
77 checkLoggedIn: checkLoggedIn,
78 message: () => $( '<div>' ).append(
81 'userlogin-authpopup-loggingin-body',
82 $( '<a>' ).attr( 'href', loginFallbackUrl ).attr( 'target', '_blank' )