/** True if the current result set is the first one */
public $mIsFirst;
+ public $mIsLast;
+
+ protected $mLastShown, $mFirstShown, $mPastTheEndIndex, $mDefaultQuery, $mNavigationBar;
+
+ /**
+ * HTMLForm object
+ *
+ * @var HTMLForm
+ */
+ protected $mHTMLForm;
/**
* Result object for the query. Warning: seek before use.
/**
* Set the offset from an other source than the request
+ *
+ * @param $offset Int|String
*/
function setOffset( $offset ) {
$this->mOffset = $offset;
}
/**
* Set the limit from an other source than the request
+ *
+ * @param $limit Int|String
*/
function setLimit( $limit ) {
$this->mLimit = $limit;
*
* @return String
*/
- function getBody() {
+ public function getBody() {
if ( !$this->mQueryDone ) {
$this->doQuery();
}
+
+ if ( $this->mResult->numRows() ) {
+ # Do any special query batches before display
+ $this->doBatchLookups();
+ }
+
# Don't use any extra rows returned by the query
$numRows = min( $this->mResult->numRows(), $this->mLimit );
);
}
+ /**
+ * Called from getBody(), before getStartBody() is called and
+ * after doQuery() was called. This will be called only if there
+ * are rows in the result set.
+ *
+ * @return void
+ */
+ protected function doBatchLookups() {}
+
/**
* Hook into getBody(), allows text to be inserted at the start. This
* will be called even if there are no rows in the result set.
*
* @return String
*/
- function getStartBody() {
+ protected function getStartBody() {
return '';
}
*
* @return String
*/
- function getEndBody() {
+ protected function getEndBody() {
return '';
}
*
* @return String
*/
- function getEmptyBody() {
+ protected function getEmptyBody() {
return '';
}
* $linkTexts will be used. Both $linkTexts and $disabledTexts are arrays
* of HTML.
*
+ * @param $linkTexts Array
+ * @param $disabledTexts Array
* @return Array
*/
function getPagingLinks( $linkTexts, $disabledTexts = array() ) {
}
foreach ( $this->mLimitsShown as $limit ) {
$links[] = $this->makeLink(
- $this->getLang()->formatNum( $limit ),
+ $this->getLanguage()->formatNum( $limit ),
array( 'offset' => $offset, 'limit' => $limit ),
'num'
);
return $links;
}
+ /**
+ * Assembles an HTMLForm for the Pager and returns the HTML
+ *
+ * @return string
+ */
+ public function buildHTMLForm() {
+ if ( $this->getHTMLFormFields() === null ) {
+ throw new MWException( __METHOD__ . " was called without any form fields being defined" );
+ }
+
+ $this->mHTMLForm = new HTMLForm( $this->getHTMLFormFields(), $this->getContext() );
+ $this->mHTMLForm->setMethod( 'get' );
+ $this->mHTMLForm->setWrapperLegendMsg( $this->getHTMLFormLegend() );
+ $this->mHTMLForm->setSubmitTextMsg( $this->getHTMLFormSubmit() );
+ $this->addHiddenFields();
+ $this->modifyHTMLForm( $this->mHTMLForm );
+ $this->mHTMLForm->prepareForm();
+
+ return $this->mHTMLForm->getHTML( '' );
+ }
+
+ /**
+ * Adds hidden elements to forms for things that are in the query string.
+ * This is so that parameters like offset stick through form submissions
+ */
+ protected function addHiddenFields() {
+ $query = $this->getRequest()->getQueryValues();
+ $fieldsBlacklist = array( 'title' );
+ $fields = $this->mHTMLForm->getFlatFields();
+ foreach ( $fields as $name => $field ) {
+ $fieldsBlacklist[] = $field->getName();
+ }
+ foreach ( $query as $name => $value ) {
+ if ( in_array( $name, $fieldsBlacklist ) ) {
+ continue;
+ }
+ $this->mHTMLForm->addHiddenField( $name, $value );
+ }
+ }
+
/**
* Abstract formatting function. This should return an HTML string
* representing the result row $row. Rows will be concatenated and
* @return Boolean
*/
protected function getDefaultDirections() { return false; }
+
+ /**
+ * Returns an array for HTMLForm fields for the pager
+ *
+ * Only used if the pager makes use of HTMLForms
+ *
+ * @return array|null
+ */
+ protected function getHTMLFormFields() { return null; }
+
+ /**
+ * Message name for the fieldset legend text
+ *
+ * Only used if the pager makes use of HTMLForms
+ *
+ * @return string
+ */
+ protected function getHTMLFormLegend() { return ''; }
+
+ /**
+ * Message name for the submit button text
+ *
+ * Only used if the pager makes use of HTMLForms
+ *
+ * @return string
+ */
+ protected function getHTMLFormSubmit() { return ''; }
+
+ /**
+ * If the pager needs to do any modifications to the Form, override this
+ * function.
+ *
+ * Only used if the pager makes use of HTMLForms
+ *
+ * @param HTMLForm $form
+ */
+ protected function modifyHTMLForm( HTMLForm $form ) {}
}
* @ingroup Pager
*/
abstract class AlphabeticPager extends IndexPager {
+
/**
* Shamelessly stolen bits from ReverseChronologicalPager,
* didn't want to do class magic as may be still revamped
+ *
+ * @return String HTML
*/
function getNavigationBar() {
if ( !$this->isNavigationBarShown() ) return '';
return $this->mNavigationBar;
}
- $lang = $this->getLang();
+ $lang = $this->getLanguage();
$opts = array( 'parsemag', 'escapenoentities' );
$linkTexts = array(
return $this->mNavigationBar;
}
- $nicenumber = $this->getLang()->formatNum( $this->mLimit );
+ $nicenumber = $this->getLanguage()->formatNum( $this->mLimit );
$linkTexts = array(
'prev' => wfMsgExt(
'pager-newer-n',
$pagingLinks = $this->getPagingLinks( $linkTexts );
$limitLinks = $this->getLimitLinks();
- $limits = $this->getLang()->pipeList( $limitLinks );
+ $limits = $this->getLanguage()->pipeList( $limitLinks );
$this->mNavigationBar = "({$pagingLinks['first']}" .
wfMsgExt( 'pipe-separator' , 'escapenoentities' ) .
var $mSort;
var $mCurrentRow;
- function __construct( RequestContext $context = null ) {
+ function __construct( IContextSource $context = null ) {
if ( $context ) {
$this->setContext( $context );
}
return "<tr><td colspan=\"$colspan\">$msgEmpty</td></tr>\n";
}
+ /**
+ * @param $row Array
+ * @return String HTML
+ */
function formatRow( $row ) {
$this->mCurrentRow = $row; # In case formatValue etc need to know
- $s = Xml::openElement( 'tr', $this->getRowAttrs($row) );
+ $s = Xml::openElement( 'tr', $this->getRowAttrs( $row ) );
$fieldNames = $this->getFieldNames();
foreach ( $fieldNames as $field => $name ) {
$value = isset( $row->$field ) ? $row->$field : null;
* Get attributes to be applied to the given row.
*
* @param $row Object: the database result row
- * @return Associative array
+ * @return Array of <attr> => <value>
*/
function getRowAttrs( $row ) {
$class = $this->getRowClass( $row );
* take this as an excuse to hardcode styles; use classes and
* CSS instead. Row context is available in $this->mCurrentRow
*
- * @param $field The column
- * @param $value The cell contents
- * @return Associative array
+ * @param $field String The column
+ * @param $value String The cell contents
+ * @return Array of attr => value
*/
function getCellAttrs( $field, $value ) {
return array( 'class' => 'TablePager_col_' . $field );
/**
* A navigation bar with images
+ * @return String HTML
*/
function getNavigationBar() {
global $wgStylePath;
'next' => 'arrow_disabled_right_25.png',
'last' => 'arrow_disabled_last_25.png',
);
- if( $this->getLang()->isRTL() ) {
+ if( $this->getLanguage()->isRTL() ) {
$keys = array_keys( $labels );
$images = array_combine( $keys, array_reverse( $images ) );
$disabledImages = array_combine( $keys, array_reverse( $disabledImages ) );
# will be a string.
if( is_int( $value ) ){
$limit = $value;
- $text = $this->getLang()->formatNum( $limit );
+ $text = $this->getLanguage()->formatNum( $limit );
} else {
$limit = $key;
$text = $value;
return $s;
}
+ /**
+ * Returns an HTMLFormField definition for the "Items per page:" dropdown
+ *
+ * @return array
+ */
+ protected function getHTMLFormLimitSelect() {
+ $f = array(
+ 'class' => 'HTMLItemsPerPageField',
+ 'label-message' => 'table_pager_limit_label',
+ 'options' => array(),
+ 'default' => $this->mDefaultLimit,
+ 'name' => 'limit',
+ );
+
+ foreach( $this->mLimitsShown as $limit ) {
+ $f['options'][$this->getLanguage()->formatNum( $limit )] = $limit;
+ }
+
+ return $f;
+ }
+
/**
* Get <input type="hidden"> elements for use in a method="get" form.
* Resubmits all defined elements of the query string, except for a
* blacklist, passed in the $blacklist parameter.
*
+ * @param $blacklist Array parameters from the request query which should not be resubmitted
* @return String: HTML fragment
*/
function getHiddenFields( $blacklist = array() ) {
* An array mapping database field names to a textual description of the
* field name, for use in the table header. The description should be plain
* text, it will be HTML-escaped later.
+ *
+ * @return Array
*/
abstract function getFieldNames();
}
+
+/**
+ * Items per page dropdown for HTMLForm
+ */
+class HTMLItemsPerPageField extends HTMLSelectField {
+ /**
+ * Basically don't do any validation. If it's a number that's fine. Also,
+ * add it to the list if it's not there already
+ *
+ * @param $value
+ * @param $alldata
+ * @return bool
+ */
+ function validate( $value, $alldata ) {
+ if ( $value == '' ) {
+ return true;
+ }
+
+ if ( !in_array( $value, $this->mParams['options'] ) ) {
+ $this->mParams['options'][ $this->mParent->getLanguage()->formatNum( $value ) ] = intval($value);
+ asort( $this->mParams['options'] );
+ }
+
+ return true;
+ }
+
+}
\ No newline at end of file