setContext( $context ); } $this->mSort = $this->getRequest()->getText( 'sort' ); if ( !array_key_exists( $this->mSort, $this->getFieldNames() ) || !$this->isFieldSortable( $this->mSort ) ) { $this->mSort = $this->getDefaultSort(); } if ( $this->getRequest()->getBool( 'asc' ) ) { $this->mDefaultDirection = IndexPager::DIR_ASCENDING; } elseif ( $this->getRequest()->getBool( 'desc' ) ) { $this->mDefaultDirection = IndexPager::DIR_DESCENDING; } /* Else leave it at whatever the class default is */ parent::__construct(); } /** * Get the formatted result list. Calls getStartBody(), formatRow() and getEndBody(), concatenates * the results and returns them. * * Also adds the required styles to our OutputPage object (this means that if context wasn't * passed to constructor or otherwise set up, you will get a pager with missing styles). * * This method has been made 'final' in 1.24. There's no reason to override it, and if there exist * any subclasses that do, the style loading hack is probably broken in them. Let's fail fast * rather than mysteriously render things wrong. * * @deprecated since 1.24, use getBodyOutput() or getFullOutput() instead * @return string */ final public function getBody() { $this->getOutput()->addModuleStyles( $this->getModuleStyles() ); return parent::getBody(); } /** * Get the formatted result list. * * Calls getBody() and getModuleStyles() and builds a ParserOutput object. (This is a bit hacky * but works well.) * * @since 1.24 * @return ParserOutput */ public function getBodyOutput() { $body = parent::getBody(); $pout = new ParserOutput; $pout->setText( $body ); $pout->addModuleStyles( $this->getModuleStyles() ); return $pout; } /** * Get the formatted result list, with navigation bars. * * Calls getBody(), getNavigationBar() and getModuleStyles() and * builds a ParserOutput object. (This is a bit hacky but works well.) * * @since 1.24 * @return ParserOutput */ public function getFullOutput() { $navigation = $this->getNavigationBar(); $body = parent::getBody(); $pout = new ParserOutput; $pout->setText( $navigation . $body . $navigation ); $pout->addModuleStyles( $this->getModuleStyles() ); return $pout; } /** * @protected * @return string */ function getStartBody() { $sortClass = $this->getSortHeaderClass(); $s = ''; $fields = $this->getFieldNames(); // Make table header foreach ( $fields as $field => $name ) { if ( strval( $name ) == '' ) { $s .= Html::rawElement( 'th', array(), ' ' ) . "\n"; } elseif ( $this->isFieldSortable( $field ) ) { $query = array( 'sort' => $field, 'limit' => $this->mLimit ); $linkType = null; $class = null; if ( $this->mSort == $field ) { // The table is sorted by this field already, make a link to sort in the other direction // We don't actually know in which direction other fields will be sorted by default… if ( $this->mDefaultDirection == IndexPager::DIR_DESCENDING ) { $linkType = 'asc'; $class = "$sortClass TablePager_sort-descending"; $query['asc'] = '1'; $query['desc'] = ''; } else { $linkType = 'desc'; $class = "$sortClass TablePager_sort-ascending"; $query['asc'] = ''; $query['desc'] = '1'; } } $link = $this->makeLink( htmlspecialchars( $name ), $query, $linkType ); $s .= Html::rawElement( 'th', array( 'class' => $class ), $link ) . "\n"; } else { $s .= Html::element( 'th', array(), $name ) . "\n"; } } $tableClass = $this->getTableClass(); $ret = Html::openElement( 'table', array( 'class' => "mw-datatable $tableClass" ) ); $ret .= Html::rawElement( 'thead', array(), Html::rawElement( 'tr', array(), "\n" . $s . "\n" ) ); $ret .= Html::openElement( 'tbody' ) . "\n"; return $ret; } /** * @protected * @return string */ function getEndBody() { return "\n"; } /** * @protected * @return string */ 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 ) ); } /** * @protected * @param stdClass $row * @return string HTML */ function formatRow( $row ) { $this->mCurrentRow = $row; // In case formatValue etc need to know $s = Html::openElement( 'tr', $this->getRowAttrs( $row ) ) . "\n"; $fieldNames = $this->getFieldNames(); foreach ( $fieldNames as $field => $name ) { $value = isset( $row->$field ) ? $row->$field : null; $formatted = strval( $this->formatValue( $field, $value ) ); if ( $formatted == '' ) { $formatted = ' '; } $s .= Html::rawElement( 'td', $this->getCellAttrs( $field, $value ), $formatted ) . "\n"; } $s .= Html::closeElement( 'tr' ) . "\n"; return $s; } /** * Get a class name to be applied to the given row. * * @protected * * @param object $row The database result row * @return string */ function getRowClass( $row ) { return ''; } /** * Get attributes to be applied to the given row. * * @protected * * @param object $row The database result row * @return array Array of attribute => value */ function getRowAttrs( $row ) { $class = $this->getRowClass( $row ); if ( $class === '' ) { // Return an empty array to avoid clutter in HTML like class="" return array(); } else { return array( 'class' => $this->getRowClass( $row ) ); } } /** * Get any extra attributes to be applied to the given cell. Don't * take this as an excuse to hardcode styles; use classes and * CSS instead. Row context is available in $this->mCurrentRow * * @protected * * @param string $field The column * @param string $value The cell contents * @return array Array of attr => value */ function getCellAttrs( $field, $value ) { return array( 'class' => 'TablePager_col_' . $field ); } /** * @protected * @return string */ function getIndexField() { return $this->mSort; } /** * @protected * @return string */ function getTableClass() { return 'TablePager'; } /** * @protected * @return string */ function getNavClass() { return 'TablePager_nav'; } /** * @protected * @return string */ function getSortHeaderClass() { return 'TablePager_sort'; } /** * A navigation bar with images * @return string HTML */ public function getNavigationBar() { if ( !$this->isNavigationBarShown() ) { return ''; } $labels = array( 'first' => 'table_pager_first', 'prev' => 'table_pager_prev', 'next' => 'table_pager_next', 'last' => 'table_pager_last', ); $linkTexts = array(); $disabledTexts = array(); foreach ( $labels as $type => $label ) { $msgLabel = $this->msg( $label )->escaped(); $linkTexts[$type] = "