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.
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.
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
25 use MediaWiki\MediaWikiServices
;
27 class NewPagesPager
extends ReverseChronologicalPager
{
35 * @var SpecialNewpages
40 * @param SpecialNewpages $form
41 * @param FormOptions $opts
43 public function __construct( $form, FormOptions
$opts ) {
44 parent
::__construct( $form->getContext() );
49 function getQueryInfo() {
50 $rcQuery = RecentChange
::getQueryInfo();
55 $username = $this->opts
->getValue( 'username' );
56 $user = Title
::makeTitleSafe( NS_USER
, $username );
58 $size = abs( intval( $this->opts
->getValue( 'size' ) ) );
60 if ( $this->opts
->getValue( 'size-mode' ) === 'max' ) {
61 $conds[] = 'page_len <= ' . $size;
63 $conds[] = 'page_len >= ' . $size;
68 $conds[] = ActorMigration
::newMigration()->getWhere(
69 $this->mDb
, 'rc_user', User
::newFromName( $user->getText(), false ), false
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'] );
76 $conds = array_merge( $conds, $this->getNamespaceCond() );
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
;
83 if ( $this->opts
->getValue( 'hidebots' ) ) {
87 if ( $this->opts
->getValue( 'hideredirs' ) ) {
88 $conds['page_is_redirect'] = 0;
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'
96 $join_conds = [ 'page' => [ 'JOIN', 'page_id=rc_cur_id' ] ] +
$rcQuery['joins'];
98 // Avoid PHP 7.1 warning from passing $this by reference
100 Hooks
::run( 'SpecialNewpagesConditions',
101 [ &$pager, $this->opts
, &$conds, &$tables, &$fields, &$join_conds ] );
108 'join_conds' => $join_conds
111 // Modify query for tags
112 ChangeTags
::modifyDisplayQuery(
118 $this->opts
['tagfilter']
124 private function canAnonymousUsersCreatePages() {
125 $pm = MediaWikiServices
::getInstance()->getPermissionManager();
126 return ( $pm->groupHasPermission( '*', 'createpage' ) ||
127 $pm->groupHasPermission( '*', 'createtalk' )
131 // Based on ContribsPager.php
132 function getNamespaceCond() {
133 $namespace = $this->opts
->getValue( 'namespace' );
134 if ( $namespace === 'all' ||
$namespace === '' ) {
138 $namespace = intval( $namespace );
139 $invert = $this->opts
->getValue( 'invert' );
140 $associated = $this->opts
->getValue( 'associated' );
142 $eq_op = $invert ?
'!=' : '=';
143 $bool_op = $invert ?
'AND' : 'OR';
145 $selectedNS = $this->mDb
->addQuotes( $namespace );
146 if ( !$associated ) {
147 return [ "rc_namespace $eq_op $selectedNS" ];
150 $associatedNS = $this->mDb
->addQuotes(
151 MediaWikiServices
::getInstance()->getNamespaceInfo()->getAssociated( $namespace )
154 "rc_namespace $eq_op $selectedNS " .
156 " rc_namespace $eq_op $associatedNS"
160 function getIndexField() {
161 return 'rc_timestamp';
164 function formatRow( $row ) {
165 return $this->mForm
->formatRow( $row );
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
);
176 $linkBatch->execute();
181 protected function getEndBody() {