MediaWiki  master
PoolWorkArticleView.php
Go to the documentation of this file.
1 <?php
21 use MediaWiki\Logger\Spi as LoggerSpi;
24 
34 
36  protected $parserOptions;
37 
39  protected $revision;
40 
42  private $renderer;
43 
45  protected $loggerSpi;
46 
54  public function __construct(
55  string $workKey,
58  RevisionRenderer $revisionRenderer,
59  LoggerSpi $loggerSpi
60  ) {
61  parent::__construct( 'ArticleView', $workKey );
62  $this->revision = $revision;
63  $this->parserOptions = $parserOptions;
64  $this->renderer = $revisionRenderer;
65  $this->loggerSpi = $loggerSpi;
66  }
67 
71  public function doWork() {
72  return $this->renderRevision();
73  }
74 
78  public function renderRevision(): Status {
79  $renderedRevision = $this->renderer->getRenderedRevision(
80  $this->revision,
81  $this->parserOptions,
82  null,
83  [ 'audience' => RevisionRecord::RAW ]
84  );
85  if ( !$renderedRevision ) {
86  // audience check failed
87  return Status::newFatal( 'pool-errorunknown' );
88  }
89 
90  $time = -microtime( true );
91  $parserOutput = $renderedRevision->getRevisionParserOutput();
92  $time += microtime( true );
93 
94  // Timing hack
95  if ( $time > 3 ) {
96  // TODO: Use Parser's logger (once it has one)
97  $logger = $this->loggerSpi->getLogger( 'slow-parse' );
98  $logger->info( 'Parsing {title} was slow, took {time} seconds', [
99  'time' => number_format( $time, 2 ),
100  'title' => (string)$this->revision->getPageAsLinkTarget(),
101  'trigger' => 'view',
102  ] );
103  }
104 
105  return Status::newGood( $parserOutput );
106  }
107 
112  public function error( $status ) {
113  return $status;
114  }
115 
116 }
Page revision base class.
The RevisionRenderer service provides access to rendered output for revisions.
Set options of the Parser.
Class for dealing with PoolCounters using class members.
PoolCounter protected work wrapping RenderedRevision->getRevisionParserOutput.
__construct(string $workKey, RevisionRecord $revision, ParserOptions $parserOptions, RevisionRenderer $revisionRenderer, LoggerSpi $loggerSpi)
RevisionRenderer $renderer
ParserOptions $parserOptions
static newFatal( $message,... $parameters)
Factory function for fatal errors.
Definition: StatusValue.php:70
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:44
Service provider interface for \Psr\Log\LoggerInterface implementation libraries.
Definition: Spi.php:38