-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add anon edit warning link parameters
Bug: T330550
- Loading branch information
Showing
10 changed files
with
105 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { inject, InjectionKey } from 'vue'; | ||
|
||
export default interface AccountLinker { | ||
/** | ||
* FIXME | ||
*/ | ||
getLoginLink(): string; | ||
|
||
/** | ||
* FIXME | ||
*/ | ||
getCreateAccountLink(): string; | ||
} | ||
|
||
export const AccountLinkerKey: InjectionKey<AccountLinker> = Symbol( 'AccountLinker' ); | ||
|
||
export function useAccountLinker(): AccountLinker { | ||
return inject( AccountLinkerKey, () => { | ||
throw new Error( 'No AccountLinker provided!' ); | ||
}, true ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { MwUtilGetUrl } from '@/@types/mediawiki'; | ||
import AccountLinker from '@/plugins/AccountLinkerPlugin/AccountLinker'; | ||
|
||
export default class MediaWikiAccountLinker implements AccountLinker { | ||
|
||
public constructor( | ||
private readonly getUrl: MwUtilGetUrl, | ||
private readonly currentPage: string, | ||
) {} | ||
|
||
public getCreateAccountLink(): string { | ||
return this.getUrl( 'Special:CreateAccount', { returnto: this.currentPage } ); | ||
} | ||
|
||
public getLoginLink(): string { | ||
return this.getUrl( 'Special:UserLogin', { returnto: this.currentPage } ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/unit/components/__snapshots__/AnonymousEditWarning.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`AnonymousEditWarning matches snapshot if anonymous 1`] = `"<div class="wikit wikit-Message wikit-Message--warning wbl-snl-anonymous-edit-warning"><span class="wikit-Message__content"><span class="wikit wikit-Icon wikit-Icon--large wikit-Icon--warning wikit-Message__icon"><svg class="wikit-Icon__svg" xmlns="http://www.w3.org/2000/svg" fill="none" aria-hidden="true" focusable="false" viewBox="0 0 16 16"><path fill="currentColor" d="M9.163 1.68234C9.06078 1.4381 8.89901 1.22746 8.69449 1.07231C8.48997 0.917151 8.25017 0.823144 7.99999 0.800049C7.75116 0.82453 7.51294 0.919178 7.30987 1.07425C7.10679 1.22933 6.94619 1.43922 6.84459 1.68234L0.672272 13.0631C0.0337565 14.2368 0.558251 15.2 1.82768 15.2H14.1723C15.4417 15.2 15.9662 14.2368 15.3277 13.0631L9.163 1.68234ZM8.76013 12.7717H7.23986V11.1528H8.76013V12.7717ZM8.76013 9.53394H7.23986V4.67728H8.76013V9.53394Z"></path></svg></span><span><!-- eslint-disable-next-line vue/no-v-html --><span>wikibase-anonymouseditwarning</span></span></span></div>"`; | ||
exports[`AnonymousEditWarning matches snapshot if anonymous 1`] = `"<div class="wikit wikit-Message wikit-Message--warning wbl-snl-anonymous-edit-warning"><span class="wikit-Message__content"><span class="wikit wikit-Icon wikit-Icon--large wikit-Icon--warning wikit-Message__icon"><svg class="wikit-Icon__svg" xmlns="http://www.w3.org/2000/svg" fill="none" aria-hidden="true" focusable="false" viewBox="0 0 16 16"><path fill="currentColor" d="M9.163 1.68234C9.06078 1.4381 8.89901 1.22746 8.69449 1.07231C8.48997 0.917151 8.25017 0.823144 7.99999 0.800049C7.75116 0.82453 7.51294 0.919178 7.30987 1.07425C7.10679 1.22933 6.94619 1.43922 6.84459 1.68234L0.672272 13.0631C0.0337565 14.2368 0.558251 15.2 1.82768 15.2H14.1723C15.4417 15.2 15.9662 14.2368 15.3277 13.0631L9.163 1.68234ZM8.76013 12.7717H7.23986V11.1528H8.76013V12.7717ZM8.76013 9.53394H7.23986V4.67728H8.76013V9.53394Z"></path></svg></span><span><!-- eslint-disable-next-line vue/no-v-html --><span>(wikibase-anonymouseditwarning, loginLink, createAccountLink)</span></span></span></div>"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import MediaWikiAccountLinker from '@/plugins/AccountLinkerPlugin/MediaWikiAccountLinker'; | ||
|
||
describe( 'MediaWikiAccountLinker', () => { | ||
it( 'delegates to mw.util.getUrl for getting the login url', () => { | ||
const url = '/w/index.php?title=Special:UserLogin&returnto=Special%3ANewLexeme'; | ||
const getUrlMock = jest.fn().mockReturnValue( url ); | ||
const accountLinker = new MediaWikiAccountLinker( getUrlMock, 'Special:NewLexeme' ); | ||
|
||
expect( accountLinker.getLoginLink() ).toBe( url ); | ||
expect( getUrlMock ).toHaveBeenCalledWith( 'Special:UserLogin', { | ||
returnto: 'Special:NewLexeme', | ||
} ); | ||
} ); | ||
|
||
it( 'delegates to mw.util.getUrl for getting the create account url', () => { | ||
const url = '/w/index.php?title=Special:CreateAccount&returnto=Special%3ANewLexeme'; | ||
const getUrlMock = jest.fn().mockReturnValue( url ); | ||
const accountLinker = new MediaWikiAccountLinker( getUrlMock, 'Special:NewLexeme' ); | ||
|
||
expect( accountLinker.getCreateAccountLink() ).toBe( url ); | ||
expect( getUrlMock ).toHaveBeenCalledWith( 'Special:CreateAccount', { | ||
returnto: 'Special:NewLexeme', | ||
} ); | ||
} ); | ||
} ); |