Add @var to Pager classes
[lhc/web/wiklou.git] / includes / pager / IndexPager.php
1 <?php
2 /**
3 * Efficient paging for SQL queries.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Pager
22 */
23
24 use Wikimedia\Rdbms\IResultWrapper;
25 use Wikimedia\Rdbms\IDatabase;
26
27 /**
28 * IndexPager is an efficient pager which uses a (roughly unique) index in the
29 * data set to implement paging, rather than a "LIMIT offset,limit" clause.
30 * In MySQL, such a limit/offset clause requires counting through the
31 * specified number of offset rows to find the desired data, which can be
32 * expensive for large offsets.
33 *
34 * ReverseChronologicalPager is a child class of the abstract IndexPager, and
35 * contains some formatting and display code which is specific to the use of
36 * timestamps as indexes. Here is a synopsis of its operation:
37 *
38 * * The query is specified by the offset, limit and direction (dir)
39 * parameters, in addition to any subclass-specific parameters.
40 * * The offset is the non-inclusive start of the DB query. A row with an
41 * index value equal to the offset will never be shown.
42 * * The query may either be done backwards, where the rows are returned by
43 * the database in the opposite order to which they are displayed to the
44 * user, or forwards. This is specified by the "dir" parameter, dir=prev
45 * means backwards, anything else means forwards. The offset value
46 * specifies the start of the database result set, which may be either
47 * the start or end of the displayed data set. This allows "previous"
48 * links to be implemented without knowledge of the index value at the
49 * start of the previous page.
50 * * An additional row beyond the user-specified limit is always requested.
51 * This allows us to tell whether we should display a "next" link in the
52 * case of forwards mode, or a "previous" link in the case of backwards
53 * mode. Determining whether to display the other link (the one for the
54 * page before the start of the database result set) can be done
55 * heuristically by examining the offset.
56 *
57 * * An empty offset indicates that the offset condition should be omitted
58 * from the query. This naturally produces either the first page or the
59 * last page depending on the dir parameter.
60 *
61 * Subclassing the pager to implement concrete functionality should be fairly
62 * simple, please see the examples in HistoryAction.php and
63 * SpecialBlockList.php. You just need to override formatRow(),
64 * getQueryInfo() and getIndexField(). Don't forget to call the parent
65 * constructor if you override it.
66 *
67 * @ingroup Pager
68 */
69 abstract class IndexPager extends ContextSource implements Pager {
70 /**
71 * Constants for the $mDefaultDirection field.
72 *
73 * These are boolean for historical reasons and should stay boolean for backwards-compatibility.
74 */
75 const DIR_ASCENDING = false;
76 const DIR_DESCENDING = true;
77
78 /** @var WebRequest */
79 public $mRequest;
80 /** @var int[] List of default entry limit options to be presented to clients */
81 public $mLimitsShown = [ 20, 50, 100, 250, 500 ];
82 /** @var int The default entry limit choosen for clients */
83 public $mDefaultLimit = 50;
84 /** @var mixed The starting point to enumerate entries */
85 public $mOffset;
86 /** @var int The maximum number of entries to show */
87 public $mLimit;
88 /** @var bool Whether the listing query completed */
89 public $mQueryDone = false;
90 /** @var IDatabase */
91 public $mDb;
92 /** @var stdClass|bool|null Extra row fetched at the end to see if the end was reached */
93 public $mPastTheEndRow;
94
95 /**
96 * The index to actually be used for ordering. This is a single column,
97 * for one ordering, even if multiple orderings are supported.
98 * @var string
99 */
100 protected $mIndexField;
101 /**
102 * An array of secondary columns to order by. These fields are not part of the offset.
103 * This is a column list for one ordering, even if multiple orderings are supported.
104 * @var string[]
105 */
106 protected $mExtraSortFields;
107 /** For pages that support multiple types of ordering, which one to use.
108 * @var string|null
109 */
110 protected $mOrderType;
111 /**
112 * $mDefaultDirection gives the direction to use when sorting results:
113 * DIR_ASCENDING or DIR_DESCENDING. If $mIsBackwards is set, we start from
114 * the opposite end, but we still sort the page itself according to
115 * $mDefaultDirection. For example, if $mDefaultDirection is DIR_ASCENDING
116 * but we're going backwards, we'll display the last page of results, but
117 * the last result will be at the bottom, not the top.
118 *
119 * Like $mIndexField, $mDefaultDirection will be a single value even if the
120 * class supports multiple default directions for different order types.
121 * @var bool
122 */
123 public $mDefaultDirection;
124 /** @var bool */
125 public $mIsBackwards;
126
127 /** @var bool True if the current result set is the first one */
128 public $mIsFirst;
129 /** @var bool */
130 public $mIsLast;
131
132 /** @var mixed */
133 protected $mLastShown;
134 /** @var mixed */
135 protected $mFirstShown;
136 /** @var mixed */
137 protected $mPastTheEndIndex;
138 /** @var array */
139 protected $mDefaultQuery;
140 /** @var string */
141 protected $mNavigationBar;
142
143 /**
144 * Whether to include the offset in the query
145 * @var bool
146 */
147 protected $mIncludeOffset = false;
148
149 /**
150 * Result object for the query. Warning: seek before use.
151 *
152 * @var IResultWrapper
153 */
154 public $mResult;
155
156 public function __construct( IContextSource $context = null ) {
157 if ( $context ) {
158 $this->setContext( $context );
159 }
160
161 $this->mRequest = $this->getRequest();
162
163 # NB: the offset is quoted, not validated. It is treated as an
164 # arbitrary string to support the widest variety of index types. Be
165 # careful outputting it into HTML!
166 $this->mOffset = $this->mRequest->getText( 'offset' );
167
168 # Use consistent behavior for the limit options
169 $this->mDefaultLimit = $this->getUser()->getIntOption( 'rclimit' );
170 if ( !$this->mLimit ) {
171 // Don't override if a subclass calls $this->setLimit() in its constructor.
172 list( $this->mLimit, /* $offset */ ) = $this->mRequest->getLimitOffset();
173 }
174
175 $this->mIsBackwards = ( $this->mRequest->getVal( 'dir' ) == 'prev' );
176 # Let the subclass set the DB here; otherwise use a replica DB for the current wiki
177 $this->mDb = $this->mDb ?: wfGetDB( DB_REPLICA );
178
179 $index = $this->getIndexField(); // column to sort on
180 $extraSort = $this->getExtraSortFields(); // extra columns to sort on for query planning
181 $order = $this->mRequest->getVal( 'order' );
182 if ( is_array( $index ) && isset( $index[$order] ) ) {
183 $this->mOrderType = $order;
184 $this->mIndexField = $index[$order];
185 $this->mExtraSortFields = isset( $extraSort[$order] )
186 ? (array)$extraSort[$order]
187 : [];
188 } elseif ( is_array( $index ) ) {
189 # First element is the default
190 $this->mIndexField = reset( $index );
191 $this->mOrderType = key( $index );
192 $this->mExtraSortFields = isset( $extraSort[$this->mOrderType] )
193 ? (array)$extraSort[$this->mOrderType]
194 : [];
195 } else {
196 # $index is not an array
197 $this->mOrderType = null;
198 $this->mIndexField = $index;
199 $this->mExtraSortFields = (array)$extraSort;
200 }
201
202 if ( !isset( $this->mDefaultDirection ) ) {
203 $dir = $this->getDefaultDirections();
204 $this->mDefaultDirection = is_array( $dir )
205 ? $dir[$this->mOrderType]
206 : $dir;
207 }
208 }
209
210 /**
211 * Get the Database object in use
212 *
213 * @return IDatabase
214 */
215 public function getDatabase() {
216 return $this->mDb;
217 }
218
219 /**
220 * Do the query, using information from the object context. This function
221 * has been kept minimal to make it overridable if necessary, to allow for
222 * result sets formed from multiple DB queries.
223 */
224 public function doQuery() {
225 # Use the child class name for profiling
226 $fname = __METHOD__ . ' (' . static::class . ')';
227 $section = Profiler::instance()->scopedProfileIn( $fname );
228
229 $descending = $this->mIsBackwards
230 ? ( $this->mDefaultDirection === self::DIR_DESCENDING )
231 : ( $this->mDefaultDirection === self::DIR_ASCENDING );
232
233 # Plus an extra row so that we can tell the "next" link should be shown
234 $queryLimit = $this->mLimit + 1;
235
236 if ( $this->mOffset == '' ) {
237 $isFirst = true;
238 } else {
239 // If there's an offset, we may or may not be at the first entry.
240 // The only way to tell is to run the query in the opposite
241 // direction see if we get a row.
242 $oldIncludeOffset = $this->mIncludeOffset;
243 $this->mIncludeOffset = !$this->mIncludeOffset;
244 $isFirst = !$this->reallyDoQuery( $this->mOffset, 1, !$descending )->numRows();
245 $this->mIncludeOffset = $oldIncludeOffset;
246 }
247
248 $this->mResult = $this->reallyDoQuery(
249 $this->mOffset,
250 $queryLimit,
251 $descending
252 );
253
254 $this->extractResultInfo( $isFirst, $queryLimit, $this->mResult );
255 $this->mQueryDone = true;
256
257 $this->preprocessResults( $this->mResult );
258 $this->mResult->rewind(); // Paranoia
259 }
260
261 /**
262 * @return IResultWrapper The result wrapper.
263 */
264 function getResult() {
265 return $this->mResult;
266 }
267
268 /**
269 * Set the offset from an other source than the request
270 *
271 * @param int|string $offset
272 */
273 function setOffset( $offset ) {
274 $this->mOffset = $offset;
275 }
276
277 /**
278 * Set the limit from an other source than the request
279 *
280 * Verifies limit is between 1 and 5000
281 *
282 * @param int|string $limit
283 */
284 function setLimit( $limit ) {
285 $limit = (int)$limit;
286 // WebRequest::getLimitOffset() puts a cap of 5000, so do same here.
287 if ( $limit > 5000 ) {
288 $limit = 5000;
289 }
290 if ( $limit > 0 ) {
291 $this->mLimit = $limit;
292 }
293 }
294
295 /**
296 * Get the current limit
297 *
298 * @return int
299 */
300 function getLimit() {
301 return $this->mLimit;
302 }
303
304 /**
305 * Set whether a row matching exactly the offset should be also included
306 * in the result or not. By default this is not the case, but when the
307 * offset is user-supplied this might be wanted.
308 *
309 * @param bool $include
310 */
311 public function setIncludeOffset( $include ) {
312 $this->mIncludeOffset = $include;
313 }
314
315 /**
316 * Extract some useful data from the result object for use by
317 * the navigation bar, put it into $this
318 *
319 * @param bool $isFirst False if there are rows before those fetched (i.e.
320 * if a "previous" link would make sense)
321 * @param int $limit Exact query limit
322 * @param IResultWrapper $res
323 */
324 function extractResultInfo( $isFirst, $limit, IResultWrapper $res ) {
325 $numRows = $res->numRows();
326 if ( $numRows ) {
327 # Remove any table prefix from index field
328 $parts = explode( '.', $this->mIndexField );
329 $indexColumn = end( $parts );
330
331 $row = $res->fetchRow();
332 $firstIndex = $row[$indexColumn];
333
334 # Discard the extra result row if there is one
335 if ( $numRows > $this->mLimit && $numRows > 1 ) {
336 $res->seek( $numRows - 1 );
337 $this->mPastTheEndRow = $res->fetchObject();
338 $this->mPastTheEndIndex = $this->mPastTheEndRow->$indexColumn;
339 $res->seek( $numRows - 2 );
340 $row = $res->fetchRow();
341 $lastIndex = $row[$indexColumn];
342 } else {
343 $this->mPastTheEndRow = null;
344 # Setting indexes to an empty string means that they will be
345 # omitted if they would otherwise appear in URLs. It just so
346 # happens that this is the right thing to do in the standard
347 # UI, in all the relevant cases.
348 $this->mPastTheEndIndex = '';
349 $res->seek( $numRows - 1 );
350 $row = $res->fetchRow();
351 $lastIndex = $row[$indexColumn];
352 }
353 } else {
354 $firstIndex = '';
355 $lastIndex = '';
356 $this->mPastTheEndRow = null;
357 $this->mPastTheEndIndex = '';
358 }
359
360 if ( $this->mIsBackwards ) {
361 $this->mIsFirst = ( $numRows < $limit );
362 $this->mIsLast = $isFirst;
363 $this->mLastShown = $firstIndex;
364 $this->mFirstShown = $lastIndex;
365 } else {
366 $this->mIsFirst = $isFirst;
367 $this->mIsLast = ( $numRows < $limit );
368 $this->mLastShown = $lastIndex;
369 $this->mFirstShown = $firstIndex;
370 }
371 }
372
373 /**
374 * Get some text to go in brackets in the "function name" part of the SQL comment
375 *
376 * @return string
377 */
378 function getSqlComment() {
379 return static::class;
380 }
381
382 /**
383 * Do a query with specified parameters, rather than using the object
384 * context
385 *
386 * @param string $offset Index offset, inclusive
387 * @param int $limit Exact query limit
388 * @param bool $descending Query direction, false for ascending, true for descending
389 * @return IResultWrapper
390 */
391 public function reallyDoQuery( $offset, $limit, $descending ) {
392 list( $tables, $fields, $conds, $fname, $options, $join_conds ) =
393 $this->buildQueryInfo( $offset, $limit, $descending );
394
395 return $this->mDb->select( $tables, $fields, $conds, $fname, $options, $join_conds );
396 }
397
398 /**
399 * Build variables to use by the database wrapper.
400 *
401 * @param string $offset Index offset, inclusive
402 * @param int $limit Exact query limit
403 * @param bool $descending Query direction, false for ascending, true for descending
404 * @return array
405 */
406 protected function buildQueryInfo( $offset, $limit, $descending ) {
407 $fname = __METHOD__ . ' (' . $this->getSqlComment() . ')';
408 $info = $this->getQueryInfo();
409 $tables = $info['tables'];
410 $fields = $info['fields'];
411 $conds = $info['conds'] ?? [];
412 $options = $info['options'] ?? [];
413 $join_conds = $info['join_conds'] ?? [];
414 $sortColumns = array_merge( [ $this->mIndexField ], $this->mExtraSortFields );
415 if ( $descending ) {
416 $options['ORDER BY'] = $sortColumns;
417 $operator = $this->mIncludeOffset ? '>=' : '>';
418 } else {
419 $orderBy = [];
420 foreach ( $sortColumns as $col ) {
421 $orderBy[] = $col . ' DESC';
422 }
423 $options['ORDER BY'] = $orderBy;
424 $operator = $this->mIncludeOffset ? '<=' : '<';
425 }
426 if ( $offset != '' ) {
427 $conds[] = $this->mIndexField . $operator . $this->mDb->addQuotes( $offset );
428 }
429 $options['LIMIT'] = intval( $limit );
430 return [ $tables, $fields, $conds, $fname, $options, $join_conds ];
431 }
432
433 /**
434 * Pre-process results; useful for performing batch existence checks, etc.
435 *
436 * @param IResultWrapper $result
437 */
438 protected function preprocessResults( $result ) {
439 }
440
441 /**
442 * Get the formatted result list. Calls getStartBody(), formatRow() and
443 * getEndBody(), concatenates the results and returns them.
444 *
445 * @return string
446 */
447 public function getBody() {
448 if ( !$this->mQueryDone ) {
449 $this->doQuery();
450 }
451
452 if ( $this->mResult->numRows() ) {
453 # Do any special query batches before display
454 $this->doBatchLookups();
455 }
456
457 # Don't use any extra rows returned by the query
458 $numRows = min( $this->mResult->numRows(), $this->mLimit );
459
460 $s = $this->getStartBody();
461 if ( $numRows ) {
462 if ( $this->mIsBackwards ) {
463 for ( $i = $numRows - 1; $i >= 0; $i-- ) {
464 $this->mResult->seek( $i );
465 $row = $this->mResult->fetchObject();
466 $s .= $this->formatRow( $row );
467 }
468 } else {
469 $this->mResult->seek( 0 );
470 for ( $i = 0; $i < $numRows; $i++ ) {
471 $row = $this->mResult->fetchObject();
472 $s .= $this->formatRow( $row );
473 }
474 }
475 } else {
476 $s .= $this->getEmptyBody();
477 }
478 $s .= $this->getEndBody();
479 return $s;
480 }
481
482 /**
483 * Make a self-link
484 *
485 * @param string $text Text displayed on the link
486 * @param array|null $query Associative array of parameter to be in the query string
487 * @param string|null $type Link type used to create additional attributes, like "rel", "class" or
488 * "title". Valid values (non-exhaustive list): 'first', 'last', 'prev', 'next', 'asc', 'desc'.
489 * @return string HTML fragment
490 */
491 function makeLink( $text, array $query = null, $type = null ) {
492 if ( $query === null ) {
493 return $text;
494 }
495
496 $attrs = [];
497 if ( in_array( $type, [ 'prev', 'next' ] ) ) {
498 $attrs['rel'] = $type;
499 }
500
501 if ( in_array( $type, [ 'asc', 'desc' ] ) ) {
502 $attrs['title'] = $this->msg( $type == 'asc' ? 'sort-ascending' : 'sort-descending' )->text();
503 }
504
505 if ( $type ) {
506 $attrs['class'] = "mw-{$type}link";
507 }
508
509 return Linker::linkKnown(
510 $this->getTitle(),
511 $text,
512 $attrs,
513 $query + $this->getDefaultQuery()
514 );
515 }
516
517 /**
518 * Called from getBody(), before getStartBody() is called and
519 * after doQuery() was called. This will be called only if there
520 * are rows in the result set.
521 *
522 * @return void
523 */
524 protected function doBatchLookups() {
525 }
526
527 /**
528 * Hook into getBody(), allows text to be inserted at the start. This
529 * will be called even if there are no rows in the result set.
530 *
531 * @return string
532 */
533 protected function getStartBody() {
534 return '';
535 }
536
537 /**
538 * Hook into getBody() for the end of the list
539 *
540 * @return string
541 */
542 protected function getEndBody() {
543 return '';
544 }
545
546 /**
547 * Hook into getBody(), for the bit between the start and the
548 * end when there are no rows
549 *
550 * @return string
551 */
552 protected function getEmptyBody() {
553 return '';
554 }
555
556 /**
557 * Get an array of query parameters that should be put into self-links.
558 * By default, all parameters passed in the URL are used, except for a
559 * short blacklist.
560 *
561 * @return array Associative array
562 */
563 function getDefaultQuery() {
564 if ( !isset( $this->mDefaultQuery ) ) {
565 $this->mDefaultQuery = $this->getRequest()->getQueryValues();
566 unset( $this->mDefaultQuery['title'] );
567 unset( $this->mDefaultQuery['dir'] );
568 unset( $this->mDefaultQuery['offset'] );
569 unset( $this->mDefaultQuery['limit'] );
570 unset( $this->mDefaultQuery['order'] );
571 unset( $this->mDefaultQuery['month'] );
572 unset( $this->mDefaultQuery['year'] );
573 }
574 return $this->mDefaultQuery;
575 }
576
577 /**
578 * Get the number of rows in the result set
579 *
580 * @return int
581 */
582 function getNumRows() {
583 if ( !$this->mQueryDone ) {
584 $this->doQuery();
585 }
586 return $this->mResult->numRows();
587 }
588
589 /**
590 * Get a URL query array for the prev, next, first and last links.
591 *
592 * @return array
593 */
594 function getPagingQueries() {
595 if ( !$this->mQueryDone ) {
596 $this->doQuery();
597 }
598
599 # Don't announce the limit everywhere if it's the default
600 $urlLimit = $this->mLimit == $this->mDefaultLimit ? null : $this->mLimit;
601
602 if ( $this->mIsFirst ) {
603 $prev = false;
604 $first = false;
605 } else {
606 $prev = [
607 'dir' => 'prev',
608 'offset' => $this->mFirstShown,
609 'limit' => $urlLimit
610 ];
611 $first = [ 'limit' => $urlLimit ];
612 }
613 if ( $this->mIsLast ) {
614 $next = false;
615 $last = false;
616 } else {
617 $next = [ 'offset' => $this->mLastShown, 'limit' => $urlLimit ];
618 $last = [ 'dir' => 'prev', 'limit' => $urlLimit ];
619 }
620 return [
621 'prev' => $prev,
622 'next' => $next,
623 'first' => $first,
624 'last' => $last
625 ];
626 }
627
628 /**
629 * Returns whether to show the "navigation bar"
630 *
631 * @return bool
632 */
633 function isNavigationBarShown() {
634 if ( !$this->mQueryDone ) {
635 $this->doQuery();
636 }
637 // Hide navigation by default if there is nothing to page
638 return !( $this->mIsFirst && $this->mIsLast );
639 }
640
641 /**
642 * Get paging links. If a link is disabled, the item from $disabledTexts
643 * will be used. If there is no such item, the unlinked text from
644 * $linkTexts will be used. Both $linkTexts and $disabledTexts are arrays
645 * of HTML.
646 *
647 * @param array $linkTexts
648 * @param array $disabledTexts
649 * @return array
650 */
651 function getPagingLinks( $linkTexts, $disabledTexts = [] ) {
652 $queries = $this->getPagingQueries();
653 $links = [];
654
655 foreach ( $queries as $type => $query ) {
656 if ( $query !== false ) {
657 $links[$type] = $this->makeLink(
658 $linkTexts[$type],
659 $queries[$type],
660 $type
661 );
662 } elseif ( isset( $disabledTexts[$type] ) ) {
663 $links[$type] = $disabledTexts[$type];
664 } else {
665 $links[$type] = $linkTexts[$type];
666 }
667 }
668
669 return $links;
670 }
671
672 function getLimitLinks() {
673 $links = [];
674 if ( $this->mIsBackwards ) {
675 $offset = $this->mPastTheEndIndex;
676 } else {
677 $offset = $this->mOffset;
678 }
679 foreach ( $this->mLimitsShown as $limit ) {
680 $links[] = $this->makeLink(
681 $this->getLanguage()->formatNum( $limit ),
682 [ 'offset' => $offset, 'limit' => $limit ],
683 'num'
684 );
685 }
686 return $links;
687 }
688
689 /**
690 * Abstract formatting function. This should return an HTML string
691 * representing the result row $row. Rows will be concatenated and
692 * returned by getBody()
693 *
694 * @param array|stdClass $row Database row
695 * @return string
696 */
697 abstract function formatRow( $row );
698
699 /**
700 * This function should be overridden to provide all parameters
701 * needed for the main paged query. It returns an associative
702 * array with the following elements:
703 * tables => Table(s) for passing to Database::select()
704 * fields => Field(s) for passing to Database::select(), may be *
705 * conds => WHERE conditions
706 * options => option array
707 * join_conds => JOIN conditions
708 *
709 * @return array
710 */
711 abstract function getQueryInfo();
712
713 /**
714 * This function should be overridden to return the name of the index fi-
715 * eld. If the pager supports multiple orders, it may return an array of
716 * 'querykey' => 'indexfield' pairs, so that a request with &count=querykey
717 * will use indexfield to sort. In this case, the first returned key is
718 * the default.
719 *
720 * Needless to say, it's really not a good idea to use a non-unique index
721 * for this! That won't page right.
722 *
723 * @return string|string[]
724 */
725 abstract function getIndexField();
726
727 /**
728 * This function should be overridden to return the names of secondary columns
729 * to order by in addition to the column in getIndexField(). These fields will
730 * not be used in the pager offset or in any links for users.
731 *
732 * If getIndexField() returns an array of 'querykey' => 'indexfield' pairs then
733 * this must return a corresponding array of 'querykey' => [ fields... ] pairs
734 * in order for a request with &count=querykey to use [ fields... ] to sort.
735 *
736 * This is useful for pagers that GROUP BY a unique column (say page_id)
737 * and ORDER BY another (say page_len). Using GROUP BY and ORDER BY both on
738 * page_len,page_id avoids temp tables (given a page_len index). This would
739 * also work if page_id was non-unique but we had a page_len,page_id index.
740 *
741 * @return string[]|array[]
742 */
743 protected function getExtraSortFields() {
744 return [];
745 }
746
747 /**
748 * Return the default sorting direction: DIR_ASCENDING or DIR_DESCENDING.
749 * You can also have an associative array of ordertype => dir,
750 * if multiple order types are supported. In this case getIndexField()
751 * must return an array, and the keys of that must exactly match the keys
752 * of this.
753 *
754 * For backward compatibility, this method's return value will be ignored
755 * if $this->mDefaultDirection is already set when the constructor is
756 * called, for instance if it's statically initialized. In that case the
757 * value of that variable (which must be a boolean) will be used.
758 *
759 * Note that despite its name, this does not return the value of the
760 * $this->mDefaultDirection member variable. That's the default for this
761 * particular instantiation, which is a single value. This is the set of
762 * all defaults for the class.
763 *
764 * @return bool
765 */
766 protected function getDefaultDirections() {
767 return self::DIR_ASCENDING;
768 }
769 }