MediaWiki  1.23.2
RandomTest.php
Go to the documentation of this file.
1 <?php
29 if( PHP_SAPI != 'cli' ) {
30  die( "Run me from the command line please.\n" );
31 }
32 
34 require_once 'UtfNormal.php';
35 require_once '../diff/DifferenceEngine.php';
36 
37 dl( 'php_utfnormal.so' );
38 
39 # mt_srand( 99999 );
40 
41 function randomString( $length, $nullOk, $ascii = false ) {
42  $out = '';
43  for( $i = 0; $i < $length; $i++ )
44  $out .= chr( mt_rand( $nullOk ? 0 : 1, $ascii ? 127 : 255 ) );
45  return $out;
46 }
47 
48 /* Duplicate of the cleanUp() path for ICU usage */
49 function donorm( $str ) {
50  # We exclude a few chars that ICU would not.
51  $str = preg_replace( '/[\x00-\x08\x0b\x0c\x0e-\x1f]/', UTF8_REPLACEMENT, $str );
52  $str = str_replace( UTF8_FFFE, UTF8_REPLACEMENT, $str );
53  $str = str_replace( UTF8_FFFF, UTF8_REPLACEMENT, $str );
54 
55  # UnicodeString constructor fails if the string ends with a head byte.
56  # Add a junk char at the end, we'll strip it off
57  return rtrim( utf8_normalize( $str . "\x01", UtfNormal::UNORM_NFC ), "\x01" );
58 }
59 
60 function showDiffs( $a, $b ) {
61  $ota = explode( "\n", str_replace( "\r\n", "\n", $a ) );
62  $nta = explode( "\n", str_replace( "\r\n", "\n", $b ) );
63 
64  $diffs = new Diff( $ota, $nta );
65  $formatter = new TableDiffFormatter();
66  $funky = $formatter->format( $diffs );
67  $matches = array();
68  preg_match_all( '/<(?:ins|del) class="diffchange">(.*?)<\/(?:ins|del)>/', $funky, $matches );
69  foreach( $matches[1] as $bit ) {
70  $hex = bin2hex( $bit );
71  echo "\t$hex\n";
72  }
73 }
74 
75 $size = 16;
76 $n = 0;
77 while( true ) {
78  $n++;
79  echo "$n\n";
80 
81  $str = randomString( $size, true);
82  $clean = UtfNormal::cleanUp( $str );
83  $norm = donorm( $str );
84 
85  echo strlen( $clean ) . ", " . strlen( $norm );
86  if( $clean == $norm ) {
87  echo " (match)\n";
88  } else {
89  echo " (FAIL)\n";
90  echo "\traw: " . bin2hex( $str ) . "\n" .
91  "\tphp: " . bin2hex( $clean ) . "\n" .
92  "\ticu: " . bin2hex( $norm ) . "\n";
93  echo "\n\tdiffs:\n";
94  showDiffs( $clean, $norm );
95  die();
96  }
97 
98 
99  $str = '';
100  $clean = '';
101  $norm = '';
102 }
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
UTF8_FFFF
const UTF8_FFFF
Definition: UtfNormalDefines.php:75
randomString
randomString( $length, $nullOk, $ascii=false)
Definition: RandomTest.php:41
UtfNormal\cleanUp
static cleanUp( $string)
The ultimate convenience function! Clean up invalid UTF-8 sequences, and convert to normal form C,...
Definition: UtfNormal.php:79
$n
$n
Definition: RandomTest.php:76
TableDiffFormatter
MediaWiki default table style diff formatter.
Definition: TableDiffFormatter.php:33
donorm
donorm( $str)
Definition: RandomTest.php:49
$out
$out
Definition: UtfNormalGenerate.php:167
UTF8_FFFE
const UTF8_FFFE
Definition: UtfNormalDefines.php:74
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
$matches
if(!defined( 'MEDIAWIKI')) if(!isset( $wgVersion)) $matches
Definition: NoLocalSettings.php:33
$size
$size
Definition: RandomTest.php:75
UtfNormal\UNORM_NFC
const UNORM_NFC
Definition: UtfNormal.php:55
showDiffs
showDiffs( $a, $b)
Definition: RandomTest.php:60
UTF8_REPLACEMENT
const UTF8_REPLACEMENT
Definition: UtfNormalDefines.php:64
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
Diff
Class representing a 'diff' between two sequences of strings.
Definition: DairikiDiff.php:705