Merge "Use title and namespace id to check if link is current page"

This commit is contained in:
jenkins-bot 2019-04-26 11:04:12 +00:00 committed by Gerrit Code Review
commit f40cc718ce
6 changed files with 36 additions and 7 deletions

Binary file not shown.

Binary file not shown.

View file

@ -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.

View file

@ -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 ) {

View file

@ -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 }`;
},

View file

@ -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 )