Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
94.12% |
16 / 17 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ViewCLI | |
94.12% |
16 / 17 |
|
50.00% |
1 / 2 |
7.01 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
92.86% |
13 / 14 |
|
0.00% |
0 / 1 |
6.01 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Show page contents. |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | * @ingroup Maintenance |
| 8 | */ |
| 9 | |
| 10 | use MediaWiki\Content\TextContent; |
| 11 | use MediaWiki\Maintenance\Maintenance; |
| 12 | use MediaWiki\Revision\RevisionRecord; |
| 13 | use MediaWiki\Title\Title; |
| 14 | |
| 15 | // @codeCoverageIgnoreStart |
| 16 | require_once __DIR__ . '/Maintenance.php'; |
| 17 | // @codeCoverageIgnoreEnd |
| 18 | |
| 19 | /** |
| 20 | * Maintenance script to show page contents. |
| 21 | * |
| 22 | * @ingroup Maintenance |
| 23 | */ |
| 24 | class ViewCLI extends Maintenance { |
| 25 | public function __construct() { |
| 26 | parent::__construct(); |
| 27 | $this->addDescription( 'Show article contents on the command line' ); |
| 28 | $this->addArg( 'title', 'Title of article to view' ); |
| 29 | } |
| 30 | |
| 31 | public function execute() { |
| 32 | $title = Title::newFromText( $this->getArg( 0 ) ); |
| 33 | if ( !$title ) { |
| 34 | $this->fatalError( "Invalid title" ); |
| 35 | } elseif ( $title->isSpecialPage() ) { |
| 36 | $this->fatalError( "Special Pages not supported" ); |
| 37 | } elseif ( !$title->exists() ) { |
| 38 | $this->fatalError( "Page does not exist" ); |
| 39 | } |
| 40 | |
| 41 | $page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title ); |
| 42 | |
| 43 | $content = $page->getContent( RevisionRecord::RAW ); |
| 44 | if ( !$content ) { |
| 45 | $this->fatalError( "Page has no content" ); |
| 46 | } |
| 47 | if ( !$content instanceof TextContent ) { |
| 48 | $this->fatalError( "Non-text content models not supported" ); |
| 49 | } |
| 50 | |
| 51 | $this->output( $content->getText() ); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | // @codeCoverageIgnoreStart |
| 56 | $maintClass = ViewCLI::class; |
| 57 | require_once RUN_MAINTENANCE_IF_MAIN; |
| 58 | // @codeCoverageIgnoreEnd |