Brion VIBBER has uploaded a new change for review. https://gerrit.wikimedia.org/r/145424
Change subject: File page cleanup hacks ...................................................................... File page cleanup hacks * hide edit section pencils that don't work * disable tapping on the actual image's link * make other links on the file page work, opening Safari Change-Id: I6f04c2e1295e3e61bc1aaf1864ac115ad584124f --- M wikipedia/View Controllers/WebView/WebViewController.m M wikipedia/assets/bundle.js M www/js/listeners.js M www/js/wikihacks.js 4 files changed, 62 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/ios/wikipedia refs/changes/24/145424/1 diff --git a/wikipedia/View Controllers/WebView/WebViewController.m b/wikipedia/View Controllers/WebView/WebViewController.m index b6da02b..71d3050 100644 --- a/wikipedia/View Controllers/WebView/WebViewController.m +++ b/wikipedia/View Controllers/WebView/WebViewController.m @@ -895,14 +895,13 @@ domain: [SessionSingleton sharedInstance].currentArticleDomain discoveryMethod: DISCOVERY_METHOD_LINK invalidatingCache: NO]; - }else if ([href hasPrefix:@"//"]) { - href = [@"http:" stringByAppendingString:href]; + } else if ([href hasPrefix:@"http:"] || [href hasPrefix:@"https:"] || [href hasPrefix:@"//"]) { + // A standard external link, either explicitly http(s) or left protocol-relative on web meaning http(s) + if ([href hasPrefix:@"//"]) { + // Expand protocol-relative link to https -- secure by default! + href = [@"https:" stringByAppendingString:href]; + } -NSString *msg = [NSString stringWithFormat:@"To do: add code for navigating to external link: %@", href]; -[weakSelf.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"alert('%@')", msg]]; - - } else if ([href hasPrefix:@"http:"] || [href hasPrefix:@"https:"]) { - // A standard link. // TODO: make all of the stuff above parse the URL into parts // unless it's /wiki/ or #anchor style. // Then validate if it's still in Wikipedia land and branch appropriately. diff --git a/wikipedia/assets/bundle.js b/wikipedia/assets/bundle.js index 349d10c..b31f0c0 100644 --- a/wikipedia/assets/bundle.js +++ b/wikipedia/assets/bundle.js @@ -144,6 +144,7 @@ wikihacks.allowDivWidthsToFlow(); */ wikihacks.hideRedLinks(); + wikihacks.tweakFilePage(); }); bridge.registerListener( "prepend", function( payload ) { @@ -360,4 +361,31 @@ } } +exports.tweakFilePage = function() { + var filetoc = document.getElementById( 'filetoc' ); + if (filetoc) { + // We're on a File: page! Do some quick hacks. + // In future, replace entire thing with a custom view most of the time. + var content = document.getElementById( 'content' ); + + // Hide edit sections + var editSections = content.querySelectorAll('.edit_section_button'); + for (var i = 0; i < editSections.length; i++) { + editSections[i].style.display = 'none'; + } + + var fullImageLink = content.querySelector('.fullImageLink a'); + if (fullImageLink) { + // Don't replace the a with a span, as it will break styles + // Just disable clicking. + fullImageLink.addEventListener( 'touchstart', function( event ) { + event.preventDefault(); + } ); + fullImageLink.addEventListener( 'click', function( event ) { + event.preventDefault(); + } ); + } + } +} + },{}]},{},[1,2,3,4,5]) \ No newline at end of file diff --git a/www/js/listeners.js b/www/js/listeners.js index f7b2bfa..019198e 100644 --- a/www/js/listeners.js +++ b/www/js/listeners.js @@ -48,6 +48,7 @@ wikihacks.allowDivWidthsToFlow(); */ wikihacks.hideRedLinks(); + wikihacks.tweakFilePage(); }); bridge.registerListener( "prepend", function( payload ) { diff --git a/www/js/wikihacks.js b/www/js/wikihacks.js index 0e26db2..455bf5b 100644 --- a/www/js/wikihacks.js +++ b/www/js/wikihacks.js @@ -80,3 +80,30 @@ redLink.parentNode.replaceChild( replacementSpan, redLink ); } } + +exports.tweakFilePage = function() { + var filetoc = document.getElementById( 'filetoc' ); + if (filetoc) { + // We're on a File: page! Do some quick hacks. + // In future, replace entire thing with a custom view most of the time. + var content = document.getElementById( 'content' ); + + // Hide edit sections + var editSections = content.querySelectorAll('.edit_section_button'); + for (var i = 0; i < editSections.length; i++) { + editSections[i].style.display = 'none'; + } + + var fullImageLink = content.querySelector('.fullImageLink a'); + if (fullImageLink) { + // Don't replace the a with a span, as it will break styles + // Just disable clicking. + fullImageLink.addEventListener( 'touchstart', function( event ) { + event.preventDefault(); + } ); + fullImageLink.addEventListener( 'click', function( event ) { + event.preventDefault(); + } ); + } + } +} -- To view, visit https://gerrit.wikimedia.org/r/145424 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6f04c2e1295e3e61bc1aaf1864ac115ad584124f Gerrit-PatchSet: 1 Gerrit-Project: apps/ios/wikipedia Gerrit-Branch: master Gerrit-Owner: Brion VIBBER <br...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits