(bug 32748) unicode URL for articles print version
authorSanthosh Thottingal <santhosh.thottingal@gmail.com>
Thu, 29 Mar 2012 05:55:27 +0000 (11:25 +0530)
committerAntoine Musso <hashar@free.fr>
Mon, 2 Apr 2012 16:14:41 +0000 (18:14 +0200)
Printer friendly version of article must encode URL in unicode.

- Patch originally written by Brion Vibber
  https://bugzilla.wikimedia.org/attachment.cgi?id=9593
- introduces wfExpandIRI() global function, uses wfExpandIRI_callback.
- phpunit test.

Change-Id: I348b9f1d2ce65cb14f20d4a5751ac9359c8b8316

RELEASE-NOTES-1.20
includes/GlobalFunctions.php
includes/Skin.php
tests/phpunit/includes/GlobalFunctions/GlobalTest.php

index b358e79..37ae690 100644 (file)
@@ -55,6 +55,7 @@ production.
 * (bug 18704) Add an unique CSS class or ID to the tagfilter table row at RecentChanges 
 * (bug 33689) Upgrade to 1.19 on Postgres fails due to incomplete query when
               trying to defer foreign key for externallinks
+* (bug 32748) Printer friendly version of article decode Unicode chars as a pretty IRI in footer.
 
 === API changes in 1.20 ===
 * (bug 34316) Add ability to retrieve maximum upload size from MediaWiki API.
index e9f22de..bcbcefe 100644 (file)
@@ -802,6 +802,31 @@ function wfParseUrl( $url ) {
        return $bits;
 }
 
+/**
+ * Take a URL, make sure it's expanded to fully qualified, and replace any
+ * encoded non-ASCII Unicode characters with their UTF-8 original forms
+ * for more compact display and legibility for local audiences.
+ *
+ * @todo handle punycode domains too
+ *
+ * @param $url string
+ * @return string
+ */
+function wfExpandIRI( $url ) {
+       return preg_replace_callback( '/((?:%[89A-F][0-9A-F])+)/i', 'wfExpandIRI_callback', wfExpandUrl( $url ) );
+}
+
+/**
+ * Private callback for wfExpandIRI
+ * @param array $matches
+ * @return string
+ */
+function wfExpandIRI_callback( $matches ) {
+       return urldecode( $matches[1] );
+}
+
+
+
 /**
  * Make URL indexes, appropriate for the el_index field of externallinks.
  *
index eb2b8ae..8b10d7f 100644 (file)
@@ -647,10 +647,10 @@ abstract class Skin extends ContextSource {
        function printSource() {
                $oldid = $this->getRevisionId();
                if ( $oldid ) {
-                       $url = htmlspecialchars( $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid ) );
+                       $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid ) ) );
                } else {
                        // oldid not available for non existing pages
-                       $url = htmlspecialchars( $this->getTitle()->getCanonicalURL() );
+                       $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL() ) );
                }
                return $this->msg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' )->text();
        }
index 3cb42f1..a12410c 100644 (file)
@@ -55,6 +55,12 @@ class GlobalTest extends MediaWikiTestCase {
                        wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
        }
 
+       function testExpandIRI() {
+               $this->assertEquals(
+                       "https://te.wikibooks.org/wiki/ఉబుంటు_వాడుకరి_మార్గదర్శని",
+                       wfExpandIRI( "https://te.wikibooks.org/wiki/%E0%B0%89%E0%B0%AC%E0%B1%81%E0%B0%82%E0%B0%9F%E0%B1%81_%E0%B0%B5%E0%B0%BE%E0%B0%A1%E0%B1%81%E0%B0%95%E0%B0%B0%E0%B0%BF_%E0%B0%AE%E0%B0%BE%E0%B0%B0%E0%B1%8D%E0%B0%97%E0%B0%A6%E0%B0%B0%E0%B1%8D%E0%B0%B6%E0%B0%A8%E0%B0%BF" ) );
+       }
+
        function testReadOnlyEmpty() {
                global $wgReadOnly;
                $wgReadOnly = null;