MediaWiki REL1_28
Go to the documentation of this file.
22require_once __DIR__ . '/Maintenance.php';
28 public function __construct() {
29 parent::__construct();
30 $this->addDescription( 'Parse random pages and compare output to cache.' );
31 $this->addOption( 'namespace', 'Page namespace number', true, true );
32 $this->addOption( 'maxpages', 'Number of pages to try', true, true );
33 }
35 public function execute() {
36 $pages = $this->getOption( 'maxpages' );
38 $dbr = $this->getDB( DB_REPLICA );
40 $totalsec = 0.0;
41 $scanned = 0;
42 $withcache = 0;
43 $withdiff = 0;
44 while ( $pages-- > 0 ) {
45 $row = $dbr->selectRow( 'page', '*',
46 [
47 'page_namespace' => $this->getOption( 'namespace' ),
48 'page_is_redirect' => 0,
49 'page_random >= ' . wfRandom()
50 ],
51 __METHOD__,
52 [
53 'ORDER BY' => 'page_random',
54 ]
55 );
57 if ( !$row ) {
58 continue;
59 }
60 ++$scanned;
62 $title = Title::newFromRow( $row );
64 $revision = $page->getRevision();
65 $content = $revision->getContent( Revision::RAW );
67 $parserOptions = $page->makeParserOptions( 'canonical' );
69 $parserOutputOld = ParserCache::singleton()->get( $page, $parserOptions );
71 if ( $parserOutputOld ) {
72 $t1 = microtime( true );
73 $parserOutputNew = $content->getParserOutput(
74 $title, $revision->getId(), $parserOptions, false );
75 $sec = microtime( true ) - $t1;
76 $totalsec += $sec;
78 $this->output( "Parsed '{$title->getPrefixedText()}' in $sec seconds.\n" );
80 $this->output( "Found cache entry found for '{$title->getPrefixedText()}'..." );
81 $oldHtml = trim( preg_replace( '#<!-- .+-->#Us', '', $parserOutputOld->getText() ) );
82 $newHtml = trim( preg_replace( '#<!-- .+-->#Us', '', $parserOutputNew->getText() ) );
83 $diff = wfDiff( $oldHtml, $newHtml );
84 if ( strlen( $diff ) ) {
85 $this->output( "differences found:\n\n$diff\n\n" );
86 ++$withdiff;
87 } else {
88 $this->output( "No differences found.\n" );
89 }
90 ++$withcache;
91 } else {
92 $this->output( "No parser cache entry found for '{$title->getPrefixedText()}'.\n" );
93 }
94 }
96 $ave = $totalsec ? $totalsec / $scanned : 0;
97 $this->output( "Checked $scanned pages; $withcache had prior cache entries.\n" );
98 $this->output( "Pages with differences found: $withdiff\n" );
99 $this->output( "Average parse time: $ave sec\n" );
100 }
103$maintClass = "CompareParserCache";
104require_once RUN_MAINTENANCE_IF_MAIN;
Get a random decimal value between 0 and 1, in a way not likely to give duplicate values for any real...
wfDiff( $before, $after, $params='-u')
Returns unified plain-text diff of two texts.
Do the actual work.
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
static singleton()
Get an instance of this object.
const RAW
Definition Revision.php:94
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition WikiPage.php:115
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
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:986
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 $content
Definition hooks.txt:1094
namespace are movable Hooks may change this value to override the return value of MWNamespace::isMovable(). 'NewDifferenceEngine' do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
Definition hooks.txt:2534
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
Definition defines.php:22