r105768 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105767‎ | r105768 | r105769 >
Date:19:30, 10 December 2011
Author:brion
Status:ok (Comments)
Tags:
Comment:
Initial commit of improved file page for MobileFrontend

Please test on various devices; may need to be altered or removed for devices with less-capable browsers, but might work fine.
Known good on iOS 5 and Android 2.3 browsers.

Based on previous mockup work.

Reformats the filetoc list and turns the links into toggles for which section to show.
Each section shows by itself, so a wide history table doesn't hose the rest of the page.
Image is fit to the screen, but still using the larger-size screen thumbnail so looks nice and high-res and zoomable.
Disables clickthrough on the image (can still copy the link etc, but tapping won't shove you through to the raw image by accident. You can still tap on the detail links, which still exist)


Similar improvements should be brought to the desktop site, perhaps. :)
Modified paths:
  • /trunk/extensions/MobileFrontend/MobileFrontend.php (modified) (history)
  • /trunk/extensions/MobileFrontend/javascripts/filepage.js (added) (history)
  • /trunk/extensions/MobileFrontend/stylesheets/filepage.css (added) (history)
  • /trunk/extensions/MobileFrontend/views/layout/application.html.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/javascripts/filepage.js
@@ -0,0 +1,107 @@
 2+(function() {
 3+
 4+function select(selector) {
 5+ if (selector.substr(0, 1) === '#') {
 6+ var node = document.getElementById(selector.substr(1));
 7+ if (node === null) {
 8+ return [];
 9+ } else {
 10+ return [node];
 11+ }
 12+ } else if (selector.substr(0, 1) === '.') {
 13+ return document.getElementsByClassName(selector.substr(1));
 14+ } else {
 15+ throw new Error("Unrecognized selector " + selector);
 16+ }
 17+}
 18+
 19+function setDisplay(selector, display) {
 20+ var nodes = select(selector);
 21+ for (var i = 0; i < nodes.length; i++) {
 22+ nodes[i].style.display = display;
 23+ }
 24+}
 25+
 26+function show(selector) {
 27+ setDisplay(selector, 'block');
 28+}
 29+
 30+function hide(selector) {
 31+ setDisplay(selector, 'none');
 32+}
 33+
 34+var chunks = {
 35+ file: [
 36+ '#file',
 37+ '.fullMedia',
 38+ '#mw-imagepage-content'
 39+ ],
 40+ filehistory: [
 41+ '#filehistory',
 42+ '#mw-imagepage-section-filehistory',
 43+ '#mw-imagepage-reupload-link',
 44+ '#mw-imagepage-edit-external'
 45+ ],
 46+ filelinks: [
 47+ '#filelinks',
 48+ '#mw-imagepage-section-linkstoimage'
 49+ ],
 50+ metadata: [
 51+ '#metadata',
 52+ '.mw-imagepage-section-metadata',
 53+ ]
 54+}
 55+
 56+function makeToggle(thisId) {
 57+ return function(event) {
 58+ for (id in chunks) {
 59+ if (chunks.hasOwnProperty(id)) {
 60+ var selectors = chunks[id], act;
 61+ if (id === thisId) {
 62+ act = show;
 63+ } else {
 64+ act = hide;
 65+ }
 66+ for (var i = 0; i < selectors.length; i++) {
 67+ act(selectors[i]);
 68+ }
 69+ }
 70+ }
 71+ return false;
 72+ };
 73+}
 74+
 75+function addToggle(id) {
 76+ var filetoc = document.getElementById('filetoc'),
 77+ items = filetoc.getElementsByTagName('a');
 78+ for (var i = 0; i < items.length; i++) {
 79+ var item = items[i],
 80+ href = item.href,
 81+ hashPos = href.search('#'),
 82+ hash = href.substr(hashPos + 1);
 83+ if (hash == id) {
 84+ items[i].onclick = makeToggle(id);
 85+ }
 86+ }
 87+}
 88+
 89+for (id in chunks) {
 90+ if (chunks.hasOwnProperty(id)) {
 91+ addToggle(id);
 92+ }
 93+}
 94+
 95+function stopClickThrough() {
 96+ var file = document.getElementById('file'),
 97+ links = file.getElementsByTagName('a');
 98+ if (links.length) {
 99+ links[0].onclick = function() {
 100+ return false;
 101+ };
 102+ }
 103+}
 104+
 105+stopClickThrough();
 106+makeToggle('file')();
 107+
 108+})();
