MediaWiki  master
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' );
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 ( MediaWikiServices::getInstance()
72  ->getPermissionManager()
73  ->groupHasPermission( '*', 'createpage' ) &&
74  $this->opts->getValue( 'hideliu' )
75  ) {
76  # If anons cannot make new pages, don't "exclude logged in users"!
77  $conds[] = ActorMigration::newMigration()->isAnon( $rcQuery['fields']['rc_user'] );
78  }
79 
80  $conds = array_merge( $conds, $this->getNamespaceCond() );
81 
82  # If this user cannot see patrolled edits or they are off, don't do dumb queries!
83  if ( $this->opts->getValue( 'hidepatrolled' ) && $this->getUser()->useNPPatrol() ) {
84  $conds['rc_patrolled'] = RecentChange::PRC_UNPATROLLED;
85  }
86 
87  if ( $this->opts->getValue( 'hidebots' ) ) {
88  $conds['rc_bot'] = 0;
89  }
90 
91  if ( $this->opts->getValue( 'hideredirs' ) ) {
92  $conds['page_is_redirect'] = 0;
93  }
94 
95  // Allow changes to the New Pages query
96  $tables = array_merge( $rcQuery['tables'], [ 'page' ] );
97  $fields = array_merge( $rcQuery['fields'], [
98  'length' => 'page_len', 'rev_id' => 'page_latest', 'page_namespace', 'page_title'
99  ] );
100  $join_conds = [ 'page' => [ 'JOIN', 'page_id=rc_cur_id' ] ] + $rcQuery['joins'];
101 
102  // Avoid PHP 7.1 warning from passing $this by reference
103  $pager = $this;
104  Hooks::run( 'SpecialNewpagesConditions',
105  [ &$pager, $this->opts, &$conds, &$tables, &$fields, &$join_conds ] );
106 
107  $info = [
108  'tables' => $tables,
109  'fields' => $fields,
110  'conds' => $conds,
111  'options' => [],
112  'join_conds' => $join_conds
113  ];
114 
115  // Modify query for tags
117  $info['tables'],
118  $info['fields'],
119  $info['conds'],
120  $info['join_conds'],
121  $info['options'],
122  $this->opts['tagfilter']
123  );
124 
125  return $info;
126  }
127 
128  // Based on ContribsPager.php
129  function getNamespaceCond() {
130  $namespace = $this->opts->getValue( 'namespace' );
131  if ( $namespace === 'all' || $namespace === '' ) {
132  return [];
133  }
134 
135  $namespace = intval( $namespace );
136  $invert = $this->opts->getValue( 'invert' );
137  $associated = $this->opts->getValue( 'associated' );
138 
139  $eq_op = $invert ? '!=' : '=';
140  $bool_op = $invert ? 'AND' : 'OR';
141 
142  if ( !$associated ) {
143  return [ "rc_namespace $eq_op " . $this->mDb->addQuotes( $namespace ) ];
144  }
145 
146  $associatedNS = MediaWikiServices::getInstance()->getNamespaceInfo()->getAssociated( $namespace );
147  return [
148  "rc_namespace $eq_op " . $this->mDb->addQuotes( $namespace ) .
149  $bool_op .
150  " rc_namespace $eq_op " . $this->mDb->addQuotes( $associatedNS )
151  ];
152  }
153 
154  function getIndexField() {
155  return 'rc_timestamp';
156  }
157 
158  function formatRow( $row ) {
159  return $this->mForm->formatRow( $row );
160  }
161 
162  protected function getStartBody() {
163  # Do a batch existence check on pages
164  $linkBatch = new LinkBatch();
165  foreach ( $this->mResult as $row ) {
166  $linkBatch->add( NS_USER, $row->rc_user_text );
167  $linkBatch->add( NS_USER_TALK, $row->rc_user_text );
168  $linkBatch->add( $row->page_namespace, $row->page_title );
169  }
170  $linkBatch->execute();
171 
172  return '<ul>';
173  }
174 
175  protected function getEndBody() {
176  return '</ul>';
177  }
178 }
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag='')
Applies all tags-related changes to a query.
Definition: ChangeTags.php:776
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
SpecialNewpages $mForm
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:193
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Efficient paging for SQL queries.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
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:966
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:34
FormOptions $opts
static newMigration()
Static constructor.
__construct( $form, FormOptions $opts)
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:620
const PRC_UNPATROLLED
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
this hook is for auditing only or null if authentication failed before getting that far $username
Definition: hooks.txt:773
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new recentchanges object...
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:535
const NS_USER_TALK
Definition: Defines.php:63
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1460
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200