50 'counterRotation' => [ [ 1, 0 ], [ 0, 1 ] ]
56 'counterRotation' => [ [ -1, 0 ], [ 0, -1 ] ]
62 'counterRotation' => [ [ 0, 1 ], [ 1, 0 ] ]
68 'counterRotation' => [ [ 0, -1 ], [ -1, 0 ] ]
73 foreach ( [
'dictionaryFile',
'minWidth',
'minHeight',
74 'maxWidth',
'maxHeight',
'shapesToDraw' ]
as $property
76 if ( isset(
$options[$property] ) ) {
82 if ( !isset( $this->dictionaryFile ) ) {
85 '/usr/share/dict/words',
87 __DIR__ .
'/words.txt'
90 if ( is_file( $dictionaryFile )
and is_readable( $dictionaryFile ) ) {
96 if ( !isset( $this->dictionaryFile ) ) {
97 throw new Exception(
"RandomImageGenerator: dictionary file not "
98 .
"found or not specified properly" );
114 foreach ( $filenames
as $filename ) {
115 $this->{$imageWriteMethod}( $this->
getImageSpec(), $format, $filename );
131 if ( $format ===
'svg' ) {
136 if ( class_exists(
'Imagick' ) && $wgExiv2Command && is_executable( $wgExiv2Command ) ) {
137 return 'writeImageWithApi';
138 } elseif ( $wgUseImageMagick
139 && $wgImageMagickConvertCommand
140 && is_executable( $wgImageMagickConvertCommand )
142 return 'writeImageWithCommandLine';
145 throw new Exception(
"RandomImageGenerator: could not find a suitable "
146 .
"method to write images in '$format' format" );
159 if ( is_null(
$dir ) ) {
164 $basename = $pair[0] .
'_' . $pair[1];
165 if ( !is_null( $extension ) ) {
166 $basename .=
'.' . $extension;
168 $basename = preg_replace(
'/\s+/',
'', $basename );
169 $filenames[] =
"$dir/$basename";
186 $spec[
'width'] = mt_rand( $this->minWidth, $this->maxWidth );
187 $spec[
'height'] = mt_rand( $this->minHeight, $this->maxHeight );
190 $diagonalLength = sqrt( pow( $spec[
'width'], 2 ) + pow( $spec[
'height'], 2 ) );
194 $radius = mt_rand( 0, $diagonalLength / 4 );
195 if ( $radius == 0 ) {
198 $originX = mt_rand( -1 * $radius, $spec[
'width'] + $radius );
199 $originY = mt_rand( -1 * $radius, $spec[
'height'] + $radius );
200 $angle = mt_rand( 0, ( 3.141592 / 2 ) * $radius ) / $radius;
201 $legDeltaX = round( $radius * sin( $angle ) );
202 $legDeltaY = round( $radius * cos( $angle ) );
207 [
'x' => $originX,
'y' => $originY - $radius ],
208 [
'x' => $originX + $legDeltaX,
'y' => $originY + $legDeltaY ],
209 [
'x' => $originX - $legDeltaX,
'y' => $originY + $legDeltaY ],
210 [
'x' => $originX,
'y' => $originY - $radius ]
215 $spec[
'draws'] = $draws;
229 foreach ( $shape
as $point ) {
230 $points[] = $point[
'x'] .
',' . $point[
'y'];
233 return implode(
" ",
$points );
246 public function writeSvg( $spec, $format, $filename ) {
247 $svg =
new SimpleXmlElement(
'<svg/>' );
248 $svg->addAttribute(
'xmlns',
'http://www.w3.org/2000/svg' );
249 $svg->addAttribute(
'version',
'1.1' );
250 $svg->addAttribute(
'width', $spec[
'width'] );
251 $svg->addAttribute(
'height', $spec[
'height'] );
252 $g = $svg->addChild(
'g' );
253 foreach ( $spec[
'draws']
as $drawSpec ) {
254 $shape = $g->addChild(
'polygon' );
255 $shape->addAttribute(
'fill', $drawSpec[
'fill'] );
256 $shape->addAttribute(
'points', self::shapePointsToString( $drawSpec[
'shape'] ) );
259 $fh = fopen( $filename,
'w' );
261 throw new Exception(
"couldn't open $filename for writing" );
263 fwrite( $fh, $svg->asXML() );
264 if ( !fclose( $fh ) ) {
265 throw new Exception(
"couldn't close $filename" );
286 $orientation = self::$orientations[0];
287 if ( $format ==
'jpg' ) {
288 $orientation = self::$orientations[array_rand( self::$orientations )];
289 $spec = self::rotateImageSpec( $spec, $orientation[
'counterRotation'] );
292 $image->newImage( $spec[
'width'], $spec[
'height'],
new ImagickPixel( $spec[
'fill'] ) );
294 foreach ( $spec[
'draws']
as $drawSpec ) {
295 $draw =
new ImagickDraw();
296 $draw->setFillColor( $drawSpec[
'fill'] );
297 $draw->polygon( $drawSpec[
'shape'] );
298 $image->drawImage( $draw );
301 $image->setImageFormat( $format );
306 $image->writeImage( $filename );
312 if ( $wgExiv2Command ) {
315 .
wfEscapeShellArg(
"set Exif.Image.Orientation " . $orientation[
'exifCode'] )
322 print "Error with $cmd: $retval, $err\n";
336 $dims = self::matrixMultiply2x2( $matrix, $spec[
'width'], $spec[
'height'] );
339 if ( $dims[
'x'] < 0 ) {
340 $correctionX = abs( $dims[
'x'] );
342 if ( $dims[
'y'] < 0 ) {
343 $correctionY = abs( $dims[
'y'] );
345 $tSpec[
'width'] = abs( $dims[
'x'] );
346 $tSpec[
'height'] = abs( $dims[
'y'] );
347 $tSpec[
'fill'] = $spec[
'fill'];
348 $tSpec[
'draws'] = [];
349 foreach ( $spec[
'draws']
as $draw ) {
351 'fill' => $draw[
'fill'],
354 foreach ( $draw[
'shape']
as $point ) {
355 $tPoint = self::matrixMultiply2x2( $matrix, $point[
'x'], $point[
'y'] );
356 $tPoint[
'x'] += $correctionX;
357 $tPoint[
'y'] += $correctionY;
358 $tDraw[
'shape'][] = $tPoint;
360 $tSpec[
'draws'][] = $tDraw;
375 'x' => $x * $matrix[0][0] + $y * $matrix[0][1],
376 'y' => $x * $matrix[1][0] + $y * $matrix[1][1]
402 foreach ( $spec[
'draws']
as $draw ) {
403 $fill = $draw[
'fill'];
404 $polygon = self::shapePointsToString( $draw[
'shape'] );
405 $drawCommand =
"fill $fill polygon $polygon";
424 for ( $i = 0; $i <= 2; $i++ ) {
425 $components[] = mt_rand( 0, 255 );
428 return 'rgb(' . implode(
', ', $components ) .
')';
443 for ( $i = 0; $i <
$count; $i += 2 ) {
465 for ( $i = 0; $i < $number_desired; $i++ ) {
474 $fh = fopen( $filepath,
"r" );
476 throw new Exception(
"couldn't open $filepath" );
479 $max_index = $number_desired - 1;
480 while ( !feof( $fh ) ) {
481 $line = fgets( $fh );
482 if (
$line !==
false ) {
485 if ( mt_rand( 0, $line_number ) <= $max_index ) {
491 if ( $line_number < $number_desired ) {
492 throw new Exception(
"not enough lines in $filepath" );
writeImages($number, $format= 'jpg', $dir=null)
Writes random images with random filenames to disk in the directory you specify, or current working d...
getRandomLines($number_desired)
Return N random lines from a file.
$wgImageMagickConvertCommand
The convert command shipped with ImageMagick.
wfShellExec($cmd, &$retval=null, $environ=[], $limits=[], $options=[])
Execute a shell command, with time and memory limits mirrored from the PHP configuration if supported...
when a variable name is used in a it is silently declared as a new local masking the global
getImageWriteMethod($format)
Figure out how we write images.
$wgExiv2Command
Some tests and extensions use exiv2 to manipulate the Exif metadata in some image formats...
$wgUseImageMagick
Resizing can be done using PHP's internal image libraries or using ImageMagick or another third-party...
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
writeSvg($spec, $format, $filename)
Based on image specification, write a very simple SVG file to disk.
getRandomWordPairs($number)
Get an array of random pairs of random words, like [ [ 'foo', 'bar' ], [ 'quux', 'baz' ] ];...
and(b) You must cause any modified files to carry prominent notices stating that You changed the files
writeImageWithApi($spec, $format, $filename)
Based on an image specification, write such an image to disk, using Imagick PHP extension.
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
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
getImageSpec()
Generate data representing an image of random size (within limits), consisting of randomly colored an...
static shapePointsToString($shape)
Given [ [ 'x' => 10, 'y' => 20 ], [ 'x' => 30, y=> 5 ] ] returns "10,20 30,5" Useful for SVG and imag...
static rotateImageSpec(&$spec, $matrix)
Given an image specification, produce rotated version This is used when simulating a rotated image ca...
RandomImageGenerator: does what it says on the tin.
static __construct($options=[])
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check $image
wfEscapeShellArg()
Version of escapeshellarg() that works better on Windows.
getRandomFilenames($number, $extension= 'jpg', $dir=null)
Return a number of randomly-generated filenames Each filename uses two words randomly drawn from the ...
static matrixMultiply2x2($matrix, $x, $y)
Given a matrix and a pair of images, return new position.
static $orientations
Orientations: 0th row, 0th column, Exif orientation code, rotation 2x2 matrix that is opposite of ori...
getRandomColor()
Generate a string of random colors for ImageMagick or SVG, like "rgb(12, 37, 98)".
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account incomplete not yet checked for validity & $retval
writeImageWithCommandLine($spec, $format, $filename)
Based on an image specification, write such an image to disk, using the command line ImageMagick prog...