MediaWiki  REL1_31
benchmarkCSSMin.php
Go to the documentation of this file.
1 <?php
23 require_once __DIR__ . '/Benchmarker.php';
24 
31  public function __construct() {
32  parent::__construct();
33  $this->addDescription( 'Benchmarks CSSMin.' );
34  $this->addOption( 'file', 'Path to CSS file (may be gzipped)', false, true );
35  $this->addOption( 'out', 'Echo output of one run to stdout for inspection', false, false );
36  }
37 
38  public function execute() {
39  $file = $this->getOption( 'file', __DIR__ . '/cssmin/styles.css' );
40  $filename = basename( $file );
41  $css = $this->loadFile( $file );
42 
43  if ( $this->hasOption( 'out' ) ) {
44  echo "## minify\n\n",
46  "\n\n";
47  echo "## remap\n\n",
48  CSSMin::remap( $css, dirname( $file ), 'https://example.org/test/', true ),
49  "\n";
50  return;
51  }
52 
53  $this->bench( [
54  "minify ($filename)" => [
55  'function' => [ CSSMin::class, 'minify' ],
56  'args' => [ $css ]
57  ],
58  "remap ($filename)" => [
59  'function' => [ CSSMin::class, 'remap' ],
60  'args' => [ $css, dirname( $file ), 'https://example.org/test/', true ]
61  ],
62  ] );
63  }
64 
65  private function loadFile( $file ) {
66  $css = file_get_contents( $file );
67  // Detect GZIP compression header
68  if ( substr( $css, 0, 2 ) === "\037\213" ) {
69  $css = gzdecode( $css );
70  }
71  return $css;
72  }
73 }
74 
76 require_once RUN_MAINTENANCE_IF_MAIN;
BenchmarkCSSMin\__construct
__construct()
Default constructor.
Definition: benchmarkCSSMin.php:31
CSSMin\minify
static minify( $css)
Removes whitespace from CSS data.
Definition: CSSMin.php:547
BenchmarkCSSMin\loadFile
loadFile( $file)
Definition: benchmarkCSSMin.php:65
BenchmarkCSSMin\execute
execute()
Do the actual work.
Definition: benchmarkCSSMin.php:38
CSSMin\remap
static remap( $source, $local, $remote, $embedData=true)
Remaps CSS URL paths and automatically embeds data URIs for CSS rules or url() values preceded by an ...
Definition: CSSMin.php:243
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:291
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Benchmarker\bench
bench(array $benchs)
Definition: Benchmarker.php:50
php
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
Definition: injection.txt:37
$css
$css
Definition: styleTest.css.php:50
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:219
$maintClass
$maintClass
Definition: benchmarkCSSMin.php:75
Benchmarker
Base class for benchmark scripts.
Definition: Benchmarker.php:40
BenchmarkCSSMin
Maintenance script that benchmarks CSSMin.
Definition: benchmarkCSSMin.php:30
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:254
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:56
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular param exists.
Definition: Maintenance.php:240