MediaWiki master
WatchlistLabelCondition.php
Go to the documentation of this file.
1<?php
2
4
5use stdClass;
7
16
17 public const LABEL_IDS = 'wlm_label_summary';
18
20 public function validateValue( $value ) {
21 if ( !is_numeric( $value ) ) {
22 throw new \InvalidArgumentException( "Watchlist label must be numeric" );
23 }
24 return (int)$value;
25 }
26
28 public function evaluate( stdClass $row, $value ): bool {
29 if ( !$row->wlm_label_summary ) {
30 return false;
31 }
32 return in_array( (string)$value, explode( ',', $row->wlm_label_summary ), true );
33 }
34
36 protected function prepareCapture( IReadableDatabase $dbr, QueryBackend $query ) {
37 $subquery = $dbr->newSelectQueryBuilder()
38 ->select( 'wlm_label' )
39 ->from( 'watchlist_label_member' )
40 ->where( [ 'wlm_item=wl_id' ] )
41 ->buildGroupConcatField( ',' );
42 $query->fields( [ self::LABEL_IDS => $subquery ] );
43 $query->joinForFields( 'watchlist' )->weakLeft();
44 }
45
47 protected function prepareConds( IReadableDatabase $dbr, QueryBackend $query ) {
48 [ $required, $excluded ] = $this->getUniqueValues();
49 if ( $required === [] ) {
50 $query->forceEmptySet();
51 } elseif ( $required ) {
52 $query->joinForConds( 'watchlist' )->reorderable();
53 $query->joinForConds( 'watchlist_label_member' )->reorderable();
54 $query->where( $dbr->expr( 'wlm_label', '=', $required ) );
55 if ( count( $required ) > 1 ) {
56 $query->distinct();
57 }
58 } elseif ( $excluded ) {
59 $query->joinForConds( 'watchlist' )->weakLeft();
60 $query->joinForConds( 'watchlist_label_member' )->left()
61 ->on( $dbr->expr( 'wlm_label', '=', $excluded ) );
62 $query->where( $dbr->expr( 'wlm_label', '=', null ) );
63 }
64 }
65}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:69
evaluate(stdClass $row, $value)
Evaluate the filter condition against a row, determining whether it is true or false....
validateValue( $value)
Validate a value and return its normalized form.mixed
prepareConds(IReadableDatabase $dbr, QueryBackend $query)
Add conditions to the query according to the values passed to require() and exclude()....
The narrow interface passed to filter modules.
forceEmptySet()
Set a flag forcing the query to return no rows when it is executed.
fields( $fields)
Add fields to the query.
where(IExpression $expr)
Add a condition to the query.
joinForFields(string $table)
Join on the specified table and declare that it will be used to provide fields for the SELECT clause.
joinForConds(string $table)
Join on the specified table and declare that it will be used to provide fields for the WHERE clause.
distinct()
Flag that the joins will inadvertently duplicate recentchanges rows and that the query will have to d...
A database connection without write operations.
newSelectQueryBuilder()
Create an empty SelectQueryBuilder which can be used to run queries against this connection.
expr(string $field, string $op, $value)
See Expression::__construct()