Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 32 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
ApiQueryProjects | |
0.00% |
0 / 32 |
|
0.00% |
0 / 6 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCacheMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
20 | |||
getAllowedParams | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
getExamplesMessages | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
getHelpUrls | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\PageAssessments\Api; |
4 | |
5 | use ApiQuery; |
6 | use ApiQueryBase; |
7 | use Wikimedia\ParamValidator\ParamValidator; |
8 | |
9 | /* |
10 | * API module for retrieving all the projects on a wiki |
11 | */ |
12 | class ApiQueryProjects extends ApiQueryBase { |
13 | |
14 | /** @inheritDoc */ |
15 | public function __construct( ApiQuery $query, $moduleName ) { |
16 | parent::__construct( $query, $moduleName, 'pj' ); |
17 | } |
18 | |
19 | /** |
20 | * Get the cache mode for the data generated by this module. |
21 | * @param array $params |
22 | * @return string |
23 | */ |
24 | public function getCacheMode( $params ) { |
25 | return 'public'; |
26 | } |
27 | |
28 | /** |
29 | * Evaluate the parameters, perform the requested query, and set up the result |
30 | */ |
31 | public function execute() { |
32 | global $wgPageAssessmentsSubprojects; |
33 | |
34 | $params = $this->extractRequestParams(); |
35 | |
36 | // Set the database query parameters |
37 | $this->addTables( [ 'page_assessments_projects' ] ); |
38 | $this->addFields( [ 'project_title' => 'pap_project_title' ] ); |
39 | // If this wiki distinguishes between projects and subprojects, exclude |
40 | // subprojects (i.e. projects with parents) unless explicitly asked for. |
41 | if ( $wgPageAssessmentsSubprojects && !$params['subprojects'] ) { |
42 | $this->addWhere( [ 'pap_parent_id' => null ] ); |
43 | } |
44 | $this->addOption( 'ORDER BY', 'pap_project_title' ); |
45 | |
46 | // Execute the query and put the results in an array |
47 | $db_res = $this->select( __METHOD__ ); |
48 | $projects = []; |
49 | foreach ( $db_res as $row ) { |
50 | $projects[] = $row->project_title; |
51 | } |
52 | |
53 | // Build the API output |
54 | $result = $this->getResult(); |
55 | $result->addValue( 'query', 'projects', $projects ); |
56 | } |
57 | |
58 | /** @inheritDoc */ |
59 | public function getAllowedParams() { |
60 | global $wgPageAssessmentsSubprojects; |
61 | |
62 | $allowedParams = []; |
63 | if ( $wgPageAssessmentsSubprojects ) { |
64 | $allowedParams[ 'subprojects' ] = [ |
65 | ParamValidator::PARAM_DEFAULT => false, |
66 | ParamValidator::PARAM_TYPE => 'boolean', |
67 | ]; |
68 | } |
69 | return $allowedParams; |
70 | } |
71 | |
72 | /** @inheritDoc */ |
73 | public function getExamplesMessages() { |
74 | global $wgPageAssessmentsSubprojects; |
75 | |
76 | $exampleMessages = [ |
77 | 'action=query&list=projects' => 'apihelp-query+projects-example', |
78 | ]; |
79 | if ( $wgPageAssessmentsSubprojects ) { |
80 | $exampleMessages[ 'action=query&list=projects&pjsubprojects=true' ] = |
81 | 'apihelp-query+projects-example-subprojects'; |
82 | } |
83 | return $exampleMessages; |
84 | } |
85 | |
86 | /** @inheritDoc */ |
87 | public function getHelpUrls() { |
88 | return 'https://www.mediawiki.org/wiki/Special:MyLanguage/Extension:PageAssessments'; |
89 | } |
90 | } |