From: Santhosh Thottingal Date: Thu, 29 Mar 2012 05:55:27 +0000 (+0530) Subject: (bug 32748) unicode URL for articles print version X-Git-Tag: 1.31.0-rc.0~24074^2 X-Git-Url: http://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=c56cca551e2e264a6eb686ece840151253c9492b (bug 32748) unicode URL for articles print version 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 --- diff --git a/RELEASE-NOTES-1.20 b/RELEASE-NOTES-1.20 index b358e79ac6..37ae690998 100644 --- a/RELEASE-NOTES-1.20 +++ b/RELEASE-NOTES-1.20 @@ -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. diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index e9f22de74c..bcbcefebb3 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -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. * diff --git a/includes/Skin.php b/includes/Skin.php index eb2b8ae20a..8b10d7fdff 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -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', '' . $url . '' )->text(); } diff --git a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php index 3cb42f126d..a12410c7c6 100644 --- a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php +++ b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php @@ -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;