Merge "resourceloader: Remove comment about XmlJsCode wrapper"
[lhc/web/wiklou.git] / includes / specials / pagers / ProtectedTitlesPager.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @ingroup Pager
20 */
21
22 /**
23 * @ingroup Pager
24 */
25 class ProtectedTitlesPager extends AlphabeticPager {
26
27 /**
28 * @var SpecialProtectedtitles
29 */
30 public $mForm;
31
32 /**
33 * @var array
34 */
35 public $mConds;
36
37 /** @var string|null */
38 private $level;
39
40 /** @var int|null */
41 private $namespace;
42
43 /**
44 * @param SpecialProtectedtitles $form
45 * @param array $conds
46 * @param string|null $type
47 * @param string|null $level
48 * @param int|null $namespace
49 * @param string|null $sizetype
50 * @param int|null $size
51 */
52 public function __construct( $form, $conds, $type, $level, $namespace,
53 $sizetype = '', $size = 0
54 ) {
55 $this->mForm = $form;
56 $this->mConds = $conds;
57 $this->level = $level;
58 $this->namespace = $namespace;
59 parent::__construct( $form->getContext() );
60 }
61
62 protected function getStartBody() {
63 # Do a link batch query
64 $this->mResult->seek( 0 );
65 $lb = new LinkBatch;
66
67 foreach ( $this->mResult as $row ) {
68 $lb->add( $row->pt_namespace, $row->pt_title );
69 }
70
71 $lb->execute();
72
73 return '';
74 }
75
76 /**
77 * @return Title
78 */
79 function getTitle() {
80 return $this->mForm->getPageTitle();
81 }
82
83 function formatRow( $row ) {
84 return $this->mForm->formatRow( $row );
85 }
86
87 /**
88 * @return array
89 */
90 function getQueryInfo() {
91 $conds = $this->mConds;
92 $conds[] = 'pt_expiry > ' . $this->mDb->addQuotes( $this->mDb->timestamp() ) .
93 ' OR pt_expiry IS NULL';
94 if ( $this->level ) {
95 $conds['pt_create_perm'] = $this->level;
96 }
97
98 if ( $this->namespace !== null ) {
99 $conds[] = 'pt_namespace=' . $this->mDb->addQuotes( $this->namespace );
100 }
101
102 return [
103 'tables' => 'protected_titles',
104 'fields' => [ 'pt_namespace', 'pt_title', 'pt_create_perm',
105 'pt_expiry', 'pt_timestamp' ],
106 'conds' => $conds
107 ];
108 }
109
110 function getIndexField() {
111 return 'pt_timestamp';
112 }
113 }