MediaWiki  1.33.0
NewPagesPager.php
Go to the documentation of this file.
1 <?php
26 
30  protected $opts;
31 
35  protected $mForm;
36 
41  public function __construct( $form, FormOptions $opts ) {
42  parent::__construct( $form->getContext() );
43  $this->mForm = $form;
44  $this->opts = $opts;
45  }
46 
47  function getQueryInfo() {
48  $rcQuery = RecentChange::getQueryInfo();
49 
50  $conds = [];
51  $conds['rc_new'] = 1;
52 
53  $namespace = $this->opts->getValue( 'namespace' );
54  $namespace = ( $namespace === 'all' ) ? false : intval( $namespace );
55 
56  $username = $this->opts->getValue( 'username' );
58 
59  $size = abs( intval( $this->opts->getValue( 'size' ) ) );
60  if ( $size > 0 ) {
61  if ( $this->opts->getValue( 'size-mode' ) === 'max' ) {
62  $conds[] = 'page_len <= ' . $size;
63  } else {
64  $conds[] = 'page_len >= ' . $size;
65  }
66  }
67 
68  if ( $namespace !== false ) {
69  if ( $this->opts->getValue( 'invert' ) ) {
70  $conds[] = 'rc_namespace != ' . $this->mDb->addQuotes( $namespace );
71  } else {
72  $conds['rc_namespace'] = $namespace;
73  }
74  }
75 
76  if ( $user ) {
77  $conds[] = ActorMigration::newMigration()->getWhere(
78  $this->mDb, 'rc_user', User::newFromName( $user->getText(), false ), false
79  )['conds'];
80  } elseif ( User::groupHasPermission( '*', 'createpage' ) &&
81  $this->opts->getValue( 'hideliu' )
82  ) {
83  # If anons cannot make new pages, don't "exclude logged in users"!
84  $conds[] = ActorMigration::newMigration()->isAnon( $rcQuery['fields']['rc_user'] );
85  }
86 
87  # If this user cannot see patrolled edits or they are off, don't do dumb queries!
88  if ( $this->opts->getValue( 'hidepatrolled' ) && $this->getUser()->useNPPatrol() ) {
89  $conds['rc_patrolled'] = RecentChange::PRC_UNPATROLLED;
90  }
91 
92  if ( $this->opts->getValue( 'hidebots' ) ) {
93  $conds['rc_bot'] = 0;
94  }
95 
96  if ( $this->opts->getValue( 'hideredirs' ) ) {
97  $conds['page_is_redirect'] = 0;
98  }
99 
100  // Allow changes to the New Pages query
101  $tables = array_merge( $rcQuery['tables'], [ 'page' ] );
102  $fields = array_merge( $rcQuery['fields'], [
103  'length' => 'page_len', 'rev_id' => 'page_latest', 'page_namespace', 'page_title'
104  ] );
105  $join_conds = [ 'page' => [ 'JOIN', 'page_id=rc_cur_id' ] ] + $rcQuery['joins'];
106 
107  // Avoid PHP 7.1 warning from passing $this by reference
108  $pager = $this;
109  Hooks::run( 'SpecialNewpagesConditions',
110  [ &$pager, $this->opts, &$conds, &$tables, &$fields, &$join_conds ] );
111 
112  $info = [
113  'tables' => $tables,
114  'fields' => $fields,
115  'conds' => $conds,
116  'options' => [],
117  'join_conds' => $join_conds
118  ];
119 
120  // Modify query for tags
122  $info['tables'],
123  $info['fields'],
124  $info['conds'],
125  $info['join_conds'],
126  $info['options'],
127  $this->opts['tagfilter']
128  );
129 
130  return $info;
131  }
132 
133  function getIndexField() {
134  return 'rc_timestamp';
135  }
136 
137  function formatRow( $row ) {
138  return $this->mForm->formatRow( $row );
139  }
140 
141  protected function getStartBody() {
142  # Do a batch existence check on pages
143  $linkBatch = new LinkBatch();
144  foreach ( $this->mResult as $row ) {
145  $linkBatch->add( NS_USER, $row->rc_user_text );
146  $linkBatch->add( NS_USER_TALK, $row->rc_user_text );
147  $linkBatch->add( $row->page_namespace, $row->page_title );
148  }
149  $linkBatch->execute();
150 
151  return '<ul>';
152  }
153 
154  protected function getEndBody() {
155  return '</ul>';
156  }
157 }
RecentChange\getQueryInfo
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new recentchanges object.
Definition: RecentChange.php:280
$user
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1476
NewPagesPager\getIndexField
getIndexField()
This function should be overridden to return the name of the index fi- eld.
Definition: NewPagesPager.php:133
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
NewPagesPager\$opts
FormOptions $opts
Definition: NewPagesPager.php:30
LinkBatch
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:34
NewPagesPager\getStartBody
getStartBody()
Hook into getBody(), allows text to be inserted at the start.
Definition: NewPagesPager.php:141
$tables
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:979
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:585
NewPagesPager\getEndBody
getEndBody()
Hook into getBody() for the end of the list.
Definition: NewPagesPager.php:154
User\groupHasPermission
static groupHasPermission( $group, $role)
Check, if the given group has the given permission.
Definition: User.php:5065
ContextSource\getUser
getUser()
Definition: ContextSource.php:120
ActorMigration\newMigration
static newMigration()
Static constructor.
Definition: ActorMigration.php:111
php
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
ChangeTags\modifyDisplayQuery
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag='')
Applies all tags-related changes to a query.
Definition: ChangeTags.php:728
NewPagesPager\getQueryInfo
getQueryInfo()
This function should be overridden to provide all parameters needed for the main paged query.
Definition: NewPagesPager.php:47
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:604
captcha-old.opts
opts
Definition: captcha-old.py:227
NS_USER_TALK
const NS_USER_TALK
Definition: Defines.php:67
NewPagesPager\formatRow
formatRow( $row)
Abstract formatting function.
Definition: NewPagesPager.php:137
NewPagesPager
Definition: NewPagesPager.php:25
SpecialNewpages
A special page that list newly created pages.
Definition: SpecialNewpages.php:29
RecentChange\PRC_UNPATROLLED
const PRC_UNPATROLLED
Definition: RecentChange.php:78
as
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
NewPagesPager\__construct
__construct( $form, FormOptions $opts)
Definition: NewPagesPager.php:41
NS_USER
const NS_USER
Definition: Defines.php:66
ReverseChronologicalPager
Efficient paging for SQL queries.
Definition: ReverseChronologicalPager.php:28
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
$username
this hook is for auditing only or null if authentication failed before getting that far $username
Definition: hooks.txt:780
NewPagesPager\$mForm
SpecialNewpages $mForm
Definition: NewPagesPager.php:35