Index: trunk/extensions/MobileFrontend/stylesheets/filepage.css
@@ -0,0 +1,31 @@
 2+#filetoc {
 3+ display: block;
 4+ background-color: black;
 5+ background-image: -moz-linear-gradient(center top, #3E3E3E 0%, #393939 14%, #2E2E2E 32%, #151515 64%, #080808 84%, #010101 100%);
 6+ background-image: -webkit-linear-gradient(center top, #3E3E3E 0%, #393939 14%, #2E2E2E 32%, #151515 64%, #080808 84%, #010101 100%);
 7+ background-image: -o-linear-gradient(center top, #3E3E3E 0%, #393939 14%, #2E2E2E 32%, #151515 64%, #080808 84%, #010101 100%);
 8+ background-image: -ms-linear-gradient(center top, #3E3E3E 0%, #393939 14%, #2E2E2E 32%, #151515 64%, #080808 84%, #010101 100%);
 9+ background-image: linear-gradient(center top, #3E3E3E 0%, #393939 14%, #2E2E2E 32%, #151515 64%, #080808 84%, #010101 100%);
 10+ color: white;
 11+ text-align: center;
 12+
 13+ padding: 0;
 14+ margin: 0;
 15+}
 16+
 17+#filetoc a {
 18+ color: white;
 19+}
 20+
 21+#filetoc li {
 22+ display: inline-block;
 23+ padding: 8px;
 24+ margin: 0;
 25+}
 26+
 27+#file img {
 28+ max-width: 100%;
 29+ height: auto;
 30+}
 31+
 32+
Index: trunk/extensions/MobileFrontend/MobileFrontend.php
@@ -132,6 +132,7 @@
133133 public static $languageUrls;
134134 public static $wsLoginToken = '';
135135 public static $wsLoginFormAction = '';
 136+ public static $isFilePage;
136137
137138 public static $messageKeys = array(
138139 'mobile-frontend-show-button',
@@ -458,6 +459,9 @@
459460 if ( Title::newMainPage()->equals( self::$title ) ) {
460461 self::$isMainPage = true;
461462 }
 463+ if ( self::$title->getNamespace() == NS_FILE ) {
 464+ self::$isFilePage = true;
 465+ }
462466
463467 self::$htmlTitle = $out->getHTMLTitle();
464468 self::$disableImages = $wgRequest->getText( 'disableImages', 0 );
Index: trunk/extensions/MobileFrontend/views/layout/application.html.php
@@ -23,7 +23,12 @@
2424
2525 $openSearchScript = $startScriptTag . $javaScriptPath . $betaPrefix . 'opensearch.js?version=12012011126437' . $endScriptTag;
2626 $jQueryScript = ( self::$device['supports_jquery'] ) ? $startScriptTag . $javaScriptPath . 'jquery-1.7.1.min.js' . $endScriptTag : '';
 27+$filePageScript = ( self::$isFilePage ) ? $startScriptTag . $javaScriptPath . 'filepage.js' . $endScriptTag : '';
2728
 29+$startLinkTag = "<link href='{$wgExtensionAssetsPath}/MobileFrontend/stylesheets/";
 30+$endLinkTag = "' media='all' rel='Stylesheet' type='text/css' />";
 31+$filePageStyle = ( self::$isFilePage ) ? $startLinkTag . 'filepage.css' . $endLinkTag : '';
 32+
2833 $applicationHtml = <<<HTML
2934 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3035 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@@ -33,6 +38,7 @@
3439 <meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
3540 <link href='{$wgExtensionAssetsPath}/MobileFrontend/stylesheets/{$betaPrefix}common.css?version=12012011121954' media='all' rel='Stylesheet' type='text/css' />
3641 <link href='{$wgExtensionAssetsPath}/MobileFrontend/stylesheets/{$cssFileName}.css?version=12012011120715' media='all' rel='Stylesheet' type='text/css' />
 42+ {$filePageStyle}
3743 <meta name="ROBOTS" content="NOINDEX, NOFOLLOW" />
3844 <meta name="viewport" content="width=device-width, initial-scale=1.0">
3945 {$appleTouchIconTag}
@@ -54,6 +60,7 @@
5561 {$footerHtml}
5662 {$startScriptTag}{$javaScriptPath}{$betaPrefix}application.js?version=12012011120915{$endScriptTag}
5763 {$openSearchScript}
 64+ {$filePageScript}
5865 </body>
5966 </html>
6067 HTML;

Sign-offs

UserFlagDate
Reedytested15:07, 16 January 2012
Reedyinspected15:07, 16 January 2012

Comments

#Comment by Reedy (talk | contribs)   15:07, 16 January 2012

Tested in:

  • Android 2.3.5
    • Default browser - Ok
    • Firefox 9 - Seems to still use the full page (but desktop chrome doesn't?). File history, metadata and file usage still displayed
    • Opera Mini 6.5.2 - Won't load network site (it sucks!)
    • Opera Mobile 11.5.3 - Ok
  • Motorola Xoom 3.2.1 (manually pointed at mobile site)
    • Default browser - Ok
    • Firefox 9 - Displays proper mobile page, rather than what it does on 2.3.5
    • Opera Mini 6.5.2 - Won't load network site (it sucks!)
    • Opera Mobile 11.5.3 - Ok
#Comment by Reedy (talk | contribs)   15:10, 16 January 2012

svn:eol-style has been fixed

Marking ok on this basis, seems to work fine from my testing

Status & tagging log