/**
* Basic pager interface.
+ * @addtogroup Pager
*/
interface Pager {
function getNavigationBar();
* please see the examples in PageHistory.php and SpecialIpblocklist.php. You just need
* to override formatRow(), getQueryInfo() and getIndexField(). Don't forget to call the
* parent constructor if you override it.
+ *
+ * @addtogroup Pager
*/
abstract class IndexPager implements Pager {
public $mRequest;
public $mResult;
function __construct() {
- global $wgRequest;
+ global $wgRequest, $wgUser;
$this->mRequest = $wgRequest;
-
+
# NB: the offset is quoted, not validated. It is treated as an arbitrary string
# to support the widest variety of index types. Be careful outputting it into
# HTML!
$this->mOffset = $this->mRequest->getText( 'offset' );
- $this->mLimit = $this->mRequest->getInt( 'limit', $this->mDefaultLimit );
- if ( $this->mLimit <= 0 ) {
- $this->mLimit = $this->mDefaultLimit;
- }
+
+ # Use consistent behavior for the limit options
+ $this->mDefaultLimit = intval( $wgUser->getOption( 'rclimit' ) );
+ list( $this->mLimit, /* $offset */ ) = $this->mRequest->getLimitOffset();
+
$this->mIsBackwards = ( $this->mRequest->getVal( 'dir' ) == 'prev' );
$this->mIndexField = $this->getIndexField();
$this->mDb = wfGetDB( DB_SLAVE );
$next = array( 'offset' => $this->mLastShown, 'limit' => $urlLimit );
$last = array( 'dir' => 'prev', 'limit' => $urlLimit );
}
- return compact( 'prev', 'next', 'first', 'last' );
+ return array( 'prev' => $prev, 'next' => $next, 'first' => $first, 'last' => $last );
}
/**
$links[] = $this->makeLink( $wgLang->formatNum( $limit ),
array( 'offset' => $offset, 'limit' => $limit ) );
}
+ return $links;
}
/**
abstract function getIndexField();
}
+
+/**
+ * IndexPager with an alphabetic list and a formatted navigation bar
+ * @addtogroup Pager
+ */
+abstract class AlphabeticPager extends IndexPager {
+ public $mDefaultDirection = false;
+
+ function __construct() {
+ parent::__construct();
+ }
+
+ /**
+ * Shamelessly stolen bits from ReverseChronologicalPager, d
+ * didn't want to do class magic as may be still revamped
+ */
+ function getNavigationBar() {
+ global $wgLang;
+
+ $linkTexts = array(
+ 'prev' => wfMsgHtml( "prevn", $this->mLimit ),
+ 'next' => wfMsgHtml( 'nextn', $this->mLimit ),
+ 'first' => wfMsgHtml('page_first'), /* Introduced the message */
+ 'last' => wfMsgHtml( 'page_last' ) /* Introduced the message */
+ );
+
+ $pagingLinks = $this->getPagingLinks( $linkTexts );
+ $limitLinks = $this->getLimitLinks();
+ $limits = implode( ' | ', $limitLinks );
+
+ $this->mNavigationBar = "({$pagingLinks['first']} | {$pagingLinks['last']}) " . wfMsgHtml("viewprevnext", $pagingLinks['prev'], $pagingLinks['next'], $limits);
+ return $this->mNavigationBar;
+
+ }
+}
+
/**
* IndexPager with a formatted navigation bar
+ * @addtogroup Pager
*/
abstract class ReverseChronologicalPager extends IndexPager {
public $mDefaultDirection = true;
$limitLinks = $this->getLimitLinks();
$limits = implode( ' | ', $limitLinks );
- $this->mNavigationBar = "($latestText | $earliestText) " . wfMsgHtml("viewprevnext", $prevText, $nextText, $limits);
+ $this->mNavigationBar = "({$pagingLinks['first']} | {$pagingLinks['last']}) " .
+ wfMsgHtml("viewprevnext", $pagingLinks['prev'], $pagingLinks['next'], $limits);
return $this->mNavigationBar;
}
}
/**
* Table-based display with a user-selectable sort order
+ * @addtogroup Pager
*/
abstract class TablePager extends IndexPager {
var $mSort;
function getStartBody() {
global $wgStylePath;
- $s = "<table border='1' class=\"TablePager\"><thead><tr>\n";
+ $tableClass = htmlspecialchars( $this->getTableClass() );
+ $sortClass = htmlspecialchars( $this->getSortHeaderClass() );
+
+ $s = "<table border='1' class=\"$tableClass\"><thead><tr>\n";
$fields = $this->getFieldNames();
+
+ # Make table header
foreach ( $fields as $field => $name ) {
if ( strval( $name ) == '' ) {
$s .= "<th> </th>\n";
$link = $this->makeLink(
"<img width=\"12\" height=\"12\" alt=\"$alt\" src=\"$image\" />" .
htmlspecialchars( $name ), $query );
- $s .= "<th class=\"TablePager_sort\">$link</th>\n";
+ $s .= "<th class=\"$sortClass\">$link</th>\n";
} else {
$s .= '<th>' . $this->makeLink( htmlspecialchars( $name ), $query ) . "</th>\n";
}
}
function getEndBody() {
- return '</tbody></table>';
+ return "</tbody></table>\n";
}
function getEmptyBody() {
if ( $formatted == '' ) {
$formatted = ' ';
}
- $s .= "<td>$formatted</td>\n";
+ $class = 'TablePager_col_' . htmlspecialchars( $field );
+ $s .= "<td class=\"$class\">$formatted</td>\n";
}
$s .= "</tr>\n";
return $s;
return $this->mSort;
}
+ function getTableClass() {
+ return 'TablePager';
+ }
+
+ function getNavClass() {
+ return 'TablePager_nav';
+ }
+
+ function getSortHeaderClass() {
+ return 'TablePager_sort';
+ }
+
/**
* A navigation bar with images
*/
function getNavigationBar() {
- global $wgStylePath;
+ global $wgStylePath, $wgContLang;
$path = "$wgStylePath/common/images";
- $labels = array(
+ $labels = array(
'first' => 'table_pager_first',
'prev' => 'table_pager_prev',
'next' => 'table_pager_next',
'last' => 'table_pager_last',
);
$images = array(
- 'first' => 'arrow_first_25.png',
- 'prev' => 'arrow_left_25.png',
- 'next' => 'arrow_right_25.png',
- 'last' => 'arrow_last_25.png',
+ 'first' => $wgContLang->isRTL() ? 'arrow_last_25.png' : 'arrow_first_25.png',
+ 'prev' => $wgContLang->isRTL() ? 'arrow_right_25.png' : 'arrow_left_25.png',
+ 'next' => $wgContLang->isRTL() ? 'arrow_left_25.png' : 'arrow_right_25.png',
+ 'last' => $wgContLang->isRTL() ? 'arrow_first_25.png' : 'arrow_last_25.png',
);
$disabledImages = array(
- 'first' => 'arrow_disabled_first_25.png',
- 'prev' => 'arrow_disabled_left_25.png',
- 'next' => 'arrow_disabled_right_25.png',
- 'last' => 'arrow_disabled_last_25.png',
+ 'first' => $wgContLang->isRTL() ? 'arrow_disabled_last_25.png' : 'arrow_disabled_first_25.png',
+ 'prev' => $wgContLang->isRTL() ? 'arrow_disabled_right_25.png' : 'arrow_disabled_left_25.png',
+ 'next' => $wgContLang->isRTL() ? 'arrow_disabled_left_25.png' : 'arrow_disabled_right_25.png',
+ 'last' => $wgContLang->isRTL() ? 'arrow_disabled_first_25.png' : 'arrow_disabled_last_25.png',
);
-
+
$linkTexts = array();
$disabledTexts = array();
foreach ( $labels as $type => $label ) {
}
$links = $this->getPagingLinks( $linkTexts, $disabledTexts );
- $s = '<table class="TablePager_nav" align="center" cellpadding="3"><tr>';
+ $navClass = htmlspecialchars( $this->getNavClass() );
+ $s = "<table class=\"$navClass\" align=\"center\" cellpadding=\"3\"><tr>\n";
$cellAttrs = 'valign="top" align="center" width="' . 100 / count( $links ) . '%"';
foreach ( $labels as $type => $label ) {
$s .= "<td $cellAttrs>{$links[$type]}</td>\n";
}
- $s .= '</tr></table>';
+ $s .= "</tr></table>\n";
return $s;
}