r97215 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97214‎ | r97215 | r97216 >
Date:22:14, 15 September 2011
Author:preilly
Status:ok
Tags:
Comment:
mft r97214 and r97076
Modified paths:
  • /branches/wmf/1.17wmf1/extensions/MobileFrontend/MobileFrontend.php (modified) (history)
  • /branches/wmf/1.17wmf1/extensions/MobileFrontend/javascripts/application.js (modified) (history)
  • /branches/wmf/1.17wmf1/extensions/MobileFrontend/views/layout/application.html.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/extensions/MobileFrontend/javascripts/application.js
@@ -1,24 +1,34 @@
2 -/* Super gross hack implemented where MOST of the JS is repeated in lib/native_app_hack.rb
3 -If you make significant changes here, make sure to update that version too!*/
 2+// Ideally, this would be loaded in the head and activated by a script at the bottom,
 3+// I think, rather than attached to an onload...
 4+window.onload = function() {
 5+ // I don't think this makes sense. Loading this here means that this button
 6+ // won't function until the page is loaded. It would probably be an
 7+ // improvement to just attach an onclick straight into the html.
 8+ document.getElementById( 'logo' ).onclick = function() {
 9+ var n = document.getElementById( 'nav' ).style;
 10+ n.display = n.display == 'block' ? 'none' : 'block';
 11+ };
412
5 -$( document ).ready( function() {
6 - $( '#logo' ).click( function() {
7 - $( '#nav' ).toggle();
8 - });
 13+ // Also problematic, not working until the page loads...
 14+ for( var h = document.getElementsByTagName( 'h2' ), i = 0; i < h.length; i++ ) {
 15+ if ( h[i].className == 'section_heading' ) {
 16+ h[i].onclick = function() {
 17+ var section_idx = parseInt( this.id.replace( /section_(\d+)/, '$1' ) );
 18+ wm_toggle_section( section_idx );
 19+ }
 20+ }
 21+ };
922
10 - $( 'h2.section_heading' ).click( function() {
11 - var section_idx = parseInt( $( this ).get( 0 ).id.replace( /section_(\d+)/, '$1' ) );
12 - wm_toggle_section( section_idx );
13 - });
14 -
15 - $( 'a' ).click( function() {
16 - var link = $( this ).get( 0 );
17 - if( link.hash.indexOf( '#' ) == 0 ) {
18 - wm_reveal_for_hash( link.hash );
 23+ // And this...
 24+ for ( var a = document.getElementsByTagName( 'a' ), i = 0; i < a.length; i++ ) {
 25+ a[i].onclick = function() {
 26+ if ( this.hash.indexOf( '#' ) == 0 ) {
 27+ wm_reveal_for_hash( this.hash );
 28+ }
1929 }
20 - });
 30+ };
2131
22 - if( document.location.hash.indexOf( '#' ) == 0 ) {
 32+ if ( document.location.hash.indexOf( '#' ) == 0 ) {
2333 wm_reveal_for_hash( document.location.hash );
2434 }
2535
@@ -27,11 +37,12 @@
2838 // Try to scroll and hide URL bar
2939 window.scrollTo( 0, 1 );
3040
31 - decode = $( '#searchField' );
32 - decode.val( unescape( decode.val() ) );
33 - decode = $( 'title' );
34 - decode.html( unescape( decode.html() ) );
35 -});
 41+ // This is a global. I don't know why.
 42+ decode = document.getElementById( 'searchField' );
 43+ decode.value = unescape( decode.value );
 44+ decode = document.getElementsByTagName( 'title' )[0];
 45+ decode.innerHTML = unescape( decode.innerHTML );
 46+};
3647
3748 /**
3849 * updateOrientation checks the current orientation, sets the body's class
@@ -53,26 +64,27 @@
5465 window.onorientationchange = updateOrientation;
5566
5667 function wm_reveal_for_hash( hash ) {
57 - var targetel = $( hash );
58 - if( targetel ) {
59 - var parentdiv = targetel.parents( 'div.content_block' );
60 - if( parentdiv.length > 0 && ! parentdiv.is( ':visible' ) ) {
61 - var section_idx = parseInt( parentdiv.get( 0 ).id.replace( /content_(\d+)/, '$1' ) );
 68+ var targetel = document.getElementById( hash.substr(1) );
 69+ if ( targetel ) {
 70+ for (var p = targetel.parentNode; p && p.className != 'content_block' && p.className != 'section_heading'; ) {
 71+ p = p.parentNode;
 72+ }
 73+ if ( p && p.style.display != 'block' ) {
 74+ var section_idx = parseInt( p.id.split( '_' )[1] );
6275 wm_toggle_section( section_idx );
6376 }
6477 }
6578 }
6679
6780 function wm_toggle_section( section_id ) {
68 - $( 'h2#section_' + section_id ).children( 'button.show' ).toggle();
69 - $( 'h2#section_' + section_id ).children( 'button.hide' ).toggle();
70 -
71 - $( 'div#content_' + section_id ).toggle();
72 - $( 'div#anchor_' + section_id ).toggle();
73 -}
74 -
75 -var wm_clearText = function() {
76 - document.getElementById( 'searchField' ).value = '';
77 - $( '#searchField' ).val( '' ).focus();
78 -}
79 -
 81+ var b = document.getElementById( 'section_' + section_id ),
 82+ bb = b.getElementsByTagName( 'button' );
 83+ for ( var i = 0; i <= 1; i++ ) {
 84+ var s = bb[i].style;
 85+ s.display = s.display == 'none' || ( i && !s.display ) ? 'inline-block' : 'none';
 86+ }
 87+ for ( var i = 0, d = ['content_','anchor_']; i<=1; i++ ) {
 88+ var s = document.getElementById( d[i] + section_id ).style;
 89+ s.display = s.display == 'block' ? 'none' : 'block';
 90+ }
 91+}
\ No newline at end of file
Index: branches/wmf/1.17wmf1/extensions/MobileFrontend/MobileFrontend.php
@@ -707,13 +707,8 @@
708708 return $s;
709709 }
710710
711 - private function removeQuerystringVar( $url, $key ) {
712 - $url = preg_replace( '/(.*)(\?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&' );
713 - $url = substr( $url, 0, -1 );
714 - return ( $url );
715 - }
716 -
717711 private function createWMLCard( $s ) {
 712+ global $wgRequest;
718713 wfProfileIn( __METHOD__ );
719714 $segments = explode( $this->WMLSectionSeperator, $s );
720715 $card = '';
@@ -727,20 +722,28 @@
728723 $card .= "<p>" . $idx . "/" . $segmentsCount . "</p>";
729724
730725 $useFormatParam = ( isset( self::$useFormat ) ) ? '&' . 'useformat=' . self::$useFormat : '';
731 -
732 - $basePage = self::$currentURL;
733 -
734 - $basePage = $this->removeQuerystringVar( $this->removeQuerystringVar( $basePage, 'useformat' ), 'seg' );
735 -
736 - $delimiter = ( strpos( $basePage, '?' ) === false ) ? '?' : '&';
737726
 727+ // Title::getLocalUrl doesn't work at this point since PHP 5.1.x, all objects have their destructors called
 728+ // before the output buffer callback function executes.
 729+ // Thus, globalized objects will not be available as expected in the function.
 730+ // This is stated to be intended behavior, as per the following: [http://bugs.php.net/bug.php?id=40104]
 731+ $mDefaultQuery = $wgRequest->getQueryValues();
 732+ unset( $mDefaultQuery['seg'] );
 733+ unset( $mDefaultQuery['useformat'] );
 734+
 735+ $qs = wfArrayToCGI( $mDefaultQuery );
 736+ $delimiter = ( !empty( $qs ) ) ? '?' : '';
 737+ $basePageParts = wfParseUrl( self::$currentURL );
 738+ $basePage = $basePageParts['scheme'] . $basePageParts['delimiter'] . $basePageParts['host'] . $basePageParts['path'] . $delimiter . $qs;
 739+ $appendDelimiter = ( $delimiter === '?' ) ? '&' : '?';
 740+
738741 if ( $idx < $segmentsCount ) {
739 - $card .= "<p><a href=\"{$basePage}{$delimiter}seg={$idx}{$useFormatParam}\">" . self::$messages['mobile-frontend-wml-continue'] . "</a></p>";
 742+ $card .= "<p><a href=\"{$basePage}{$appendDelimiter}seg={$idx}{$useFormatParam}\">" . self::$messages['mobile-frontend-wml-continue'] . "</a></p>";
740743 }
741744
742745 if ( $idx > 1 ) {
743746 $back_idx = $requestedSegment - 1;
744 - $card .= "<p><a href=\"{$basePage}{$delimiter}seg={$back_idx}{$useFormatParam}\">" . self::$messages['mobile-frontend-wml-back'] . "</a></p>";
 747+ $card .= "<p><a href=\"{$basePage}{$appendDelimiter}seg={$back_idx}{$useFormatParam}\">" . self::$messages['mobile-frontend-wml-back'] . "</a></p>";
745748 }
746749
747750 $card .= '</card>';
@@ -931,6 +934,8 @@
932935 && empty( self::$search ) && !self::$isMainPage ) {
933936 $contentHtml = $this->headingTransform( $contentHtml );
934937 } elseif ( $this->contentFormat == 'WML' ) {
 938+ $homeButton = self::$messages['mobile-frontend-home-button'];
 939+ $randomButton = self::$messages['mobile-frontend-random-button'];
935940 //header( 'Content-Type: text/vnd.wap.wml' );
936941
937942 // TODO: Content transformations required
Index: branches/wmf/1.17wmf1/extensions/MobileFrontend/views/layout/application.html.php
@@ -34,7 +34,6 @@
3535 }
3636 //]]>
3737 </script>
38 - <script type="text/javascript" language="javascript" src="{$wgExtensionAssetsPath}/MobileFrontend/javascripts/jquery.js"></script>
3938 <script type="text/javascript" language="javascript" src="{$wgExtensionAssetsPath}/MobileFrontend/javascripts/application.js"></script>
4039 </head>
4140 <body>

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r97076fix for r97026 based on c22503preilly17:38, 14 September 2011
r97214fix for bug 30650 - remove jQuery from mobile sitepreilly22:10, 15 September 2011

Status & tagging log