// Make table header
foreach ( $fields as $field => $name ) {
if ( strval( $name ) == '' ) {
- $s .= Html::rawElement( 'th', array(), ' ' ) . "\n";
+ $s .= Html::rawElement( 'th', [], ' ' ) . "\n";
} elseif ( $this->isFieldSortable( $field ) ) {
- $query = array( 'sort' => $field, 'limit' => $this->mLimit );
+ $query = [ 'sort' => $field, 'limit' => $this->mLimit ];
$linkType = null;
$class = null;
}
$link = $this->makeLink( htmlspecialchars( $name ), $query, $linkType );
- $s .= Html::rawElement( 'th', array( 'class' => $class ), $link ) . "\n";
+ $s .= Html::rawElement( 'th', [ 'class' => $class ], $link ) . "\n";
} else {
- $s .= Html::element( 'th', array(), $name ) . "\n";
+ $s .= Html::element( 'th', [], $name ) . "\n";
}
}
$tableClass = $this->getTableClass();
- $ret = Html::openElement( 'table', array(
- 'class' => "mw-datatable $tableClass" )
+ $ret = Html::openElement( 'table', [
+ 'class' => "mw-datatable $tableClass" ]
);
- $ret .= Html::rawElement( 'thead', array(), Html::rawElement( 'tr', array(), "\n" . $s . "\n" ) );
+ $ret .= Html::rawElement( 'thead', [], Html::rawElement( 'tr', [], "\n" . $s . "\n" ) );
$ret .= Html::openElement( 'tbody' ) . "\n";
return $ret;
function getEmptyBody() {
$colspan = count( $this->getFieldNames() );
$msgEmpty = $this->msg( 'table_pager_empty' )->text();
- return Html::rawElement( 'tr', array(),
- Html::element( 'td', array( 'colspan' => $colspan ), $msgEmpty ) );
+ return Html::rawElement( 'tr', [],
+ Html::element( 'td', [ 'colspan' => $colspan ], $msgEmpty ) );
}
/**
$class = $this->getRowClass( $row );
if ( $class === '' ) {
// Return an empty array to avoid clutter in HTML like class=""
- return array();
+ return [];
} else {
- return array( 'class' => $this->getRowClass( $row ) );
+ return [ 'class' => $this->getRowClass( $row ) ];
}
}
* @return array Array of attr => value
*/
function getCellAttrs( $field, $value ) {
- return array( 'class' => 'TablePager_col_' . $field );
+ return [ 'class' => 'TablePager_col_' . $field ];
}
/**
}
/**
- * @protected
* @return string
*/
- function getTableClass() {
+ protected function getTableClass() {
return 'TablePager';
}
/**
- * @protected
* @return string
*/
- function getNavClass() {
+ protected function getNavClass() {
return 'TablePager_nav';
}
/**
- * @protected
* @return string
*/
- function getSortHeaderClass() {
+ protected function getSortHeaderClass() {
return 'TablePager_sort';
}
return '';
}
- $labels = array(
- 'first' => 'table_pager_first',
- 'prev' => 'table_pager_prev',
- 'next' => 'table_pager_next',
- 'last' => 'table_pager_last',
- );
+ $this->getOutput()->enableOOUI();
- $linkTexts = array();
- $disabledTexts = array();
- foreach ( $labels as $type => $label ) {
- $msgLabel = $this->msg( $label )->escaped();
- $linkTexts[$type] = "<div class='TablePager_nav-enabled'>$msgLabel</div>";
- $disabledTexts[$type] = "<div class='TablePager_nav-disabled'>$msgLabel</div>";
- }
- $links = $this->getPagingLinks( $linkTexts, $disabledTexts );
-
- $s = Html::openElement( 'table', array( 'class' => $this->getNavClass() ) );
- $s .= Html::openElement( 'tr' ) . "\n";
- $width = 100 / count( $links ) . '%';
- foreach ( $labels as $type => $label ) {
- // We want every cell to have the same width. We could use table-layout: fixed; in CSS,
- // but it only works if we specify the width of a cell or the table and we don't want to.
- // There is no better way. <http://www.w3.org/TR/CSS2/tables.html#fixed-table-layout>
- $s .= Html::rawElement( 'td',
- array( 'style' => "width: $width;", 'class' => "TablePager_nav-$type" ),
- $links[$type] ) . "\n";
+ $types = [ 'first', 'prev', 'next', 'last' ];
+
+ $queries = $this->getPagingQueries();
+ $links = [];
+
+ $buttons = [];
+
+ $title = $this->getTitle();
+
+ foreach ( $types as $type ) {
+ $buttons[] = new \OOUI\ButtonWidget( [
+ // Messages used here:
+ // * table_pager_first
+ // * table_pager_prev
+ // * table_pager_next
+ // * table_pager_last
+ 'label' => $this->msg( 'table_pager_' . $type )->text(),
+ 'href' => $queries[ $type ] ?
+ $title->getLinkURL( $queries[ $type ] + $this->getDefaultQuery() ) :
+ null,
+ 'icon' => $type === 'prev' ? 'previous' : $type,
+ 'disabled' => $queries[ $type ] === false
+ ] );
}
- $s .= Html::closeElement( 'tr' ) . Html::closeElement( 'table' ) . "\n";
- return $s;
+ return new \OOUI\ButtonGroupWidget( [
+ 'classes' => [ $this->getNavClass() ],
+ 'items' => $buttons,
+ ] );
}
/**
* @return string[]
*/
public function getModuleStyles() {
- return array( 'mediawiki.pager.tablePager' );
+ return [ 'mediawiki.pager.tablePager', 'oojs-ui.styles.icons-movement' ];
}
/**
* Get a "<select>" element which has options for each of the allowed limits
*
- * @param string $attribs Extra attributes to set
+ * @param string[] $attribs Extra attributes to set
* @return string HTML fragment
*/
- public function getLimitSelect( $attribs = array() ) {
+ public function getLimitSelect( $attribs = [] ) {
$select = new XmlSelect( 'limit', false, $this->mLimit );
$select->addOptions( $this->getLimitSelectList() );
foreach ( $attribs as $name => $value ) {
$this->mLimitsShown[] = $this->mLimit;
sort( $this->mLimitsShown );
}
- $ret = array();
+ $ret = [];
foreach ( $this->mLimitsShown as $key => $value ) {
# The pair is either $index => $limit, in which case the $value
# will be numeric, or $limit => $text, in which case the $value
* @param array $blacklist Parameters from the request query which should not be resubmitted
* @return string HTML fragment
*/
- function getHiddenFields( $blacklist = array() ) {
+ function getHiddenFields( $blacklist = [] ) {
$blacklist = (array)$blacklist;
$query = $this->getRequest()->getQueryValues();
foreach ( $blacklist as $name ) {
function getLimitForm() {
return Html::rawElement(
'form',
- array(
+ [
'method' => 'get',
'action' => wfScript(),
- ),
+ ],
"\n" . $this->getLimitDropdown()
) . "\n";
}
return $this->msg( 'table_pager_limit' )
->rawParams( $this->getLimitSelect() )->escaped() .
"\n<input type=\"submit\" value=\"$msgSubmit\"/>\n" .
- $this->getHiddenFields( array( 'limit' ) );
+ $this->getHiddenFields( [ 'limit' ] );
}
/**