MediaWiki REL1_34
NewPagesPager.php
Go to the documentation of this file.
1<?php
26
28
32 protected $opts;
33
37 protected $mForm;
38
43 public function __construct( $form, FormOptions $opts ) {
44 parent::__construct( $form->getContext() );
45 $this->mForm = $form;
46 $this->opts = $opts;
47 }
48
49 function getQueryInfo() {
50 $rcQuery = RecentChange::getQueryInfo();
51
52 $conds = [];
53 $conds['rc_new'] = 1;
54
55 $username = $this->opts->getValue( 'username' );
56 $user = Title::makeTitleSafe( NS_USER, $username );
57
58 $size = abs( intval( $this->opts->getValue( 'size' ) ) );
59 if ( $size > 0 ) {
60 if ( $this->opts->getValue( 'size-mode' ) === 'max' ) {
61 $conds[] = 'page_len <= ' . $size;
62 } else {
63 $conds[] = 'page_len >= ' . $size;
64 }
65 }
66
67 if ( $user ) {
68 $conds[] = ActorMigration::newMigration()->getWhere(
69 $this->mDb, 'rc_user', User::newFromName( $user->getText(), false ), false
70 )['conds'];
71 } elseif ( $this->canAnonymousUsersCreatePages() && $this->opts->getValue( 'hideliu' ) ) {
72 # If anons cannot make new pages, don't "exclude logged in users"!
73 $conds[] = ActorMigration::newMigration()->isAnon( $rcQuery['fields']['rc_user'] );
74 }
75
76 $conds = array_merge( $conds, $this->getNamespaceCond() );
77
78 # If this user cannot see patrolled edits or they are off, don't do dumb queries!
79 if ( $this->opts->getValue( 'hidepatrolled' ) && $this->getUser()->useNPPatrol() ) {
80 $conds['rc_patrolled'] = RecentChange::PRC_UNPATROLLED;
81 }
82
83 if ( $this->opts->getValue( 'hidebots' ) ) {
84 $conds['rc_bot'] = 0;
85 }
86
87 if ( $this->opts->getValue( 'hideredirs' ) ) {
88 $conds['page_is_redirect'] = 0;
89 }
90
91 // Allow changes to the New Pages query
92 $tables = array_merge( $rcQuery['tables'], [ 'page' ] );
93 $fields = array_merge( $rcQuery['fields'], [
94 'length' => 'page_len', 'rev_id' => 'page_latest', 'page_namespace', 'page_title'
95 ] );
96 $join_conds = [ 'page' => [ 'JOIN', 'page_id=rc_cur_id' ] ] + $rcQuery['joins'];
97
98 // Avoid PHP 7.1 warning from passing $this by reference
99 $pager = $this;
100 Hooks::run( 'SpecialNewpagesConditions',
101 [ &$pager, $this->opts, &$conds, &$tables, &$fields, &$join_conds ] );
102
103 $info = [
104 'tables' => $tables,
105 'fields' => $fields,
106 'conds' => $conds,
107 'options' => [],
108 'join_conds' => $join_conds
109 ];
110
111 // Modify query for tags
113 $info['tables'],
114 $info['fields'],
115 $info['conds'],
116 $info['join_conds'],
117 $info['options'],
118 $this->opts['tagfilter']
119 );
120
121 return $info;
122 }
123
124 private function canAnonymousUsersCreatePages() {
125 $pm = MediaWikiServices::getInstance()->getPermissionManager();
126 return ( $pm->groupHasPermission( '*', 'createpage' ) ||
127 $pm->groupHasPermission( '*', 'createtalk' )
128 );
129 }
130
131 // Based on ContribsPager.php
132 function getNamespaceCond() {
133 $namespace = $this->opts->getValue( 'namespace' );
134 if ( $namespace === 'all' || $namespace === '' ) {
135 return [];
136 }
137
138 $namespace = intval( $namespace );
139 $invert = $this->opts->getValue( 'invert' );
140 $associated = $this->opts->getValue( 'associated' );
141
142 $eq_op = $invert ? '!=' : '=';
143 $bool_op = $invert ? 'AND' : 'OR';
144
145 $selectedNS = $this->mDb->addQuotes( $namespace );
146 if ( !$associated ) {
147 return [ "rc_namespace $eq_op $selectedNS" ];
148 }
149
150 $associatedNS = $this->mDb->addQuotes(
151 MediaWikiServices::getInstance()->getNamespaceInfo()->getAssociated( $namespace )
152 );
153 return [
154 "rc_namespace $eq_op $selectedNS " .
155 $bool_op .
156 " rc_namespace $eq_op $associatedNS"
157 ];
158 }
159
160 function getIndexField() {
161 return 'rc_timestamp';
162 }
163
164 function formatRow( $row ) {
165 return $this->mForm->formatRow( $row );
166 }
167
168 protected function getStartBody() {
169 # Do a batch existence check on pages
170 $linkBatch = new LinkBatch();
171 foreach ( $this->mResult as $row ) {
172 $linkBatch->add( NS_USER, $row->rc_user_text );
173 $linkBatch->add( NS_USER_TALK, $row->rc_user_text );
174 $linkBatch->add( $row->page_namespace, $row->page_title );
175 }
176 $linkBatch->execute();
177
178 return '<ul>';
179 }
180
181 protected function getEndBody() {
182 return '</ul>';
183 }
184}
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag='')
Applies all tags-related changes to a query.
Helper class to keep track of options when mixing links and form elements.
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition LinkBatch.php:34
MediaWikiServices is the service locator for the application scope of MediaWiki.
formatRow( $row)
Abstract formatting function.
SpecialNewpages $mForm
FormOptions $opts
__construct( $form, FormOptions $opts)
getQueryInfo()
This function should be overridden to provide all parameters needed for the main paged query.
getStartBody()
Hook into getBody(), allows text to be inserted at the start.
getIndexField()
This function should be overridden to return the name of the index fi- eld.
getEndBody()
Hook into getBody() for the end of the list.
Efficient paging for SQL queries.
A special page that list newly created pages.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:518
const NS_USER
Definition Defines.php:71
const NS_USER_TALK
Definition Defines.php:72