| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
const UiElement = require( './mmv.ui.js' ); |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
class StripeButtons extends UiElement { |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
constructor( $container ) { |
| 30 |
super( $container ); |
| 31 |
|
| 32 |
this.$buttonContainer = $( '<div>' ) |
| 33 |
.addClass( 'mw-mmv-stripe-button-container' ) |
| 34 |
.appendTo( $container ); |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
this.$descriptionPage = $( '<a>' ) |
| 40 |
.addClass( 'mw-mmv-stripe-button empty mw-mmv-description-page-button cdx-button cdx-button--weight-primary cdx-button--action-progressive cdx-button--size-large cdx-button--fake-button cdx-button--fake-button--enabled' ) |
| 41 |
|
| 42 |
.prependTo( this.$buttonContainer ); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
set( image, imageInfo ) { |
| 51 |
const match = image && image.src ? |
| 52 |
image.src.match( /(lang|page)([\d\-a-z]+)-(\d+)px/ ) : |
| 53 |
null; |
| 54 |
|
| 55 |
const commons = '//commons.wikimedia.org'; |
| 56 |
const isCommonsServer = String( mw.config.get( 'wgServer' ) ).includes( commons ); |
| 57 |
let descriptionUrl = imageInfo.descriptionUrl; |
| 58 |
let isCommons = String( descriptionUrl ).includes( commons ); |
| 59 |
|
| 60 |
if ( imageInfo.pageID && !isCommonsServer ) { |
| 61 |
const params = {}; |
| 62 |
if ( match ) { |
| 63 |
params[ match[ 1 ] ] = match[ 2 ]; |
| 64 |
} |
| 65 |
|
| 66 |
descriptionUrl = imageInfo.title.getUrl( params ); |
| 67 |
isCommons = false; |
| 68 |
} else { |
| 69 |
const parsedUrl = new URL( descriptionUrl, location ); |
| 70 |
if ( match ) { |
| 71 |
parsedUrl.searchParams.set( match[ 1 ], match[ 2 ] ); |
| 72 |
} |
| 73 |
descriptionUrl = parsedUrl.toString(); |
| 74 |
} |
| 75 |
|
| 76 |
this.$descriptionPage.empty() |
| 77 |
.append( $( '<span>' ).addClass( 'cdx-button__icon' ) ) |
| 78 |
.append( mw.message( 'multimediaviewer-repository-local' ).escaped() ) |
| 79 |
.attr( 'href', descriptionUrl ) |
| 80 |
.removeClass( 'empty' ) |
| 81 |
.toggleClass( 'mw-mmv-repo-button-commons', isCommons ); |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
empty() { |
| 88 |
this.$descriptionPage.attr( { href: null, title: null, 'original-title': null } ) |
| 89 |
.addClass( 'empty' ) |
| 90 |
.removeClass( 'mw-mmv-repo-button-commons' ); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
module.exports = StripeButtons; |