MediaWiki  1.29.1
NewFilesPager.php
Go to the documentation of this file.
1 <?php
26 
28 
32  protected $gallery;
33 
37  protected $opts;
38 
44  $this->opts = $opts;
45 
46  $this->setLimit( $opts->getValue( 'limit' ) );
47 
48  parent::__construct( $context );
49  }
50 
51  function getQueryInfo() {
53  $conds = $jconds = [];
54  $tables = [ 'image' ];
55  $fields = [ 'img_name', 'img_user', 'img_timestamp' ];
56  $options = [];
57 
58  $user = $opts->getValue( 'user' );
59  if ( $user !== '' ) {
60  $userId = User::idFromName( $user );
61  if ( $userId ) {
62  $conds['img_user'] = $userId;
63  } else {
64  $conds['img_user_text'] = $user;
65  }
66  }
67 
68  if ( !$opts->getValue( 'showbots' ) ) {
69  $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
70 
71  if ( count( $groupsWithBotPermission ) ) {
72  $dbr = wfGetDB( DB_REPLICA );
73  $tables[] = 'user_groups';
74  $conds[] = 'ug_group IS NULL';
75  $jconds['user_groups'] = [
76  'LEFT JOIN',
77  [
78  'ug_group' => $groupsWithBotPermission,
79  'ug_user = img_user',
80  'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() )
81  ]
82  ];
83  }
84  }
85 
86  if ( $opts->getValue( 'hidepatrolled' ) ) {
87  $tables[] = 'recentchanges';
88  $conds['rc_type'] = RC_LOG;
89  $conds['rc_log_type'] = 'upload';
90  $conds['rc_patrolled'] = 0;
91  $conds['rc_namespace'] = NS_FILE;
92  $jconds['recentchanges'] = [
93  'INNER JOIN',
94  [
95  'rc_title = img_name',
96  'rc_user = img_user',
97  'rc_timestamp = img_timestamp'
98  ]
99  ];
100  // We're ordering by img_timestamp, so we have to make sure MariaDB queries `image` first.
101  // It sometimes decides to query `recentchanges` first and filesort the result set later
102  // to get the right ordering. T124205 / https://mariadb.atlassian.net/browse/MDEV-8880
103  $options[] = 'STRAIGHT_JOIN';
104  }
105 
106  $likeVal = $opts->getValue( 'like' );
107  if ( !$this->getConfig()->get( 'MiserMode' ) && $likeVal !== '' ) {
108  $dbr = wfGetDB( DB_REPLICA );
109  $likeObj = Title::newFromText( $likeVal );
110  if ( $likeObj instanceof Title ) {
111  $like = $dbr->buildLike(
112  $dbr->anyString(),
113  strtolower( $likeObj->getDBkey() ),
114  $dbr->anyString()
115  );
116  $conds[] = "LOWER(img_name) $like";
117  }
118  }
119 
120  $query = [
121  'tables' => $tables,
122  'fields' => $fields,
123  'join_conds' => $jconds,
124  'conds' => $conds,
125  'options' => $options,
126  ];
127 
128  return $query;
129  }
130 
131  function getIndexField() {
132  return 'img_timestamp';
133  }
134 
135  function getStartBody() {
136  if ( !$this->gallery ) {
137  // Note that null for mode is taken to mean use default.
138  $mode = $this->getRequest()->getVal( 'gallerymode', null );
139  try {
140  $this->gallery = ImageGalleryBase::factory( $mode, $this->getContext() );
141  } catch ( Exception $e ) {
142  // User specified something invalid, fallback to default.
143  $this->gallery = ImageGalleryBase::factory( false, $this->getContext() );
144  }
145  }
146 
147  return '';
148  }
149 
150  function getEndBody() {
151  return $this->gallery->toHTML();
152  }
153 
154  function formatRow( $row ) {
155  $name = $row->img_name;
156  $user = User::newFromId( $row->img_user );
157 
159  $ul = MediaWikiServices::getInstance()->getLinkRenderer()->makeLink(
160  $user->getUserPage(),
161  $user->getName()
162  );
163  $time = $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() );
164 
165  $this->gallery->add(
166  $title,
167  "$ul<br />\n<i>"
168  . htmlspecialchars( $time )
169  . "</i><br />\n"
170  );
171  }
172 }
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:34
ContextSource\getConfig
getConfig()
Get the Config object.
Definition: ContextSource.php:68
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:579
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:265
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:41
$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
FormOptions\getValue
getValue( $name)
Get the value for the given option name.
Definition: FormOptions.php:180
captcha-old.count
count
Definition: captcha-old.py:225
ImageGalleryBase
Image gallery.
Definition: ImageGalleryBase.php:30
RC_LOG
const RC_LOG
Definition: Defines.php:142
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
$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
NS_FILE
const NS_FILE
Definition: Defines.php:68
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:304
NewFilesPager\$gallery
ImageGalleryBase $gallery
Definition: NewFilesPager.php:32
ContextSource\getRequest
getRequest()
Get the WebRequest object.
Definition: ContextSource.php:78
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
NewFilesPager\formatRow
formatRow( $row)
Abstract formatting function.
Definition: NewFilesPager.php:154
ContextSource\getLanguage
getLanguage()
Get the Language object.
Definition: ContextSource.php:143
$query
null for the wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1572
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
IndexPager\setLimit
setLimit( $limit)
Set the limit from an other source than the request.
Definition: IndexPager.php:257
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3060
NewFilesPager\getStartBody
getStartBody()
Hook into getBody(), allows text to be inserted at the start.
Definition: NewFilesPager.php:135
$time
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1769
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:514
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
captcha-old.opts
opts
Definition: captcha-old.py:203
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2122
$ul
$ul
Definition: upgradeLogging.php:180
NewFilesPager\$opts
FormOptions $opts
Definition: NewFilesPager.php:37
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:55
NewFilesPager\getQueryInfo
getQueryInfo()
This function should be overridden to provide all parameters needed for the main paged query.
Definition: NewFilesPager.php:51
Title
Represents a title within MediaWiki.
Definition: Title.php:39
$dbr
if(! $regexes) $dbr
Definition: cleanup.php:94
User\idFromName
static idFromName( $name, $flags=self::READ_NORMAL)
Get database id given a user name.
Definition: User.php:759
NewFilesPager\getEndBody
getEndBody()
Hook into getBody() for the end of the list.
Definition: NewFilesPager.php:150
NewFilesPager\getIndexField
getIndexField()
This function should be overridden to return the name of the index fi- eld.
Definition: NewFilesPager.php:131
ReverseChronologicalPager
IndexPager with a formatted navigation bar.
Definition: ReverseChronologicalPager.php:29
ImageGalleryBase\factory
static factory( $mode=false, IContextSource $context=null)
Get a new image gallery.
Definition: ImageGalleryBase.php:87
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
MediaWikiServices
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
NewFilesPager\__construct
__construct(IContextSource $context, FormOptions $opts)
Definition: NewFilesPager.php:43
NewFilesPager
Definition: NewFilesPager.php:27
$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
User\getGroupsWithPermission
static getGroupsWithPermission( $role)
Get all the groups who have a given permission.
Definition: User.php:4743