Mwjames has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/58646


Change subject: Use correponding PageLanguage to determine NS_FILE
......................................................................

Use correponding PageLanguage to determine NS_FILE

Change-Id: If4dc285504153a69877986b84e2c985ee480553b
---
M formats/gallery/Gallery.php
M formats/gallery/resources/ext.srf.gallery.overlay.js
2 files changed, 24 insertions(+), 10 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticResultFormats 
refs/changes/46/58646/1

diff --git a/formats/gallery/Gallery.php b/formats/gallery/Gallery.php
index 7d40339..bce550c 100644
--- a/formats/gallery/Gallery.php
+++ b/formats/gallery/Gallery.php
@@ -178,7 +178,8 @@
                        $attribs = array (
                                'class'  => 'srf-gallery' . $class,
                                'align'  => 'justify',
-                               'data-redirect-type' => $redirectType
+                               'data-redirect-type' => $redirectType,
+                               'data-ns-text' => 
$this->getContext()->getTitle()->getPageLanguage()->getNsText( NS_FILE )
                        );
 
                        $html = Html::rawElement( 'div', $attribs, $processing 
. $ig->toHTML() );
diff --git a/formats/gallery/resources/ext.srf.gallery.overlay.js 
b/formats/gallery/resources/ext.srf.gallery.overlay.js
index d168e13..83e9e2b 100644
--- a/formats/gallery/resources/ext.srf.gallery.overlay.js
+++ b/formats/gallery/resources/ext.srf.gallery.overlay.js
@@ -35,8 +35,13 @@
        srf.formats.gallery = function() {};
 
        srf.formats.gallery.prototype = {
-               overlay: function( context ) {
-                       return context.each( function() {
+               overlay: function( context, ns ) {
+
+                       // Encode the namespace (NS_FILE) otherwise languages
+                       // like Japanese, Chinese will fail
+                       var encodedNsText = encodeURIComponent( ns );
+
+                       context.each( function() {
                                var $this = $( this ),
                                        galleryID = $this.attr( 'id' ),
                                        srfPath = mw.config.get( 'srf.options' 
).srfgScriptPath;
@@ -60,19 +65,20 @@
                                                $this.html( '<span 
class="error">' + mw.message( 'srf-gallery-image-url-error' ).escaped() + 
'</span>' );
                                        } else {
 
-                                               // There should be a better way 
to find the title object but there isn't
-                                               var title = image.attr( 'href' 
).replace(/.+?\File:(.*)$/, "$1" ).replace( "%27", "\'" ),
+                                               // There should be a better way 
to get the title object but there isn't
+                                               // var title = image.attr( 
'href' ).replace(/.+?\File:(.*)$/, "$1" ).replace( "%27", "\'" ),
+                                               var title = image.attr( 'href' 
).split( encodedNsText + ':' ),
                                                        imageSource = 
image.attr( 'href' );
 
                                                // Prepare overlay icon 
placeholder
                                                image.before( h.element( 'a', { 
'class': 'overlayicon', 'href': imageSource }, null ) );
-                                               var overlay = $this.find( 
'.overlayicon' ).hide();
+                                               var overlayIcon = $this.find( 
'.overlayicon' ).hide();
 
                                                // Add spinner while fetching 
the URL
                                                util.spinner.create( { context: 
$this, selector: 'img' } );
 
                                                // Re-assign image url
-                                               util.getImageURL( { 'title': 
'File:' + title },
+                                               util.getImageURL( { 'title': ns 
+ ':' + title[1] },
                                                        function( url ) { if ( 
url === false ) {
                                                                image.attr( 
'href', '' );
                                                                // Release 
thumb image
@@ -82,7 +88,7 @@
                                                                // Release 
thumb image
                                                                
util.spinner.replace( { context: $this, selector: 'img' } );
                                                                // Release 
overlay icon
-                                                               overlay.show();
+                                                               
overlayIcon.show();
                                                        }
                                                } );
                                        }
@@ -112,8 +118,15 @@
        var util = new srf.util();
 
        $( document ).ready( function() {
-               $( '.srf-overlay' ).each(function() {
-                       gallery.overlay( $( this ) );
+               var ns = 'File';
+
+               // Find the namespace used for the current instance
+               $( '.srf-gallery,.srf-gallery-slideshow,.srf-gallery-carousel' 
).each( function() {
+                       ns = $( this ).data( 'ns-text' );
+               } );
+
+               $( '.srf-overlay' ).each( function() {
+                       gallery.overlay( $( this ), ns );
                } );
        } );
 } )( jQuery, mediaWiki, semanticFormats  );
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/58646
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If4dc285504153a69877986b84e2c985ee480553b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticResultFormats
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to