Go to the documentation of this file.
25 require __DIR__ .
'/../Maintenance.php';
50 parent::__construct();
52 $this->
addArg(
'title',
'The name of the page to parse' );
53 $this->
addOption(
'warmup',
'Repeat the parse operation this number of times to warm the cache',
55 $this->
addOption(
'loops',
'Number of times to repeat parse operation post-warmup',
58 'Use the version of the page which was current at the given time',
61 'Use templates which were current at the given time (except that moves and ' .
62 'deletes are not handled properly)',
64 $this->
addOption(
'reset-linkcache',
'Reset the LinkCache after every parse.',
71 Hooks::register(
'BeforeParserFetchTemplateAndtitle', [ $this,
'onFetchTemplate' ] );
74 $this->clearLinkCache = $this->
hasOption(
'reset-linkcache' );
76 $this->linkCache = MediaWikiServices::getInstance()->getLinkCache();
80 $this->
error(
"Invalid title" );
88 $this->
error(
"The page did not exist at that time" );
98 $this->
error(
"Unable to load revision, incorrect title?" );
102 $warmup = $this->
getOption(
'warmup', 1 );
103 for ( $i = 0; $i < $warmup; $i++ ) {
109 $this->
fatalError(
'Invalid number of loops specified' );
111 $startUsage = getrusage();
112 $startTime = microtime(
true );
113 for ( $i = 0; $i < $loops; $i++ ) {
116 $endUsage = getrusage();
117 $endTime = microtime(
true );
119 printf(
"CPU time = %.3f s, wall clock time = %.3f s\n",
121 ( $endUsage[
'ru_utime.tv_sec'] + $endUsage[
'ru_utime.tv_usec'] * 1
e-6
122 - $startUsage[
'ru_utime.tv_sec'] - $startUsage[
'ru_utime.tv_usec'] * 1
e-6 ) / $loops,
124 ( $endTime - $startTime ) / $loops
138 $id =
$dbr->selectField(
139 [
'revision',
'page' ],
142 'page_namespace' =>
$title->getNamespace(),
143 'page_title' =>
$title->getDBkey(),
144 'rev_timestamp <= ' .
$dbr->addQuotes( $timestamp )
147 [
'ORDER BY' =>
'rev_timestamp DESC',
'LIMIT' => 1 ],
148 [
'revision' => [
'INNER JOIN',
'rev_page=page_id' ] ]
162 if ( $this->clearLinkCache ) {
163 $this->linkCache->clear();
178 $pdbk =
$title->getPrefixedDBkey();
179 if ( !isset( $this->idCache[$pdbk] ) ) {
180 $proposedId = $this->
getRevIdForTime( $title, $this->templateTimestamp );
181 $this->idCache[$pdbk] = $proposedId;
183 if ( $this->idCache[$pdbk] !==
false ) {
184 $id = $this->idCache[$pdbk];
Cache for article titles (prefixed DB keys) and ids linked from one source.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addDescription( $text)
Set the description text.
getContent( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision content if it's available to the specified audience.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
require_once RUN_MAINTENANCE_IF_MAIN
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
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
static newFromTitle(LinkTarget $linkTarget, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given link target.
Maintenance script to benchmark how long it takes to parse a given title at an optionally specified t...
namespace and then decline to actually register it file or subcat img or subcat $title
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
string $templateTimestamp
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
see documentation in includes Linker php for Linker::makeImageLink or false for current used if you return false $parser
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
getTitle()
Returns the title of the page associated with this entry.
onFetchTemplate(Parser $parser, Title $title, &$skip, &$id)
Hook into the parser's revision ID fetcher.
in this case you re responsible for computing and outputting the entire conflict i e
runParser(Revision $revision)
Parse the text from a given Revision.
static register( $name, $callback)
Attach an event handler to a given hook.
execute()
Do the actual work.
Represents a title within MediaWiki.
getOption( $name, $default=null)
Get an option, or return the default.
addArg( $arg, $description, $required=true)
Add some args that are needed.
__construct()
Default constructor.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
error( $err, $die=0)
Throw an error to the user.
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
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 MediaWikiServices
hasOption( $name)
Checks to see if a particular option exists.
getArg( $argId=0, $default=null)
Get an argument.
array $idCache
Cache that maps a Title DB key to revision ID for the requested timestamp.
getRevIdForTime(Title $title, $timestamp)
Fetch the ID of the revision of a Title that occurred.