1 | <?php |
||
20 | class SimpleSubPageFinder implements SubPageFinder, SubPageCounter { |
||
21 | |||
22 | const OPT_INCLUDE_REDIRECTS = 'redirects'; |
||
23 | const OPT_LIMIT = 'limit'; |
||
24 | const OPT_OFFSET = 'offset'; |
||
25 | const OPT_SORT_ORDER = 'sort'; |
||
26 | const SORT_ASCENDING = 'asc'; |
||
27 | const SORT_DESCENDING = 'desc'; |
||
28 | |||
29 | /** |
||
30 | * @var DBConnectionProvider |
||
31 | */ |
||
32 | private $connectionProvider; |
||
33 | |||
34 | /** |
||
35 | * @var array |
||
36 | */ |
||
37 | private $options; |
||
38 | |||
39 | /** |
||
40 | * @since 1.2 |
||
41 | * |
||
42 | * @param DBConnectionProvider $connectionProvider |
||
43 | */ |
||
44 | 27 | public function __construct( DBConnectionProvider $connectionProvider ) { |
|
54 | |||
55 | /** |
||
56 | * @param string $option |
||
57 | * @param mixed $value |
||
58 | */ |
||
59 | 19 | private function setOption( $option, $value ) { |
|
62 | |||
63 | /** |
||
64 | * @see SubPageFinder::setLimit |
||
65 | * |
||
66 | * @since 1.2 |
||
67 | * |
||
68 | * @param int $limit |
||
69 | * |
||
70 | * @throws InvalidArgumentException |
||
71 | */ |
||
72 | 19 | public function setLimit( $limit ) { |
|
79 | |||
80 | /** |
||
81 | * @param string $sortOrder |
||
82 | * |
||
83 | * @throws InvalidArgumentException |
||
84 | */ |
||
85 | 19 | public function setSortOrder( $sortOrder ) { |
|
92 | |||
93 | /** |
||
94 | * @see SubPageFinder::setIncludeRedirects |
||
95 | * |
||
96 | * @since 1.4.0 |
||
97 | * |
||
98 | * @param bool $includeRedirects |
||
99 | * |
||
100 | * @throws InvalidArgumentException |
||
101 | */ |
||
102 | 19 | public function setIncludeRedirects( $includeRedirects ) { |
|
109 | |||
110 | /** |
||
111 | * @see SubPageFinder::setOffset |
||
112 | * |
||
113 | * @since 1.2 |
||
114 | * |
||
115 | * @param int $offset |
||
116 | * |
||
117 | * @throws InvalidArgumentException |
||
118 | */ |
||
119 | public function setOffset( $offset ) { |
||
126 | |||
127 | /** |
||
128 | * @see SubPageFinder::getSubPagesFor |
||
129 | * |
||
130 | * @since 1.2 |
||
131 | * |
||
132 | * @param Title $title |
||
133 | * |
||
134 | * @return Title[] |
||
135 | */ |
||
136 | 22 | public function getSubPagesFor( Title $title ) { |
|
137 | /** |
||
138 | * @var \DatabaseBase $dbr |
||
139 | */ |
||
140 | 22 | $dbr = $this->connectionProvider->getConnection(); |
|
141 | |||
142 | 22 | $titleArray = TitleArray::newFromResult( |
|
143 | 22 | $dbr->select( 'page', |
|
144 | 22 | [ 'page_id', 'page_namespace', 'page_title', 'page_is_redirect' ], |
|
145 | 22 | $this->getConditions( $title ), |
|
146 | 22 | __METHOD__, |
|
147 | 22 | $this->getOptions() |
|
148 | ) |
||
149 | ); |
||
150 | |||
151 | 22 | $this->connectionProvider->releaseConnection(); |
|
152 | |||
153 | 22 | return iterator_to_array( $titleArray ); |
|
154 | } |
||
155 | |||
156 | /** |
||
157 | * @see SubPageCounter::countSubPages |
||
158 | * |
||
159 | * @since 1.2 |
||
160 | * |
||
161 | * @param Title $title |
||
162 | * |
||
163 | * @return integer |
||
164 | */ |
||
165 | 4 | public function countSubPages( Title $title ) { |
|
184 | |||
185 | /** |
||
186 | * @since 1.2 |
||
187 | * |
||
188 | * @param Title $title |
||
189 | * |
||
190 | * @return array |
||
191 | */ |
||
192 | 26 | private function getConditions( Title $title ) { |
|
209 | |||
210 | /** |
||
211 | * @since 1.2 |
||
212 | * |
||
213 | * @return array |
||
214 | */ |
||
215 | 22 | private function getOptions() { |
|
227 | |||
228 | } |
||
229 |