AlphabeticPager.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Efficient paging for SQL queries.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. * http://www.gnu.org/copyleft/gpl.html
  19. *
  20. * @file
  21. * @ingroup Pager
  22. */
  23. /**
  24. * IndexPager with an alphabetic list and a formatted navigation bar
  25. * @ingroup Pager
  26. */
  27. abstract class AlphabeticPager extends IndexPager {
  28. /**
  29. * Shamelessly stolen bits from ReverseChronologicalPager,
  30. * didn't want to do class magic as may be still revamped
  31. *
  32. * @return string HTML
  33. */
  34. function getNavigationBar() {
  35. if ( !$this->isNavigationBarShown() ) {
  36. return '';
  37. }
  38. if ( isset( $this->mNavigationBar ) ) {
  39. return $this->mNavigationBar;
  40. }
  41. $linkTexts = [
  42. 'prev' => $this->msg( 'prevn' )->numParams( $this->mLimit )->escaped(),
  43. 'next' => $this->msg( 'nextn' )->numParams( $this->mLimit )->escaped(),
  44. 'first' => $this->msg( 'page_first' )->escaped(),
  45. 'last' => $this->msg( 'page_last' )->escaped()
  46. ];
  47. $lang = $this->getLanguage();
  48. $pagingLinks = $this->getPagingLinks( $linkTexts );
  49. $limitLinks = $this->getLimitLinks();
  50. $limits = $lang->pipeList( $limitLinks );
  51. $this->mNavigationBar = $this->msg( 'parentheses' )->rawParams(
  52. $lang->pipeList( [ $pagingLinks['first'],
  53. $pagingLinks['last'] ] ) )->escaped() . " " .
  54. $this->msg( 'viewprevnext' )->rawParams( $pagingLinks['prev'],
  55. $pagingLinks['next'], $limits )->escaped();
  56. if ( !is_array( $this->getIndexField() ) ) {
  57. # Early return to avoid undue nesting
  58. return $this->mNavigationBar;
  59. }
  60. $extra = '';
  61. $first = true;
  62. $msgs = $this->getOrderTypeMessages();
  63. foreach ( array_keys( $msgs ) as $order ) {
  64. if ( $first ) {
  65. $first = false;
  66. } else {
  67. $extra .= $this->msg( 'pipe-separator' )->escaped();
  68. }
  69. if ( $order == $this->mOrderType ) {
  70. $extra .= $this->msg( $msgs[$order] )->escaped();
  71. } else {
  72. $extra .= $this->makeLink(
  73. $this->msg( $msgs[$order] )->escaped(),
  74. [ 'order' => $order ]
  75. );
  76. }
  77. }
  78. if ( $extra !== '' ) {
  79. $extra = ' ' . $this->msg( 'parentheses' )->rawParams( $extra )->escaped();
  80. $this->mNavigationBar .= $extra;
  81. }
  82. return $this->mNavigationBar;
  83. }
  84. /**
  85. * If this supports multiple order type messages, give the message key for
  86. * enabling each one in getNavigationBar. The return type is an associative
  87. * array whose keys must exactly match the keys of the array returned
  88. * by getIndexField(), and whose values are message keys.
  89. *
  90. * @return array
  91. */
  92. protected function getOrderTypeMessages() {
  93. return null;
  94. }
  95. }