Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 47 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| GeneratePageFile | |
0.00% |
0 / 41 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Wikispeech; |
| 4 | |
| 5 | /** |
| 6 | * @file |
| 7 | * @ingroup Extensions |
| 8 | * @license GPL-2.0-or-later |
| 9 | */ |
| 10 | |
| 11 | use Maintenance; |
| 12 | use MediaWiki\MediaWikiServices; |
| 13 | use RequestContext; |
| 14 | |
| 15 | /** @var string MediaWiki installation path */ |
| 16 | $IP = getenv( 'MW_INSTALL_PATH' ); |
| 17 | if ( $IP === false ) { |
| 18 | $IP = __DIR__ . '/../../..'; |
| 19 | } |
| 20 | require_once "$IP/maintenance/Maintenance.php"; |
| 21 | |
| 22 | /** |
| 23 | * Maintenance script to generate audio files for pages. |
| 24 | * |
| 25 | * @since 0.1.14 |
| 26 | */ |
| 27 | class GeneratePageFile extends Maintenance { |
| 28 | |
| 29 | public function __construct() { |
| 30 | parent::__construct(); |
| 31 | |
| 32 | $this->requireExtension( 'Wikispeech' ); |
| 33 | $this->addDescription( |
| 34 | 'Generate an audio file from a page.' |
| 35 | . 'This requires the programs `opusdec` and `opusenc` to be' |
| 36 | . "installed. See https://opus-codec.org or your OS' repository." |
| 37 | ); |
| 38 | $this->addOption( |
| 39 | 'page', |
| 40 | 'Name of the page to generate from', |
| 41 | true, |
| 42 | true, |
| 43 | 'p' |
| 44 | ); |
| 45 | $this->addOption( |
| 46 | 'language', |
| 47 | 'Generate using this language.', |
| 48 | true, |
| 49 | true, |
| 50 | 'l' |
| 51 | ); |
| 52 | $this->addOption( |
| 53 | 'consumer', |
| 54 | 'URL to consumer wiki', |
| 55 | withArg: true, |
| 56 | shortName: 'c' |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @return bool success |
| 62 | */ |
| 63 | public function execute() { |
| 64 | $context = new RequestContext(); |
| 65 | $generator = new PageFileGenerator( |
| 66 | $context, |
| 67 | WikispeechServices::getSegmentPageFactory(), |
| 68 | WikispeechServices::getUtteranceGenerator(), |
| 69 | WikispeechServices::getVoiceHandler(), |
| 70 | MediaWikiServices::getInstance()->getTitleFactory(), |
| 71 | $this->getConfig() |
| 72 | ); |
| 73 | |
| 74 | $page = $this->getOption( 'page', null ); |
| 75 | $language = $this->getOption( 'language', null ); |
| 76 | $consumerUrl = $this->getOption( 'consumer', null ); |
| 77 | $generator->makePageFile( $page, $language, $consumerUrl ); |
| 78 | |
| 79 | return true; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /** @var string This class, required to start via Maintenance. */ |
| 84 | $maintClass = GeneratePageFile::class; |
| 85 | |
| 86 | require_once RUN_MAINTENANCE_IF_MAIN; |