Kaldari has uploaded a new change for review.

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


Change subject: Refactor some of the warning code for footer links.
......................................................................

Refactor some of the warning code for footer links.

Rather than assuming that the links are using certain messages, it
now retrieves the messages that are set for the skin template by
the SkinMobile class. If the messages are using a local link, leave
them alone. If they are using an external link, add the data
charges warning.

This makes the handling of the footer links more flexible and less
fragile.

Change-Id: I41e636911613ac1cade752618b219d7a3011ccdb
---
M includes/PageRenderingHooks.php
1 file changed, 16 insertions(+), 11 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ZeroRatedMobileAccess 
refs/changes/91/85391/1

diff --git a/includes/PageRenderingHooks.php b/includes/PageRenderingHooks.php
index 2bf1c15..14cb7d6 100644
--- a/includes/PageRenderingHooks.php
+++ b/includes/PageRenderingHooks.php
@@ -167,9 +167,10 @@
 
                $skin = new SkinTemplate();
 
-               self::addWarning( $template, 'mobile-license', $req, wfMessage( 
'mobile-frontend-footer-license' )->parse() );
-               self::addWarning( $template, 'privacy', $req, 
$skin->footerLink( 'mobile-frontend-privacy-link-text', 'privacypage' ) );
-               self::addWarning( $template, 'terms-use', $req, wfMessage( 
'mobile-frontend-terms-use-text' )->parse() );
+               // Add warnings to footer links
+               self::addWarning( $template, 'mobile-license', $req );
+               self::addWarning( $template, 'privacy', $req );
+               self::addWarning( $template, 'terms-use', $req );
 
                return true;
        }
@@ -770,17 +771,21 @@
         * @param BaseTemplate $template
         * @param string $templateValName The name of the template
         * @param WebRequest $request The request object that will contain the 
request path.
-        * @param string $link The full link, usually parsed wikitext.
         */
-       private static function addWarning( BaseTemplate $template, 
$templateValName, WebRequest $request, $link ) {
+       private static function addWarning( BaseTemplate $template, 
$templateValName, WebRequest $request ) {
+               $link = $template->get( $templateValName );
                if ( preg_match( '/href=[\'"](.*?)[\'"]/', $link, $match ) ) {
-                       $link = str_replace(
-                               $match[1],
-                               $request->appendQuery( 
'&renderZeroRatedRedirect=true&returnto=' ) . urlencode( $match[1] ),
-                               $link
-                       );
+                       // If it's a local link (begins with '/w' for example), 
don't add warning
+                       if ( !preg_match( '/^\/[^\/]/', $match[1] ) ) {
+                               // Add data charges warning to the link
+                               $link = str_replace(
+                                       $match[1],
+                                       $request->appendQuery( 
'&renderZeroRatedRedirect=true&returnto=' ) . urlencode( $match[1] ),
+                                       $link
+                               );
+                               $template->set( $templateValName, $link );
+                       }
                }
-               $template->set( $templateValName, $link );
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I41e636911613ac1cade752618b219d7a3011ccdb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ZeroRatedMobileAccess
Gerrit-Branch: master
Gerrit-Owner: Kaldari <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to