Jdlrobson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/148557
Change subject: WIP: Use Special:EditWatchlist for A-Z View
......................................................................
WIP: Use Special:EditWatchlist for A-Z View
Change-Id: I2a92e6bfd76fd41c5efef6988a95dad2d7fae6e1
Dependency: Id04c8b1f41894c724ca8ea403078b3389666ebc9
---
M MobileFrontend.php
M includes/MobileFrontend.hooks.php
M includes/MobilePage.php
A includes/specials/SpecialMobileEditWatchlist.php
M includes/specials/SpecialMobileWatchlist.php
5 files changed, 99 insertions(+), 188 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/57/148557/1
diff --git a/MobileFrontend.php b/MobileFrontend.php
index d8ce9ac..f0292a6 100644
--- a/MobileFrontend.php
+++ b/MobileFrontend.php
@@ -74,6 +74,7 @@
'SpecialMobileOptions' => 'specials/SpecialMobileOptions',
'SpecialMobileMenu' => 'specials/SpecialMobileMenu',
'SpecialMobileWatchlist' => 'specials/SpecialMobileWatchlist',
+ 'SpecialMobileEditWatchlist' => 'specials/SpecialMobileEditWatchlist',
'SpecialMobileContributions' => 'specials/SpecialMobileContributions',
'SpecialNearby' => 'specials/SpecialNearby',
'SpecialMobileLanguages' => 'specials/SpecialMobileLanguages',
diff --git a/includes/MobileFrontend.hooks.php
b/includes/MobileFrontend.hooks.php
index b360a8a..534308c 100644
--- a/includes/MobileFrontend.hooks.php
+++ b/includes/MobileFrontend.hooks.php
@@ -301,6 +301,7 @@
if ( $ctx->shouldDisplayMobileView() ) {
// Replace the standard watchlist view with our custom
one
$list['Watchlist'] = 'SpecialMobileWatchlist';
+ $list['EditWatchlist'] = 'SpecialMobileEditWatchlist';
/* Special:MobileContributions redefines
Special:History in
* such a way that for Special:Contributions/Foo, Foo
is a
diff --git a/includes/MobilePage.php b/includes/MobilePage.php
index 78c2c6e..5766c35 100644
--- a/includes/MobilePage.php
+++ b/includes/MobilePage.php
@@ -47,10 +47,11 @@
/**
* Get a placeholder div container for thumbnails
* @param string $className
+ * @param string $iconClass controls size of thumbnail, defaults to
icon-32px
*/
- static function getPlaceHolderThumbnailHtml( $className ) {
+ static function getPlaceHolderThumbnailHtml( $className,
$iconClassName='icon-32px' ) {
return Html::element( 'div', array(
- 'class' => 'listThumb list-thumb-placeholder icon
icon-32px ' . $className,
+ 'class' => 'listThumb list-thumb-placeholder icon ' .
$iconClassName . ' ' . $className,
) );
}
diff --git a/includes/specials/SpecialMobileEditWatchlist.php
b/includes/specials/SpecialMobileEditWatchlist.php
new file mode 100644
index 0000000..ce7c54b
--- /dev/null
+++ b/includes/specials/SpecialMobileEditWatchlist.php
@@ -0,0 +1,83 @@
+<?php
+/**
+ * SpecialMobileWatchlist.php
+ */
+
+class SpecialMobileEditWatchlist extends SpecialEditWatchlist {
+ protected function outputSubtitle() {
+ $user = $this->getUser();
+ $this->getOutput()->addHtml(
SpecialMobileWatchlist::getWatchlistHeader( $user ) );
+ }
+
+ public static function getLineHtml( $title, $ts, $thumb ) {
+ wfProfileIn( __METHOD__ );
+ $titleText = $title->getPrefixedText();
+ if ( $ts ) {
+ $ts = new MWTimestamp( $ts );
+ $lastModified = wfMessage(
+ 'mobile-frontend-watchlist-modified',
+ $ts->getHumanTimestamp()
+ )->text();
+ $className = 'title';
+ } else {
+ $className = 'title new';
+ $lastModified = '';
+ }
+
+ $html =
+ Html::openElement( 'li', array(
+ 'class' => 'page-summary',
+ 'title' => $titleText,
+ 'data-id' => $title->getArticleId()
+ ) ) .
+ Html::openElement( 'a', array( 'href' =>
$title->getLocalUrl(), 'class' => $className ) );
+ $html .= $thumb;
+ $html .=
+ Html::element( 'h3', array(), $titleText ).
+ Html::element( 'div', array( 'class' => 'info' ),
$lastModified ) .
+ Html::closeElement( 'a' ) .
+ Html::closeElement( 'li' );
+
+ wfProfileOut( __METHOD__ );
+ return $html;
+ }
+
+ public function execute( $par ) {
+ $out = $this->getOutput();
+ // turn off #content element
+ $out->setProperty( 'unstyledContent', true );
+ parent::execute( $par );
+ $out->setPageTitle( $this->msg( 'watchlist' ) );
+ }
+
+ protected function executeViewEditWatchlist() {
+ global $wgContLang;
+ $html = '';
+ foreach ( $this->getWatchlistInfo() as $ns => $pages ) {
+ if ( $ns === NS_MAIN ) {
+ $html .= '<ul class="watchlist page-list
thumbs">';
+ foreach ( array_keys( $pages ) as $dbkey ) {
+ $title = Title::makeTitleSafe( $ns,
$dbkey );
+ $mobilePage = new MobilePage( $title );
+ // @todo: Doubt this is performant...
+ $thumb =
$mobilePage->getSmallThumbnailHtml();
+ if ( !$thumb ) {
+ $thumb =
$mobilePage::getPlaceHolderThumbnailHtml( 'needsPhoto', 'icon-max-x' );
+ }
+ $html .= self::getLineHtml( $title,
$title->getTouched(), $thumb );
+ }
+ $html .= '</ul>';
+ }
+ }
+ $out = $this->getOutput();
+ $out->addHtml( $html );
+ $out->addModuleStyles(
+ array(
+ 'skins.minerva.special.styles',
+ 'mobile.pagelist.styles',
+ 'mobile.special.pagefeed.styles',
+ 'mobile.special.watchlist.styles'
+ )
+ );
+ }
+}
diff --git a/includes/specials/SpecialMobileWatchlist.php
b/includes/specials/SpecialMobileWatchlist.php
index 9d5d5fc..fdfe133 100644
--- a/includes/specials/SpecialMobileWatchlist.php
+++ b/includes/specials/SpecialMobileWatchlist.php
@@ -97,25 +97,15 @@
// This needs to be done before calling getWatchlistHeader
$this->updateStickyTabs();
- $output->addHtml( '<div class="content-header">' .
$this->getWatchlistHeader() . '</div>' );
+ $output->addHtml( $this->getWatchlistHeader( $user ) );
- if ( $this->view === 'feed' ) {
- $this->showRecentChangesHeader();
- $res = $this->doFeedQuery();
+ $this->showRecentChangesHeader();
+ $res = $this->doFeedQuery();
- if ( $res->numRows() ) {
- $this->showFeedResults( $res );
- } else {
- $this->showEmptyList( true );
- }
+ if ( $res->numRows() ) {
+ $this->showFeedResults( $res );
} else {
- $this->filter = $this->getRequest()->getVal( 'filter',
'articles' );
- $res = $this->doListQuery();
- if ( $res->numRows() ) {
- $this->showListResults( $res );
- } else {
- $this->showEmptyList( false );
- }
+ $this->showEmptyList( true );
}
if ( $this->optionsChanged ) {
@@ -188,11 +178,12 @@
/**
* Get the header for the watchlist page
+ * @param User user
* @return string Parsed HTML
*/
- protected function getWatchlistHeader() {
- $user = $this->getUser();
+ public static function getWatchlistHeader( User $user ) {
$sp = SpecialPage::getTitleFor( 'Watchlist' );
+ $spEdit = SpecialPage::getTitleFor( 'EditWatchlist' );
$attrsList = $attrsFeed = array();
$view = $user->getOption(
SpecialMobileWatchlist::VIEW_OPTION_NAME, 'a-z' );
$filter = $user->getOption(
SpecialMobileWatchlist::FILTER_OPTION_NAME, 'all' );
@@ -209,7 +200,7 @@
$html =
Html::openElement( 'ul', array( 'class' => 'button-bar
mw-ui-button-group' ) ) .
Html::openElement( 'li', $attrsList ) .
- Linker::link( $sp,
+ Linker::link( $spEdit,
wfMessage( 'mobile-frontend-watchlist-a-z'
)->text(),
array( 'class' => 'button' ),
array( 'watchlistview' => 'a-z' )
@@ -224,7 +215,7 @@
Html::closeElement( 'li' ) .
Html::closeElement( 'ul' );
- return $html;
+ return '<div class="content-header">' . $html . '</div>';
}
/**
@@ -331,59 +322,6 @@
}
/**
- * Get watchlist items for a-z view
- * @return ResultWrapper
- *
- * @see doPageImages()
- */
- function doListQuery() {
- wfProfileIn( __METHOD__ );
-
- $user = $this->getUser();
- $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
-
- # Possible where conditions
- $conds = $this->getNSConditions( 'wl_namespace' );
- $conds['wl_user'] = $user->getId();
- $tables = array( 'watchlist', 'page', 'revision' );
- $fields = array(
- 'wl_namespace','wl_title',
- // get the timestamp of the last change only
- 'MAX(' . $dbr->tableName( 'revision' ) .
'.rev_timestamp) AS rev_timestamp'
- );
- $joinConds = array(
- 'page' => array( 'LEFT JOIN', array(
- 'wl_namespace = page_namespace',
- 'wl_title = page_title'
- ) ),
- 'revision' => array( 'LEFT JOIN', array(
- 'page_id = rev_page'
- ) )
- );
- $options = array(
- 'GROUP BY' => 'wl_namespace, wl_title',
- 'ORDER BY' => 'wl_namespace, wl_title'
- );
-
- $this->doPageImages( $tables, $fields, $joinConds, 'page' );
-
- $options['LIMIT'] = self::LIMIT + 1; // add one to decide
whether to show the more button
-
- if ( $this->fromPageTitle ) {
- $ns = $this->fromPageTitle->getNamespace();
- $titleQuoted = $dbr->addQuotes(
$this->fromPageTitle->getDBkey() );
- $conds[] = "wl_namespace > $ns OR (wl_namespace = $ns
AND wl_title >= $titleQuoted)";
- }
-
- wfProfileIn( __METHOD__ . '-query' );
- $res = $dbr->select( $tables, $fields, $conds, __METHOD__,
$options, $joinConds );
- wfProfileOut( __METHOD__ . '-query' );
-
- wfProfileOut( __METHOD__ );
- return $res;
- }
-
- /**
* Show results of doFeedQuery
* @param ResultWrapper $res ResultWrapper returned from db
*
@@ -391,21 +329,6 @@
*/
protected function showFeedResults( ResultWrapper $res ) {
$this->showResults( $res, true );
- }
-
- /**
- * Show results of doListQuery after an ul element added
- * @param ResultWrapper $res ResultWrapper returned from db
- *
- * @see showResults()
- */
- protected function showListResults( ResultWrapper $res ) {
- $output = $this->getOutput();
- $output->addHtml(
- Html::openElement( 'ul', array( 'class' => 'watchlist '
. 'page-list thumbs' ) )
- );
-
- $this->showResults( $res, false );
}
/**
@@ -426,15 +349,6 @@
if ( $feed ) {
foreach( $res as $row ) {
$this->showFeedResultRow( $row );
- }
- } else {
- foreach( $res as $row ) {
- if ( $lookahead <= self::LIMIT ) {
- $this->showListResultRow( $row );
- } else {
- $fromTitle = Title::makeTitle(
$row->wl_namespace, $row->wl_title );
- }
- $lookahead++;
}
}
@@ -497,53 +411,6 @@
}
/**
- * Render a thumbnail returned from db as PageImage or a needsPhoto
placeholder to add a picture
- * @param object $row a row of the returned db result
- * @return array
- *
- * @todo FIXME: Refactor to use MobilePage
- */
- private function renderThumb( $row ) {
- wfProfileIn( __METHOD__ );
-
- if ( $this->usePageImages ) {
- $needsPhoto = true;
- $props = array(
- 'class' => 'listThumb needsPhoto icon
icon-max-x',
- );
- if ( !is_null( $row->pp_value ) ) {
- $file = wfFindFile( $row->pp_value );
- if ( $file ) {
- $thumb = $file->transform( array(
- 'width' => self::THUMB_SIZE,
- 'height' => self::THUMB_SIZE )
- );
-
- if ( $thumb ) {
- $needsPhoto = false;
- $props = array(
- 'class' => 'listThumb '
. ( $thumb->getWidth() > $thumb->getHeight()
- ? 'icon
icon-max-y'
- : 'icon
icon-max-x' ),
- 'style' =>
'background-image: url("' .
- wfExpandUrl(
$thumb->getUrl(), PROTO_CURRENT ) . '")',
- );
- }
- }
- }
- return array(
- 'html' => Html::element( 'div', $props ),
- 'needsPhoto' => $needsPhoto,
- );
- }
-
- wfProfileOut( __METHOD__ );
- return array(
- 'html' => '',
- );
- }
-
- /**
* Render a result row in feed view
* @param object $row a row of db result
*/
@@ -582,48 +449,6 @@
$this->renderFeedItemHtml( $ts, $diffLink, $username, $comment,
$title, $isAnon, $bytes,
$isMinor );
- wfProfileOut( __METHOD__ );
- }
-
- /**
- * Render a result row in list view
- * @param object $row a row of db result
- */
- protected function showListResultRow( $row ) {
- wfProfileIn( __METHOD__ );
-
- $output = $this->getOutput();
- $title = Title::makeTitle( $row->wl_namespace, $row->wl_title );
- $titleText = $title->getPrefixedText();
- $ts = $row->rev_timestamp;
- if ( $ts ) {
- $ts = new MWTimestamp( $ts );
- $lastModified = wfMessage(
- 'mobile-frontend-watchlist-modified',
- $ts->getHumanTimestamp()
- )->text();
- $className = 'title';
- } else {
- $className = 'title new';
- $lastModified = '';
- }
-
- $thumb = $this->renderThumb( $row );
-
- $output->addHtml(
- Html::openElement( 'li', array(
- 'class' => 'page-summary',
- 'title' => $titleText,
- 'data-id' => $title->getArticleId()
- ) ) .
- Html::openElement( 'a', array( 'href' =>
$title->getLocalUrl(), 'class' => $className ) ) .
- $thumb['html'] .
- Html::element( 'h3', array(), $titleText ).
- Html::element( 'div', array( 'class' => 'info' ),
$lastModified ) .
- Html::closeElement( 'a' ) .
- Html::closeElement( 'li' )
- );
-
wfProfileOut( __METHOD__ );
}
--
To view, visit https://gerrit.wikimedia.org/r/148557
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2a92e6bfd76fd41c5efef6988a95dad2d7fae6e1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits