mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-14 11:15:08 +00:00
Minimize createStubTitle() helper method
Pretty much all usages of this function do *not* use the second parameter to pass a page name prefixed with a namespace, but pass the page name only. This patch here removes the redundancy. The namespace prefix is now a generated one, saying "Namespace <number>:…". It turns out no test relies on this so far. Bug: T220097 Change-Id: Ibd45d49c91e86a2647afe676a5e3bb07dfeab6ed
This commit is contained in:
parent
6c535739bf
commit
8305eb8634
BIN
resources/dist/index.js
vendored
BIN
resources/dist/index.js
vendored
Binary file not shown.
BIN
resources/dist/index.js.map.json
vendored
BIN
resources/dist/index.js.map.json
vendored
Binary file not shown.
|
@ -114,7 +114,7 @@ export function createNullModel( title, url ) {
|
|||
* @return {string|null}
|
||||
*/
|
||||
export function getPreviewType( el, config, title ) {
|
||||
if ( !isSelfLink( config, title ) ) {
|
||||
if ( !isSelfLink( title, config ) ) {
|
||||
return previewTypes.TYPE_PAGE;
|
||||
}
|
||||
|
||||
|
@ -131,13 +131,11 @@ export function getPreviewType( el, config, title ) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Check if a link is pointing to the current page
|
||||
*
|
||||
* @param {mw.Map} config
|
||||
* @param {mw.Title} title
|
||||
* @return {boolean}
|
||||
* @param {mw.Map} config
|
||||
* @return {boolean} True when the link points to the current page.
|
||||
*/
|
||||
function isSelfLink( config, title ) {
|
||||
function isSelfLink( title, config ) {
|
||||
return title.getNamespaceId() === config.get( 'wgNamespaceNumber' ) &&
|
||||
title.getNameText() === config.get( 'wgTitle' );
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import { previewTypes } from '../../src/preview/model';
|
|||
|
||||
const mw = mediaWiki,
|
||||
REFERRER = 'https://en.wikipedia.org/wiki/Kitten',
|
||||
TEST_TITLE = createStubTitle( 1, 'Foo' );
|
||||
TEST_TITLE = createStubTitle( 0, 'Foo' );
|
||||
|
||||
function generateToken() {
|
||||
return 'ABC';
|
||||
|
@ -19,7 +19,7 @@ QUnit.test( '#boot', ( assert ) => {
|
|||
stubUser = createStubUser( /* isAnon = */ true );
|
||||
|
||||
config.set( 'wgTitle', 'Foo' );
|
||||
config.set( 'wgNamespaceNumber', 1 );
|
||||
config.set( 'wgNamespaceNumber', 0 );
|
||||
config.set( 'wgArticleId', 2 );
|
||||
config.set( 'wgUserEditCount', 3 );
|
||||
config.set( 'wgPopupsConflictsWithNavPopupGadget', true );
|
||||
|
@ -49,7 +49,7 @@ QUnit.test( '#boot', ( assert ) => {
|
|||
page: {
|
||||
url: REFERRER,
|
||||
title: 'Foo',
|
||||
namespaceId: 1,
|
||||
namespaceId: 0,
|
||||
id: 2
|
||||
},
|
||||
user: {
|
||||
|
@ -129,7 +129,7 @@ QUnit.test( '#linkDwell', function ( assert ) {
|
|||
token: 'ABC',
|
||||
timestamp: mw.now(),
|
||||
title: 'Foo',
|
||||
namespaceId: 1,
|
||||
namespaceId: 0,
|
||||
promise: $.Deferred().promise( { abort() {} } )
|
||||
},
|
||||
'The dispatcher was called with the correct arguments.'
|
||||
|
@ -292,7 +292,7 @@ QUnit.test( 'it should fetch data from the gateway immediately', function ( asse
|
|||
type: actionTypes.FETCH_START,
|
||||
el: this.el,
|
||||
title: 'Foo',
|
||||
namespaceId: 1,
|
||||
namespaceId: 0,
|
||||
timestamp: this.now,
|
||||
promise: $.Deferred().promise( { abort() {} } )
|
||||
},
|
||||
|
|
|
@ -407,7 +407,7 @@ QUnit.test( 'RESTBase gateway handles missing extracts', function ( assert ) {
|
|||
gateway = createRESTBaseGateway(
|
||||
api, DEFAULT_CONSTANTS, provideParsedExtract );
|
||||
|
||||
return gateway.fetchPreviewForTitle( createStubTitle( 1, 'Test Title with missing extract' ) )
|
||||
return gateway.fetchPreviewForTitle( createStubTitle( 0, 'Test Title with missing extract' ) )
|
||||
.then( ( result ) => {
|
||||
assert.strictEqual( result.title, 'Test Title with missing extract', 'Title' );
|
||||
assert.strictEqual( result.extract, '!!', 'Extract' );
|
||||
|
@ -420,7 +420,7 @@ QUnit.test( 'RESTBase gateway handles no content success responses', function (
|
|||
gateway = createRESTBaseGateway(
|
||||
api, DEFAULT_CONSTANTS, provideParsedExtract );
|
||||
|
||||
return gateway.fetchPreviewForTitle( createStubTitle( 1, 'Test Title with empty response' ) )
|
||||
return gateway.fetchPreviewForTitle( createStubTitle( 0, 'Test Title with empty response' ) )
|
||||
.then( ( result ) => {
|
||||
assert.strictEqual( result.title, 'Test Title with empty response', 'Title' );
|
||||
assert.strictEqual( result.extract, '!!', 'Extract' );
|
||||
|
|
|
@ -93,7 +93,7 @@ QUnit.module( 'ext.popups.preview#getPreviewType', {
|
|||
this.config.set( 'wgPopupsReferencePreviews', true );
|
||||
this.config.set( 'wgTitle', 'Foo' );
|
||||
this.config.set( 'wgNamespaceNumber', 1 );
|
||||
this.referenceLink = createStubTitle( 1, 'Benutzerin:Foo', 'ref-fragment', 'Foo' );
|
||||
this.referenceLink = createStubTitle( 1, 'Foo', 'ref-fragment' );
|
||||
this.validEl = $( '<a>' ).appendTo( $( '<span>' ).addClass( 'reference' ) );
|
||||
}
|
||||
} );
|
||||
|
|
|
@ -56,25 +56,24 @@ export function createStubExperiments( bucket ) {
|
|||
* `mw.Title`.
|
||||
*
|
||||
* @param {number} namespace
|
||||
* @param {string} prefixedDb, e.g. Foo, or User:Foo
|
||||
* @param {string} name Page name without namespace prefix
|
||||
* @param {string|null} [fragment]
|
||||
* @param {string|null} name, the page name without extension or namespace prefix
|
||||
* @return {Object}
|
||||
*/
|
||||
export function createStubTitle( namespace, prefixedDb, fragment = null, name = null ) {
|
||||
export function createStubTitle( namespace, name, fragment = null ) {
|
||||
return {
|
||||
namespace,
|
||||
getPrefixedDb() {
|
||||
return prefixedDb;
|
||||
return ( namespace ? `Namespace ${ namespace }:` : '' ) + name;
|
||||
},
|
||||
getNameText() {
|
||||
return name || prefixedDb;
|
||||
return name;
|
||||
},
|
||||
getNamespaceId() {
|
||||
return namespace;
|
||||
},
|
||||
getUrl() {
|
||||
return `/wiki/${ prefixedDb }`;
|
||||
return `/wiki/${ this.getPrefixedDb() }`;
|
||||
},
|
||||
getFragment() {
|
||||
return fragment;
|
||||
|
|
Loading…
Reference in a new issue