Jhernandez has uploaded a new change for review.
https://gerrit.wikimedia.org/r/187395
Change subject: WIP: Introduce Mobile collection models
......................................................................
WIP: Introduce Mobile collection models
* DONOTMERGE: Dependent on core patch for the base abstractions
(WatchlistPageCollection PageCollectionItem PageCollection)
Change-Id: I6b5ca2a02f3c71392d3777568bf06dc8b6cf2ea7
Dependency: Id31349cfa0db815d41d9c205bad3c7448ae120e7
---
M MobileFrontend.php
D includes/models/MobileCollection.php
A includes/models/MobileWatchlistCollection.php
M includes/specials/SpecialMobileEditWatchlist.php
4 files changed, 74 insertions(+), 35 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/95/187395/1
diff --git a/MobileFrontend.php b/MobileFrontend.php
index 2a3c0f4..e8b8dce 100644
--- a/MobileFrontend.php
+++ b/MobileFrontend.php
@@ -61,7 +61,7 @@
'MobileContext' => 'MobileContext',
'MobileFormatter' => 'MobileFormatter',
- 'MobileCollection' => 'models/MobileCollection',
+ 'MobileWatchlistCollection' => 'models/MobileWatchlistCollection',
'MobilePage' => 'models/MobilePage',
'MobileUI' => 'MobileUI',
diff --git a/includes/models/MobileCollection.php
b/includes/models/MobileCollection.php
deleted file mode 100644
index 9a87bb1..0000000
--- a/includes/models/MobileCollection.php
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-
-/**
- * MobileCollection.php
- */
-
-/**
- * A collection of pages, which are represented by the MobilePage class.
- */
-class MobileCollection implements IteratorAggregate {
-
- /**
- * The internal collection of pages.
- *
- * @var MobilePage[]
- */
- protected $pages = array();
-
- /**
- * Adds a page to the collection.
- *
- * @param MobilePage $page
- */
- public function add( MobilePage $page ) {
- $this->pages[] = $page;
- }
-
- public function getIterator() {
- return new ArrayIterator( $this->pages );
- }
-}
diff --git a/includes/models/MobileWatchlistCollection.php
b/includes/models/MobileWatchlistCollection.php
new file mode 100644
index 0000000..7941b14
--- /dev/null
+++ b/includes/models/MobileWatchlistCollection.php
@@ -0,0 +1,70 @@
+<?php
+
+/**
+ * MobileWatchlistCollection.php
+ */
+
+/**
+ * A collection of pages, which are represented by the MobilePage class.
+ */
+class MobileWatchlistCollection extends WatchlistPageCollection {
+ protected $description = 'Pages I keep an eye on for editing purposes.';
+ protected $title = '';
+
+ public function __construct( $user ) {
+ $this->user = $user;
+ $this->title = $this->getOwner()->getName() . '\'s Watchlist';
+ parent::__construct( $user );
+ }
+
+ public function add( MobilePage $item ) {
+ $this->items[] = $item;
+ }
+
+ public function load() {
+ $ids = array();
+ $map = array();
+ foreach ( $this->items as $item ) {
+ $id = $item->getTitle()->getArticleID();
+ if ( $id !== 0 ) {
+ $ids[] = $id;
+ $map[$id] = $item;
+ }
+ }
+
+ if ( count( $ids ) ) {
+ $api = new ApiMain(
+ new DerivativeRequest(
+ new FauxRequest(),
+ array(
+ 'action' => 'query',
+ 'prop' => 'extracts',
+ 'exlimit' => count( $ids ),
+ 'exintro' => true,
+ 'explaintext' => true,
+ 'pageids' => implode( '|', $ids
)
+ )
+ )
+ );
+ $api->execute();
+ $data = $api->getResult()->getData();
+ $pagesData = $data["query"]["pages"];
+ foreach ( $pagesData as $pageData ) {
+ $item = $map[$pageData['pageid']];
+ $item->getMobilePage()->setExtract(
$pageData["extract"]["*"] );
+ }
+ }
+ }
+
+ public function getDescription() {
+ return $this->description;
+ }
+
+ public function getTitle() {
+ return $this->title;
+ }
+
+ public function getLastModified() {
+ return new MWTimestamp();
+ }
+}
diff --git a/includes/specials/SpecialMobileEditWatchlist.php
b/includes/specials/SpecialMobileEditWatchlist.php
index 9412e17..caf2b4e 100644
--- a/includes/specials/SpecialMobileEditWatchlist.php
+++ b/includes/specials/SpecialMobileEditWatchlist.php
@@ -174,7 +174,7 @@
}
// create list of pages
- $mobilePages = new MobileCollection();
+ $mobilePages = new MobileWatchlistCollection( $this->getUser()
);
$pageKeys = array_keys( $watchlist[$ns] );
foreach ( $pageKeys as $dbkey ) {
if ( isset( $images[$ns][$dbkey] ) ) {
@@ -217,10 +217,10 @@
}
/**
- * @param MobileCollection $collection
+ * @param MobileWatchlistCollection $collection
* @return string html representation of collection in watchlist view
*/
- protected function getViewHtml( MobileCollection $collection ) {
+ protected function getViewHtml( MobileWatchlistCollection $collection )
{
$html = '<ul class="watchlist page-list thumbs">';
foreach ( $collection as $mobilePage ) {
$thumb = $mobilePage->getSmallThumbnailHtml();
--
To view, visit https://gerrit.wikimedia.org/r/187395
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6b5ca2a02f3c71392d3777568bf06dc8b6cf2ea7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jhernandez <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits