Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| BasicZObjectPager | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getQueryInfo | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| getEmptyBody | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * WikiLambda BasicZObjectPager extends AbstractZObjectPager by |
| 4 | * adding filter conditions to the base table of all zobjects and |
| 5 | * their preferred labels given by AbstractZObjectPager::getQueryInfo |
| 6 | * |
| 7 | * @file |
| 8 | * @ingroup Extensions |
| 9 | * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt |
| 10 | * @license MIT |
| 11 | */ |
| 12 | |
| 13 | namespace MediaWiki\Extension\WikiLambda\Pagers; |
| 14 | |
| 15 | use MediaWiki\Context\IContextSource; |
| 16 | use MediaWiki\Extension\WikiLambda\ZObjectStore; |
| 17 | |
| 18 | /** |
| 19 | * Basic pager for listing ZObjects of a given type. Accepts simple |
| 20 | * filters such as type. Used for the following special pages: |
| 21 | * - Special:ListMissingLabels |
| 22 | * - Special:ListObjectsByType |
| 23 | */ |
| 24 | class BasicZObjectPager extends AbstractZObjectPager { |
| 25 | |
| 26 | private array $filters; |
| 27 | |
| 28 | /** |
| 29 | * @param IContextSource|null $context Context. |
| 30 | * @param ZObjectStore $zObjectStore |
| 31 | * @param array $languageZids |
| 32 | * @param string|null $orderby |
| 33 | * @param bool|null $excludePreDefined |
| 34 | * @param array $filters |
| 35 | */ |
| 36 | public function __construct( |
| 37 | $context, $zObjectStore, $languageZids, $orderby = null, $excludePreDefined = null, $filters = [] |
| 38 | ) { |
| 39 | parent::__construct( $context, $zObjectStore, $languageZids, $orderby, $excludePreDefined ); |
| 40 | |
| 41 | $this->filters = $filters; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Gets the base conditions from the parent class and adds the |
| 46 | * additional conditions for this pager, depending on the filters: |
| 47 | * - WHERE wlzl_type = type |
| 48 | * - WHERE wlzl_language != missing_language |
| 49 | * |
| 50 | * @return array |
| 51 | */ |
| 52 | public function getQueryInfo() { |
| 53 | // Get base queryInfo from parent |
| 54 | $queryInfo = parent::getQueryInfo(); |
| 55 | |
| 56 | // Special:ListObjectsByType and Special:ListMissingLabels |
| 57 | if ( array_key_exists( 'type', $this->filters ) ) { |
| 58 | $queryInfo[ 'conds' ][ 'wlzl_type' ] = $this->filters[ 'type' ]; |
| 59 | } |
| 60 | |
| 61 | // Special:ListMissingLabels |
| 62 | if ( array_key_exists( 'missing_language', $this->filters ) ) { |
| 63 | $queryInfo[ 'conds' ][] = $this->getDatabase() |
| 64 | ->expr( 'wlzl_language', '!=', $this->filters[ 'missing_language' ] ); |
| 65 | } |
| 66 | |
| 67 | return $queryInfo; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @return string |
| 72 | */ |
| 73 | public function getEmptyBody() { |
| 74 | return $this->msg( 'wikilambda-special-objectsbytype-empty' )->parse(); |
| 75 | } |
| 76 | } |