r103118 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103117‎ | r103118 | r103119 >
Date:01:41, 15 November 2011
Author:brion
Status:deferred
Tags:
Comment:
Frame proxy stub for Athena UI mockup; loads pages in mobile style, but removes the header/footer and starts on setting up a frame interface to send data & navigation events to the parent window.
An interface like this on the 'native' mobile UI view could allow multiple alternate UIs to embed content safely.
Modified paths:
  • /trunk/mockups/athena/frame-inner.js (added) (history)
  • /trunk/mockups/athena/proxy.php (added) (history)

Diff [purge]

Index: trunk/mockups/athena/proxy.php
@@ -0,0 +1,59 @@
 2+<?php
 3+
 4+$base = 'http://en.wikipedia.org/wiki/$1?useformat=mobile';
 5+
 6+function failOut($http, $text) {
 7+ header('HTTP/1.x ' . $http);
 8+ die(htmlspecialchars($text));
 9+}
 10+
 11+if (!isset($_GET['title'])) {
 12+ failOut('400 Invalid Request', 'No title');
 13+}
 14+if (!is_string($_GET['title'])) {
 15+ failOut('400 Invalid Request', 'Invalid title');
 16+}
 17+
 18+$title = $_GET['title'];
 19+
 20+if (get_magic_quotes_gpc()) {
 21+ $title = removeslashes($title);
 22+}
 23+
 24+$url = str_replace(
 25+ '$1',
 26+ urlencode(str_replace(' ', '_', $title)),
 27+ $base
 28+);
 29+
 30+
 31+$context = stream_context_create(
 32+ array(
 33+ 'http' => array(
 34+ 'user_agent' => 'Wikipedia Mobile (Athena mockup)',
 35+ ),
 36+ )
 37+);
 38+
 39+$content = file_get_contents($url, false, $context);
 40+
 41+$dom = new DOMDocument();
 42+$dom->loadHTML($content);
 43+
 44+// Inject our frame client API
 45+$head = $dom->getElementsByTagName('head')->item(0);
 46+$script = $dom->createElement('script');
 47+$script->setAttribute('src', 'frame-inner.js');
 48+$head->appendChild($script);
 49+
 50+// Hide header/footer
 51+function hide($element) {
 52+ // don't remove header or some scripts will break
 53+ $element->setAttribute('style', 'display: none');
 54+}
 55+hide($dom->getElementById('header'));
 56+hide($dom->getElementById('footer'));
 57+
 58+$html = $dom->saveHTML();
 59+echo $html;
 60+
Property changes on: trunk/mockups/athena/proxy.php
___________________________________________________________________
Added: svn:eol-style
161 + native
Index: trunk/mockups/athena/frame-inner.js
@@ -0,0 +1,40 @@
 2+// Limited embed frame-inner API
 3+// Sends some events up to the parent when we navigate
 4+
 5+(function() {
 6+
 7+function messageParent(data) {
 8+ var msg = '[wiki-mobile-embed]' + JSON.stringify(data);
 9+ if (window.parent && window.parent !== window) {
 10+ window.parent.postMessage(msg, '*');
 11+ } else {
 12+ alert(msg);
 13+ }
 14+}
 15+
 16+window.addEventListener('DOMContentLoaded', function(event) {
 17+ messageParent({
 18+ event: 'ready'
 19+ });
 20+}, false);
 21+
 22+window.addEventListener('load', function(event) {
 23+ messageParent({
 24+ event: 'load'
 25+ });
 26+}, false);
 27+
 28+window.addEventListener('click', function(event) {
 29+ var target = event.target;
 30+ if (target.nodeName.toLowerCase() == 'a') {
 31+ event.stopPropagation();
 32+ event.preventDefault();
 33+ messageParent({
 34+ event: 'navigate',
 35+ url: target.getAttribute('href')
 36+ });
 37+ }
 38+}, true );
 39+
 40+})();
 41+
Property changes on: trunk/mockups/athena/frame-inner.js
___________________________________________________________________
Added: svn:eol-style
142 + native

Status & tagging log