From 8f416baead93a48e5799e44b8bd2e2c4859f4e04 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Fri, 14 Sep 2007 13:18:58 +0200 Subject: auf Version 1.11 aktualisiert; Login-Bug behoben --- includes/Pager.php | 122 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 69 insertions(+), 53 deletions(-) (limited to 'includes/Pager.php') diff --git a/includes/Pager.php b/includes/Pager.php index a475dc16..70d0873c 100644 --- a/includes/Pager.php +++ b/includes/Pager.php @@ -12,41 +12,42 @@ interface Pager { /** * IndexPager is an efficient pager which uses a (roughly unique) index in the * data set to implement paging, rather than a "LIMIT offset,limit" clause. - * In MySQL, such a limit/offset clause requires counting through the specified number - * of offset rows to find the desired data, which can be expensive for large offsets. + * In MySQL, such a limit/offset clause requires counting through the + * specified number of offset rows to find the desired data, which can be + * expensive for large offsets. * - * ReverseChronologicalPager is a child class of the abstract IndexPager, and contains - * some formatting and display code which is specific to the use of timestamps as - * indexes. Here is a synopsis of its operation: + * ReverseChronologicalPager is a child class of the abstract IndexPager, and + * contains some formatting and display code which is specific to the use of + * timestamps as indexes. Here is a synopsis of its operation: * - * * The query is specified by the offset, limit and direction (dir) parameters, in - * addition to any subclass-specific parameters. + * * The query is specified by the offset, limit and direction (dir) + * parameters, in addition to any subclass-specific parameters. + * * The offset is the non-inclusive start of the DB query. A row with an + * index value equal to the offset will never be shown. + * * The query may either be done backwards, where the rows are returned by + * the database in the opposite order to which they are displayed to the + * user, or forwards. This is specified by the "dir" parameter, dir=prev + * means backwards, anything else means forwards. The offset value + * specifies the start of the database result set, which may be either + * the start or end of the displayed data set. This allows "previous" + * links to be implemented without knowledge of the index value at the + * start of the previous page. + * * An additional row beyond the user-specified limit is always requested. + * This allows us to tell whether we should display a "next" link in the + * case of forwards mode, or a "previous" link in the case of backwards + * mode. Determining whether to display the other link (the one for the + * page before the start of the database result set) can be done + * heuristically by examining the offset. * - * * The offset is the non-inclusive start of the DB query. A row with an index value - * equal to the offset will never be shown. + * * An empty offset indicates that the offset condition should be omitted + * from the query. This naturally produces either the first page or the + * last page depending on the dir parameter. * - * * The query may either be done backwards, where the rows are returned by the database - * in the opposite order to which they are displayed to the user, or forwards. This is - * specified by the "dir" parameter, dir=prev means backwards, anything else means - * forwards. The offset value specifies the start of the database result set, which - * may be either the start or end of the displayed data set. This allows "previous" - * links to be implemented without knowledge of the index value at the start of the - * previous page. - * - * * An additional row beyond the user-specified limit is always requested. This allows - * us to tell whether we should display a "next" link in the case of forwards mode, - * or a "previous" link in the case of backwards mode. Determining whether to - * display the other link (the one for the page before the start of the database - * result set) can be done heuristically by examining the offset. - * - * * An empty offset indicates that the offset condition should be omitted from the query. - * This naturally produces either the first page or the last page depending on the - * dir parameter. - * - * Subclassing the pager to implement concrete functionality should be fairly simple, - * 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. + * Subclassing the pager to implement concrete functionality should be fairly + * simple, 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 */ @@ -75,9 +76,9 @@ abstract class IndexPager implements Pager { 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! + # 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' ); # Use consistent behavior for the limit options @@ -106,6 +107,9 @@ abstract class IndexPager implements Pager { $this->mResult = $this->reallyDoQuery( $this->mOffset, $queryLimit, $descending ); $this->extractResultInfo( $this->mOffset, $queryLimit, $this->mResult ); $this->mQueryDone = true; + + $this->preprocessResults( $this->mResult ); + $this->mResult->rewind(); // Paranoia wfProfileOut( $fname ); } @@ -131,9 +135,10 @@ abstract class IndexPager implements Pager { $lastIndex = $row[$this->mIndexField]; } else { $this->mPastTheEndRow = null; - # Setting indexes to an empty string means that they will be omitted - # if they would otherwise appear in URLs. It just so happens that this - # is the right thing to do in the standard UI, in all the relevant cases. + # Setting indexes to an empty string means that they will be + # omitted if they would otherwise appear in URLs. It just so + # happens that this is the right thing to do in the standard + # UI, in all the relevant cases. $this->mPastTheEndIndex = ''; $res->seek( $numRows - 1 ); $row = $res->fetchRow(); @@ -160,21 +165,22 @@ abstract class IndexPager implements Pager { } /** - * Do a query with specified parameters, rather than using the object context + * Do a query with specified parameters, rather than using the object + * context * * @param string $offset Index offset, inclusive * @param integer $limit Exact query limit * @param boolean $descending Query direction, false for ascending, true for descending * @return ResultWrapper */ - function reallyDoQuery( $offset, $limit, $ascending ) { + function reallyDoQuery( $offset, $limit, $descending ) { $fname = __METHOD__ . ' (' . get_class( $this ) . ')'; $info = $this->getQueryInfo(); $tables = $info['tables']; $fields = $info['fields']; $conds = isset( $info['conds'] ) ? $info['conds'] : array(); $options = isset( $info['options'] ) ? $info['options'] : array(); - if ( $ascending ) { + if ( $descending ) { $options['ORDER BY'] = $this->mIndexField; $operator = '>'; } else { @@ -189,6 +195,13 @@ abstract class IndexPager implements Pager { return new ResultWrapper( $this->mDb, $res ); } + /** + * Pre-process results; useful for performing batch existence checks, etc. + * + * @param ResultWrapper $result Result wrapper + */ + protected function preprocessResults( $result ) {} + /** * Get the formatted result list. Calls getStartBody(), formatRow() and * getEndBody(), concatenates the results and returns them. @@ -331,9 +344,10 @@ abstract class IndexPager implements Pager { } /** - * Get paging links. If a link is disabled, the item from $disabledTexts will - * be used. If there is no such item, the unlinked text from $linkTexts will - * be used. Both $linkTexts and $disabledTexts are arrays of HTML. + * Get paging links. If a link is disabled, the item from $disabledTexts + * will be used. If there is no such item, the unlinked text from + * $linkTexts will be used. Both $linkTexts and $disabledTexts are arrays + * of HTML. */ function getPagingLinks( $linkTexts, $disabledTexts = array() ) { $queries = $this->getPagingQueries(); @@ -667,20 +681,22 @@ abstract class TablePager extends IndexPager { } /** - * Return true if the named field should be sortable by the UI, false otherwise + * Return true if the named field should be sortable by the UI, false + * otherwise + * * @param string $field */ abstract function isFieldSortable( $field ); /** - * Format a table cell. The return value should be HTML, but use an empty string - * not   for empty cells. Do not include the and . + * Format a table cell. The return value should be HTML, but use an empty + * string not   for empty cells. Do not include the and . + * + * The current result row is available as $this->mCurrentRow, in case you + * need more context. * * @param string $name The database field name * @param string $value The value retrieved from the database - * - * The current result row is available as $this->mCurrentRow, in case you need - * more context. */ abstract function formatValue( $name, $value ); @@ -690,10 +706,10 @@ abstract class TablePager extends IndexPager { abstract function getDefaultSort(); /** - * 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. + * 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. */ abstract function getFieldNames(); } -?> + -- cgit v1.2.2