MediaWiki  1.27.2
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 (bug 46014)
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  'trigger' => 'view',
151  ] );
152  }
153 
154  if ( $this->cacheable && $this->parserOutput->isCacheable() && $isCurrent ) {
155  ParserCache::singleton()->save(
156  $this->parserOutput, $this->page, $this->parserOptions, $cacheTime, $this->revid );
157  }
158 
159  // Make sure file cache is not used on uncacheable content.
160  // Output that has magic words in it can still use the parser cache
161  // (if enabled), though it will generally expire sooner.
162  if ( !$this->parserOutput->isCacheable() ) {
163  $wgUseFileCache = false;
164  }
165 
166  if ( $isCurrent ) {
167  $this->page->triggerOpportunisticLinksUpdate( $this->parserOutput );
168  }
169 
170  return true;
171  }
172 
176  public function getCachedWork() {
177  $this->parserOutput = ParserCache::singleton()->get( $this->page, $this->parserOptions );
178 
179  if ( $this->parserOutput === false ) {
180  wfDebug( __METHOD__ . ": parser cache miss\n" );
181  return false;
182  } else {
183  wfDebug( __METHOD__ . ": parser cache hit\n" );
184  return true;
185  }
186  }
187 
191  public function fallback() {
192  $this->parserOutput = ParserCache::singleton()->getDirty( $this->page, $this->parserOptions );
193 
194  if ( $this->parserOutput === false ) {
195  wfDebugLog( 'dirty', 'dirty missing' );
196  wfDebug( __METHOD__ . ": no dirty cache\n" );
197  return false;
198  } else {
199  wfDebug( __METHOD__ . ": sending dirty output\n" );
200  wfDebugLog( 'dirty', "dirty output {$this->cacheKey}" );
201  $this->isDirty = true;
202  return true;
203  }
204  }
205 
210  public function error( $status ) {
211  $this->error = $status;
212  return false;
213  }
214 }
ParserOutput bool $parserOutput
per default it will return the text for text based content
Set options of the Parser.
static getInstance($channel)
Get a named logger instance from the currently configured logger factory.
__construct(WikiPage $page, ParserOptions $parserOptions, $revid, $useParserCache, $content=null)
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
getIsDirty()
Get whether the ParserOutput is a dirty one (i.e.
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:117
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1612
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
getParserOutput()
Get the ParserOutput from this object, or false in case of failure.
getRevision()
Get the latest revision.
Definition: WikiPage.php:633
wfDebugLog($logGroup, $text, $dest= 'all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not...
$wgUseFileCache
This will cache static pages for non-logged-in users to reduce database traffic on public sites...
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
getTitle()
Get the title object of the article.
Definition: WikiPage.php:217
static makeContent($text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
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:1584
const RAW
Definition: Revision.php:85
static singleton()
Get an instance of this object.
Definition: ParserCache.php:36
Class representing a MediaWiki article and history.
Definition: WikiPage.php:29
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
getError()
Get a Status object in case of error or false otherwise.
ParserOptions $parserOptions
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 $status
Definition: hooks.txt:1004
wfMemcKey()
Make a cache key for the local wiki.
getParserOutput(Title $title, $revId=null, ParserOptions $options=null, $generateHtml=true)
Parse the Content object and generate a ParserOutput from the result.
Class for dealing with PoolCounters using class members.
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 one of or reset my talk page
Definition: hooks.txt:2338