MediaWiki  1.23.13
UtfNormalUtil.php
Go to the documentation of this file.
1 <?php
36 function codepointToUtf8( $codepoint ) {
37  if($codepoint < 0x80) return chr($codepoint);
38  if($codepoint < 0x800) return chr($codepoint >> 6 & 0x3f | 0xc0) .
39  chr($codepoint & 0x3f | 0x80);
40  if($codepoint < 0x10000) return chr($codepoint >> 12 & 0x0f | 0xe0) .
41  chr($codepoint >> 6 & 0x3f | 0x80) .
42  chr($codepoint & 0x3f | 0x80);
43  if($codepoint < 0x110000) return chr($codepoint >> 18 & 0x07 | 0xf0) .
44  chr($codepoint >> 12 & 0x3f | 0x80) .
45  chr($codepoint >> 6 & 0x3f | 0x80) .
46  chr($codepoint & 0x3f | 0x80);
47 
48  echo "Asked for code outside of range ($codepoint)\n";
49  die( -1 );
50 }
51 
61 function hexSequenceToUtf8( $sequence ) {
62  $utf = '';
63  foreach( explode( ' ', $sequence ) as $hex ) {
64  $n = hexdec( $hex );
65  $utf .= codepointToUtf8( $n );
66  }
67  return $utf;
68 }
69 
78 function utf8ToHexSequence( $str ) {
79  $buf = '';
80  foreach ( preg_split( '//u', $str, -1, PREG_SPLIT_NO_EMPTY ) as $cp ) {
81  $buf .= sprintf( '%04x ', utf8ToCodepoint( $cp ) );
82  }
83  return rtrim( $buf );
84 }
85 
94 function utf8ToCodepoint( $char ) {
95  # Find the length
96  $z = ord( $char[0] );
97  if ( $z & 0x80 ) {
98  $length = 0;
99  while ( $z & 0x80 ) {
100  $length++;
101  $z <<= 1;
102  }
103  } else {
104  $length = 1;
105  }
106 
107  if ( $length != strlen( $char ) ) {
108  return false;
109  }
110  if ( $length == 1 ) {
111  return ord( $char );
112  }
113 
114  # Mask off the length-determining bits and shift back to the original location
115  $z &= 0xff;
116  $z >>= $length;
117 
118  # Add in the free bits from subsequent bytes
119  for ( $i=1; $i < $length; $i++ ) {
120  $z <<= 6;
121  $z |= ord( $char[$i] ) & 0x3f;
122  }
123 
124  return $z;
125 }
126 
134 function escapeSingleString( $string ) {
135  return strtr( $string,
136  array(
137  '\\' => '\\\\',
138  '\'' => '\\\''
139  ));
140 }
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
utf8ToHexSequence
utf8ToHexSequence( $str)
Take a UTF-8 string and return a space-separated series of hex numbers representing Unicode code poin...
Definition: UtfNormalUtil.php:78
$n
$n
Definition: RandomTest.php:76
codepointToUtf8
codepointToUtf8( $codepoint)
Return UTF-8 sequence for a given Unicode code point.
Definition: UtfNormalUtil.php:36
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
hexSequenceToUtf8
hexSequenceToUtf8( $sequence)
Take a series of space-separated hexadecimal numbers representing Unicode code points and return a UT...
Definition: UtfNormalUtil.php:61
escapeSingleString
escapeSingleString( $string)
Escape a string for inclusion in a PHP single-quoted string literal.
Definition: UtfNormalUtil.php:134
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
utf8ToCodepoint
utf8ToCodepoint( $char)
Determine the Unicode codepoint of a single-character UTF-8 sequence.
Definition: UtfNormalUtil.php:94