MediaWiki  1.29.1
PoolWorkArticleView.php
Go to the documentation of this file.
1 <?php
23  private $page;
24 
26  private $cacheKey;
27 
29  private $revid;
30 
32  private $parserOptions;
33 
35  private $content = null;
36 
38  private $parserOutput = false;
39 
41  private $isDirty = false;
42 
44  private $error = false;
45 
56  $revid, $useParserCache, $content = null
57  ) {
58  if ( is_string( $content ) ) { // BC: old style call
59  $modelId = $page->getRevision()->getContentModel();
60  $format = $page->getRevision()->getContentFormat();
61  $content = ContentHandler::makeContent( $content, $page->getTitle(), $modelId, $format );
62  }
63 
64  $this->page = $page;
65  $this->revid = $revid;
66  $this->cacheable = $useParserCache;
67  $this->parserOptions = $parserOptions;
68  $this->content = $content;
69  $this->cacheKey = ParserCache::singleton()->getKey( $page, $parserOptions );
70  $keyPrefix = $this->cacheKey ?: wfMemcKey( 'articleview', 'missingcachekey' );
71  parent::__construct( 'ArticleView', $keyPrefix . ':revid:' . $revid );
72  }
73 
79  public function getParserOutput() {
80  return $this->parserOutput;
81  }
82 
88  public function getIsDirty() {
89  return $this->isDirty;
90  }
91 
97  public function getError() {
98  return $this->error;
99  }
100 
104  public function doWork() {
106 
107  // @todo several of the methods called on $this->page are not declared in Page, but present
108  // in WikiPage and delegated by Article.
109 
110  $isCurrent = $this->revid === $this->page->getLatest();
111 
112  if ( $this->content !== null ) {
114  } elseif ( $isCurrent ) {
115  // XXX: why use RAW audience here, and PUBLIC (default) below?
116  $content = $this->page->getContent( Revision::RAW );
117  } else {
118  $rev = Revision::newFromTitle( $this->page->getTitle(), $this->revid );
119 
120  if ( $rev === null ) {
121  $content = null;
122  } else {
123  // XXX: why use PUBLIC audience here (default), and RAW above?
124  $content = $rev->getContent();
125  }
126  }
127 
128  if ( $content === null ) {
129  return false;
130  }
131 
132  // Reduce effects of race conditions for slow parses (T48014)
133  $cacheTime = wfTimestampNow();
134 
135  $time = - microtime( true );
136  $this->parserOutput = $content->getParserOutput(
137  $this->page->getTitle(),
138  $this->revid,
140  );
141  $time += microtime( true );
142 
143  // Timing hack
144  if ( $time > 3 ) {
145  // TODO: Use Parser's logger (once it has one)
146  $logger = MediaWiki\Logger\LoggerFactory::getInstance( 'slow-parse' );
147  $logger->info( '{time} {title}', [
148  'time' => number_format( $time, 2 ),
149  'title' => $this->page->getTitle()->getPrefixedDBkey(),
150  'ns' => $this->page->getTitle()->getNamespace(),
151  'trigger' => 'view',
152  ] );
153  }
154 
155  if ( $this->cacheable && $this->parserOutput->isCacheable() && $isCurrent ) {
156  ParserCache::singleton()->save(
157  $this->parserOutput, $this->page, $this->parserOptions, $cacheTime, $this->revid );
158  }
159 
160  // Make sure file cache is not used on uncacheable content.
161  // Output that has magic words in it can still use the parser cache
162  // (if enabled), though it will generally expire sooner.
163  if ( !$this->parserOutput->isCacheable() ) {
164  $wgUseFileCache = false;
165  }
166 
167  if ( $isCurrent ) {
168  $this->page->triggerOpportunisticLinksUpdate( $this->parserOutput );
169  }
170 
171  return true;
172  }
173 
177  public function getCachedWork() {
178  $this->parserOutput = ParserCache::singleton()->get( $this->page, $this->parserOptions );
179 
180  if ( $this->parserOutput === false ) {
181  wfDebug( __METHOD__ . ": parser cache miss\n" );
182  return false;
183  } else {
184  wfDebug( __METHOD__ . ": parser cache hit\n" );
185  return true;
186  }
187  }
188 
192  public function fallback() {
193  $this->parserOutput = ParserCache::singleton()->getDirty( $this->page, $this->parserOptions );
194 
195  if ( $this->parserOutput === false ) {
196  wfDebugLog( 'dirty', 'dirty missing' );
197  wfDebug( __METHOD__ . ": no dirty cache\n" );
198  return false;
199  } else {
200  wfDebug( __METHOD__ . ": sending dirty output\n" );
201  wfDebugLog( 'dirty', "dirty output {$this->cacheKey}" );
202  $this->isDirty = true;
203  return true;
204  }
205  }
206 
211  public function error( $status ) {
212  $this->error = $status;
213  return false;
214  }
215 }
ParserOptions
Set options of the Parser.
Definition: ParserOptions.php:33
ParserOutput
Definition: ParserOutput.php:24
PoolWorkArticleView\doWork
doWork()
Definition: PoolWorkArticleView.php:104
content
per default it will return the text for text based content
Definition: contenthandler.txt:104
MediaWiki\Logger\LoggerFactory\getInstance
static getInstance( $channel)
Get a named logger instance from the currently configured logger factory.
Definition: LoggerFactory.php:93
$status
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup 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 $status
Definition: hooks.txt:1049
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:36
PoolWorkArticleView
Definition: PoolWorkArticleView.php:21
PoolWorkArticleView\__construct
__construct(WikiPage $page, ParserOptions $parserOptions, $revid, $useParserCache, $content=null)
Definition: PoolWorkArticleView.php:55
WikiPage\getRevision
getRevision()
Get the latest revision.
Definition: WikiPage.php:642
wfDebugLog
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
Definition: GlobalFunctions.php:1092
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:35
PoolWorkArticleView\$page
WikiPage $page
Definition: PoolWorkArticleView.php:23
Status
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:40
PoolWorkArticleView\$parserOptions
ParserOptions $parserOptions
Definition: PoolWorkArticleView.php:32
Revision\newFromTitle
static newFromTitle(LinkTarget $linkTarget, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given link target.
Definition: Revision.php:134
PoolWorkArticleView\$parserOutput
ParserOutput bool $parserOutput
Definition: PoolWorkArticleView.php:38
PoolWorkArticleView\$revid
int $revid
Definition: PoolWorkArticleView.php:29
wfMemcKey
wfMemcKey()
Make a cache key for the local wiki.
Definition: GlobalFunctions.php:2961
PoolWorkArticleView\$error
Status bool $error
Definition: PoolWorkArticleView.php:44
$wgUseFileCache
$wgUseFileCache
This will cache static pages for non-logged-in users to reduce database traffic on public sites.
Definition: DefaultSettings.php:2532
WikiPage\getTitle
getTitle()
Get the title object of the article.
Definition: WikiPage.php:237
$time
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1769
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:2023
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:999
ContentHandler\makeContent
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
Definition: ContentHandler.php:129
PoolWorkArticleView\$cacheKey
string $cacheKey
Definition: PoolWorkArticleView.php:26
PoolWorkArticleView\getError
getError()
Get a Status object in case of error or false otherwise.
Definition: PoolWorkArticleView.php:97
ParserCache\singleton
static singleton()
Get an instance of this object.
Definition: ParserCache.php:36
Revision\RAW
const RAW
Definition: Revision.php:100
Content
Base interface for content objects.
Definition: Content.php:34
page
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 my talk page
Definition: hooks.txt:2536
$rev
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition: hooks.txt:1741
PoolCounterWork
Class for dealing with PoolCounters using class members.
Definition: PoolCounterWork.php:27
PoolWorkArticleView\getParserOutput
getParserOutput()
Get the ParserOutput from this object, or false in case of failure.
Definition: PoolWorkArticleView.php:79
PoolWorkArticleView\error
error( $status)
Definition: PoolWorkArticleView.php:211
PoolWorkArticleView\$isDirty
bool $isDirty
Definition: PoolWorkArticleView.php:41
Content\getParserOutput
getParserOutput(Title $title, $revId=null, ParserOptions $options=null, $generateHtml=true)
Parse the Content object and generate a ParserOutput from the result.
PoolWorkArticleView\fallback
fallback()
Definition: PoolWorkArticleView.php:192
PoolWorkArticleView\getCachedWork
getCachedWork()
Definition: PoolWorkArticleView.php:177
PoolWorkArticleView\getIsDirty
getIsDirty()
Get whether the ParserOutput is a dirty one (i.e.
Definition: PoolWorkArticleView.php:88
PoolWorkArticleView\$content
Content null $content
Definition: PoolWorkArticleView.php:35