Addshore has uploaded a new change for review.
https://gerrit.wikimedia.org/r/277770
Change subject: Use WIS::getWatchedItemsForUser in SpecialEditWatchlist
......................................................................
Use WIS::getWatchedItemsForUser in SpecialEditWatchlist
This also adds a order option to:
WacthedItemStore::getWatchedItemsForUser
Tests are also updated
Change-Id: Ia683b92846ad79bde3f37068a8e168c5a8bdc201
---
M includes/WatchedItemStore.php
M includes/specials/SpecialEditWatchlist.php
M tests/phpunit/includes/WatchedItemStoreUnitTest.php
3 files changed, 20 insertions(+), 15 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/70/277770/1
diff --git a/includes/WatchedItemStore.php b/includes/WatchedItemStore.php
index af6e2bf..6f6eebd 100644
--- a/includes/WatchedItemStore.php
+++ b/includes/WatchedItemStore.php
@@ -401,6 +401,7 @@
* @param array $options Allowed keys:
* 'db' => int options DB_MASTER or DB_SLAVE (defaults to
DB_SLAVE)
* 'namespaceId' => int optional namespace ID to filter by
(default to all namespaces)
+ * 'ordered' => bool optional ordering by namespace ID and title
*
* @return WatchedItem[]
*/
@@ -414,12 +415,18 @@
$conds['wl_namespace'] = (int)$options['namespaceId'];
}
+ $dbOptions = [];
+ if ( array_key_exists( 'ordered', $options ) &&
$options['ordered'] ) {
+ $dbOptions['ORDER BY'] = [ 'wl_namespace', 'wl_title' ];
+ }
+
$db = $this->getConnection( $options['db'] );
$res = $db->select(
'watchlist',
[ 'wl_namespace', 'wl_title',
'wl_notificationtimestamp' ],
$conds,
- __METHOD__
+ __METHOD__,
+ $dbOptions
);
$this->reuseConnection( $db );
diff --git a/includes/specials/SpecialEditWatchlist.php
b/includes/specials/SpecialEditWatchlist.php
index ad1eecf..0b5f268 100644
--- a/includes/specials/SpecialEditWatchlist.php
+++ b/includes/specials/SpecialEditWatchlist.php
@@ -347,22 +347,18 @@
*/
protected function getWatchlistInfo() {
$titles = [];
- $dbr = wfGetDB( DB_SLAVE );
- $res = $dbr->select(
- [ 'watchlist' ],
- [ 'wl_namespace', 'wl_title' ],
- [ 'wl_user' => $this->getUser()->getId() ],
- __METHOD__,
- [ 'ORDER BY' => [ 'wl_namespace', 'wl_title' ] ]
- );
+ $watchedItems = WatchedItemStore::getDefaultInstance()
+ ->getWatchedItemsForUser( $this->getUser(), [ 'ordered'
=> true ] );
$lb = new LinkBatch();
- foreach ( $res as $row ) {
- $lb->add( $row->wl_namespace, $row->wl_title );
- if ( !MWNamespace::isTalk( $row->wl_namespace ) ) {
- $titles[$row->wl_namespace][$row->wl_title] = 1;
+ foreach ( $watchedItems as $watchedItem ) {
+ $namespace =
$watchedItem->getLinkTarget()->getNamespace();
+ $dbKey = $watchedItem->getLinkTarget()->getDBkey();
+ $lb->add( $namespace, $dbKey );
+ if ( !MWNamespace::isTalk( $namespace ) ) {
+ $titles[$namespace][$dbKey] = 1;
}
}
diff --git a/tests/phpunit/includes/WatchedItemStoreUnitTest.php
b/tests/phpunit/includes/WatchedItemStoreUnitTest.php
index f16f088..a4e4d70 100644
--- a/tests/phpunit/includes/WatchedItemStoreUnitTest.php
+++ b/tests/phpunit/includes/WatchedItemStoreUnitTest.php
@@ -1217,7 +1217,9 @@
->with(
'watchlist',
[ 'wl_namespace', 'wl_title',
'wl_notificationtimestamp' ],
- [ 'wl_user' => 1, 'wl_namespace' => 9 ]
+ [ 'wl_user' => 1, 'wl_namespace' => 9 ],
+ $this->isType( 'string' ),
+ [ 'ORDER BY' => [ 'wl_namespace', 'wl_title' ] ]
)
->will( $this->returnValue( [] ) );
@@ -1228,7 +1230,7 @@
$watchedItems = $store->getWatchedItemsForUser(
$user,
- [ 'namespaceId' => 9, 'db' => $dbType ]
+ [ 'namespaceId' => 9, 'db' => $dbType, 'ordered' =>
true ]
);
$this->assertEquals( [], $watchedItems );
}
--
To view, visit https://gerrit.wikimedia.org/r/277770
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia683b92846ad79bde3f37068a8e168c5a8bdc201
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits