Nikerabbit has uploaded a new change for review.

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


Change subject: Simple paging for translation search search results
......................................................................

Simple paging for translation search search results

Bug: 46097
Change-Id: I3727311cf23989042c12825c7c015ba50db674fa
---
M TranslateSearch.i18n.php
M specials/SpecialSearchTranslations.php
2 files changed, 38 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate 
refs/changes/18/57718/1

diff --git a/TranslateSearch.i18n.php b/TranslateSearch.i18n.php
index 4db9b83..573e073 100644
--- a/TranslateSearch.i18n.php
+++ b/TranslateSearch.i18n.php
@@ -29,6 +29,8 @@
        'tux-sst-solr-offline-title' => 'Search unavailable',
        'tux-sst-solr-offline-body' => 'Search service is temporarily 
unavailable.',
 
+       'tux-sst-next' => 'Next results',
+       'tux-sst-prev' => 'Previous results',
 );
 
 /** Message documentation (Message documentation)
@@ -65,6 +67,9 @@
        'tux-sst-solr-offline-body' => 'Used as error message.
 
 The page title for this message is {{msg-mw|tux-sst-solr-offline-title}}.',
+
+       'tux-sst-next' => 'Link to browser more search results',
+       'tux-sst-prev' => 'Link to browser more search results',
 );
 
 /** Asturian (asturianu)
diff --git a/specials/SpecialSearchTranslations.php 
b/specials/SpecialSearchTranslations.php
index e17434e..a7d3d47 100644
--- a/specials/SpecialSearchTranslations.php
+++ b/specials/SpecialSearchTranslations.php
@@ -23,6 +23,12 @@
         */
        protected $hl = array();
 
+       /**
+        * How many search results to display per page
+        * @var int
+        */
+       protected $limit = 25;
+
        public function __construct() {
                parent::__construct( 'SearchTranslations' );
                $this->hl = array(
@@ -145,13 +151,37 @@
                                $uri = wfAppendQuery( $document->uri, array( 
'action' => 'edit' ) );
                                $link = Html::element( 'a', array(
                                        'href' => $uri,
-                               ), $this->msg( 'tux-sst-edit' ) );
+                               ), $this->msg( 'tux-sst-edit' )->text() );
                                $result .= Html::rawElement( 'div', array( 
'class' => 'row tux-edit tux-message-item' ), $link );
                        }
 
                        $result .= Html::closeElement( 'div' );
                        $results .= $result;
                }
+
+               $prev = $next = '';
+               $total = $resultset->getNumFound();
+               $offset = $this->getRequest()->getInt( 'offset' );
+               $params = $this->getRequest()->getValues();
+
+               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() );
+               }
+
+               $results .= Html::rawElement( 'div', array(), "$prev $next" );
 
                $search = $this->getSearchInput( $queryString );
                $count = $this->msg( 'tux-sst-count' )->numParams( 
$resultset->getNumFound() );
@@ -164,7 +194,8 @@
                $dismax = $query->getDisMax();
                $dismax->setQueryParser( 'edismax' );
                $query->setQuery( $queryString );
-               $query->setRows( 20 );
+               $query->setRows( $this->limit );
+               $query->setStart( $this->getRequest()->getInt( 'offset' ) );
 
                list( $pre, $post ) = $this->hl;
                $hl = $query->getHighlighting();

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3727311cf23989042c12825c7c015ba50db674fa
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <niklas.laxst...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to