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