10use Wikimedia\Timestamp\TimestampFormat as TS;
19 private ?
int $userId =
null;
21 private const ALL_VALUES = [
'notwatched',
'watchedold',
'watchednew' ];
27 $this->userId = $user->
getId();
35 if ( !in_array( $value, self::ALL_VALUES,
true ) ) {
36 throw new \InvalidArgumentException(
'unknown value for watched filter' );
42 public function evaluate( stdClass $row, $value ): bool {
44 || ( $this->enableExpiry && $row->we_expiry !== null
46 || $row->wl_user === null
48 return $value ===
'notwatched';
49 } elseif ( $row->rc_timestamp &&
50 $row->wl_notificationtimestamp &&
51 $row->rc_timestamp >= $row->wl_notificationtimestamp
53 return $value ===
'watchednew';
55 return $value ===
'watchedold';
61 if ( !$this->userId ) {
65 $query->
fields( [
'wl_user',
'wl_notificationtimestamp',
'rc_timestamp' ] );
66 if ( $this->enableExpiry ) {
68 $query->
fields(
'we_expiry' );
74 $set = $this->getEnumValues( self::ALL_VALUES );
75 if ( $set ===
null ) {
77 } elseif ( $set === [] ) {
81 $notwatched = in_array(
'notwatched', $set,
true );
82 $watchedold = in_array(
'watchedold', $set,
true );
83 $watchednew = in_array(
'watchednew', $set,
true );
85 if ( !$this->userId ) {
96 $orConds[] = $dbr->
expr(
'wl_user',
'=',
null );
97 if ( $this->enableExpiry ) {
99 $orConds[] = $dbr->
expr(
'we_expiry',
'<=', $dbr->
timestamp() );
106 if ( $this->enableExpiry ) {
109 $dbr->
expr(
'we_expiry',
'=',
null )
110 ->or(
'we_expiry',
'>', $dbr->
timestamp() )
115 if ( $watchedold xor $watchednew ) {
117 $oldExpr = (
new RawSQLExpression(
'rc_timestamp < wl_notificationtimestamp' ) )
118 ->or(
'wl_notificationtimestamp',
'=',
null );
120 $oldExpr =
new RawSQLExpression(
'rc_timestamp >= wl_notificationtimestamp' );
125 $oldExpr = $dbr->
expr(
'wl_user',
'!=',
null )->andExpr( $oldExpr );
127 $orConds[] = $oldExpr;
130 if ( count( $orConds ) === 1 ) {
131 $query->
where( $orConds[0] );
132 } elseif ( count( $orConds ) ) {
wfTimestamp( $outputtype=TS::UNIX, $ts=0)
Get a timestamp string in one of various formats.
if(!defined('MW_SETUP_CALLBACK'))