AYUSH GARG has uploaded a new change for review.
https://gerrit.wikimedia.org/r/195315
Change subject: SearchTranslation: Add styling for previous/next in Search
Translations
......................................................................
SearchTranslation: Add styling for previous/next in Search Translations
Bug: T49920
Change-Id: I7218da36707dd510d4582476ccd0e21703ccdba0
---
M i18n/search/en.json
M specials/SpecialSearchTranslations.php
2 files changed, 81 insertions(+), 23 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate
refs/changes/15/195315/1
diff --git a/i18n/search/en.json b/i18n/search/en.json
index 4e83be6..d8e037d 100644
--- a/i18n/search/en.json
+++ b/i18n/search/en.json
@@ -8,7 +8,7 @@
"tux-sst-edit": "Edit translation",
"tux-sst-search": "Search",
"tux-sst-search-ph": "Search translations",
- "tux-sst-count": "{{PLURAL:$1|One result found|$1 results found}}",
+ "tux-sst-count": "Showing {{PLURAL:$4|Result <strong>$1</strong> of
<strong>$3</strong>|Results <strong>$1 - $2</strong> of <strong>$3</strong>}}",
"tux-sst-facet-language": "Languages",
"tux-sst-facet-group": "Message groups",
"tux-sst-facet-orphan": "(orphan)",
@@ -16,6 +16,11 @@
"tux-sst-nosolr-body": "This wiki does not have a translation search
service.",
"tux-sst-solr-offline-title": "Search unavailable",
"tux-sst-solr-offline-body": "The search service is temporarily
unavailable.",
- "tux-sst-next": "Next results",
- "tux-sst-prev": "Previous results"
+ "tux-sst-next": "Next {{PLURAL:$1|$1}}",
+ "tux-sst-prev": "Previous {{PLURAL:$1|$1}}",
+ "tux-sst-view": "View ($1 {{int:pipe-separator}} $2) ($3)",
+ "prev-tooltiptext": "Previous $1 {{PLURAL:$1|result|results}}",
+ "next-tooltiptext": "Next $1 {{PLURAL:$1|result|results}}",
+ "num-tooltiptext": "Show $1 {{PLURAL:$1|result|results}} per page",
+ "pipe-separator": " | "
}
\ No newline at end of file
diff --git a/specials/SpecialSearchTranslations.php
b/specials/SpecialSearchTranslations.php
index 1336f43..8dce261 100644
--- a/specials/SpecialSearchTranslations.php
+++ b/specials/SpecialSearchTranslations.php
@@ -30,7 +30,7 @@
* How many search results to display per page
* @var int
*/
- protected $limit = 25;
+ protected $limit;
public function __construct() {
parent::__construct( 'SearchTranslations' );
@@ -62,6 +62,8 @@
$out = $this->getOutput();
$out->addModules( 'ext.translate.special.searchtranslations' );
+ $request = $this->getRequest();
+ list( $this->limit, $this->offset ) = $request->getLimitOffset(
20, '' );
$this->opts = $opts = new FormOptions();
$opts->add( 'query', '' );
@@ -161,36 +163,87 @@
. Html::closeElement( 'div' );
}
- $prev = $next = '';
$total = $server->getTotalHits( $resultset );
$offset = $this->opts->getValue( 'offset' );
$params = $this->opts->getChangedValues();
+ $limit = $this->opts->getValue( 'limit' );
+ $prevnext = null;
- if ( $total - $offset > $this->limit ) {
- $newParams = array( 'offset' => $offset + $this->limit
) + $params;
- $attribs = array(
- 'class' => 'pager-next',
- 'href' => $this->getTitle()->getLocalUrl(
$newParams ),
- );
- $next = Html::element( 'a', $attribs, $this->msg(
'tux-sst-next' )->text() );
- }
- if ( $offset ) {
- $newParams = array( 'offset' => max( 0, $offset -
$this->limit ) ) + $params;
- $attribs = array(
- 'class' => 'pager-prev',
- 'href' => $this->getTitle()->getLocalUrl(
$newParams ),
- );
- $prev = Html::element( 'a', $attribs, $this->msg(
'tux-sst-prev' )->text() );
- }
+ if ( $total > $limit || $offset ) {
+ $prevnext =
$this->getLanguage()->viewPrevNext(
+ $this->getTitle(),
+ $offset,
+ $limit,
+ $params,
+ $limit + $offset >= $total
+ );
+ }
- $resultsHtml .= Html::rawElement( 'div', array(), "$prev $next"
);
+ $resultsHtml .= Html::rawElement( 'div', array( 'class' => 'row
tux-text' ), $prevnext );
$search = $this->getSearchInput( $queryString );
- $count = $this->msg( 'tux-sst-count' )->numParams( $total );
+
+ $result = $total - $offset;
+ if ( $limit < $result ) {
+ $result = $limit;
+ }
+ if ( $total > 0 && $offset < $total ) {
+ $count = $this->msg( 'tux-sst-count' )
+ ->numParams( $offset + 1, $offset + $result ,
$total )
+ ->numParams( $result )
+ ->parse();
+ }
$this->showSearch( $search, $count, $facetHtml, $resultsHtml );
}
+ protected function viewPrevNext( Title $title, $offset, $limit,
+ array $newParams = array(), $atend = false ) {
+ # Make 'previous' link
+ $prev = $this->msg( 'tux-sst-prev' )->inLanguage( $this
)->title( $title )->numParams( $limit )->text();
+
+ if ( $offset > 0 ) {
+ $plink = $this->numLink( $title, max( 0, $offset -
$limit ), $limit,
+ $newParams, $prev, 'prev-tooltiptext',
'pager-prev' );
+ } else {
+ $plink = htmlspecialchars( $prev );
+ }
+
+ # Make 'next' link
+ $next = $this->msg( 'tux-sst-next' )->inLanguage( $this
)->title( $title )->numParams( $limit )->text();
+
+ if ( $atend ) {
+ $nlink = htmlspecialchars( $next );
+ } else {
+ $nlink = $this->numLink( $title, $offset + $limit,
$limit,
+ $newParams, $next, 'next-tooltiptext',
'pager-next' );
+ }
+
+ # Make links to set number of items per page
+ $numLinks = array();
+ foreach ( array( 20, 50, 100, 250, 500 ) as $num ) {
+ $numLinks[] = $this->numLink( $title, $offset, $num,
+ $newParams, $num, 'num-tooltiptext',
'pager-num' );
+ }
+
+ return $this->msg( 'tux-sst-view' )->inLanguage( $this
)->title( $title
+ )->rawParams( $plink, $nlink, $this->pipeList(
$numLinks ) )->escaped();
+ }
+
+ protected function numLink( Title $title, $offset, $limit, array
$newParams, $link,
+ $tooltipMsg, $class ) {
+ $newParams = array( 'limit' => $limit, 'offset' => $offset ) +
$newParams;
+ $tooltip = $this->msg( $tooltipMsg )->inLanguage( $this
)->title( $title )
+ ->numParams( $limit )->text();
+
+ return Html::element( 'a', array( 'href' =>
$title->getLocalURL( $newParams ),
+ 'title' => $tooltip, 'class' => $class ), $link );
+ }
+
+ protected function pipeList( array $list ) {
+ return implode( $this->msg( 'pipe-separator' )->inLanguage(
$this )->escaped(), $list );
+ }
+
protected function getLanguages( array $facet ) {
$output = array();
--
To view, visit https://gerrit.wikimedia.org/r/195315
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7218da36707dd510d4582476ccd0e21703ccdba0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: AYUSH GARG <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits