Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 44 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| ApiQueryPageProps | |
0.00% |
0 / 43 |
|
0.00% |
0 / 7 |
240 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
72 | |||
| addPageProps | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| getCacheMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getAllowedParams | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| getExamplesMessages | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| getHelpUrls | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Copyright © 2010 soxred93, Bryan Tong Minh |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | */ |
| 8 | |
| 9 | namespace MediaWiki\Api; |
| 10 | |
| 11 | use MediaWiki\Page\PageProps; |
| 12 | use MediaWiki\Title\Title; |
| 13 | use Wikimedia\ParamValidator\ParamValidator; |
| 14 | |
| 15 | /** |
| 16 | * A query module to show basic page information. |
| 17 | * |
| 18 | * @ingroup API |
| 19 | */ |
| 20 | class ApiQueryPageProps extends ApiQueryBase { |
| 21 | |
| 22 | private PageProps $pageProps; |
| 23 | |
| 24 | public function __construct( |
| 25 | ApiQuery $query, |
| 26 | string $moduleName, |
| 27 | PageProps $pageProps |
| 28 | ) { |
| 29 | parent::__construct( $query, $moduleName, 'pp' ); |
| 30 | $this->pageProps = $pageProps; |
| 31 | } |
| 32 | |
| 33 | public function execute() { |
| 34 | # Only operate on existing pages |
| 35 | $pages = $this->getPageSet()->getGoodPages(); |
| 36 | |
| 37 | $params = $this->extractRequestParams(); |
| 38 | if ( $params['continue'] ) { |
| 39 | $cont = $this->parseContinueParamOrDie( $params['continue'], [ 'int' ] ); |
| 40 | $continueValue = $cont[0]; |
| 41 | $filteredPages = []; |
| 42 | foreach ( $pages as $id => $page ) { |
| 43 | if ( $id >= $continueValue ) { |
| 44 | $filteredPages[$id] = $page; |
| 45 | } |
| 46 | } |
| 47 | $pages = $filteredPages; |
| 48 | } |
| 49 | |
| 50 | if ( $pages === [] ) { |
| 51 | # Nothing to do |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | if ( $params['prop'] ) { |
| 56 | $properties = $this->pageProps->getProperties( $pages, $params['prop'] ); |
| 57 | } else { |
| 58 | $properties = $this->pageProps->getAllProperties( $pages ); |
| 59 | } |
| 60 | |
| 61 | ksort( $properties ); |
| 62 | |
| 63 | $result = $this->getResult(); |
| 64 | foreach ( $properties as $pageid => $props ) { |
| 65 | if ( !$this->addPageProps( $result, $pageid, $props ) ) { |
| 66 | break; |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Add page properties to an ApiResult, adding a continue |
| 73 | * parameter if it doesn't fit. |
| 74 | * |
| 75 | * @param ApiResult $result |
| 76 | * @param int $page |
| 77 | * @param array $props |
| 78 | * @return bool True if it fits in the result |
| 79 | */ |
| 80 | private function addPageProps( $result, $page, $props ) { |
| 81 | ApiResult::setArrayType( $props, 'assoc' ); |
| 82 | $fit = $result->addValue( [ 'query', 'pages', $page ], 'pageprops', $props ); |
| 83 | |
| 84 | if ( !$fit ) { |
| 85 | $this->setContinueEnumParameter( 'continue', $page ); |
| 86 | } |
| 87 | |
| 88 | return $fit; |
| 89 | } |
| 90 | |
| 91 | /** @inheritDoc */ |
| 92 | public function getCacheMode( $params ) { |
| 93 | return 'public'; |
| 94 | } |
| 95 | |
| 96 | /** @inheritDoc */ |
| 97 | public function getAllowedParams() { |
| 98 | return [ |
| 99 | 'continue' => [ |
| 100 | ApiBase::PARAM_HELP_MSG => 'api-help-param-continue', |
| 101 | ], |
| 102 | 'prop' => [ |
| 103 | ParamValidator::PARAM_ISMULTI => true, |
| 104 | ], |
| 105 | ]; |
| 106 | } |
| 107 | |
| 108 | /** @inheritDoc */ |
| 109 | protected function getExamplesMessages() { |
| 110 | $title = Title::newMainPage()->getPrefixedText(); |
| 111 | $mp = rawurlencode( $title ); |
| 112 | |
| 113 | return [ |
| 114 | "action=query&prop=pageprops&titles={$mp}|MediaWiki" |
| 115 | => 'apihelp-query+pageprops-example-simple', |
| 116 | ]; |
| 117 | } |
| 118 | |
| 119 | /** @inheritDoc */ |
| 120 | public function getHelpUrls() { |
| 121 | return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Pageprops'; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /** @deprecated class alias since 1.43 */ |
| 126 | class_alias( ApiQueryPageProps::class, 'ApiQueryPageProps' ); |