Jdlrobson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/183755

Change subject: Make PageCollection countable
......................................................................

Make PageCollection countable

Change-Id: I452d618d81271badf47040a174626ecb272ebb2c
---
M includes/collections/PageCollection.php
M includes/specials/SpecialEditWatchlist.php
2 files changed, 28 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/55/183755/1

diff --git a/includes/collections/PageCollection.php 
b/includes/collections/PageCollection.php
index e11b0d6..1103dff 100644
--- a/includes/collections/PageCollection.php
+++ b/includes/collections/PageCollection.php
@@ -7,7 +7,7 @@
 /**
  * A collection of PageCollectionItems
  */
-class PageCollection implements IteratorAggregate {
+class PageCollection implements IteratorAggregate, Countable {
        /**
         * The user who owns the collection.
         *
@@ -32,6 +32,14 @@
        }
 
        /**
+        * Returns the size of the collection
+        * @return integer
+        */
+       public function count() {
+               return count( $this->items );
+       }
+
+       /**
         * Returns the owner of the collection
         *
         * @return User
diff --git a/includes/specials/SpecialEditWatchlist.php 
b/includes/specials/SpecialEditWatchlist.php
index 3028ec5..51f6f8b 100644
--- a/includes/specials/SpecialEditWatchlist.php
+++ b/includes/specials/SpecialEditWatchlist.php
@@ -233,18 +233,33 @@
        }
 
        public function submitClear( $data ) {
-               $current = $this->getWatchlist();
-               $this->getWatchlistPageCollection()->clearInDatabase();
+               $collection = $this->getWatchlistPageCollection();
+               $collection->loadFromDatabase();
+               $collection->clearInDatabase();
                $this->getUser()->invalidateCache();
                $this->successMessage = $this->msg( 'watchlistedit-clear-done' 
)->parse();
                $this->successMessage .= ' ' . $this->msg( 
'watchlistedit-clear-removed' )
-                       ->numParams( count( $current ) )->parse();
-               $this->showTitles( $current, $this->successMessage );
+                       ->numParams( count( $collection ) )->parse();
+               $this->showCollection( $collection, $this->successMessage );
 
                return true;
        }
 
        /**
+        * Render the given collection
+        *
+        * @param WatchlistPageCollection $collection
+        * @param string $output
+        */
+       private function showCollection( $collection, &$output ) {
+               $titles = array();
+               foreach ( $collection as $item ) {
+                       $titles[] = $item->getTitle();
+               }
+               $this->showTitles( $titles, $output );
+       }
+
+       /**
         * Print out a list of linked titles
         *
         * $titles can be an array of strings or Title objects; the former

-- 
To view, visit https://gerrit.wikimedia.org/r/183755
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I452d618d81271badf47040a174626ecb272ebb2c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to