Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ApiQueryLangLinksCount | |
0.00% |
0 / 20 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
| execute | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
12 | |||
| getExamplesMessages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * A query module to get total number of langlinks (links to corresponding foreign language pages). |
| 4 | * |
| 5 | * @copyright See AUTHORS.txt |
| 6 | * @license GPL-2.0-or-later |
| 7 | */ |
| 8 | |
| 9 | namespace ContentTranslation\ActionApi; |
| 10 | |
| 11 | use MediaWiki\Api\ApiQueryBase; |
| 12 | |
| 13 | class ApiQueryLangLinksCount extends ApiQueryBase { |
| 14 | public function execute() { |
| 15 | if ( $this->getPageSet()->getGoodTitleCount() < 1 ) { |
| 16 | return; |
| 17 | } |
| 18 | |
| 19 | $this->addTables( 'langlinks' ); |
| 20 | $this->addFields( [ |
| 21 | 'll_from', |
| 22 | 'll_count' => 'COUNT(*)' |
| 23 | ] ); |
| 24 | $this->addWhereFld( 'll_from', array_keys( $this->getPageSet()->getGoodPages() ) ); |
| 25 | $this->addOption( 'GROUP BY', [ 'll_from' ] ); |
| 26 | |
| 27 | // Generated SQL query example |
| 28 | // SELECT /* ApiQueryLangLinksCount::execute */ ll_from,COUNT(*) AS ll_count |
| 29 | // FROM `langlinks` WHERE ll_from IN ('16','22') GROUP BY ll_from |
| 30 | $res = $this->select( __METHOD__ ); |
| 31 | |
| 32 | foreach ( $res as $row ) { |
| 33 | $this->getResult()->addValue( |
| 34 | [ 'query', 'pages', $row->ll_from ], |
| 35 | $this->getModuleName(), |
| 36 | (int)$row->ll_count |
| 37 | ); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | /** @inheritDoc */ |
| 42 | protected function getExamplesMessages() { |
| 43 | return [ |
| 44 | 'action=query&prop=langlinkscount&titles=Dog&redirects=1' |
| 45 | => 'apihelp-query+langlinkscount-example-1', |
| 46 | ]; |
| 47 | } |
| 48 | } |