10use Wikimedia\Timestamp\TimestampFormat as TS;
21 private ?
int $userId =
null;
23 private const ALL_VALUES = [
'notwatched',
'watchedold',
'watchednew' ];
29 $this->userId = $user->
getId();
37 if ( !in_array( $value, self::ALL_VALUES,
true ) ) {
38 throw new \InvalidArgumentException(
'unknown value for watched filter' );
44 public function evaluate( stdClass $row, $value ): bool {
46 || ( $this->enableExpiry && $row->we_expiry !== null
48 || $row->wl_user === null
50 return $value ===
'notwatched';
51 } elseif ( $row->rc_timestamp &&
52 $row->wl_notificationtimestamp &&
53 $row->rc_timestamp >= $row->wl_notificationtimestamp
55 return $value ===
'watchednew';
57 return $value ===
'watchedold';
63 if ( !$this->userId ) {
67 $query->
fields( [
'wl_user',
'wl_notificationtimestamp',
'rc_timestamp' ] );
68 if ( $this->enableExpiry ) {
70 $query->
fields(
'we_expiry' );
76 $set = $this->getEnumValues( self::ALL_VALUES );
77 if ( $set ===
null ) {
79 } elseif ( $set === [] ) {
83 $notwatched = in_array(
'notwatched', $set,
true );
84 $watchedold = in_array(
'watchedold', $set,
true );
85 $watchednew = in_array(
'watchednew', $set,
true );
87 if ( !$this->userId ) {
98 $orConds[] = $dbr->
expr(
'wl_user',
'=',
null );
99 if ( $this->enableExpiry ) {
101 $orConds[] = $dbr->
expr(
'we_expiry',
'<=', $dbr->
timestamp() );
108 if ( $this->enableExpiry ) {
111 $dbr->
expr(
'we_expiry',
'=',
null )
112 ->or(
'we_expiry',
'>', $dbr->
timestamp() )
117 if ( $watchedold xor $watchednew ) {
119 $oldExpr = (
new RawSQLExpression(
'rc_timestamp < wl_notificationtimestamp' ) )
120 ->or(
'wl_notificationtimestamp',
'=',
null );
122 $oldExpr =
new RawSQLExpression(
'rc_timestamp >= wl_notificationtimestamp' );
127 $oldExpr = $dbr->
expr(
'wl_user',
'!=',
null )->andExpr( $oldExpr );
129 $orConds[] = $oldExpr;
132 if ( count( $orConds ) === 1 ) {
133 $query->
where( $orConds[0] );
134 } elseif ( count( $orConds ) ) {
wfTimestamp( $outputtype=TS::UNIX, $ts=0)
Get a timestamp string in one of various formats.
if(!defined('MW_SETUP_CALLBACK'))