Addshore has uploaded a new change for review.
https://gerrit.wikimedia.org/r/245881
Change subject: WIP look at watchlist expiry stuff
......................................................................
WIP look at watchlist expiry stuff
TODO: Think about how to remove expired
items from the db in the best way
Change-Id: I6c2b13ec08c3e90572b26a76a6788bde5e38c99b
---
M includes/User.php
M includes/WatchedItem.php
M includes/actions/InfoAction.php
M includes/actions/WatchAction.php
M includes/api/ApiDelete.php
M includes/api/ApiEditPage.php
M includes/api/ApiMove.php
M includes/api/ApiProtect.php
M includes/api/ApiQueryInfo.php
M includes/api/ApiQueryUserInfo.php
M includes/api/ApiQueryWatchlist.php
M includes/api/ApiQueryWatchlistRaw.php
M includes/api/ApiRollback.php
M includes/api/ApiUndelete.php
M includes/api/ApiUpload.php
M includes/api/ApiWatch.php
M includes/installer/MysqlUpdater.php
M includes/mail/EmailNotification.php
M includes/specials/SpecialEditWatchlist.php
M includes/specials/SpecialRecentchanges.php
M includes/specials/SpecialRecentchangeslinked.php
M includes/specials/SpecialUnwatchedpages.php
M includes/specials/SpecialWatchlist.php
A maintenance/archives/patch-watchlist-wl_expirytimestamp.sql
24 files changed, 51 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/81/245881/1
diff --git a/includes/User.php b/includes/User.php
index 75649a7..cb25784 100644
--- a/includes/User.php
+++ b/includes/User.php
@@ -3364,6 +3364,7 @@
* @param Title $title Title of the article to look at
* @param int $checkRights Whether to check
'viewmywatchlist'/'editmywatchlist' rights.
* Pass WatchedItem::CHECK_USER_RIGHTS or
WatchedItem::IGNORE_USER_RIGHTS.
+ * @todo add an expiry param?
*/
public function addWatch( $title, $checkRights =
WatchedItem::CHECK_USER_RIGHTS ) {
$this->getWatchedItem( $title, $checkRights )->addWatch();
diff --git a/includes/WatchedItem.php b/includes/WatchedItem.php
index adee126..1a6154e 100644
--- a/includes/WatchedItem.php
+++ b/includes/WatchedItem.php
@@ -45,6 +45,8 @@
/** @var string */
private $timestamp;
+ // TODO add an expiry!
+
/**
* Constant to specify that user rights 'editmywatchlist' and
* 'viewmywatchlist' should not be checked.
@@ -78,6 +80,7 @@
* @param int $checkRights Whether to check the 'viewmywatchlist' and
'editmywatchlist' rights.
* Pass either WatchedItem::IGNORE_USER_RIGHTS or
WatchedItem::CHECK_USER_RIGHTS.
* @return WatchedItem
+ * @todo add expiry?
*/
public static function fromUserTitle( $user, $title,
$checkRights = WatchedItem::CHECK_USER_RIGHTS
@@ -121,6 +124,8 @@
protected function getUserId() {
return $this->mUser->getId();
}
+
+ // TODO add getExpiry method?
/**
* Return an array of conditions to select or update the appropriate
database
@@ -169,6 +174,7 @@
} else {
$this->watched = true;
$this->timestamp = $row->wl_notificationtimestamp;
+ //TODO set $this->expiry
}
}
@@ -191,6 +197,9 @@
}
$this->load();
+
+ // TODO eatched but not expired?
+
return $this->watched;
}
@@ -320,6 +329,7 @@
'wl_namespace' => MWNamespace::getSubject(
$item->getTitleNs() ),
'wl_title' => $item->getTitleDBkey(),
'wl_notificationtimestamp' => null,
+ //TODO add expiry
);
// Every single watched page needs now to be listed in
watchlist;
// namespace:page and namespace_talk:page need separate
entries:
@@ -328,6 +338,7 @@
'wl_namespace' => MWNamespace::getTalk(
$item->getTitleNs() ),
'wl_title' => $item->getTitleDBkey(),
'wl_notificationtimestamp' => null
+ //TODO add expiry
);
$item->watched = true;
}
@@ -459,4 +470,6 @@
return true;
}
+
+ //TODO some method to remove expired entires? Similar to one of the
methods above
}
diff --git a/includes/actions/InfoAction.php b/includes/actions/InfoAction.php
index 7389ae2..c765618 100644
--- a/includes/actions/InfoAction.php
+++ b/includes/actions/InfoAction.php
@@ -694,6 +694,7 @@
array(
'wl_namespace' =>
$title->getNamespace(),
'wl_title' =>
$title->getDBkey(),
+ //TODO where not expired!?
),
$fname
);
@@ -714,6 +715,7 @@
'wl_notificationtimestamp >= ' .
$dbrWatchlist->addQuotes( $threshold ) .
' OR
wl_notificationtimestamp IS NULL'
+ //TODO where not
expired?
),
$fname
);
diff --git a/includes/actions/WatchAction.php b/includes/actions/WatchAction.php
index 30b83d7..4be64a5 100644
--- a/includes/actions/WatchAction.php
+++ b/includes/actions/WatchAction.php
@@ -103,6 +103,7 @@
* @param User $user User who is watching/unwatching
* @param int $checkRights Passed through to $user->addWatch()
* @return Status
+ * @todo add expiry param
*/
public static function doWatch( Title $title, User $user,
$checkRights = WatchedItem::CHECK_USER_RIGHTS
@@ -116,9 +117,11 @@
$page = WikiPage::factory( $title );
$status = Status::newFatal( 'hookaborted' );
+ // TODO WatchArticle hook will have an expiry param
if ( Hooks::run( 'WatchArticle', array( &$user, &$page,
&$status ) ) ) {
$status = Status::newGood();
$user->addWatch( $title, $checkRights );
+ // TODO WatchArticleComplete might have an extra param?
Hooks::run( 'WatchArticleComplete', array( &$user,
&$page ) );
}
diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php
index acb260c..bfb9382 100644
--- a/includes/api/ApiDelete.php
+++ b/includes/api/ApiDelete.php
@@ -197,6 +197,7 @@
ApiBase::PARAM_DFLT => false,
ApiBase::PARAM_DEPRECATED => true,
),
+ //TODO could optional watch with an expiry?
'watchlist' => array(
ApiBase::PARAM_DFLT => 'preferences',
ApiBase::PARAM_TYPE => array(
diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php
index 2f1c01c..8db65b4 100644
--- a/includes/api/ApiEditPage.php
+++ b/includes/api/ApiEditPage.php
@@ -601,6 +601,7 @@
ApiBase::PARAM_DFLT => false,
ApiBase::PARAM_DEPRECATED => true,
),
+ //TODO could optional watch with an expiry?
'watchlist' => array(
ApiBase::PARAM_DFLT => 'preferences',
ApiBase::PARAM_TYPE => array(
diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php
index 60fd426..26d65ba 100644
--- a/includes/api/ApiMove.php
+++ b/includes/api/ApiMove.php
@@ -230,6 +230,7 @@
ApiBase::PARAM_DFLT => false,
ApiBase::PARAM_DEPRECATED => true,
),
+ //TODO could optional watch with an expiry?
'watchlist' => array(
ApiBase::PARAM_DFLT => 'preferences',
ApiBase::PARAM_TYPE => array(
diff --git a/includes/api/ApiProtect.php b/includes/api/ApiProtect.php
index c07aaca..4e0c920 100644
--- a/includes/api/ApiProtect.php
+++ b/includes/api/ApiProtect.php
@@ -162,6 +162,7 @@
ApiBase::PARAM_DFLT => false,
ApiBase::PARAM_DEPRECATED => true,
),
+ //TODO could optional watch with an expiry?
'watchlist' => array(
ApiBase::PARAM_DFLT => 'preferences',
ApiBase::PARAM_TYPE => array(
diff --git a/includes/api/ApiQueryInfo.php b/includes/api/ApiQueryInfo.php
index b05c75c..0cff06c 100644
--- a/includes/api/ApiQueryInfo.php
+++ b/includes/api/ApiQueryInfo.php
@@ -741,6 +741,7 @@
$this->addTables( array( 'watchlist' ) );
$this->addFields( array( 'wl_title', 'wl_namespace' ) );
$this->addFieldsIf( 'wl_notificationtimestamp',
$this->fld_notificationtimestamp );
+ //TODO dont get expired watchlist items?
$this->addWhere( array(
$lb->constructSet( 'wl', $db ),
'wl_user' => $user->getID()
@@ -786,6 +787,7 @@
$this->addWhere( array(
$lb->constructSet( 'wl', $db )
) );
+ //TODO where not expired!!!
$this->addOption( 'GROUP BY', array( 'wl_namespace', 'wl_title'
) );
if ( !$canUnwatchedpages ) {
$this->addOption( 'HAVING', "COUNT(*) >=
$unwatchedPageThreshold" );
diff --git a/includes/api/ApiQueryUserInfo.php
b/includes/api/ApiQueryUserInfo.php
index f916537..ac4829e 100644
--- a/includes/api/ApiQueryUserInfo.php
+++ b/includes/api/ApiQueryUserInfo.php
@@ -193,6 +193,7 @@
array(
'wl_user' => $user->getId(),
'wl_notificationtimestamp IS NOT NULL',
+ //TODO where not expired
),
__METHOD__,
array( 'LIMIT' => self::WL_UNREAD_LIMIT )
diff --git a/includes/api/ApiQueryWatchlist.php
b/includes/api/ApiQueryWatchlist.php
index 648d259..eacc175 100644
--- a/includes/api/ApiQueryWatchlist.php
+++ b/includes/api/ApiQueryWatchlist.php
@@ -129,6 +129,7 @@
'wl_user' => $userId,
'wl_namespace=rc_namespace',
'wl_title=rc_title'
+ // TODO where (wl_expirytimestamp > NOW() OR
wl_expirytimestamp IS NULL)
)
) ) );
diff --git a/includes/api/ApiQueryWatchlistRaw.php
b/includes/api/ApiQueryWatchlistRaw.php
index fc7b80c..a636879 100644
--- a/includes/api/ApiQueryWatchlistRaw.php
+++ b/includes/api/ApiQueryWatchlistRaw.php
@@ -68,6 +68,7 @@
$this->addWhereFld( 'wl_namespace', $params['namespace'] );
$this->addWhereIf( 'wl_notificationtimestamp IS NOT NULL',
isset( $show['changed'] ) );
$this->addWhereIf( 'wl_notificationtimestamp IS NULL', isset(
$show['!changed'] ) );
+ //TODO where not expired!
if ( isset( $params['continue'] ) ) {
$cont = explode( '|', $params['continue'] );
diff --git a/includes/api/ApiRollback.php b/includes/api/ApiRollback.php
index 6a3346f..9d5a643 100644
--- a/includes/api/ApiRollback.php
+++ b/includes/api/ApiRollback.php
@@ -113,6 +113,7 @@
),
'summary' => '',
'markbot' => false,
+ //TODO could optional watch with an expiry?
'watchlist' => array(
ApiBase::PARAM_DFLT => 'preferences',
ApiBase::PARAM_TYPE => array(
diff --git a/includes/api/ApiUndelete.php b/includes/api/ApiUndelete.php
index cd50ee6..c8dec5e 100644
--- a/includes/api/ApiUndelete.php
+++ b/includes/api/ApiUndelete.php
@@ -112,6 +112,7 @@
ApiBase::PARAM_TYPE => 'integer',
ApiBase::PARAM_ISMULTI => true,
),
+ //TODO could optional watch with an expiry?
'watchlist' => array(
ApiBase::PARAM_DFLT => 'preferences',
ApiBase::PARAM_TYPE => array(
diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php
index b621cb0..c82e598 100644
--- a/includes/api/ApiUpload.php
+++ b/includes/api/ApiUpload.php
@@ -767,6 +767,7 @@
ApiBase::PARAM_DFLT => false,
ApiBase::PARAM_DEPRECATED => true,
),
+ //TODO could optional watch with an expiry?
'watchlist' => array(
ApiBase::PARAM_DFLT => 'preferences',
ApiBase::PARAM_TYPE => array(
diff --git a/includes/api/ApiWatch.php b/includes/api/ApiWatch.php
index 85d051d..e19b842 100644
--- a/includes/api/ApiWatch.php
+++ b/includes/api/ApiWatch.php
@@ -115,6 +115,7 @@
->title( $title )->parseAsBlock();
}
} else {
+ // TODO pass expiry param to doWatch
$status = WatchAction::doWatch( $title, $user );
$res['watched'] = $status->isOK();
if ( $status->isOK() ) {
@@ -167,6 +168,7 @@
'continue' => array(
ApiBase::PARAM_HELP_MSG =>
'api-help-param-continue',
),
+ // TODO add optional expiry param
);
if ( $flags ) {
$result += $this->getPageSet()->getFinalParams( $flags
);
@@ -183,6 +185,7 @@
=> 'apihelp-watch-example-unwatch',
'action=watch&generator=allpages&gapnamespace=0&token=123ABC'
=> 'apihelp-watch-example-generator',
+ //TODO add exmaple with expiry
);
}
diff --git a/includes/installer/MysqlUpdater.php
b/includes/installer/MysqlUpdater.php
index aa60c01..778768a 100644
--- a/includes/installer/MysqlUpdater.php
+++ b/includes/installer/MysqlUpdater.php
@@ -275,6 +275,9 @@
array( 'dropTable', 'hitcounter' ),
array( 'dropField', 'site_stats', 'ss_total_views',
'patch-drop-ss_total_views.sql' ),
array( 'dropField', 'page', 'page_counter',
'patch-drop-page_counter.sql' ),
+
+ // 1.27
+ array( 'addField', 'watchlist', 'wl_expirytimestamp',
'patch-watchlist-wl_expirytimestamp.sql' ),
);
}
diff --git a/includes/mail/EmailNotification.php
b/includes/mail/EmailNotification.php
index 31dd395..def2038 100644
--- a/includes/mail/EmailNotification.php
+++ b/includes/mail/EmailNotification.php
@@ -93,6 +93,7 @@
'wl_namespace' => $title->getNamespace(),
'wl_title' => $title->getDBkey(),
'wl_notificationtimestamp IS NULL',
+ //TODO where not expired?
), __METHOD__
);
diff --git a/includes/specials/SpecialEditWatchlist.php
b/includes/specials/SpecialEditWatchlist.php
index 952ae0e..2053ab4 100644
--- a/includes/specials/SpecialEditWatchlist.php
+++ b/includes/specials/SpecialEditWatchlist.php
@@ -312,6 +312,7 @@
'wl_namespace', 'wl_title'
), array(
'wl_user' => $this->getUser()->getId(),
+ //TODO where not expired
),
__METHOD__
);
@@ -352,6 +353,7 @@
$titles = array();
$dbr = wfGetDB( DB_SLAVE );
+ //TODO where not expired
$res = $dbr->select(
array( 'watchlist' ),
array( 'wl_namespace', 'wl_title' ),
@@ -463,6 +465,7 @@
}
if ( $title instanceof Title ) {
+ //TODO possible need to edit expiry here? needs
UI first
$rows[] = array(
'wl_user' => $this->getUser()->getId(),
'wl_namespace' =>
MWNamespace::getSubject( $title->getNamespace() ),
diff --git a/includes/specials/SpecialRecentchanges.php
b/includes/specials/SpecialRecentchanges.php
index 96d512c..61b5c66 100644
--- a/includes/specials/SpecialRecentchanges.php
+++ b/includes/specials/SpecialRecentchanges.php
@@ -213,6 +213,7 @@
'wl_user' => $user->getId(),
'wl_title=rc_title',
'wl_namespace=rc_namespace'
+ //TODO where not expired?
) );
}
@@ -346,6 +347,7 @@
array(
'wl_namespace'
=> $obj->rc_namespace,
'wl_title' =>
$obj->rc_title,
+ //TODO where
not expired?
),
__METHOD__ . '-watchers'
);
diff --git a/includes/specials/SpecialRecentchangeslinked.php
b/includes/specials/SpecialRecentchangeslinked.php
index 3c403fe..dc371f3 100644
--- a/includes/specials/SpecialRecentchangeslinked.php
+++ b/includes/specials/SpecialRecentchangeslinked.php
@@ -93,6 +93,7 @@
'wl_user' => $uid,
'wl_title=rc_title',
'wl_namespace=rc_namespace'
+ //TODO where not expired?
) );
}
if ( $this->getUser()->isAllowed( 'rollback' ) ) {
diff --git a/includes/specials/SpecialUnwatchedpages.php
b/includes/specials/SpecialUnwatchedpages.php
index 4ad6ac0..8de99476 100644
--- a/includes/specials/SpecialUnwatchedpages.php
+++ b/includes/specials/SpecialUnwatchedpages.php
@@ -56,6 +56,7 @@
'page_is_redirect' => 0,
"page_namespace != '" . NS_MEDIAWIKI . "'"
),
+ //TODO where not expired?
'join_conds' => array( 'watchlist' => array(
'LEFT JOIN', array( 'wl_title = page_title',
'wl_namespace = page_namespace' ) ) )
diff --git a/includes/specials/SpecialWatchlist.php
b/includes/specials/SpecialWatchlist.php
index 20f5776..9719f64 100644
--- a/includes/specials/SpecialWatchlist.php
+++ b/includes/specials/SpecialWatchlist.php
@@ -226,6 +226,7 @@
'wl_user' => $user->getId(),
'wl_namespace=rc_namespace',
'wl_title=rc_title'
+ // TODO where (wl_expirytimestamp >
NOW() OR wl_expirytimestamp IS NULL)
),
),
);
@@ -367,6 +368,7 @@
if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
&& $user->getOption( 'shownumberswatching' )
) {
+ //TODO where not expired?
$rc->numberofWatchingusers = $dbr->selectField(
'watchlist',
'COUNT(*)',
array(
@@ -609,6 +611,7 @@
# Fetch the raw count
$rows = $dbr->select( 'watchlist', array( 'count' => 'COUNT(*)'
),
array( 'wl_user' => $this->getUser()->getId() ),
__METHOD__ );
+ //TODO where not expired?
$row = $dbr->fetchObject( $rows );
$count = $row->count;
diff --git a/maintenance/archives/patch-watchlist-wl_expirytimestamp.sql
b/maintenance/archives/patch-watchlist-wl_expirytimestamp.sql
new file mode 100644
index 0000000..ec3aa78
--- /dev/null
+++ b/maintenance/archives/patch-watchlist-wl_expirytimestamp.sql
@@ -0,0 +1,3 @@
+-- TODO index?
+ALTER TABLE /*$wgDBprefix*/watchlist
+ ADD wl_expirytimestamp varbinary(14) NULL default NULL;
--
To view, visit https://gerrit.wikimedia.org/r/245881
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6c2b13ec08c3e90572b26a76a6788bde5e38c99b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits