MediaWiki  1.23.12
preprocessorFuzzTest.php
Go to the documentation of this file.
1 <?php
24 require_once __DIR__ . '/commandLine.inc';
25 
26 $wgHooks['BeforeParserFetchTemplateAndtitle'][] = 'PPFuzzTester::templateHook';
27 
28 class PPFuzzTester {
29  public $hairs = array(
30  '[[', ']]', '{{', '{{', '}}', '}}', '{{{', '}}}',
31  '<', '>', '<nowiki', '<gallery', '</nowiki>', '</gallery>', '<nOwIkI>', '</NoWiKi>',
32  '<!--', '-->',
33  "\n==", "==\n",
34  '|', '=', "\n", ' ', "\t", "\x7f",
35  '~~', '~~~', '~~~~', 'subst:',
36  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
37  'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
38 
39  // extensions
40  // '<ref>', '</ref>', '<references/>',
41  );
42  public $minLength = 0;
43  public $maxLength = 20;
44  public $maxTemplates = 5;
45  // public $outputTypes = array( 'OT_HTML', 'OT_WIKI', 'OT_PREPROCESS' );
46  public $entryPoints = array( 'testSrvus', 'testPst', 'testPreprocess' );
47  public $verbose = false;
48  static $currentTest = false;
49 
50  function execute() {
51  if ( !file_exists( 'results' ) ) {
52  mkdir( 'results' );
53  }
54  if ( !is_dir( 'results' ) ) {
55  echo "Unable to create 'results' directory\n";
56  exit( 1 );
57  }
58  $overallStart = microtime( true );
59  $reportInterval = 1000;
60  for ( $i = 1; true; $i++ ) {
61  $t = -microtime( true );
62  try {
63  self::$currentTest = new PPFuzzTest( $this );
64  self::$currentTest->execute();
65  $passed = 'passed';
66  } catch ( MWException $e ) {
67  $testReport = self::$currentTest->getReport();
68  $exceptionReport = $e->getText();
69  $hash = md5( $testReport );
70  file_put_contents( "results/ppft-$hash.in", serialize( self::$currentTest ) );
71  file_put_contents( "results/ppft-$hash.fail",
72  "Input:\n$testReport\n\nException report:\n$exceptionReport\n" );
73  print "Test $hash failed\n";
74  $passed = 'failed';
75  }
76  $t += microtime( true );
77 
78  if ( $this->verbose ) {
79  printf( "Test $passed in %.3f seconds\n", $t );
80  print self::$currentTest->getReport();
81  }
82 
83  $reportMetric = ( microtime( true ) - $overallStart ) / $i * $reportInterval;
84  if ( $reportMetric > 25 ) {
85  if ( substr( $reportInterval, 0, 1 ) === '1' ) {
86  $reportInterval /= 2;
87  } else {
88  $reportInterval /= 5;
89  }
90  } elseif ( $reportMetric < 4 ) {
91  if ( substr( $reportInterval, 0, 1 ) === '1' ) {
92  $reportInterval *= 5;
93  } else {
94  $reportInterval *= 2;
95  }
96  }
97  if ( $i % $reportInterval == 0 ) {
98  print "$i tests done\n";
99  /*
100  $testReport = self::$currentTest->getReport();
101  $filename = 'results/ppft-' . md5( $testReport ) . '.pass';
102  file_put_contents( $filename, "Input:\n$testReport\n" );*/
103  }
104  }
105  }
106 
107  function makeInputText( $max = false ) {
108  if ( $max === false ) {
109  $max = $this->maxLength;
110  }
111  $length = mt_rand( $this->minLength, $max );
112  $s = '';
113  for ( $i = 0; $i < $length; $i++ ) {
114  $hairIndex = mt_rand( 0, count( $this->hairs ) - 1 );
115  $s .= $this->hairs[$hairIndex];
116  }
117  // Send through the UTF-8 normaliser
118  // This resolves a few differences between the old preprocessor and the
119  // XML-based one, which doesn't like illegals and converts line endings.
120  // It's done by the MW UI, so it's a reasonably legitimate thing to do.
122  $s = $wgContLang->normalize( $s );
123  return $s;
124  }
125 
126  function makeTitle() {
127  return Title::newFromText( mt_rand( 0, 1000000 ), mt_rand( 0, 10 ) );
128  }
129 
130  /*
131  function pickOutputType() {
132  $count = count( $this->outputTypes );
133  return $this->outputTypes[ mt_rand( 0, $count - 1 ) ];
134  }*/
135 
136  function pickEntryPoint() {
137  $count = count( $this->entryPoints );
138  return $this->entryPoints[ mt_rand( 0, $count - 1 ) ];
139  }
140 }
141 
142 class PPFuzzTest {
144 
145  function __construct( $tester ) {
146  global $wgMaxSigChars;
147  $this->parent = $tester;
148  $this->mainText = $tester->makeInputText();
149  $this->title = $tester->makeTitle();
150  // $this->outputType = $tester->pickOutputType();
151  $this->entryPoint = $tester->pickEntryPoint();
152  $this->nickname = $tester->makeInputText( $wgMaxSigChars + 10 );
153  $this->fancySig = (bool)mt_rand( 0, 1 );
154  $this->templates = array();
155  }
156 
160  function templateHook( $title ) {
161  $titleText = $title->getPrefixedDBkey();
162 
163  if ( !isset( $this->templates[$titleText] ) ) {
164  $finalTitle = $title;
165  if ( count( $this->templates ) >= $this->parent->maxTemplates ) {
166  // Too many templates
167  $text = false;
168  } else {
169  if ( !mt_rand( 0, 1 ) ) {
170  // Redirect
171  $finalTitle = $this->parent->makeTitle();
172  }
173  if ( !mt_rand( 0, 5 ) ) {
174  // Doesn't exist
175  $text = false;
176  } else {
177  $text = $this->parent->makeInputText();
178  }
179  }
180  $this->templates[$titleText] = array(
181  'text' => $text,
182  'finalTitle' => $finalTitle );
183  }
184  return $this->templates[$titleText];
185  }
186 
187  function execute() {
189 
190  $wgUser = new PPFuzzUser;
191  $wgUser->mName = 'Fuzz';
192  $wgUser->mFrom = 'name';
193  $wgUser->ppfz_test = $this;
194 
196  $options->setTemplateCallback( array( $this, 'templateHook' ) );
197  $options->setTimestamp( wfTimestampNow() );
198  $this->output = call_user_func( array( $wgParser, $this->entryPoint ), $this->mainText, $this->title, $options );
199  return $this->output;
200  }
201 
202  function getReport() {
203  $s = "Title: " . $this->title->getPrefixedDBkey() . "\n" .
204 // "Output type: {$this->outputType}\n" .
205  "Entry point: {$this->entryPoint}\n" .
206  "User: " . ( $this->fancySig ? 'fancy' : 'no-fancy' ) . ' ' . var_export( $this->nickname, true ) . "\n" .
207  "Main text: " . var_export( $this->mainText, true ) . "\n";
208  foreach ( $this->templates as $titleText => $template ) {
209  $finalTitle = $template['finalTitle'];
210  if ( $finalTitle != $titleText ) {
211  $s .= "[[$titleText]] -> [[$finalTitle]]: " . var_export( $template['text'], true ) . "\n";
212  } else {
213  $s .= "[[$titleText]]: " . var_export( $template['text'], true ) . "\n";
214  }
215  }
216  $s .= "Output: " . var_export( $this->output, true ) . "\n";
217  return $s;
218  }
219 }
220 
221 class PPFuzzUser extends User {
223 
224  function load() {
225  if ( $this->mDataLoaded ) {
226  return;
227  }
228  $this->mDataLoaded = true;
229  $this->loadDefaults( $this->mName );
230  }
231 
232  function getOption( $oname, $defaultOverride = null, $ignoreHidden = false ) {
233  if ( $oname === 'fancysig' ) {
234  return $this->ppfz_test->fancySig;
235  } elseif ( $oname === 'nickname' ) {
236  return $this->ppfz_test->nickname;
237  } else {
238  return parent::getOption( $oname, $defaultOverride, $ignoreHidden );
239  }
240  }
241 }
242 
243 ini_set( 'memory_limit', '50M' );
244 if ( isset( $args[0] ) ) {
245  $testText = file_get_contents( $args[0] );
246  if ( !$testText ) {
247  print "File not found\n";
248  exit( 1 );
249  }
250  $test = unserialize( $testText );
251  $result = $test->execute();
252  print "Test passed.\n";
253 } else {
254  $tester = new PPFuzzTester;
255  $tester->verbose = isset( $options['verbose'] );
256  $tester->execute();
257 }
PPFuzzTester\$maxTemplates
$maxTemplates
Definition: preprocessorFuzzTest.php:44
PPFuzzTester\$verbose
$verbose
Definition: preprocessorFuzzTest.php:47
$wgUser
$wgUser
Definition: Setup.php:572
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. $title:Title object for the current page $request:WebRequest $ignoreRedirect:boolean to skip redirect check $target:Title/string of redirect target $article:Article object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) $article:article(object) being checked 'IsTrustedProxy':Override the result of wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of User::isValidEmailAddr(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetMagic':DEPRECATED, use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetSpecialPageAliases':DEPRECATED, use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Associative array mapping language codes to prefixed links of the form "language:title". & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LinkBegin':Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1528
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
PPFuzzTest\$mainText
$mainText
Definition: preprocessorFuzzTest.php:143
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
PPFuzzTester\pickEntryPoint
pickEntryPoint()
Definition: preprocessorFuzzTest.php:136
PPFuzzTest\getReport
getReport()
Definition: preprocessorFuzzTest.php:202
PPFuzzUser\$mDataLoaded
$mDataLoaded
Definition: preprocessorFuzzTest.php:222
PPFuzzTester\makeTitle
makeTitle()
Definition: preprocessorFuzzTest.php:126
PPFuzzTester\$minLength
$minLength
Definition: preprocessorFuzzTest.php:42
User\loadDefaults
loadDefaults( $name=false)
Set cached properties to default.
Definition: User.php:970
PPFuzzTester
Definition: preprocessorFuzzTest.php:28
PPFuzzUser\getOption
getOption( $oname, $defaultOverride=null, $ignoreHidden=false)
Get the user's current setting for a given option.
Definition: preprocessorFuzzTest.php:232
PPFuzzTest\execute
execute()
Definition: preprocessorFuzzTest.php:187
$s
$s
Definition: mergeMessageFileList.php:156
PPFuzzUser\$ppfz_test
$ppfz_test
Definition: preprocessorFuzzTest.php:222
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
PPFuzzTester\$hairs
$hairs
Definition: preprocessorFuzzTest.php:29
PPFuzzTest\templateHook
templateHook( $title)
Definition: preprocessorFuzzTest.php:160
title
to move a page</td >< td > &*You are moving the page across *A non empty talk page already exists under the new or *You uncheck the box below In those you will have to move or merge the page manually if desired</td >< td > be sure to &You are responsible for making sure that links continue to point where they are supposed to go Note that the page will &a page at the new title
Definition: All_system_messages.txt:2703
$test
$test
Definition: Utf8Test.php:89
PPFuzzTester\$entryPoints
$entryPoints
Definition: preprocessorFuzzTest.php:46
MWException
MediaWiki exception.
Definition: MWException.php:26
PPFuzzTest
Definition: preprocessorFuzzTest.php:142
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:2561
PPFuzzUser
Definition: preprocessorFuzzTest.php:221
$options
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1530
PPFuzzTester\$maxLength
$maxLength
Definition: preprocessorFuzzTest.php:43
$tester
$tester
Definition: parserTests.php:76
PPFuzzUser\load
load()
Load the user table data for this object from the source given by mFrom.
Definition: preprocessorFuzzTest.php:224
PPFuzzTest\$entryPoint
$entryPoint
Definition: preprocessorFuzzTest.php:143
PPFuzzTester\execute
execute()
Definition: preprocessorFuzzTest.php:50
PPFuzzTester\makeInputText
makeInputText( $max=false)
Definition: preprocessorFuzzTest.php:107
PPFuzzTest\$templates
$templates
Definition: preprocessorFuzzTest.php:143
verbose
$tester verbose
Definition: preprocessorFuzzTest.php:255
$hash
return false to override stock group addition can be modified try getUserPermissionsErrors userCan checks are continued by internal code can override on output return false to not delete it return false to override the default password checks & $hash
Definition: hooks.txt:2702
$count
$count
Definition: UtfNormalTest2.php:96
$args
if( $line===false) $args
Definition: cdb.php:62
$wgParser
$wgParser
Definition: Setup.php:587
output
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
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
PPFuzzTest\$title
$title
Definition: preprocessorFuzzTest.php:143
PPFuzzTester\$currentTest
static $currentTest
Definition: preprocessorFuzzTest.php:48
PPFuzzTest\__construct
__construct( $tester)
Definition: preprocessorFuzzTest.php:145
$t
$t
Definition: testCompression.php:65
$wgHooks
$wgHooks['BeforeParserFetchTemplateAndtitle'][]
Definition: preprocessorFuzzTest.php:26
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
PPFuzzTest\$output
$output
Definition: preprocessorFuzzTest.php:143
ParserOptions\newFromUser
static newFromUser( $user)
Get a ParserOptions object from a given user.
Definition: ParserOptions.php:375
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:1632