Jdlrobson has uploaded a new change for review.

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


Change subject: Provide access to the device from javascript
......................................................................

Provide access to the device from javascript

We need to be able to communicate to CentralNotice what device is requesting
a banner so we can distinguish between desktop and mobile

add getDeviceId function to DeviceProperties to allow identification
of a device - prefixed with mobile to allow desktop to follow suite in
future

add global wgMobileDeviceName to allow other extensions/js modules to
identify which device is being used

Change-Id: I7523ea86e1cc588d268f54d9e538efaca1fbf3b7
---
M includes/DeviceDetection.php
M includes/MobileFrontend.hooks.php
2 files changed, 16 insertions(+), 1 deletion(-)


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

diff --git a/includes/DeviceDetection.php b/includes/DeviceDetection.php
index b7af4cc..5c6667f 100644
--- a/includes/DeviceDetection.php
+++ b/includes/DeviceDetection.php
@@ -213,6 +213,17 @@
                        return '';
                }
        }
+
+       /**
+        * access a unique name that describes the type of device
+        *
+        * @return string
+        */
+       public function getDeviceId() {
+               $name = isset( $this->device['name'] ) ? $this->device['name'] 
: 'unknown';
+               $prefix = $this->isMobileDevice() ? 'mobile/' : 'desktop/';
+               return $prefix . $name;
+       }
 }
 
 /**
@@ -411,9 +422,12 @@
         */
        public function getDeviceProperties( $deviceName, $userAgent ) {
                if ( isset( self::$formats[$deviceName] ) ) {
-                       return new DeviceProperties( 
self::$formats[$deviceName], $userAgent );
+                       $deviceCapabilities = self::$formats[$deviceName];
+                       $deviceCapabilities['name'] = $deviceName;
+                       return new DeviceProperties( $deviceCapabilities, 
$userAgent );
                } else {
                        return new DeviceProperties( array(
+                               'name' => $deviceName,
                                'view_format' => 'html',
                                'css_file_name' => 'default',
                                'supports_javascript' => true,
diff --git a/includes/MobileFrontend.hooks.php 
b/includes/MobileFrontend.hooks.php
index dbbcbe3..fbbcf7c 100644
--- a/includes/MobileFrontend.hooks.php
+++ b/includes/MobileFrontend.hooks.php
@@ -28,6 +28,7 @@
                                $title->getText() => $user->isWatched( $title ),
                        );
                }
+               $vars[ 'wgMobileDeviceName' ] = 
MobileContext::singleton()->getDevice()->getDeviceId();
                return true;
        }
 

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

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