MediaWiki  master
PoolWorkArticleView.php
Go to the documentation of this file.
1 <?php
21 use MediaWiki\Logger\Spi as LoggerSpi;
24 
35  protected $parserOptions;
37  protected $revision;
39  private $renderer;
41  protected $loggerSpi;
42 
50  public function __construct(
51  string $workKey,
54  RevisionRenderer $revisionRenderer,
55  LoggerSpi $loggerSpi
56  ) {
57  parent::__construct( 'ArticleView', $workKey );
58  $this->revision = $revision;
59  $this->parserOptions = $parserOptions;
60  $this->renderer = $revisionRenderer;
61  $this->loggerSpi = $loggerSpi;
62  }
63 
67  public function doWork() {
68  return $this->renderRevision();
69  }
70 
74  public function renderRevision(): Status {
75  $renderedRevision = $this->renderer->getRenderedRevision(
76  $this->revision,
77  $this->parserOptions,
78  null,
79  [ 'audience' => RevisionRecord::RAW ]
80  );
81  if ( !$renderedRevision ) {
82  // audience check failed
83  return Status::newFatal( 'pool-errorunknown' );
84  }
85 
86  $time = -microtime( true );
87  $parserOutput = $renderedRevision->getRevisionParserOutput();
88  $time += microtime( true );
89 
90  // Timing hack
91  if ( $time > 3 ) {
92  // TODO: Use Parser's logger (once it has one)
93  $logger = $this->loggerSpi->getLogger( 'slow-parse' );
94  $logger->info( 'Parsing {title} was slow, took {time} seconds', [
95  'time' => number_format( $time, 2 ),
96  'title' => (string)$this->revision->getPageAsLinkTarget(),
97  'trigger' => 'view',
98  ] );
99  }
100 
101  return Status::newGood( $parserOutput );
102  }
103 
108  public function error( $status ) {
109  return $status;
110  }
111 
112 }
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)
ParserOptions $parserOptions
static newFatal( $message,... $parameters)
Factory function for fatal errors.
Definition: StatusValue.php:73
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:85
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:45
Service provider interface for \Psr\Log\LoggerInterface implementation libraries.
Definition: Spi.php:38