Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
ApiTranscodeStatus | |
0.00% |
0 / 27 |
|
0.00% |
0 / 5 |
90 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
30 | |||
getCacheMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAllowedParams | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Allows for api queries to get detailed information about the transcode state of a particular |
4 | * media asset. ( basically directly returns the transcode status table ) |
5 | * |
6 | * This information can be used to generate status tables similar to the one seen |
7 | * on the image page. |
8 | */ |
9 | |
10 | namespace MediaWiki\TimedMediaHandler; |
11 | |
12 | use ApiQuery; |
13 | use ApiQueryBase; |
14 | use File; |
15 | use MediaWiki\TimedMediaHandler\WebVideoTranscode\WebVideoTranscode; |
16 | use RepoGroup; |
17 | |
18 | class ApiTranscodeStatus extends ApiQueryBase { |
19 | /** @var RepoGroup */ |
20 | private $repoGroup; |
21 | |
22 | /** @var TranscodableChecker */ |
23 | private $transcodableChecker; |
24 | |
25 | /** |
26 | * @param ApiQuery $queryModule |
27 | * @param string $moduleName |
28 | * @param RepoGroup $repoGroup |
29 | */ |
30 | public function __construct( |
31 | ApiQuery $queryModule, |
32 | $moduleName, |
33 | RepoGroup $repoGroup |
34 | ) { |
35 | parent::__construct( $queryModule, $moduleName ); |
36 | $this->repoGroup = $repoGroup; |
37 | $this->transcodableChecker = new TranscodableChecker( |
38 | $this->getConfig(), |
39 | $repoGroup |
40 | ); |
41 | } |
42 | |
43 | public function execute() { |
44 | $pageIds = $this->getPageSet()->getAllTitlesByNamespace(); |
45 | // Make sure we have files in the title set: |
46 | if ( !empty( $pageIds[NS_FILE] ) ) { |
47 | $titles = array_keys( $pageIds[NS_FILE] ); |
48 | // Ensure the order is always the same |
49 | asort( $titles ); |
50 | |
51 | $result = $this->getResult(); |
52 | $images = $this->repoGroup->findFiles( $titles ); |
53 | /** |
54 | * @var $img File |
55 | */ |
56 | foreach ( $images as $img ) { |
57 | // if its a "transcode" add the transcode status table output |
58 | if ( $this->transcodableChecker->isTranscodableTitle( $img->getTitle() ) ) { |
59 | $transcodeStatus = WebVideoTranscode::getTranscodeState( $img ); |
60 | // remove useless properties |
61 | foreach ( $transcodeStatus as &$val ) { |
62 | unset( $val['id'], $val['image_name'], $val['key'] ); |
63 | } |
64 | unset( $val ); |
65 | $result->addValue( [ |
66 | 'query', 'pages', $img->getTitle()->getArticleID() ], 'transcodestatus', $transcodeStatus |
67 | ); |
68 | } |
69 | } |
70 | } |
71 | } |
72 | |
73 | /** @inheritDoc */ |
74 | public function getCacheMode( $params ) { |
75 | return 'public'; |
76 | } |
77 | |
78 | /** @inheritDoc */ |
79 | public function getAllowedParams() { |
80 | return []; |
81 | } |
82 | |
83 | /** |
84 | * @see ApiBase::getExamplesMessages() |
85 | * @return array |
86 | */ |
87 | protected function getExamplesMessages() { |
88 | return [ |
89 | 'action=query&prop=transcodestatus&titles=File:Clip.webm' |
90 | => 'apihelp-query+transcodestatus-example-1', |
91 | ]; |
92 | } |
93 | } |