From: Amir E. Aharoni Date: Sat, 31 Mar 2012 10:19:37 +0000 (+0300) Subject: Adding getDirMarkEntity(). X-Git-Tag: 1.31.0-rc.0~24088 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22auteur_infos%22%2C%22id_auteur=%24connect_id_auteur%22%29%20.%20%22?a=commitdiff_plain;h=b2b3075afddccafeda95b35698c50482771dd7be;p=lhc%2Fweb%2Fwiklou.git Adding getDirMarkEntity(). This function is similar to getDirMark(), but it adds HTML entities instead of invisible Unicode characters. It's based on MaxSem's suggestion in https://gerrit.wikimedia.org/r/#change,3929 Change-Id: I5bd362d6e6a56478bf9f58b2b81fcad31be12d35 --- diff --git a/languages/Language.php b/languages/Language.php index d705b49d77..1ef5a74591 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -2597,16 +2597,35 @@ class Language { } /** - * A hidden direction mark (LRM or RLM), depending on the language direction + * A hidden direction mark (LRM or RLM), depending on the language direction. + * Unlike getDirMark(), this function returns the character as an HTML entity. + * This function should be used when the output is guaranteed to be HTML, + * because it makes the output HTML source code more readable. When + * the output is plain text or can be escaped, getDirMark() should be used. + * + * @param $opposite Boolean Get the direction mark opposite to your language + * @return string + */ + function getDirMarkEntity( $opposite = false ) { + if ( $opposite ) { return $this->isRTL() ? '‎' : '‏'; } + return $this->isRTL() ? '‏' : '‎'; + } + + /** + * A hidden direction mark (LRM or RLM), depending on the language direction. + * This function produces them as invisible Unicode characters and + * the output may be hard to read and debug, so it should only be used + * when the output is plain text or can be escaped. When the output is + * HTML, use getDirMarkEntity() instead. * * @param $opposite Boolean Get the direction mark opposite to your language * @return string */ function getDirMark( $opposite = false ) { - $rtl = "\xE2\x80\x8F"; - $ltr = "\xE2\x80\x8E"; - if ( $opposite ) { return $this->isRTL() ? $ltr : $rtl; } - return $this->isRTL() ? $rtl : $ltr; + $lrm = "\xE2\x80\x8E"; # LEFT-TO-RIGHT MARK, commonly abbreviated LRM + $rlm = "\xE2\x80\x8F"; # RIGHT-TO-LEFT MARK, commonly abbreviated RLM + if ( $opposite ) { return $this->isRTL() ? $lrm : $rlm; } + return $this->isRTL() ? $rlm : $lrm; } /**