MediaWiki REL1_32
NewPagesPager.php
Go to the documentation of this file.
1<?php
26
27 // Stored opts
28 protected $opts;
29
33 protected $mForm;
34
35 function __construct( $form, FormOptions $opts ) {
36 parent::__construct( $form->getContext() );
37 $this->mForm = $form;
38 $this->opts = $opts;
39 }
40
41 function getQueryInfo() {
42 $rcQuery = RecentChange::getQueryInfo();
43
44 $conds = [];
45 $conds['rc_new'] = 1;
46
47 $namespace = $this->opts->getValue( 'namespace' );
48 $namespace = ( $namespace === 'all' ) ? false : intval( $namespace );
49
50 $username = $this->opts->getValue( 'username' );
51 $user = Title::makeTitleSafe( NS_USER, $username );
52
53 $size = abs( intval( $this->opts->getValue( 'size' ) ) );
54 if ( $size > 0 ) {
55 if ( $this->opts->getValue( 'size-mode' ) === 'max' ) {
56 $conds[] = 'page_len <= ' . $size;
57 } else {
58 $conds[] = 'page_len >= ' . $size;
59 }
60 }
61
62 $rcIndexes = [];
63
64 if ( $namespace !== false ) {
65 if ( $this->opts->getValue( 'invert' ) ) {
66 $conds[] = 'rc_namespace != ' . $this->mDb->addQuotes( $namespace );
67 } else {
68 $conds['rc_namespace'] = $namespace;
69 }
70 }
71
72 if ( $user ) {
73 $conds[] = ActorMigration::newMigration()->getWhere(
74 $this->mDb, 'rc_user', User::newFromName( $user->getText(), false ), false
75 )['conds'];
76 } elseif ( User::groupHasPermission( '*', 'createpage' ) &&
77 $this->opts->getValue( 'hideliu' )
78 ) {
79 # If anons cannot make new pages, don't "exclude logged in users"!
80 $conds[] = ActorMigration::newMigration()->isAnon( $rcQuery['fields']['rc_user'] );
81 }
82
83 # If this user cannot see patrolled edits or they are off, don't do dumb queries!
84 if ( $this->opts->getValue( 'hidepatrolled' ) && $this->getUser()->useNPPatrol() ) {
85 $conds['rc_patrolled'] = RecentChange::PRC_UNPATROLLED;
86 }
87
88 if ( $this->opts->getValue( 'hidebots' ) ) {
89 $conds['rc_bot'] = 0;
90 }
91
92 if ( $this->opts->getValue( 'hideredirs' ) ) {
93 $conds['page_is_redirect'] = 0;
94 }
95
96 // Allow changes to the New Pages query
97 $tables = array_merge( $rcQuery['tables'], [ 'page' ] );
98 $fields = array_merge( $rcQuery['fields'], [
99 'length' => 'page_len', 'rev_id' => 'page_latest', 'page_namespace', 'page_title'
100 ] );
101 $join_conds = [ 'page' => [ 'INNER JOIN', 'page_id=rc_cur_id' ] ] + $rcQuery['joins'];
102
103 // Avoid PHP 7.1 warning from passing $this by reference
104 $pager = $this;
105 Hooks::run( 'SpecialNewpagesConditions',
106 [ &$pager, $this->opts, &$conds, &$tables, &$fields, &$join_conds ] );
107
108 $options = [];
109
110 if ( $rcIndexes ) {
111 $options = [ 'USE INDEX' => [ 'recentchanges' => $rcIndexes ] ];
112 }
113
114 $info = [
115 'tables' => $tables,
116 'fields' => $fields,
117 'conds' => $conds,
118 'options' => $options,
119 'join_conds' => $join_conds
120 ];
121
122 // Modify query for tags
123 ChangeTags::modifyDisplayQuery(
124 $info['tables'],
125 $info['fields'],
126 $info['conds'],
127 $info['join_conds'],
128 $info['options'],
129 $this->opts['tagfilter']
130 );
131
132 return $info;
133 }
134
135 function getIndexField() {
136 return 'rc_timestamp';
137 }
138
139 function formatRow( $row ) {
140 return $this->mForm->formatRow( $row );
141 }
142
143 function getStartBody() {
144 # Do a batch existence check on pages
145 $linkBatch = new LinkBatch();
146 foreach ( $this->mResult as $row ) {
147 $linkBatch->add( NS_USER, $row->rc_user_text );
148 $linkBatch->add( NS_USER_TALK, $row->rc_user_text );
149 $linkBatch->add( $row->page_namespace, $row->page_title );
150 }
151 $linkBatch->execute();
152
153 return '<ul>';
154 }
155
156 function getEndBody() {
157 return '</ul>';
158 }
159}
Helper class to keep track of options when mixing links and form elements.
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition HTMLForm.php:136
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition LinkBatch.php:34
formatRow( $row)
Abstract formatting function.
__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.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:592
static groupHasPermission( $group, $role)
Check, if the given group has the given permission.
Definition User.php:5013
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition hooks.txt:2050
this hook is for auditing only RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
Definition hooks.txt:1035
this hook is for auditing only or null if authentication failed before getting that far $username
Definition hooks.txt:815
const NS_USER_TALK
Definition Defines.php:67