Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 82 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
LqtDiscussionPager | |
0.00% |
0 / 82 |
|
0.00% |
0 / 10 |
930 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getPageLimit | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 | |||
getQueryInfo | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
getRows | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
42 | |||
formatRow | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getIndexField | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
30 | |||
getDefaultDirections | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
30 | |||
getNavigationBar | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
30 | |||
getModuleStyles | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getNavClass | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | use MediaWiki\Pager\IndexPager; |
4 | |
5 | class LqtDiscussionPager extends IndexPager { |
6 | |
7 | /** @var Article|false */ |
8 | protected $article; |
9 | |
10 | /** @var string|false */ |
11 | protected $orderType; |
12 | |
13 | public function __construct( $article, $orderType ) { |
14 | $this->article = $article; |
15 | $this->orderType = $orderType; |
16 | |
17 | parent::__construct(); |
18 | |
19 | $this->setLimit( min( 50, $this->getPageLimit() ) ); |
20 | } |
21 | |
22 | public function getPageLimit() { |
23 | $article = $this->article; |
24 | |
25 | $requestedLimit = $this->getRequest()->getIntOrNull( 'limit' ); |
26 | if ( $requestedLimit ) { |
27 | return $requestedLimit; |
28 | } |
29 | |
30 | if ( $article->getPage()->exists() ) { |
31 | $pout = $article->getParserOutput(); |
32 | $setLimit = $pout->getPageProperty( 'lqt-page-limit' ); |
33 | |
34 | if ( $setLimit ) { |
35 | return $setLimit; |
36 | } |
37 | } |
38 | |
39 | global $wgLiquidThreadsDefaultPageLimit; |
40 | return $wgLiquidThreadsDefaultPageLimit; |
41 | } |
42 | |
43 | public function getQueryInfo() { |
44 | $queryInfo = [ |
45 | 'tables' => [ 'thread' ], |
46 | 'fields' => '*', |
47 | 'conds' => [ |
48 | Threads::articleClause( $this->article->getPage() ), |
49 | Threads::topLevelClause(), |
50 | $this->mDb->expr( 'thread_type', '!=', Threads::TYPE_DELETED ), |
51 | ], |
52 | ]; |
53 | |
54 | return $queryInfo; |
55 | } |
56 | |
57 | public function getRows() { |
58 | if ( !$this->mQueryDone ) { |
59 | $this->doQuery(); |
60 | } |
61 | |
62 | # Don't use any extra rows returned by the query |
63 | $numRows = min( $this->mResult->numRows(), $this->mLimit ); |
64 | |
65 | $rows = []; |
66 | |
67 | if ( $numRows ) { |
68 | if ( $this->mIsBackwards ) { |
69 | for ( $i = $numRows - 1; $i >= 0; $i-- ) { |
70 | $this->mResult->seek( $i ); |
71 | $row = $this->mResult->fetchObject(); |
72 | $rows[] = $row; |
73 | } |
74 | } else { |
75 | $this->mResult->seek( 0 ); |
76 | for ( $i = 0; $i < $numRows; $i++ ) { |
77 | $row = $this->mResult->fetchObject(); |
78 | $rows[] = $row; |
79 | } |
80 | } |
81 | } |
82 | |
83 | return $rows; |
84 | } |
85 | |
86 | public function formatRow( $row ) { |
87 | // No-op, we get the list of rows from getRows() |
88 | // Return a string to make the function signature happy |
89 | return ''; |
90 | } |
91 | |
92 | public function getIndexField() { |
93 | switch ( $this->orderType ) { |
94 | case TalkpageView::LQT_NEWEST_CHANGES: |
95 | return 'thread_sortkey'; |
96 | case TalkpageView::LQT_OLDEST_THREADS: |
97 | case TalkpageView::LQT_NEWEST_THREADS: |
98 | return 'thread_created'; |
99 | default: |
100 | throw new LogicException( "Unknown sort order " . $this->orderType ); |
101 | } |
102 | } |
103 | |
104 | public function getDefaultDirections() { |
105 | switch ( $this->orderType ) { |
106 | case TalkpageView::LQT_NEWEST_CHANGES: |
107 | case TalkpageView::LQT_NEWEST_THREADS: |
108 | return true; // Descending |
109 | case TalkpageView::LQT_OLDEST_THREADS: |
110 | return false; // Ascending |
111 | default: |
112 | throw new LogicException( "Unknown sort order " . $this->orderType ); |
113 | } |
114 | } |
115 | |
116 | /** |
117 | * A navigation bar with images |
118 | * Stolen from TablePager because it's pretty. |
119 | * @return string |
120 | */ |
121 | public function getNavigationBar() { |
122 | if ( !$this->isNavigationBarShown() ) { |
123 | return ''; |
124 | } |
125 | |
126 | $this->getOutput()->enableOOUI(); |
127 | |
128 | $types = [ 'first', 'prev', 'next', 'last' ]; |
129 | |
130 | $queries = $this->getPagingQueries(); |
131 | |
132 | $buttons = []; |
133 | |
134 | $title = $this->getTitle(); |
135 | |
136 | foreach ( $types as $type ) { |
137 | $buttons[] = new \OOUI\ButtonWidget( [ |
138 | // Messages used here: |
139 | // * table_pager_first |
140 | // * table_pager_prev |
141 | // * table_pager_next |
142 | // * table_pager_last |
143 | 'classes' => [ 'TablePager-button-' . $type ], |
144 | 'flags' => [ 'progressive' ], |
145 | 'framed' => false, |
146 | 'label' => $this->msg( 'table_pager_' . $type )->text(), |
147 | 'href' => $queries[ $type ] ? |
148 | $title->getLinkURL( $queries[ $type ] + $this->getDefaultQuery() ) : |
149 | null, |
150 | 'icon' => $type === 'prev' ? 'previous' : $type, |
151 | 'disabled' => $queries[ $type ] === false |
152 | ] ); |
153 | } |
154 | return new \OOUI\ButtonGroupWidget( [ |
155 | 'classes' => [ $this->getNavClass() ], |
156 | 'items' => $buttons, |
157 | ] ); |
158 | } |
159 | |
160 | /** |
161 | * @inheritDoc |
162 | */ |
163 | public function getModuleStyles() { |
164 | return array_merge( |
165 | parent::getModuleStyles(), [ 'oojs-ui.styles.icons-movement' ] |
166 | ); |
167 | } |
168 | |
169 | public function getNavClass() { |
170 | return 'TablePager_nav'; |
171 | } |
172 | } |