X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FPager.php;h=c4d55b6ea675e1eb31ef216189b498033c531e19;hb=797c7653cf29930b389e0d39117ec550663a888c;hp=fdd883a27f8c7c0a91faed4ecb994cff08ed2d50;hpb=60f645cf0b2b766eff322ba91bd955848483c885;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Pager.php b/includes/Pager.php index fdd883a27f..c4d55b6ea6 100644 --- a/includes/Pager.php +++ b/includes/Pager.php @@ -1,8 +1,14 @@ 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! @@ -119,25 +124,16 @@ abstract class IndexPager implements Pager { } if( !isset( $this->mDefaultDirection ) ) { - $dir = $this->getDefaultDirection(); + $dir = $this->getDefaultDirections(); $this->mDefaultDirection = is_array( $dir ) ? $dir[$this->mOrderType] : $dir; } - - # FIXME: Can we figure out a less confusing convention than using a - # "direction" parameter when we already have "dir" and "order"? - if( $this->mRequest->getVal( 'direction' ) == 'asc' ) { - $this->mDefaultDirection = false; - } - if( $this->mRequest->getVal( 'direction' ) == 'desc' ) { - $this->mDefaultDirection = true; - } } /** - * Do the query, using information from the object context. This function - * has been kept minimal to make it overridable if necessary, to allow for + * Do the query, using information from the object context. This function + * has been kept minimal to make it overridable if necessary, to allow for * result sets formed from multiple DB queries. */ function doQuery() { @@ -152,7 +148,7 @@ 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 @@ -160,7 +156,7 @@ abstract class IndexPager implements Pager { } /** - * Extract some useful data from the result object for use by + * Extract some useful data from the result object for use by * the navigation bar, put it into $this */ function extractResultInfo( $offset, $limit, ResultWrapper $res ) { @@ -225,6 +221,7 @@ abstract class IndexPager implements Pager { $fields = $info['fields']; $conds = isset( $info['conds'] ) ? $info['conds'] : array(); $options = isset( $info['options'] ) ? $info['options'] : array(); + $join_conds = isset( $info['join_conds'] ) ? $info['join_conds'] : array(); if ( $descending ) { $options['ORDER BY'] = $this->mIndexField; $operator = '>'; @@ -236,7 +233,7 @@ abstract class IndexPager implements Pager { $conds[] = $this->mIndexField . $operator . $this->mDb->addQuotes( $offset ); } $options['LIMIT'] = intval( $limit ); - $res = $this->mDb->select( $tables, $fields, $conds, $fname, $options ); + $res = $this->mDb->select( $tables, $fields, $conds, $fname, $options, $join_conds ); return new ResultWrapper( $this->mDb, $res ); } @@ -248,7 +245,7 @@ abstract class IndexPager implements Pager { protected function preprocessResults( $result ) {} /** - * Get the formatted result list. Calls getStartBody(), formatRow() and + * Get the formatted result list. Calls getStartBody(), formatRow() and * getEndBody(), concatenates the results and returns them. */ function getBody() { @@ -283,16 +280,25 @@ abstract class IndexPager implements Pager { /** * Make a self-link */ - function makeLink($text, $query = null) { + function makeLink($text, $query = null, $type=null) { if ( $query === null ) { return $text; } + if( $type == 'prev' || $type == 'next' ) { + $attrs = "rel=\"$type\""; + } elseif( $type == 'first' ) { + $attrs = "rel=\"start\""; + } else { + # HTML 4 has no rel="end" . . . + $attrs = ''; + } return $this->getSkin()->makeKnownLinkObj( $this->getTitle(), $text, - wfArrayToCGI( $query, $this->getDefaultQuery() ) ); + wfArrayToCGI( $query, $this->getDefaultQuery() ), '', '', + $attrs ); } /** - * Hook into getBody(), allows text to be inserted at the start. This + * 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. */ function getStartBody() { @@ -307,15 +313,15 @@ abstract class IndexPager implements Pager { } /** - * Hook into getBody(), for the bit between the start and the + * Hook into getBody(), for the bit between the start and the * end when there are no rows */ function getEmptyBody() { return ''; } - + /** - * Title used for self-links. Override this if you want to be able to + * Title used for self-links. Override this if you want to be able to * use a title other than $wgTitle */ function getTitle() { @@ -334,8 +340,8 @@ abstract class IndexPager implements Pager { } /** - * Get an array of query parameters that should be put into self-links. - * By default, all parameters passed in the URL are used, except for a + * Get an array of query parameters that should be put into self-links. + * By default, all parameters passed in the URL are used, except for a * short blacklist. */ function getDefaultQuery() { @@ -345,7 +351,6 @@ abstract class IndexPager implements Pager { unset( $this->mDefaultQuery['dir'] ); unset( $this->mDefaultQuery['offset'] ); unset( $this->mDefaultQuery['limit'] ); - unset( $this->mDefaultQuery['direction'] ); unset( $this->mDefaultQuery['order'] ); } return $this->mDefaultQuery; @@ -362,16 +367,16 @@ abstract class IndexPager implements Pager { } /** - * Get a query array for the prev, next, first and last links. + * Get a URL query array for the prev, next, first and last links. */ function getPagingQueries() { if ( !$this->mQueryDone ) { $this->doQuery(); } - + # Don't announce the limit everywhere if it's the default $urlLimit = $this->mLimit == $this->mDefaultLimit ? '' : $this->mLimit; - + if ( $this->mIsFirst ) { $prev = false; $first = false; @@ -400,7 +405,7 @@ abstract class IndexPager implements Pager { $links = array(); foreach ( $queries as $type => $query ) { if ( $query !== false ) { - $links[$type] = $this->makeLink( $linkTexts[$type], $queries[$type] ); + $links[$type] = $this->makeLink( $linkTexts[$type], $queries[$type], $type ); } elseif ( isset( $disabledTexts[$type] ) ) { $links[$type] = $disabledTexts[$type]; } else { @@ -426,15 +431,15 @@ abstract class IndexPager implements Pager { } /** - * Abstract formatting function. This should return an HTML string + * Abstract formatting function. This should return an HTML string * representing the result row $row. Rows will be concatenated and * returned by getBody() */ abstract function formatRow( $row ); /** - * This function should be overridden to provide all parameters - * needed for the main paged query. It returns an associative + * This function should be overridden to provide all parameters + * needed for the main paged query. It returns an associative * array with the following elements: * tables => Table(s) for passing to Database::select() * fields => Field(s) for passing to Database::select(), may be * @@ -449,6 +454,9 @@ abstract class IndexPager implements Pager { * 'querykey' => 'indexfield' pairs, so that a request with &count=querykey * will use indexfield to sort. In this case, the first returned key is * the default. + * + * Needless to say, it's really not a good idea to use a non-unique index + * for this! That won't page right. */ abstract function getIndexField(); @@ -464,27 +472,23 @@ abstract class IndexPager implements Pager { * called, for instance if it's statically initialized. In that case the * value of that variable (which must be a boolean) will be used. * - * Note that despite its name, this does not return the value of the now- - * misnamed $this->mDefaultDirection member variable. That is not a - * default, it's the actual direction used. This is just the default and - * can be overridden by user input. + * Note that despite its name, this does not return the value of the + * $this->mDefaultDirection member variable. That's the default for this + * particular instantiation, which is a single value. This is the set of + * all defaults for the class. */ - protected function getDefaultDirection() { return false; } + protected function getDefaultDirections() { return false; } } /** * IndexPager with an alphabetic list and a formatted navigation bar - * @addtogroup Pager + * @ingroup Pager */ abstract class AlphabeticPager extends IndexPager { - function __construct() { - parent::__construct(); - } - - /** - * Shamelessly stolen bits from ReverseChronologicalPager, d - * didn't want to do class magic as may be still revamped + /** + * Shamelessly stolen bits from ReverseChronologicalPager, + * didn't want to do class magic as may be still revamped */ function getNavigationBar() { global $wgLang; @@ -493,11 +497,12 @@ abstract class AlphabeticPager extends IndexPager { return $this->mNavigationBar; } + $opts = array( 'parsemag', 'escapenoentities' ); $linkTexts = array( - 'prev' => wfMsgHtml( 'prevn', $wgLang->formatNum( $this->mLimit ) ), - 'next' => wfMsgHtml( 'nextn', $wgLang->formatNum($this->mLimit ) ), - 'first' => wfMsgHtml( 'page_first' ), - 'last' => wfMsgHtml( 'page_last' ) + 'prev' => wfMsgExt( 'prevn', $opts, $wgLang->formatNum( $this->mLimit ) ), + 'next' => wfMsgExt( 'nextn', $opts, $wgLang->formatNum($this->mLimit ) ), + 'first' => wfMsgExt( 'page_first', $opts ), + 'last' => wfMsgExt( 'page_last', $opts ) ); $pagingLinks = $this->getPagingLinks( $linkTexts ); @@ -509,26 +514,6 @@ abstract class AlphabeticPager extends IndexPager { wfMsgHtml( 'viewprevnext', $pagingLinks['prev'], $pagingLinks['next'], $limits ); - $dirlinks = array(); - # Note for grep: uses pager-sort-asc, pager-sort-desc (each in two - # places) - foreach( array( 'asc', 'desc' ) as $dir ) { - if( ($this->mDefaultDirection ? 'desc' : 'asc' ) == $dir ) { - # Don't print a link, just some text - $dirlinks[$dir] = wfMsgHTML( "pager-sort-$dir" ); - } else { - $query = array( 'direction' => $dir ); - if( $this->mOrderType !== null ) { - $query['order'] = $this->mOrderType; - } - $dirlinks[$dir] = $this->makeLink( - wfMsgHTML( "pager-sort-$dir" ), - $query - ); - } - } - $this->mNavigationBar .= ' (' . implode( ' | ', $dirlinks ) . ')'; - if( !is_array( $this->getIndexField() ) ) { # Early return to avoid undue nesting return $this->mNavigationBar; @@ -543,7 +528,7 @@ abstract class AlphabeticPager extends IndexPager { } else { $extra .= ' | '; } - + if( $order == $this->mOrderType ) { $extra .= wfMsgHTML( $msgs[$order] ); } else { @@ -575,10 +560,12 @@ abstract class AlphabeticPager extends IndexPager { /** * IndexPager with a formatted navigation bar - * @addtogroup Pager + * @ingroup Pager */ abstract class ReverseChronologicalPager extends IndexPager { public $mDefaultDirection = true; + public $mYear; + public $mMonth; function __construct() { parent::__construct(); @@ -602,15 +589,62 @@ abstract class ReverseChronologicalPager extends IndexPager { $limitLinks = $this->getLimitLinks(); $limits = implode( ' | ', $limitLinks ); - $this->mNavigationBar = "({$pagingLinks['first']} | {$pagingLinks['last']}) " . + $this->mNavigationBar = "({$pagingLinks['first']} | {$pagingLinks['last']}) " . wfMsgHtml("viewprevnext", $pagingLinks['prev'], $pagingLinks['next'], $limits); return $this->mNavigationBar; } + + function getDateCond( $year, $month ) { + $year = intval($year); + $month = intval($month); + // Basic validity checks + $this->mYear = $year > 0 ? $year : false; + $this->mMonth = ($month > 0 && $month < 13) ? $month : false; + // Given an optional year and month, we need to generate a timestamp + // to use as "WHERE rev_timestamp <= result" + // Examples: year = 2006 equals < 20070101 (+000000) + // year=2005, month=1 equals < 20050201 + // year=2005, month=12 equals < 20060101 + if ( !$this->mYear && !$this->mMonth ) { + return; + } + if ( $this->mYear ) { + $year = $this->mYear; + } else { + // If no year given, assume the current one + $year = gmdate( 'Y' ); + // If this month hasn't happened yet this year, go back to last year's month + if( $this->mMonth > gmdate( 'n' ) ) { + $year--; + } + } + if ( $this->mMonth ) { + $month = $this->mMonth + 1; + // For December, we want January 1 of the next year + if ($month > 12) { + $month = 1; + $year++; + } + } else { + // No month implies we want up to the end of the year in question + $month = 1; + $year++; + } + // Y2K38 bug + if ( $year > 2032 ) { + $year = 2032; + } + $ymd = (int)sprintf( "%04d%02d01", $year, $month ); + if ( $ymd > 20320101 ) { + $ymd = 20320101; + } + $this->mOffset = $this->mDb->timestamp( "${ymd}000000" ); + } } /** * Table-based display with a user-selectable sort order - * @addtogroup Pager + * @ingroup Pager */ abstract class TablePager extends IndexPager { var $mSort; @@ -635,7 +669,7 @@ abstract class TablePager extends IndexPager { global $wgStylePath; $tableClass = htmlspecialchars( $this->getTableClass() ); $sortClass = htmlspecialchars( $this->getSortHeaderClass() ); - + $s = "\n"; $fields = $this->getFieldNames(); @@ -662,7 +696,7 @@ abstract class TablePager extends IndexPager { $alt = htmlspecialchars( wfMsg( 'ascending_abbrev' ) ); } $image = htmlspecialchars( "$wgStylePath/common/images/$image" ); - $link = $this->makeLink( + $link = $this->makeLink( "\"$alt\"" . htmlspecialchars( $name ), $query ); $s .= "\n"; @@ -674,7 +708,7 @@ abstract class TablePager extends IndexPager { } } $s .= "\n"; - return $s; + return $s; } function getEndBody() { @@ -780,8 +814,8 @@ abstract class TablePager extends IndexPager { } /** - * Get elements for use in a method="get" form. - * Resubmits all defined elements of the $_GET array, except for a + * Get elements for use in a method="get" form. + * Resubmits all defined elements of the $_GET array, except for a * blacklist, passed in the $blacklist parameter. */ function getHiddenFields( $blacklist = array() ) { @@ -807,10 +841,10 @@ abstract class TablePager extends IndexPager { $url = $this->getTitle()->escapeLocalURL(); $msgSubmit = wfMsgHtml( 'table_pager_limit_submit' ); return - "" . - wfMsgHtml( 'table_pager_limit', $this->getLimitSelect() ) . + "" . + wfMsgHtml( 'table_pager_limit', $this->getLimitSelect() ) . "\n\n" . - $this->getHiddenFields( 'limit' ) . + $this->getHiddenFields( 'limit' ) . "\n"; } @@ -824,7 +858,7 @@ abstract class TablePager extends IndexPager { /** * Format a table cell. The return value should be HTML, but use an empty - * string not   for empty cells. Do not include the . + * string not   for empty cells. Do not include the . * * The current result row is available as $this->mCurrentRow, in case you * need more context.
$link
and and