MediaWiki REL1_40
NewPagesPager.php
Go to the documentation of this file.
1<?php
29
34
38 protected $opts;
39
43 protected $mForm;
44
46 private $groupPermissionsLookup;
47
49 private $hookRunner;
50
52 private $linkBatchFactory;
53
55 private $namespaceInfo;
56
66 public function __construct(
67 SpecialNewpages $form,
68 GroupPermissionsLookup $groupPermissionsLookup,
69 HookContainer $hookContainer,
70 LinkBatchFactory $linkBatchFactory,
71 ILoadBalancer $loadBalancer,
72 NamespaceInfo $namespaceInfo,
73 FormOptions $opts
74 ) {
75 // Set database before parent constructor to avoid setting it there with wfGetDB
76 $this->mDb = $loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA );
77 parent::__construct( $form->getContext() );
78 $this->groupPermissionsLookup = $groupPermissionsLookup;
79 $this->hookRunner = new HookRunner( $hookContainer );
80 $this->linkBatchFactory = $linkBatchFactory;
81 $this->namespaceInfo = $namespaceInfo;
82 $this->mForm = $form;
83 $this->opts = $opts;
84 }
85
86 public function getQueryInfo() {
87 $rcQuery = RecentChange::getQueryInfo();
88
89 $conds = [];
90 $conds['rc_new'] = 1;
91
92 $username = $this->opts->getValue( 'username' );
93 $user = Title::makeTitleSafe( NS_USER, $username );
94
95 $size = abs( intval( $this->opts->getValue( 'size' ) ) );
96 if ( $size > 0 ) {
97 if ( $this->opts->getValue( 'size-mode' ) === 'max' ) {
98 $conds[] = 'page_len <= ' . $size;
99 } else {
100 $conds[] = 'page_len >= ' . $size;
101 }
102 }
103
104 if ( $user ) {
105 $conds['actor_name'] = $user->getText();
106 } elseif ( $this->canAnonymousUsersCreatePages() && $this->opts->getValue( 'hideliu' ) ) {
107 # If anons cannot make new pages, don't "exclude logged in users"!
108 $conds['actor_user'] = null;
109 }
110
111 $conds = array_merge( $conds, $this->getNamespaceCond() );
112
113 # If this user cannot see patrolled edits or they are off, don't do dumb queries!
114 if ( $this->opts->getValue( 'hidepatrolled' ) && $this->getUser()->useNPPatrol() ) {
115 $conds['rc_patrolled'] = RecentChange::PRC_UNPATROLLED;
116 }
117
118 if ( $this->opts->getValue( 'hidebots' ) ) {
119 $conds['rc_bot'] = 0;
120 }
121
122 if ( $this->opts->getValue( 'hideredirs' ) ) {
123 $conds['page_is_redirect'] = 0;
124 }
125
126 // Allow changes to the New Pages query
127 $tables = array_merge( $rcQuery['tables'], [ 'page' ] );
128 $fields = array_merge( $rcQuery['fields'], [
129 'length' => 'page_len', 'rev_id' => 'page_latest', 'page_namespace', 'page_title',
130 'page_content_model',
131 ] );
132 $join_conds = [ 'page' => [ 'JOIN', 'page_id=rc_cur_id' ] ] + $rcQuery['joins'];
133
134 $this->hookRunner->onSpecialNewpagesConditions(
135 $this, $this->opts, $conds, $tables, $fields, $join_conds );
136
137 $info = [
138 'tables' => $tables,
139 'fields' => $fields,
140 'conds' => $conds,
141 'options' => [],
142 'join_conds' => $join_conds
143 ];
144
145 // Modify query for tags
147 $info['tables'],
148 $info['fields'],
149 $info['conds'],
150 $info['join_conds'],
151 $info['options'],
152 $this->opts['tagfilter']
153 );
154
155 return $info;
156 }
157
158 private function canAnonymousUsersCreatePages() {
159 return $this->groupPermissionsLookup->groupHasPermission( '*', 'createpage' ) ||
160 $this->groupPermissionsLookup->groupHasPermission( '*', 'createtalk' );
161 }
162
163 // Based on ContribsPager.php
164 private function getNamespaceCond() {
165 $namespace = $this->opts->getValue( 'namespace' );
166 if ( $namespace === 'all' || $namespace === '' ) {
167 return [];
168 }
169
170 $namespace = intval( $namespace );
171 if ( $namespace < NS_MAIN ) {
172 // Negative namespaces are invalid
173 return [];
174 }
175
176 $invert = $this->opts->getValue( 'invert' );
177 $associated = $this->opts->getValue( 'associated' );
178
179 $eq_op = $invert ? '!=' : '=';
180 $bool_op = $invert ? 'AND' : 'OR';
181
182 $dbr = $this->getDatabase();
183 $selectedNS = $dbr->addQuotes( $namespace );
184 if ( !$associated ) {
185 return [ "rc_namespace $eq_op $selectedNS" ];
186 }
187
188 $associatedNS = $dbr->addQuotes(
189 $this->namespaceInfo->getAssociated( $namespace )
190 );
191 return [
192 "rc_namespace $eq_op $selectedNS " .
193 $bool_op .
194 " rc_namespace $eq_op $associatedNS"
195 ];
196 }
197
198 public function getIndexField() {
199 return [ [ 'rc_timestamp', 'rc_id' ] ];
200 }
201
202 public function formatRow( $row ) {
203 return $this->mForm->formatRow( $row );
204 }
205
206 protected function getStartBody() {
207 # Do a batch existence check on pages
208 $linkBatch = $this->linkBatchFactory->newLinkBatch();
209 foreach ( $this->mResult as $row ) {
210 $linkBatch->add( NS_USER, $row->rc_user_text );
211 $linkBatch->add( NS_USER_TALK, $row->rc_user_text );
212 $linkBatch->add( $row->page_namespace, $row->page_title );
213 }
214 $linkBatch->execute();
215
216 return '<ul>';
217 }
218
219 protected function getEndBody() {
220 return '</ul>';
221 }
222}
const NS_USER
Definition Defines.php:66
const NS_MAIN
Definition Defines.php:64
const NS_USER_TALK
Definition Defines.php:67
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag='', bool $exclude=false)
Applies all tags-related changes to a query.
getDatabase()
Get the Database object in use.
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Helper class to keep track of options when mixing links and form elements.
Represents a title within MediaWiki.
Definition Title.php:82
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
formatRow( $row)
Returns an HTML string representing the result row $row.
SpecialNewpages $mForm
FormOptions $opts
getQueryInfo()
Provides all parameters needed for the main paged query.
getStartBody()
Hook into getBody(), allows text to be inserted at the start.
getIndexField()
Returns the name of the index field.
getEndBody()
Hook into getBody() for the end of the list.
__construct(SpecialNewpages $form, GroupPermissionsLookup $groupPermissionsLookup, HookContainer $hookContainer, LinkBatchFactory $linkBatchFactory, ILoadBalancer $loadBalancer, NamespaceInfo $namespaceInfo, FormOptions $opts)
IndexPager with a formatted navigation bar.
A special page that list newly created pages.
getContext()
Gets the context this SpecialPage is executed in.
This class is a delegate to ILBFactory for a given database cluster.
getConnectionRef( $i, $groups=[], $domain=false, $flags=0)