Add L10n parameter to Pager classes

This commit is contained in:
Hypolite Petovan 2020-02-16 11:53:52 -05:00
parent 682fb7e4e2
commit 561472b975
20 changed files with 53 additions and 52 deletions

View file

@ -107,7 +107,7 @@ function common_content(App $a)
return $o; return $o;
} }
$pager = new Pager(DI::args()->getQueryString()); $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
if ($cid) { if ($cid) {
$common_friends = Model\GContact::commonFriends($uid, $cid, $pager->getStart(), $pager->getItemsPerPage()); $common_friends = Model\GContact::commonFriends($uid, $cid, $pager->getStart(), $pager->getItemsPerPage());

View file

@ -296,7 +296,7 @@ function message_content(App $a)
$total = $r[0]['total']; $total = $r[0]['total'];
} }
$pager = new Pager(DI::args()->getQueryString()); $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
$r = get_messages(local_user(), $pager->getStart(), $pager->getItemsPerPage()); $r = get_messages(local_user(), $pager->getStart(), $pager->getItemsPerPage());

View file

@ -377,7 +377,7 @@ function networkFlatView(App $a, $update = 0)
} }
} }
$pager = new Pager(DI::args()->getQueryString()); $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
networkPager($a, $pager, $update); networkPager($a, $pager, $update);
@ -669,7 +669,7 @@ function networkThreadedView(App $a, $update, $parent)
$sql_range = ''; $sql_range = '';
} }
$pager = new Pager(DI::args()->getQueryString()); $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
$pager_sql = networkPager($a, $pager, $update); $pager_sql = networkPager($a, $pager, $update);

View file

@ -69,7 +69,7 @@ function notes_content(App $a, $update = false)
$condition = ['uid' => local_user(), 'post-type' => Item::PT_PERSONAL_NOTE, 'gravity' => GRAVITY_PARENT, $condition = ['uid' => local_user(), 'post-type' => Item::PT_PERSONAL_NOTE, 'gravity' => GRAVITY_PARENT,
'contact-id'=> $a->contact['id']]; 'contact-id'=> $a->contact['id']];
$pager = new Pager(DI::args()->getQueryString(), 40); $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 40);
$params = ['order' => ['created' => true], $params = ['order' => ['created' => true],
'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];

View file

@ -1023,7 +1023,7 @@ function photos_content(App $a)
$total = count($r); $total = count($r);
} }
$pager = new Pager(DI::args()->getQueryString(), 20); $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
/// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it? /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
$order_field = $_GET['order'] ?? ''; $order_field = $_GET['order'] ?? '';
@ -1299,7 +1299,7 @@ function photos_content(App $a)
$condition = ["`parent` = ? AND `parent` != `id`", $link_item['parent']]; $condition = ["`parent` = ? AND `parent` != `id`", $link_item['parent']];
$total = DBA::count('item', $condition); $total = DBA::count('item', $condition);
$pager = new Pager(DI::args()->getQueryString()); $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
$params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
$result = Item::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params); $result = Item::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params);
@ -1565,7 +1565,7 @@ function photos_content(App $a)
$total = count($r); $total = count($r);
} }
$pager = new Pager(DI::args()->getQueryString(), 20); $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
$r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`, $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`, ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,

View file

@ -225,7 +225,7 @@ function videos_content(App $a)
$total = count($r); $total = count($r);
} }
$pager = new Pager(DI::args()->getQueryString(), 20); $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
$r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`, $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype` ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`

View file

@ -21,17 +21,18 @@
namespace Friendica\Content; namespace Friendica\Content;
use Friendica\Core\L10n;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Util\Network; use Friendica\Util\Network;
use Friendica\Util\Strings; use Friendica\Util\Strings;
/** /**
* This pager should be used by lists using the since_id/max_id parameters * This pager should be used by lists using the since_id/max_id parameters
* *
* In this context, "id" refers to the value of the column that the list is ordered by. * This pager automatically identifies if the sorting is done increasingly or decreasingly if the first item id†
* This pager automatically identifies if the sorting is done increasingly or decreasingly if the first item id * and last item id† are different. Otherwise it defaults to decreasingly like reverse chronological lists.
* and last item id are different. Otherwise it defaults to decreasingly like reverse chronological lists. *
* In this context, "id" refers to the value of the column that the item list is ordered by.
*/ */
class BoundariesPager extends Pager class BoundariesPager extends Pager
{ {
@ -42,14 +43,15 @@ class BoundariesPager extends Pager
/** /**
* Instantiates a new Pager with the base parameters. * Instantiates a new Pager with the base parameters.
* *
* @param L10n $l10n
* @param string $queryString The query string of the current page * @param string $queryString The query string of the current page
* @param string $first_item_id The i * @param string $first_item_id The id† of the first item in the displayed item list
* @param string $last_item_id * @param string $last_item_id The id† of the last item in the displayed item list
* @param integer $itemsPerPage An optional number of items per page to override the default value * @param integer $itemsPerPage An optional number of items per page to override the default value
*/ */
public function __construct($queryString, $first_item_id = null, $last_item_id = null, $itemsPerPage = 50) public function __construct(L10n $l10n, $queryString, $first_item_id = null, $last_item_id = null, $itemsPerPage = 50)
{ {
parent::__construct($queryString, $itemsPerPage); parent::__construct($l10n, $queryString, $itemsPerPage);
$this->first_item_id = $first_item_id; $this->first_item_id = $first_item_id;
$this->last_item_id = $last_item_id; $this->last_item_id = $last_item_id;
@ -111,7 +113,7 @@ class BoundariesPager extends Pager
($this->first_item_id >= $this->last_item_id ? ($this->first_item_id >= $this->last_item_id ?
'&since_id=' . $this->first_item_id : '&max_id=' . $this->first_item_id) '&since_id=' . $this->first_item_id : '&max_id=' . $this->first_item_id)
), ),
'text' => DI::l10n()->t('newer'), 'text' => $this->l10n->t('newer'),
'class' => 'previous' . ($this->first_page ? ' disabled' : '') 'class' => 'previous' . ($this->first_page ? ' disabled' : '')
], ],
'next' => [ 'next' => [
@ -119,7 +121,7 @@ class BoundariesPager extends Pager
($this->first_item_id >= $this->last_item_id ? ($this->first_item_id >= $this->last_item_id ?
'&max_id=' . $this->last_item_id : '&since_id=' . $this->last_item_id) '&max_id=' . $this->last_item_id : '&since_id=' . $this->last_item_id)
), ),
'text' => DI::l10n()->t('older'), 'text' => $this->l10n->t('older'),
'class' => 'next' . ($displayedItemCount < $this->getItemsPerPage() ? ' disabled' : '') 'class' => 'next' . ($displayedItemCount < $this->getItemsPerPage() ? ' disabled' : '')
] ]
]; ];

View file

@ -21,8 +21,8 @@
namespace Friendica\Content; namespace Friendica\Content;
use Friendica\Core\L10n;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Util\Strings; use Friendica\Util\Strings;
/** /**
@ -30,30 +30,29 @@ use Friendica\Util\Strings;
*/ */
class Pager class Pager
{ {
/** /** @var integer */
* @var integer
*/
private $page = 1; private $page = 1;
/** /** @var integer */
* @var integer
*/
protected $itemsPerPage = 50; protected $itemsPerPage = 50;
/** @var string */
/**
* @var string
*/
protected $baseQueryString = ''; protected $baseQueryString = '';
/** @var L10n */
protected $l10n;
/** /**
* Instantiates a new Pager with the base parameters. * Instantiates a new Pager with the base parameters.
* *
* Guesses the page number from the GET parameter 'page'. * Guesses the page number from the GET parameter 'page'.
* *
* @param L10n $l10n
* @param string $queryString The query string of the current page * @param string $queryString The query string of the current page
* @param integer $itemsPerPage An optional number of items per page to override the default value * @param integer $itemsPerPage An optional number of items per page to override the default value
*/ */
public function __construct($queryString, $itemsPerPage = 50) public function __construct(L10n $l10n, $queryString, $itemsPerPage = 50)
{ {
$this->l10n = $l10n;
$this->setQueryString($queryString); $this->setQueryString($queryString);
$this->setItemsPerPage($itemsPerPage); $this->setItemsPerPage($itemsPerPage);
$this->setPage(($_GET['page'] ?? 0) ?: 1); $this->setPage(($_GET['page'] ?? 0) ?: 1);
@ -166,12 +165,12 @@ class Pager
'class' => 'pager', 'class' => 'pager',
'prev' => [ 'prev' => [
'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() - 1)), 'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() - 1)),
'text' => DI::l10n()->t('newer'), 'text' => $this->l10n->t('newer'),
'class' => 'previous' . ($this->getPage() == 1 ? ' disabled' : '') 'class' => 'previous' . ($this->getPage() == 1 ? ' disabled' : '')
], ],
'next' => [ 'next' => [
'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() + 1)), 'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() + 1)),
'text' => DI::l10n()->t('older'), 'text' => $this->l10n->t('older'),
'class' => 'next' . ($displayedItemCount < $this->getItemsPerPage() ? ' disabled' : '') 'class' => 'next' . ($displayedItemCount < $this->getItemsPerPage() ? ' disabled' : '')
] ]
]; ];
@ -211,12 +210,12 @@ class Pager
if ($totalItemCount > $this->getItemsPerPage()) { if ($totalItemCount > $this->getItemsPerPage()) {
$data['first'] = [ $data['first'] = [
'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=1'), 'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=1'),
'text' => DI::l10n()->t('first'), 'text' => $this->l10n->t('first'),
'class' => $this->getPage() == 1 ? 'disabled' : '' 'class' => $this->getPage() == 1 ? 'disabled' : ''
]; ];
$data['prev'] = [ $data['prev'] = [
'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() - 1)), 'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() - 1)),
'text' => DI::l10n()->t('prev'), 'text' => $this->l10n->t('prev'),
'class' => $this->getPage() == 1 ? 'disabled' : '' 'class' => $this->getPage() == 1 ? 'disabled' : ''
]; ];
@ -271,12 +270,12 @@ class Pager
$data['next'] = [ $data['next'] = [
'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() + 1)), 'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() + 1)),
'text' => DI::l10n()->t('next'), 'text' => $this->l10n->t('next'),
'class' => $this->getPage() == $lastpage ? 'disabled' : '' 'class' => $this->getPage() == $lastpage ? 'disabled' : ''
]; ];
$data['last'] = [ $data['last'] = [
'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . $lastpage), 'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . $lastpage),
'text' => DI::l10n()->t('last'), 'text' => $this->l10n->t('last'),
'class' => $this->getPage() == $lastpage ? 'disabled' : '' 'class' => $this->getPage() == $lastpage ? 'disabled' : ''
]; ];
} }

View file

@ -1805,7 +1805,7 @@ class Contact
$cid, GRAVITY_PARENT, GRAVITY_COMMENT, local_user()]; $cid, GRAVITY_PARENT, GRAVITY_COMMENT, local_user()];
} }
$pager = new Pager(DI::args()->getQueryString()); $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
$params = ['order' => ['received' => true], $params = ['order' => ['received' => true],
'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];

View file

@ -68,7 +68,7 @@ class Contact extends BaseAdmin
$total = DBA::count('contact', $condition); $total = DBA::count('contact', $condition);
$pager = new Pager(DI::args()->getQueryString(), 30); $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 30);
$contacts = Model\Contact::selectToArray([], $condition, ['limit' => [$pager->getStart(), $pager->getItemsPerPage()]]); $contacts = Model\Contact::selectToArray([], $condition, ['limit' => [$pager->getStart(), $pager->getItemsPerPage()]]);

View file

@ -194,7 +194,7 @@ class Users extends BaseAdmin
/* get pending */ /* get pending */
$pending = Register::getPending(); $pending = Register::getPending();
$pager = new Pager(DI::args()->getQueryString(), 100); $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 100);
// @TODO Move below block to Model\User::getUsers($start, $count, $order = 'contact.name', $order_direction = '+') // @TODO Move below block to Model\User::getUsers($start, $count, $order = 'contact.name', $order_direction = '+')
$valid_orders = [ $valid_orders = [

View file

@ -67,7 +67,7 @@ class AllFriends extends BaseModule
$total = Model\GContact::countAllFriends(local_user(), $cid); $total = Model\GContact::countAllFriends(local_user(), $cid);
$pager = new Pager(DI::args()->getQueryString()); $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
$friends = Model\GContact::allFriends(local_user(), $cid, $pager->getStart(), $pager->getItemsPerPage()); $friends = Model\GContact::allFriends(local_user(), $cid, $pager->getStart(), $pager->getItemsPerPage());
if (empty($friends)) { if (empty($friends)) {

View file

@ -102,7 +102,7 @@ abstract class BaseNotifications extends BaseModule
} }
// Set the pager // Set the pager
$pager = new Pager(DI::args()->getQueryString(), self::ITEMS_PER_PAGE); $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), self::ITEMS_PER_PAGE);
// Add additional informations (needed for json output) // Add additional informations (needed for json output)
$notifications = [ $notifications = [
@ -132,7 +132,7 @@ abstract class BaseNotifications extends BaseModule
$tabs = self::getTabs(); $tabs = self::getTabs();
// Set the pager // Set the pager
$pager = new Pager(DI::args()->getQueryString(), self::ITEMS_PER_PAGE); $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), self::ITEMS_PER_PAGE);
$notif_tpl = Renderer::getMarkupTemplate('notifications/notifications.tpl'); $notif_tpl = Renderer::getMarkupTemplate('notifications/notifications.tpl');
return Renderer::replaceMacros($notif_tpl, [ return Renderer::replaceMacros($notif_tpl, [

View file

@ -81,8 +81,7 @@ class BaseSearch extends BaseModule
$header = DI::l10n()->t('Forum Search - %s', $search); $header = DI::l10n()->t('Forum Search - %s', $search);
} }
$args = DI::args(); $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
$pager = new Pager($args->getQueryString());
if ($localSearch && empty($results)) { if ($localSearch && empty($results)) {
$pager->setItemsPerPage(80); $pager->setItemsPerPage(80);

View file

@ -731,7 +731,7 @@ class Contact extends BaseModule
} }
DBA::close($stmt); DBA::close($stmt);
$pager = new Pager(DI::args()->getQueryString()); $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
$sql_values[] = $pager->getStart(); $sql_values[] = $pager->getStart();
$sql_values[] = $pager->getItemsPerPage(); $sql_values[] = $pager->getItemsPerPage();

View file

@ -104,6 +104,7 @@ class Community extends BaseModule
$o .= conversation(DI::app(), $items, 'community', false, false, 'commented', local_user()); $o .= conversation(DI::app(), $items, 'community', false, false, 'commented', local_user());
$pager = new BoundariesPager( $pager = new BoundariesPager(
DI::l10n(),
DI::args()->getQueryString(), DI::args()->getQueryString(),
$items[0]['commented'], $items[0]['commented'],
$items[count($items) - 1]['commented'], $items[count($items) - 1]['commented'],

View file

@ -70,7 +70,7 @@ class Directory extends BaseModule
$gDirPath = Profile::zrl($dirURL, true); $gDirPath = Profile::zrl($dirURL, true);
} }
$pager = new Pager(DI::args()->getQueryString(), 60); $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 60);
$profiles = Profile::searchProfiles($pager->getStart(), $pager->getItemsPerPage(), $search); $profiles = Profile::searchProfiles($pager->getStart(), $pager->getItemsPerPage(), $search);

View file

@ -85,7 +85,7 @@ class Contacts extends BaseProfile
$total = DBA::count('contact', $condition); $total = DBA::count('contact', $condition);
$pager = new Pager(DI::args()->getQueryString()); $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
$params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; $params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];

View file

@ -180,7 +180,7 @@ class Status extends BaseProfile
$itemspage_network = $a->force_max_items; $itemspage_network = $a->force_max_items;
} }
$pager = new Pager($args->getQueryString(), $itemspage_network); $pager = new Pager(DI::l10n(), $args->getQueryString(), $itemspage_network);
$pager_sql = sprintf(" LIMIT %d, %d ", $pager->getStart(), $pager->getItemsPerPage()); $pager_sql = sprintf(" LIMIT %d, %d ", $pager->getStart(), $pager->getItemsPerPage());

View file

@ -137,7 +137,7 @@ class Index extends BaseSearch
// OR your own posts if you are a logged in member // OR your own posts if you are a logged in member
// No items will be shown if the member has a blocked profile wall. // No items will be shown if the member has a blocked profile wall.
$pager = new Pager(DI::args()->getQueryString()); $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
if ($tag) { if ($tag) {
Logger::info('Start tag search.', ['q' => $search]); Logger::info('Start tag search.', ['q' => $search]);