2014-06-22 01:29:03 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
2018-08-14 16:37:30 +00:00
|
|
|
|
2023-12-15 15:52:25 +00:00
|
|
|
namespace MediaWiki\PoolCounter;
|
|
|
|
|
|
2020-11-17 20:34:43 +00:00
|
|
|
use MediaWiki\Logger\Spi as LoggerSpi;
|
2024-02-18 13:33:18 +00:00
|
|
|
use MediaWiki\Page\ParserOutputAccess;
|
2018-09-20 17:29:04 +00:00
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
2018-08-14 16:37:30 +00:00
|
|
|
use MediaWiki\Revision\RevisionRenderer;
|
2023-08-25 12:29:41 +00:00
|
|
|
use MediaWiki\Status\Status;
|
2023-12-15 15:52:25 +00:00
|
|
|
use ParserOptions;
|
2014-06-22 01:29:03 +00:00
|
|
|
|
2020-11-13 11:46:05 +00:00
|
|
|
/**
|
|
|
|
|
* PoolCounter protected work wrapping RenderedRevision->getRevisionParserOutput.
|
2020-11-16 20:05:03 +00:00
|
|
|
* Caching behavior may be defined by subclasses.
|
|
|
|
|
*
|
2020-11-13 11:46:05 +00:00
|
|
|
* @note No audience checks are applied.
|
|
|
|
|
*
|
|
|
|
|
* @internal
|
|
|
|
|
*/
|
2014-06-22 01:29:03 +00:00
|
|
|
class PoolWorkArticleView extends PoolCounterWork {
|
|
|
|
|
/** @var ParserOptions */
|
2020-11-16 20:05:03 +00:00
|
|
|
protected $parserOptions;
|
2022-05-03 11:16:08 +00:00
|
|
|
/** @var RevisionRecord */
|
|
|
|
|
protected $revision;
|
2018-08-14 16:37:30 +00:00
|
|
|
/** @var RevisionRenderer */
|
2022-05-03 11:16:08 +00:00
|
|
|
private $renderer;
|
2020-11-17 20:34:43 +00:00
|
|
|
/** @var LoggerSpi */
|
2022-04-11 15:10:14 +00:00
|
|
|
protected $loggerSpi;
|
2020-11-17 20:34:43 +00:00
|
|
|
|
2014-06-22 01:29:03 +00:00
|
|
|
/**
|
2020-11-16 20:05:03 +00:00
|
|
|
* @param string $workKey
|
2020-11-13 11:46:05 +00:00
|
|
|
* @param RevisionRecord $revision Revision to render
|
2014-08-13 19:41:39 +00:00
|
|
|
* @param ParserOptions $parserOptions ParserOptions to use for the parse
|
2020-11-13 11:46:05 +00:00
|
|
|
* @param RevisionRenderer $revisionRenderer
|
2020-11-17 20:34:43 +00:00
|
|
|
* @param LoggerSpi $loggerSpi
|
2014-06-22 01:29:03 +00:00
|
|
|
*/
|
2020-11-13 11:46:05 +00:00
|
|
|
public function __construct(
|
2020-11-16 20:05:03 +00:00
|
|
|
string $workKey,
|
2020-11-13 11:46:05 +00:00
|
|
|
RevisionRecord $revision,
|
|
|
|
|
ParserOptions $parserOptions,
|
2020-11-17 20:34:43 +00:00
|
|
|
RevisionRenderer $revisionRenderer,
|
|
|
|
|
LoggerSpi $loggerSpi
|
2014-06-22 01:29:03 +00:00
|
|
|
) {
|
2020-11-16 20:05:03 +00:00
|
|
|
parent::__construct( 'ArticleView', $workKey );
|
2018-08-14 16:37:30 +00:00
|
|
|
$this->revision = $revision;
|
2020-11-13 11:46:05 +00:00
|
|
|
$this->parserOptions = $parserOptions;
|
|
|
|
|
$this->renderer = $revisionRenderer;
|
2020-11-17 20:34:43 +00:00
|
|
|
$this->loggerSpi = $loggerSpi;
|
2014-06-22 01:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-04-05 16:37:01 +00:00
|
|
|
* @return Status
|
2014-06-22 01:29:03 +00:00
|
|
|
*/
|
|
|
|
|
public function doWork() {
|
2022-05-03 11:16:08 +00:00
|
|
|
return $this->renderRevision();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-02-18 13:33:18 +00:00
|
|
|
* Render the given revision.
|
|
|
|
|
*
|
|
|
|
|
* @see ParserOutputAccess::renderRevision
|
|
|
|
|
*
|
2022-05-03 11:16:08 +00:00
|
|
|
* @return Status with the value being a ParserOutput or null
|
|
|
|
|
*/
|
|
|
|
|
public function renderRevision(): Status {
|
2018-08-14 16:37:30 +00:00
|
|
|
$renderedRevision = $this->renderer->getRenderedRevision(
|
2020-11-13 11:46:05 +00:00
|
|
|
$this->revision,
|
2018-08-14 16:37:30 +00:00
|
|
|
$this->parserOptions,
|
|
|
|
|
null,
|
2020-11-13 11:46:05 +00:00
|
|
|
[ 'audience' => RevisionRecord::RAW ]
|
2018-08-14 16:37:30 +00:00
|
|
|
);
|
2014-06-22 01:29:03 +00:00
|
|
|
|
2022-04-05 16:37:01 +00:00
|
|
|
$parserOutput = $renderedRevision->getRevisionParserOutput();
|
2014-06-22 01:29:03 +00:00
|
|
|
|
2022-04-05 16:37:01 +00:00
|
|
|
return Status::newGood( $parserOutput );
|
2014-06-22 01:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param Status $status
|
2022-04-05 16:37:01 +00:00
|
|
|
* @return Status
|
2014-06-22 01:29:03 +00:00
|
|
|
*/
|
|
|
|
|
public function error( $status ) {
|
2022-04-05 16:37:01 +00:00
|
|
|
return $status;
|
2014-06-22 01:29:03 +00:00
|
|
|
}
|
2020-11-17 20:34:43 +00:00
|
|
|
|
2014-06-22 01:29:03 +00:00
|
|
|
}
|
2023-12-15 15:52:25 +00:00
|
|
|
|
2024-07-05 16:16:27 +00:00
|
|
|
/** @deprecated class alias since 1.42 */
|
2023-12-15 15:52:25 +00:00
|
|
|
class_alias( PoolWorkArticleView::class, 'PoolWorkArticleView' );
|