Jdlrobson has uploaded a new change for review.

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


Change subject: Story 774: Allow people to navigate to nearby places
......................................................................

Story 774: Allow people to navigate to nearby places

Currently only for iphone, android and windows phone users
Other devices to not show the directions link

Change-Id: Ic160bd370b394f9760c42ffb47b30f0272c44002
Note: in future the label should be replaced by text
---
M MobileFrontend.i18n.php
M includes/Resources.php
M javascripts/specials/nearby.js
M javascripts/specials/overlays/preview.js
M templates/articleList.html
M templates/overlays/pagePreview.html
6 files changed, 41 insertions(+), 2 deletions(-)


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

diff --git a/MobileFrontend.i18n.php b/MobileFrontend.i18n.php
index 0cb9f67..b8b231e 100644
--- a/MobileFrontend.i18n.php
+++ b/MobileFrontend.i18n.php
@@ -140,6 +140,7 @@
        'mobile-frontend-nearby-error' => '{{SITENAME}} Nearby is having some 
issues.',
        'mobile-frontend-nearby-error-guidance' => 'Try refreshing your 
location.',
        'mobile-frontend-nearby-link' => 'Read this page in full',
+       'mobile-frontend-nearby-directions' => 'Navigate here',
        'mobile-frontend-needs-photo' => 'Needs photo',
 
        // image donation
@@ -524,6 +525,7 @@
        'mobile-frontend-nearby-error' => 'Text of generic error message when 
querying geodata api',
        'mobile-frontend-nearby-error-guidance' => 'Message explaining actions 
user can take when keying error {{msg-mw|mobile-frontend-nearby-error}}',
        'mobile-frontend-nearby-link' => 'Text of link that takes user to full 
page',
+       'mobile-frontend-nearby-directions' => 'Text of directions link',
        'mobile-frontend-needs-photo' => 'Text that appears on page item in 
[[Special:Nearby]] list telling user to upload a photo',
        'mobile-frontend-donate-image-login' => 'Title for 
[[Special:UserLogin]] when being redirected to [[Special:Uploads]].
 
diff --git a/includes/Resources.php b/includes/Resources.php
index 8fe564a..c374c31 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -583,6 +583,7 @@
                        'mobile-frontend-nearby-noresults',
                        'mobile-frontend-nearby-noresults-guidance',
                        'mobile-frontend-nearby-link',
+                       'mobile-frontend-nearby-directions',
                ),
                'scripts' => array(
                        'javascripts/specials/nearby.js',
diff --git a/javascripts/specials/nearby.js b/javascripts/specials/nearby.js
index 9ddc702..64c4505 100644
--- a/javascripts/specials/nearby.js
+++ b/javascripts/specials/nearby.js
@@ -136,6 +136,8 @@
                                coords = page.coordinates[0],
                                lngLat = { latitude: coords.lat, longitude: 
coords.lon };
                                page.dist = calculateDistance( curLocation, 
lngLat );
+                               page.latitude = coords.lat;
+                               page.longitude = coords.lon;
                                page.proximity = distanceMessage( page.dist );
                        }
                        pages.push( page );
diff --git a/javascripts/specials/overlays/preview.js 
b/javascripts/specials/overlays/preview.js
index 7589fc9..cfbe429 100644
--- a/javascripts/specials/overlays/preview.js
+++ b/javascripts/specials/overlays/preview.js
@@ -1,5 +1,10 @@
 ( function( M, $ ) {
        var Overlay = M.require( 'Overlay' ),
+               ua = window.navigator.userAgent,
+               _device = 'unknown',
+               getDevice = function() {
+                       return _device;
+               },
                Page = M.require( 'page' ),
                LoadingOverlay = Overlay.extend( {
                        defaults: {
@@ -10,10 +15,28 @@
                PagePreviewOverlay = Overlay.extend( {
                        template: M.template.get( 'overlays/pagePreview' ),
                        preRender: function( options ) {
+                               var directionUrl, device = getDevice();
                                options.heading = options.page.title;
                                options.preview = options.page.lead;
                                options.url = M.history.getArticleUrl( 
options.heading );
                                options.readMoreLink = mw.msg( 
'mobile-frontend-nearby-link' );
+
+                               if ( options.latLngString ) {
+                                       // Yeeyyy no standards!
+                                       // FIXME: would be nice to provide an 
opensource alternative
+                                       if ( device === 'iphone' ) {
+                                               directionUrl = 
'http://maps.apple.com/?daddr=' + options.latLngString;
+                                       } else if ( device === 'android' ) {
+                                               directionUrl = 'geo:' + 
options.latLngString + '?z=15';
+                                       } else if ( device === 'wp' ) {
+                                               directionUrl = 'maps:' + 
options.latLngString;
+                                       } // FIXME: what in other cases?!
+
+                                       if ( directionUrl ) {
+                                               options.directionUrl = 
directionUrl;
+                                               options.directionLabel = 
mw.msg( 'mobile-frontend-nearby-directions' );
+                                       }
+                               }
                        },
                        postRender: function( options ) {
                                var $preview, nodes;
@@ -33,6 +56,14 @@
                module = M.require( 'nearby' ),
                endpoint = module.endpoint;
 
+       if ( ua.match( /OS [0-9]_0 like Mac OS X/ ) ) {
+               _device = 'iphone';
+       } else if ( ua.match( /Android/ ) ) {
+               _device = 'android';
+       } else if ( ua.match( /Windows Phone/ ) ) {
+               _device = 'wp';
+       }
+
        $( function() {
                // FIXME: temporary code, replace if previews get to stable or 
are removed
                module.getOverlay().openPage = function( ev ) {
@@ -43,7 +74,9 @@
                        loader.show();
 
                        M.history.retrievePage( title, endpoint, true ).done( 
function( page ) {
-                               var preview = new PagePreviewOverlay( { page: 
new Page( page ), img: $( '<div>' ).append( $a.find( '.listThumb' ).clone() 
).html() } );
+                               var preview = new PagePreviewOverlay( { page: 
new Page( page ),
+                                       latLngString: $a.data( 'latlng' ),
+                                       img: $( '<div>' ).append( $a.find( 
'.listThumb' ).clone() ).html() } );
                                loader.hide();
                                preview.show();
                        } ).fail( function() {
diff --git a/templates/articleList.html b/templates/articleList.html
index a941b48..3dc20ea 100644
--- a/templates/articleList.html
+++ b/templates/articleList.html
@@ -8,7 +8,7 @@
 <ul class="mw-mf-watchlist-results a-to-z">
        {{#pages}}
        <li title="{{title}}">
-               <a href="{{url}}" class="title" name="{{anchor}}">
+               <a href="{{url}}" class="title" name="{{anchor}}" 
data-latlng="{{latitude}},{{longitude}}">
                        <div class="listThumb {{pageimageClass}}" 
style="{{listThumbStyleAttribute}}"></div>
                        <h2>{{title}}</h2>
                        <div class="info proximity">{{proximity}}</div>
diff --git a/templates/overlays/pagePreview.html 
b/templates/overlays/pagePreview.html
index afeeae3..be0be28 100644
--- a/templates/overlays/pagePreview.html
+++ b/templates/overlays/pagePreview.html
@@ -1,5 +1,6 @@
 <div class="header">
        <button class="cancel escapeOverlay">{{closeMsg}}</button>
+       {{#directionUrl}}<a 
href="{{directionUrl}}">{{directionLabel}}</a>{{/directionUrl}}
 </div>
 <p class="message">
        <a href="{{url}}">{{readMoreLink}}</a>

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic160bd370b394f9760c42ffb47b30f0272c44002
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