mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-15 11:46:55 +00:00
Merge "Use title and namespace id to check if link is current page"
This commit is contained in:
commit
f40cc718ce
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 ( title.getPrefixedDb() !== config.get( 'wgPageName' ) ) {
|
||||
if ( !isSelfLink( config, title ) ) {
|
||||
return previewTypes.TYPE_PAGE;
|
||||
}
|
||||
|
||||
|
@ -130,6 +130,18 @@ export function getPreviewType( el, config, title ) {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a link is pointing to the current page
|
||||
*
|
||||
* @param {mw.Map} config
|
||||
* @param {mw.Title} title
|
||||
* @return {boolean}
|
||||
*/
|
||||
function isSelfLink( config, title ) {
|
||||
return title.getNamespaceId() === config.get( 'wgNamespaceNumber' ) &&
|
||||
title.getName() === config.get( 'wgTitle' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the extract returned by the TextExtracts MediaWiki API query
|
||||
* module.
|
||||
|
|
|
@ -91,8 +91,9 @@ QUnit.module( 'ext.popups.preview#getPreviewType', {
|
|||
beforeEach() {
|
||||
this.config = new Map(); /* global Map */
|
||||
this.config.set( 'wgPopupsReferencePreviews', true );
|
||||
this.config.set( 'wgPageName', 'Foo' );
|
||||
this.referenceLink = createStubTitle( 1, 'Foo', 'ref-fragment' );
|
||||
this.config.set( 'wgTitle', 'Foo' );
|
||||
this.config.set( 'wgNamespaceNumber', 1 );
|
||||
this.referenceLink = createStubTitle( 1, 'Benutzerin:Foo', 'ref-fragment', 'Foo' );
|
||||
this.validEl = $( '<a>' ).appendTo( $( '<span>' ).addClass( 'reference' ) );
|
||||
}
|
||||
} );
|
||||
|
@ -131,6 +132,15 @@ QUnit.test( 'it uses the page gateway when on links to a different page', functi
|
|||
),
|
||||
previewTypes.TYPE_PAGE
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
getPreviewType(
|
||||
this.validEl,
|
||||
this.config,
|
||||
createStubTitle( 2, 'Foo', 'fragment' )
|
||||
),
|
||||
previewTypes.TYPE_PAGE
|
||||
);
|
||||
} );
|
||||
|
||||
QUnit.test( 'it does not use the reference gateway when there is no fragment', function ( assert ) {
|
||||
|
|
|
@ -56,16 +56,23 @@ export function createStubExperiments( bucket ) {
|
|||
* `mw.Title`.
|
||||
*
|
||||
* @param {number} namespace
|
||||
* @param {string} prefixedDb, e.g. Foo, or File:Bar.jpg
|
||||
* @param {string} prefixedDb, e.g. Foo, or User:Foo
|
||||
* @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 ) {
|
||||
export function createStubTitle( namespace, prefixedDb, fragment = null, name = null ) {
|
||||
return {
|
||||
namespace,
|
||||
getPrefixedDb() {
|
||||
return prefixedDb;
|
||||
},
|
||||
getName() {
|
||||
return name || prefixedDb;
|
||||
},
|
||||
getNamespaceId() {
|
||||
return namespace;
|
||||
},
|
||||
getUrl() {
|
||||
return `/wiki/${ prefixedDb }`;
|
||||
},
|
||||
|
|
|
@ -110,8 +110,8 @@ module.exports = ( env, argv ) => ( {
|
|||
// Minified uncompressed size limits for chunks / assets and entrypoints. Keep these numbers
|
||||
// up-to-date and rounded to the nearest 10th of a kibibyte so that code sizing costs are
|
||||
// well understood. Related to bundlesize minified, gzipped compressed file size tests.
|
||||
maxAssetSize: 40.5 * 1024,
|
||||
maxEntrypointSize: 40.5 * 1024,
|
||||
maxAssetSize: 41 * 1024,
|
||||
maxEntrypointSize: 41 * 1024,
|
||||
|
||||
// The default filter excludes map files but we rename ours.
|
||||
assetFilter: ( filename ) => !filename.endsWith( srcMapExt )
|
||||
|
|
Loading…
Reference in a new issue