From 10950c5b24eb94060f301103355d9e8b8461598e Mon Sep 17 00:00:00 2001
From: Benjamin Rau <rau@codearts.at>
Date: Sun, 26 Jan 2014 14:00:26 +0100
Subject: [PATCH] [BUGFIX] Several typos in Page Browsing ViewHelper
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Fixing several typos and slips of the pen in the
PageBrowsing ViewHelper.

Without fixing all of them the page browsing ViewHelper
is not functional properly, that´s why i want to submit
them at once and also supply the fix for it.

That are these errors:
* Undefined but used class property prefixId
* Overwriting instead of appending content to already defined variable
* Not using UpperCamelCase for extensionName in Localization Utilty
* Accidentally using wrong variables
* Defining variable in for-loop which could be defined outside also
* Using undefined variable freeIndexUid

Resolves: #55340
Releases: 6.2, 6.1
Change-Id: I708a7af4876eba0e69fa666694315e0babcf6800
Reviewed-on: https://review.typo3.org/27058
Reviewed-by: Dmitry Dulepov
Reviewed-by: Wouter Wolters
Reviewed-by: Cedric Ziel
Reviewed-by: Tymoteusz Motylewski
Tested-by: Tymoteusz Motylewski
Reviewed-by: Markus Klein
Tested-by: Markus Klein
---
 .../ViewHelpers/PageBrowsingViewHelper.php    | 57 +++++++++++--------
 1 file changed, 33 insertions(+), 24 deletions(-)

diff --git a/typo3/sysext/indexed_search/Classes/ViewHelpers/PageBrowsingViewHelper.php b/typo3/sysext/indexed_search/Classes/ViewHelpers/PageBrowsingViewHelper.php
index fb9c2c702dd3..8e0419197296 100644
--- a/typo3/sysext/indexed_search/Classes/ViewHelpers/PageBrowsingViewHelper.php
+++ b/typo3/sysext/indexed_search/Classes/ViewHelpers/PageBrowsingViewHelper.php
@@ -38,16 +38,21 @@ namespace TYPO3\CMS\IndexedSearch\ViewHelpers;
 class PageBrowsingViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
 
 	/**
-	 * main render function
+	 * @var string
+	 */
+	protected $prefixId = 'tx_indexedsearch';
+
+	/**
+	 * Main render function
 	 *
 	 * @param integer $maximumNumberOfResultPages
 	 * @param integer $numberOfResults
 	 * @param integer $resultsPerPage
 	 * @param integer $currentPage
-	 * @return the content
+	 * @param string|NULL $freeIndexUid
+	 * @return string The content
 	 */
-	public function render($maximumNumberOfResultPages, $numberOfResults, $resultsPerPage, $currentPage = 1) {
-		$maximumNumberOfResultPages = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($maximumNumberOfResultPages, 1, 100, 10);
+	public function render($maximumNumberOfResultPages, $numberOfResults, $resultsPerPage, $currentPage = 1, $freeIndexUid = NULL) {
 		$pageCount = ceil($numberOfResults / $resultsPerPage);
 		$content = '';
 		// only show the result browser if more than one page is needed
@@ -56,33 +61,33 @@ class PageBrowsingViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractVi
 			// prev page
 			// show on all pages after the 1st one
 			if ($currentPage > 0) {
-				$label = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('displayResults.previous', 'indexed_search');
-				$content .= '<li>' . $this->makecurrentPageSelector_link($label, ($currentPage - 1), $freeIndexUid) . '</li>';
+				$label = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('displayResults.previous', 'IndexedSearch');
+				$content .= '<li>' . $this->makecurrentPageSelector_link($label, $currentPage - 1, $freeIndexUid) . '</li>';
 			}
-			for ($a = 0; $a < $pageCount; $a++) {
-				$min = max(0, $currentPage + 1 - ceil($maximumNumberOfResultPages / 2));
-				$max = $min + $maximumNumberOfResultPages;
-				if ($max > $pageCount) {
-					$min = $min - ($max - $pageCount);
-				}
-				if ($a >= $min && $a < $max) {
-					$label = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('displayResults.page', 'indexed_search');
-					$label = trim($label . ' ' . ($a + 1));
-					$label = $this->makecurrentPageSelector_link($label, $a, $freeIndexUid);
-					if ($a == $currentPage) {
-						$content .= '<li class="tx-indexedsearch-browselist-currentPage"><strong>' . $label . '</strong></li>';
-					} else {
-						$content .= '<li>' . $label . '</li>';
-					}
+			$maximumNumberOfResultPages = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($maximumNumberOfResultPages, 1, 200000000, 10);
+			$min = max(0, $currentPage + 1 - ceil($maximumNumberOfResultPages / 2));
+			$max = $min + $maximumNumberOfResultPages;
+			if ($max > $pageCount) {
+				$min -= $max - $pageCount;
+			}
+			for ($a = $min; $a < $pageCount && $a < $max; $a++) {
+				$label = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('displayResults.page', 'IndexedSearch');
+				$label = trim($label . ' ' . ($a + 1));
+				$label = $this->makecurrentPageSelector_link($label, $a, $freeIndexUid);
+				if ($a === $currentPage) {
+					$content .= '<li class="tx-indexedsearch-browselist-currentPage"><strong>' . $label . '</strong></li>';
+				} else {
+					$content .= '<li>' . $label . '</li>';
 				}
 			}
 			// next link
 			if ($currentPage + 1 < $pageCount) {
-				$label = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('displayResults.next', 'indexed_search');
-				$content = '<li>' . $this->makecurrentPageSelector_link($label, ($currentPage + 1), $freeIndexUid) . '</li>';
+				$label = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('displayResults.next', 'IndexedSearch');
+				$content .= '<li>' . $this->makecurrentPageSelector_link($label, ($currentPage + 1), $freeIndexUid) . '</li>';
 			}
 			$content = '<ul class="tx-indexedsearch-browsebox">' . $content . '</ul>';
 		}
+
 		return $content;
 	}
 
@@ -97,7 +102,11 @@ class PageBrowsingViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractVi
 	 * @todo Define visibility
 	 */
 	public function makecurrentPageSelector_link($str, $p, $freeIndexUid) {
-		$onclick = 'document.getElementById(\'' . $this->prefixId . '_currentPage\').value=\'' . $p . '\';' . 'document.getElementById(\'' . $this->prefixId . '_freeIndexUid\').value=\'' . rawurlencode($freeIndexUid) . '\';' . 'document.getElementById(\'' . $this->prefixId . '\').submit();return false;';
+		$onclick = 'document.getElementById(\'' . $this->prefixId . '_pointer\').value=\'' . $p . '\';';
+		if ($freeIndexUid !== NULL) {
+			$onclick .= 'document.getElementById(\'' . $this->prefixId . '_freeIndexUid\').value=\'' . rawurlencode($freeIndexUid) . '\';';
+		}
+		$onclick .= 'document.getElementById(\'' . $this->prefixId . '\').submit();return false;';
 		return '<a href="#" onclick="' . htmlspecialchars($onclick) . '">' . $str . '</a>';
 	}
 
-- 
GitLab