MediaWiki  1.23.3
Fallback.php
Go to the documentation of this file.
1 <?php
26 class Fallback {
27 
34  public static function iconv( $from, $to, $string ) {
35  if ( substr( $to, -8 ) == '//IGNORE' ) {
36  $to = substr( $to, 0, strlen( $to ) - 8 );
37  }
38  if ( strcasecmp( $from, $to ) == 0 ) {
39  return $string;
40  }
41  if ( strcasecmp( $from, 'utf-8' ) == 0 ) {
42  return utf8_decode( $string );
43  }
44  if ( strcasecmp( $to, 'utf-8' ) == 0 ) {
45  return utf8_encode( $string );
46  }
47  return $string;
48  }
49 
66  public static function mb_substr( $str, $start, $count = 'end' ) {
67  if ( $start != 0 ) {
68  $split = self::mb_substr_split_unicode( $str, intval( $start ) );
69  $str = substr( $str, $split );
70  }
71 
72  if ( $count !== 'end' ) {
73  $split = self::mb_substr_split_unicode( $str, intval( $count ) );
74  $str = substr( $str, 0, $split );
75  }
76 
77  return $str;
78  }
79 
85  public static function mb_substr_split_unicode( $str, $splitPos ) {
86  if ( $splitPos == 0 ) {
87  return 0;
88  }
89 
90  $byteLen = strlen( $str );
91 
92  if ( $splitPos > 0 ) {
93  if ( $splitPos > 256 ) {
94  // Optimize large string offsets by skipping ahead N bytes.
95  // This will cut out most of our slow time on Latin-based text,
96  // and 1/2 to 1/3 on East European and Asian scripts.
97  $bytePos = $splitPos;
98  while ( $bytePos < $byteLen && $str[$bytePos] >= "\x80" && $str[$bytePos] < "\xc0" ) {
99  ++$bytePos;
100  }
101  $charPos = mb_strlen( substr( $str, 0, $bytePos ) );
102  } else {
103  $charPos = 0;
104  $bytePos = 0;
105  }
106 
107  while ( $charPos++ < $splitPos ) {
108  ++$bytePos;
109  // Move past any tail bytes
110  while ( $bytePos < $byteLen && $str[$bytePos] >= "\x80" && $str[$bytePos] < "\xc0" ) {
111  ++$bytePos;
112  }
113  }
114  } else {
115  $splitPosX = $splitPos + 1;
116  $charPos = 0; // relative to end of string; we don't care about the actual char position here
117  $bytePos = $byteLen;
118  while ( $bytePos > 0 && $charPos-- >= $splitPosX ) {
119  --$bytePos;
120  // Move past any tail bytes
121  while ( $bytePos > 0 && $str[$bytePos] >= "\x80" && $str[$bytePos] < "\xc0" ) {
122  --$bytePos;
123  }
124  }
125  }
126 
127  return $bytePos;
128  }
129 
136  public static function mb_strlen( $str, $enc = '' ) {
137  $counts = count_chars( $str );
138  $total = 0;
139 
140  // Count ASCII bytes
141  for ( $i = 0; $i < 0x80; $i++ ) {
142  $total += $counts[$i];
143  }
144 
145  // Count multibyte sequence heads
146  for ( $i = 0xc0; $i < 0xff; $i++ ) {
147  $total += $counts[$i];
148  }
149  return $total;
150  }
151 
160  public static function mb_strpos( $haystack, $needle, $offset = 0, $encoding = '' ) {
161  $needle = preg_quote( $needle, '/' );
162 
163  $ar = array();
164  preg_match( '/' . $needle . '/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset );
165 
166  if ( isset( $ar[0][1] ) ) {
167  return $ar[0][1];
168  } else {
169  return false;
170  }
171  }
172 
181  public static function mb_strrpos( $haystack, $needle, $offset = 0, $encoding = '' ) {
182  $needle = preg_quote( $needle, '/' );
183 
184  $ar = array();
185  preg_match_all( '/' . $needle . '/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset );
186 
187  if ( isset( $ar[0] ) && count( $ar[0] ) > 0 &&
188  isset( $ar[0][count( $ar[0] ) - 1][1] ) ) {
189  return $ar[0][count( $ar[0] ) - 1][1];
190  } else {
191  return false;
192  }
193  }
194 }
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
Fallback\mb_substr_split_unicode
static mb_substr_split_unicode( $str, $splitPos)
Definition: Fallback.php:85
$from
$from
Definition: importImages.php:90
Fallback\mb_strpos
static mb_strpos( $haystack, $needle, $offset=0, $encoding='')
Fallback implementation of mb_strpos, hardcoded to UTF-8.
Definition: Fallback.php:160
$total
$total
Definition: Utf8Test.php:92
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
Fallback\mb_strlen
static mb_strlen( $str, $enc='')
Fallback implementation of mb_strlen, hardcoded to UTF-8.
Definition: Fallback.php:136
$count
$count
Definition: UtfNormalTest2.php:96
Fallback\mb_strrpos
static mb_strrpos( $haystack, $needle, $offset=0, $encoding='')
Fallback implementation of mb_strrpos, hardcoded to UTF-8.
Definition: Fallback.php:181
Fallback
Fallback functions for PHP installed without mbstring support.
Definition: Fallback.php:26
Fallback\iconv
static iconv( $from, $to, $string)
Definition: Fallback.php:34
Fallback\mb_substr
static mb_substr( $str, $start, $count='end')
Fallback implementation for mb_substr, hardcoded to UTF-8.
Definition: Fallback.php:66