Jdlrobson has uploaded a new change for review.

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


Change subject: Bug 44484: Use template to render language section
......................................................................

Bug 44484: Use template to render language section

In process surface translated article titles since we have that
additional information available.

This assumes langname is in the response (introduced by 
I6c3025fae89cafd80c7844542c2a5b49aeb6660e)
Without this it will just show the article title in brackets (arguably better 
than the language code)
Change-Id: Iae272dcf22ccc9739f5da3399c167ef3a5753fc9
---
M MobileFrontend.php
M javascripts/common/mf-history-jquery.js
A templates/languageSection.html
3 files changed, 33 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/73/52173/1

diff --git a/MobileFrontend.php b/MobileFrontend.php
index 01224e2..494183a 100644
--- a/MobileFrontend.php
+++ b/MobileFrontend.php
@@ -234,9 +234,20 @@
        'mobileTargets' => array( 'stable', 'beta', 'alpha' ),
 );
 
+$wgResourceModules['mobile.beta.templates'] = array(
+       'localBasePath' => $localBasePath,
+       'localTemplateBasePath' => $localBasePath . '/templates',
+       'templates' => array(
+               'languageSection',
+       ),
+       'class' => 'MFResourceLoaderModule',
+       'mobileTargets' => array( 'beta', 'alpha' ),
+);
+
 $wgResourceModules['mobile.beta'] = $wgMFMobileResourceBoilerplate + array(
        'dependencies' => array(
                'mobile.stable',
+               'mobile.beta.templates',
        ),
        'scripts' => array(
                'javascripts/modules/mf-languages.js',
@@ -257,6 +268,7 @@
                // mf-history-jquery.js
                'mobile-frontend-ajax-page-loading',
                'mobile-frontend-ajax-page-error',
+               'mobile-frontend-language-article-heading',
        ),
        'mobileTargets' => array( 'beta', 'alpha' ),
 );
diff --git a/javascripts/common/mf-history-jquery.js 
b/javascripts/common/mf-history-jquery.js
index 5fa4e09..253935a 100644
--- a/javascripts/common/mf-history-jquery.js
+++ b/javascripts/common/mf-history-jquery.js
@@ -9,12 +9,7 @@
                navigateToPage,
                loadPage,
                loadLanguages,
-               languagesTemplate,
                apiUrl = M.getConfig( 'scriptPath', '' ) + '/api.php';
-
-       function gatherTemplates() {
-               languagesTemplate = $( '#mw-mf-language-section' ).clone();
-       }
 
        function updateUILinks( title ) {
                // FIXME: make this more generic
@@ -46,19 +41,16 @@
                } );
        }
 
-       // FIXME: use a template engine this is not maintainable
        function renderLanguages( langlinks ) {
-               $( languagesTemplate ).insertAfter( $( '.section' ).last() );
-               var $list = $( '#mw-mf-language-selection' ).empty(), $item, i, 
lang;
+               var template = M.template.get( 'languageSection' ),
+                       data = {
+                               langlinks: langlinks,
+                               heading: mw.msg( 
'mobile-frontend-language-article-heading' ),
+                               description: mw.msg( 
'mobile-frontend-language-header', langlinks.length )
+                       },
+                       html = template.render( data );
 
-               $( '#mw-mf-language-header' ).text( mw.message( 
'mobile-frontend-language-header', langlinks.length ) );
-               for ( i = 0 ; i < langlinks.length; i++ ) {
-                       lang = langlinks[i];
-                       $item = $( '<li>' ).appendTo( $list );
-                       // FIXME: show label as language name rather than code
-                       $( '<a>' ).attr( 'href', lang.url ).
-                               attr( 'lang', lang.lang ).text( lang.lang 
).appendTo( $item );
-               }
+               $( html ).insertAfter( $( '.section' ).last() );
                M.emit( 'languages-loaded' );
        }
 
@@ -211,7 +203,6 @@
                } );
        }
 
-       gatherTemplates();
        M.history.makeStubPage = makeStubPage;
        M.history.hijackLinks = hijackLinks;
        M.history.loadPage = loadPage;
diff --git a/templates/languageSection.html b/templates/languageSection.html
new file mode 100644
index 0000000..668ae29
--- /dev/null
+++ b/templates/languageSection.html
@@ -0,0 +1,13 @@
+<div class="section" id="mw-mf-language-section">
+       <h2 id="section_language" class="section_heading">{{heading}}</h2>
+       <div id="content_language">
+               <p id="mw-mf-language-header">{{description}}</p>
+               <ul id="mw-mf-language-selection">
+               {{#langlinks}}
+                       <li>
+                               <a href="{{url}}" hreflang="{{lang}}" 
lang="{{lang}}">{{langname}} ({{*}})</a>
+                       </li>
+               {{/langlinks}}
+               </ul>
+       </div>
+</div>

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iae272dcf22ccc9739f5da3399c167ef3a5753fc9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>

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

Reply via email to