MediaWiki  1.29.2
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  $conds = [];
43  $conds['rc_new'] = 1;
44 
45  $namespace = $this->opts->getValue( 'namespace' );
46  $namespace = ( $namespace === 'all' ) ? false : intval( $namespace );
47 
48  $username = $this->opts->getValue( 'username' );
50 
51  $size = abs( intval( $this->opts->getValue( 'size' ) ) );
52  if ( $size > 0 ) {
53  if ( $this->opts->getValue( 'size-mode' ) === 'max' ) {
54  $conds[] = 'page_len <= ' . $size;
55  } else {
56  $conds[] = 'page_len >= ' . $size;
57  }
58  }
59 
60  $rcIndexes = [];
61 
62  if ( $namespace !== false ) {
63  if ( $this->opts->getValue( 'invert' ) ) {
64  $conds[] = 'rc_namespace != ' . $this->mDb->addQuotes( $namespace );
65  } else {
66  $conds['rc_namespace'] = $namespace;
67  }
68  }
69 
70  if ( $user ) {
71  $conds['rc_user_text'] = $user->getText();
72  $rcIndexes = 'rc_user_text';
73  } elseif ( User::groupHasPermission( '*', 'createpage' ) &&
74  $this->opts->getValue( 'hideliu' )
75  ) {
76  # If anons cannot make new pages, don't "exclude logged in users"!
77  $conds['rc_user'] = 0;
78  }
79 
80  # If this user cannot see patrolled edits or they are off, don't do dumb queries!
81  if ( $this->opts->getValue( 'hidepatrolled' ) && $this->getUser()->useNPPatrol() ) {
82  $conds['rc_patrolled'] = 0;
83  }
84 
85  if ( $this->opts->getValue( 'hidebots' ) ) {
86  $conds['rc_bot'] = 0;
87  }
88 
89  if ( $this->opts->getValue( 'hideredirs' ) ) {
90  $conds['page_is_redirect'] = 0;
91  }
92 
93  // Allow changes to the New Pages query
94  $tables = [ 'recentchanges', 'page' ];
95  $fields = [
96  'rc_namespace', 'rc_title', 'rc_cur_id', 'rc_user', 'rc_user_text',
97  'rc_comment', 'rc_timestamp', 'rc_patrolled', 'rc_id', 'rc_deleted',
98  'length' => 'page_len', 'rev_id' => 'page_latest', 'rc_this_oldid',
99  'page_namespace', 'page_title'
100  ];
101  $join_conds = [ 'page' => [ 'INNER JOIN', 'page_id=rc_cur_id' ] ];
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
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 }
NewPagesPager\getIndexField
getIndexField()
This function should be overridden to return the name of the index fi- eld.
Definition: NewPagesPager.php:135
$tables
this hook is for auditing only RecentChangesLinked and Watchlist 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:990
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:143
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:246
NewPagesPager\$opts
$opts
Definition: NewPagesPager.php:28
NewPagesPager\getEndBody
getEndBody()
Hook into getBody() for the end of the list.
Definition: NewPagesPager.php:156
User\groupHasPermission
static groupHasPermission( $group, $role)
Check, if the given group has the given permission.
Definition: User.php:4766
ContextSource\getUser
getUser()
Get the User object.
Definition: ContextSource.php:133
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=false)
Applies all tags-related changes to a query.
Definition: ChangeTags.php:632
NewPagesPager\getQueryInfo
getQueryInfo()
This function should be overridden to provide all parameters needed for the main paged query.
Definition: NewPagesPager.php:41
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:538
captcha-old.opts
opts
Definition: captcha-old.py:203
NS_USER_TALK
const NS_USER_TALK
Definition: Defines.php:65
NewPagesPager\formatRow
formatRow( $row)
Abstract formatting function.
Definition: NewPagesPager.php:139
NewPagesPager
Definition: NewPagesPager.php:25
NewPagesPager\$mForm
HtmlForm $mForm
Definition: NewPagesPager.php:33
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:35
NS_USER
const NS_USER
Definition: Defines.php:64
ReverseChronologicalPager
IndexPager with a formatted navigation bar.
Definition: ReverseChronologicalPager.php:29
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:131
$username
this hook is for auditing only or null if authentication failed before getting that far $username
Definition: hooks.txt:783
$options
this hook is for auditing only RecentChangesLinked and Watchlist 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 and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition: hooks.txt:1049