Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApiQueryLangLinksCount
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 execute
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
12
 getExamplesMessages
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
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
9namespace ContentTranslation\ActionApi;
10
11use MediaWiki\Api\ApiQueryBase;
12use MediaWiki\Deferred\LinksUpdate\LangLinksTable;
13
14class ApiQueryLangLinksCount extends ApiQueryBase {
15    public function execute() {
16        if ( $this->getPageSet()->getGoodTitleCount() < 1 ) {
17            return;
18        }
19
20        $this->setVirtualDomain( LangLinksTable::VIRTUAL_DOMAIN );
21
22        $this->addTables( 'langlinks' );
23        $this->addFields( [
24            'll_from',
25            'll_count' => 'COUNT(*)'
26        ] );
27        $this->addWhereFld( 'll_from', array_keys( $this->getPageSet()->getGoodPages() ) );
28        $this->addOption( 'GROUP BY', [ 'll_from' ] );
29
30        // Generated SQL query example
31        // SELECT /* ApiQueryLangLinksCount::execute  */  ll_from,COUNT(*) AS ll_count
32        // FROM `langlinks` WHERE ll_from IN ('16','22')  GROUP BY ll_from
33        $res = $this->select( __METHOD__ );
34
35        foreach ( $res as $row ) {
36            $this->getResult()->addValue(
37                [ 'query', 'pages', $row->ll_from ],
38                $this->getModuleName(),
39                (int)$row->ll_count
40            );
41        }
42    }
43
44    /** @inheritDoc */
45    protected function getExamplesMessages() {
46        return [
47            'action=query&prop=langlinkscount&titles=Dog&redirects=1'
48                => 'apihelp-query+langlinkscount-example-1',
49        ];
50    }
51}