Merge "Improve docs for Title::getInternalURL/getCanonicalURL"
[lhc/web/wiklou.git] / includes / specials / pagers / NewPagesPager.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 NewPagesPager extends ReverseChronologicalPager {
26
27 /**
28 * @var FormOptions
29 */
30 protected $opts;
31
32 /**
33 * @var SpecialNewpages
34 */
35 protected $mForm;
36
37 /**
38 * @param SpecialNewpages $form
39 * @param FormOptions $opts
40 */
41 public function __construct( $form, FormOptions $opts ) {
42 parent::__construct( $form->getContext() );
43 $this->mForm = $form;
44 $this->opts = $opts;
45 }
46
47 function getQueryInfo() {
48 $rcQuery = RecentChange::getQueryInfo();
49
50 $conds = [];
51 $conds['rc_new'] = 1;
52
53 $namespace = $this->opts->getValue( 'namespace' );
54 $namespace = ( $namespace === 'all' ) ? false : intval( $namespace );
55
56 $username = $this->opts->getValue( 'username' );
57 $user = Title::makeTitleSafe( NS_USER, $username );
58
59 $size = abs( intval( $this->opts->getValue( 'size' ) ) );
60 if ( $size > 0 ) {
61 if ( $this->opts->getValue( 'size-mode' ) === 'max' ) {
62 $conds[] = 'page_len <= ' . $size;
63 } else {
64 $conds[] = 'page_len >= ' . $size;
65 }
66 }
67
68 if ( $namespace !== false ) {
69 if ( $this->opts->getValue( 'invert' ) ) {
70 $conds[] = 'rc_namespace != ' . $this->mDb->addQuotes( $namespace );
71 } else {
72 $conds['rc_namespace'] = $namespace;
73 }
74 }
75
76 if ( $user ) {
77 $conds[] = ActorMigration::newMigration()->getWhere(
78 $this->mDb, 'rc_user', User::newFromName( $user->getText(), false ), false
79 )['conds'];
80 } elseif ( User::groupHasPermission( '*', 'createpage' ) &&
81 $this->opts->getValue( 'hideliu' )
82 ) {
83 # If anons cannot make new pages, don't "exclude logged in users"!
84 $conds[] = ActorMigration::newMigration()->isAnon( $rcQuery['fields']['rc_user'] );
85 }
86
87 # If this user cannot see patrolled edits or they are off, don't do dumb queries!
88 if ( $this->opts->getValue( 'hidepatrolled' ) && $this->getUser()->useNPPatrol() ) {
89 $conds['rc_patrolled'] = RecentChange::PRC_UNPATROLLED;
90 }
91
92 if ( $this->opts->getValue( 'hidebots' ) ) {
93 $conds['rc_bot'] = 0;
94 }
95
96 if ( $this->opts->getValue( 'hideredirs' ) ) {
97 $conds['page_is_redirect'] = 0;
98 }
99
100 // Allow changes to the New Pages query
101 $tables = array_merge( $rcQuery['tables'], [ 'page' ] );
102 $fields = array_merge( $rcQuery['fields'], [
103 'length' => 'page_len', 'rev_id' => 'page_latest', 'page_namespace', 'page_title'
104 ] );
105 $join_conds = [ 'page' => [ 'JOIN', 'page_id=rc_cur_id' ] ] + $rcQuery['joins'];
106
107 // Avoid PHP 7.1 warning from passing $this by reference
108 $pager = $this;
109 Hooks::run( 'SpecialNewpagesConditions',
110 [ &$pager, $this->opts, &$conds, &$tables, &$fields, &$join_conds ] );
111
112 $info = [
113 'tables' => $tables,
114 'fields' => $fields,
115 'conds' => $conds,
116 'options' => [],
117 'join_conds' => $join_conds
118 ];
119
120 // Modify query for tags
121 ChangeTags::modifyDisplayQuery(
122 $info['tables'],
123 $info['fields'],
124 $info['conds'],
125 $info['join_conds'],
126 $info['options'],
127 $this->opts['tagfilter']
128 );
129
130 return $info;
131 }
132
133 function getIndexField() {
134 return 'rc_timestamp';
135 }
136
137 function formatRow( $row ) {
138 return $this->mForm->formatRow( $row );
139 }
140
141 protected function getStartBody() {
142 # Do a batch existence check on pages
143 $linkBatch = new LinkBatch();
144 foreach ( $this->mResult as $row ) {
145 $linkBatch->add( NS_USER, $row->rc_user_text );
146 $linkBatch->add( NS_USER_TALK, $row->rc_user_text );
147 $linkBatch->add( $row->page_namespace, $row->page_title );
148 }
149 $linkBatch->execute();
150
151 return '<ul>';
152 }
153
154 protected function getEndBody() {
155 return '</ul>';
156 }
157 }