Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.00% |
9 / 10 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| NamedConditionHelper | |
90.00% |
9 / 10 |
|
66.67% |
2 / 3 |
7.05 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isNamed | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| getExpression | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
4.03 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\RecentChanges\ChangesListQuery; |
| 4 | |
| 5 | use MediaWiki\User\TempUser\TempUserConfig; |
| 6 | use stdClass; |
| 7 | use Wikimedia\Rdbms\IExpression; |
| 8 | use Wikimedia\Rdbms\IReadableDatabase; |
| 9 | |
| 10 | /** |
| 11 | * Shared code between the named and experience filter conditions |
| 12 | * |
| 13 | * @since 1.45 |
| 14 | */ |
| 15 | class NamedConditionHelper { |
| 16 | public function __construct( |
| 17 | private TempUserConfig $tempUserConfig |
| 18 | ) { |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Determine whether a result row contains a named user |
| 23 | * |
| 24 | * @param stdClass $row |
| 25 | * @return bool |
| 26 | */ |
| 27 | public function isNamed( stdClass $row ) { |
| 28 | return $row->rc_user && !$this->tempUserConfig->isTempName( $row->rc_user_text ); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * @param IReadableDatabase $dbr |
| 33 | * @param bool $isNamed |
| 34 | * @return IExpression |
| 35 | */ |
| 36 | public function getExpression( IReadableDatabase $dbr, bool $isNamed ) { |
| 37 | $expr = $dbr->expr( 'actor_user', $isNamed ? '!=' : '=', null ); |
| 38 | if ( !$this->tempUserConfig->isKnown() ) { |
| 39 | return $expr; |
| 40 | } |
| 41 | if ( $isNamed ) { |
| 42 | return $expr->andExpr( $this->tempUserConfig->getMatchCondition( $dbr, |
| 43 | 'actor_name', IExpression::NOT_LIKE ) ); |
| 44 | } else { |
| 45 | return $expr->orExpr( $this->tempUserConfig->getMatchCondition( $dbr, |
| 46 | 'actor_name', IExpression::LIKE ) ); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | } |