Debian Codegraph @

includes/poolcounter/PoolWorkArticleViewOld.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 namespace MediaWiki\PoolCounter;
22
23 use MediaWiki\Logger\Spi as LoggerSpi;
24 use MediaWiki\MainConfigNames;
25 use MediaWiki\MediaWikiServices;
26 use MediaWiki\Parser\ParserOptions;
27 use MediaWiki\Parser\ParserOutput;
28 use MediaWiki\Parser\RevisionOutputCache;
29 use MediaWiki\Revision\RevisionRecord;
30 use MediaWiki\Revision\RevisionRenderer;
31 use MediaWiki\Status\Status;
32
33 /**
34 * PoolWorkArticleView for an old revision of a page, using a simple cache.
35 *
36 * @internal
37 */
38 class PoolWorkArticleViewOld extends PoolWorkArticleView {
39 /** @var RevisionOutputCache */
40 private $cache;
41
42 /**
43 * @param string $workKey PoolCounter key.
44 * @param RevisionOutputCache $cache The cache to store ParserOutput in.
45 * @param RevisionRecord $revision Revision to render
46 * @param ParserOptions $parserOptions ParserOptions to use for the parse
47 * @param RevisionRenderer $revisionRenderer
48 * @param LoggerSpi $loggerSpi
49 */
50 public function __construct(
51 string $workKey,
52 RevisionOutputCache $cache,
53 RevisionRecord $revision,
54 ParserOptions $parserOptions,
55 RevisionRenderer $revisionRenderer,
56 LoggerSpi $loggerSpi
57 ) {
58 parent::__construct( $workKey, $revision, $parserOptions, $revisionRenderer, $loggerSpi );
59
60 $this->cache = $cache;
61
62 $this->cacheable = true;
63 }
64
65 /**
66 * @return Status
67 */
68 public function doWork() {
69 // T371713: Temporary statistics collection code to determine
70 // feasibility of Parsoid selective update
71 $sampleRate = MediaWikiServices::getInstance()->getMainConfig()->get(
72 MainConfigNames::ParsoidSelectiveUpdateSampleRate
73 );
74 $doSample = ( $sampleRate && mt_rand( 1, $sampleRate ) === 1 );
75
76 // Reduce effects of race conditions for slow parses (T48014)
77 $cacheTime = wfTimestampNow();
78
79 $status = $this->renderRevision(
80 null, /* don't attempt Parsoid selective updates on this path */
81 $doSample, 'PoolWorkArticleViewOld'
82 );
83 /** @var ParserOutput|null $output */
84 $output = $status->getValue();
85
86 if ( $output && $output->isCacheable() ) {
87 $this->cache->save( $output, $this->revision, $this->parserOptions, $cacheTime );
88 }
89
90 return $status;
91 }
92
93 /**
94 * @return Status|false
95 */
96 public function getCachedWork() {
97 $parserOutput = $this->cache->get( $this->revision, $this->parserOptions );
98
99 return $parserOutput ? Status::newGood( $parserOutput ) : false;
100 }
101
102 }
103
104 /** @deprecated class alias since 1.42 */
105 class_alias( PoolWorkArticleViewOld::class, 'PoolWorkArticleViewOld' );