MediaWiki  1.33.0
NewFilesPager.php
Go to the documentation of this file.
1 <?php
26 
28 
32  protected $gallery;
33 
37  protected $opts;
38 
44  parent::__construct( $context );
45 
46  $this->opts = $opts;
47  $this->setLimit( $opts->getValue( 'limit' ) );
48 
49  $startTimestamp = '';
50  $endTimestamp = '';
51  if ( $opts->getValue( 'start' ) ) {
52  $startTimestamp = $opts->getValue( 'start' ) . ' 00:00:00';
53  }
54  if ( $opts->getValue( 'end' ) ) {
55  $endTimestamp = $opts->getValue( 'end' ) . ' 23:59:59';
56  }
57  $this->getDateRangeCond( $startTimestamp, $endTimestamp );
58  }
59 
60  function getQueryInfo() {
62  $conds = [];
63  $imgQuery = LocalFile::getQueryInfo();
64  $tables = $imgQuery['tables'];
65  $fields = [ 'img_name', 'img_timestamp' ] + $imgQuery['fields'];
66  $options = [];
67  $jconds = $imgQuery['joins'];
68 
69  $user = $opts->getValue( 'user' );
70  if ( $user !== '' ) {
71  $conds[] = ActorMigration::newMigration()
72  ->getWhere( wfGetDB( DB_REPLICA ), 'img_user', User::newFromName( $user, false ) )['conds'];
73  }
74 
75  if ( $opts->getValue( 'newbies' ) ) {
76  // newbie = most recent 1% of users
77  $dbr = wfGetDB( DB_REPLICA );
78  $max = $dbr->selectField( 'user', 'max(user_id)', '', __METHOD__ );
79  $conds[] = $imgQuery['fields']['img_user'] . ' >' . (int)( $max - $max / 100 );
80 
81  // there's no point in looking for new user activity in a far past;
82  // beyond a certain point, we'd just end up scanning the rest of the
83  // table even though the users we're looking for didn't yet exist...
84  // see T140537, (for ContribsPages, but similar to this)
85  $conds[] = 'img_timestamp > ' .
86  $dbr->addQuotes( $dbr->timestamp( wfTimestamp() - 30 * 24 * 60 * 60 ) );
87  }
88 
89  if ( !$opts->getValue( 'showbots' ) ) {
90  $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
91 
92  if ( count( $groupsWithBotPermission ) ) {
93  $dbr = wfGetDB( DB_REPLICA );
94  $tables[] = 'user_groups';
95  $conds[] = 'ug_group IS NULL';
96  $jconds['user_groups'] = [
97  'LEFT JOIN',
98  [
99  'ug_group' => $groupsWithBotPermission,
100  'ug_user = ' . $imgQuery['fields']['img_user'],
101  'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() )
102  ]
103  ];
104  }
105  }
106 
107  if ( $opts->getValue( 'hidepatrolled' ) ) {
109 
110  $tables[] = 'recentchanges';
111  $conds['rc_type'] = RC_LOG;
112  $conds['rc_log_type'] = 'upload';
113  $conds['rc_patrolled'] = RecentChange::PRC_UNPATROLLED;
114  $conds['rc_namespace'] = NS_FILE;
115 
117  $jcond = 'rc_actor = ' . $imgQuery['fields']['img_actor'];
118  } else {
119  $rcQuery = ActorMigration::newMigration()->getJoin( 'rc_user' );
120  $tables += $rcQuery['tables'];
121  $jconds += $rcQuery['joins'];
122  $jcond = $rcQuery['fields']['rc_user'] . ' = ' . $imgQuery['fields']['img_user'];
123  }
124  $jconds['recentchanges'] = [
125  'JOIN',
126  [
127  'rc_title = img_name',
128  $jcond,
129  'rc_timestamp = img_timestamp'
130  ]
131  ];
132  // We're ordering by img_timestamp, so we have to make sure MariaDB queries `image` first.
133  // It sometimes decides to query `recentchanges` first and filesort the result set later
134  // to get the right ordering. T124205 / https://mariadb.atlassian.net/browse/MDEV-8880
135  $options[] = 'STRAIGHT_JOIN';
136  }
137 
138  if ( $opts->getValue( 'mediatype' ) ) {
139  $conds['img_media_type'] = $opts->getValue( 'mediatype' );
140  }
141 
142  $likeVal = $opts->getValue( 'like' );
143  if ( !$this->getConfig()->get( 'MiserMode' ) && $likeVal !== '' ) {
144  $dbr = wfGetDB( DB_REPLICA );
145  $likeObj = Title::newFromText( $likeVal );
146  if ( $likeObj instanceof Title ) {
147  $like = $dbr->buildLike(
148  $dbr->anyString(),
149  strtolower( $likeObj->getDBkey() ),
150  $dbr->anyString()
151  );
152  $conds[] = "LOWER(img_name) $like";
153  }
154  }
155 
156  $query = [
157  'tables' => $tables,
158  'fields' => $fields,
159  'join_conds' => $jconds,
160  'conds' => $conds,
161  'options' => $options,
162  ];
163 
164  return $query;
165  }
166 
167  function getIndexField() {
168  return 'img_timestamp';
169  }
170 
171  protected function getStartBody() {
172  if ( !$this->gallery ) {
173  // Note that null for mode is taken to mean use default.
174  $mode = $this->getRequest()->getVal( 'gallerymode', null );
175  try {
176  $this->gallery = ImageGalleryBase::factory( $mode, $this->getContext() );
177  } catch ( Exception $e ) {
178  // User specified something invalid, fallback to default.
179  $this->gallery = ImageGalleryBase::factory( false, $this->getContext() );
180  }
181  }
182 
183  return '';
184  }
185 
186  protected function getEndBody() {
187  return $this->gallery->toHTML();
188  }
189 
190  function formatRow( $row ) {
191  $name = $row->img_name;
192  $user = User::newFromId( $row->img_user );
193 
195  $ul = MediaWikiServices::getInstance()->getLinkRenderer()->makeLink(
196  $user->getUserPage(),
197  $user->getName()
198  );
199  $time = $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() );
200 
201  $this->gallery->add(
202  $title,
203  "$ul<br />\n<i>"
204  . htmlspecialchars( $time )
205  . "</i><br />\n"
206  );
207  return '';
208  }
209 }
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:33
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:63
$user
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1476
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:609
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:306
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:40
SCHEMA_COMPAT_READ_NEW
const SCHEMA_COMPAT_READ_NEW
Definition: Defines.php:287
FormOptions\getValue
getValue( $name)
Get the value for the given option name.
Definition: FormOptions.php:180
captcha-old.count
count
Definition: captcha-old.py:249
ImageGalleryBase
Image gallery.
Definition: ImageGalleryBase.php:32
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1912
RC_LOG
const RC_LOG
Definition: Defines.php:144
$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
NS_FILE
const NS_FILE
Definition: Defines.php:70
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:585
NewFilesPager\$gallery
ImageGalleryBase $gallery
Definition: NewFilesPager.php:32
ContextSource\getRequest
getRequest()
Definition: ContextSource.php:71
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
$dbr
$dbr
Definition: testCompression.php:50
NewFilesPager\formatRow
formatRow( $row)
Abstract formatting function.
Definition: NewFilesPager.php:190
ContextSource\getLanguage
getLanguage()
Definition: ContextSource.php:128
$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:1588
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
IndexPager\setLimit
setLimit( $limit)
Set the limit from an other source than the request.
Definition: IndexPager.php:299
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2636
RangeChronologicalPager\getDateRangeCond
getDateRangeCond( $startStamp, $endStamp)
Set and return a date range condition using timestamps provided by the user.
Definition: RangeChronologicalPager.php:43
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
NewFilesPager\getStartBody
getStartBody()
Hook into getBody(), allows text to be inserted at the start.
Definition: NewFilesPager.php:171
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:576
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
RangeChronologicalPager
Pager for filtering by a range of dates.
Definition: RangeChronologicalPager.php:27
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
captcha-old.opts
opts
Definition: captcha-old.py:227
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2162
$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:53
NewFilesPager\getQueryInfo
getQueryInfo()
This function should be overridden to provide all parameters needed for the main paged query.
Definition: NewFilesPager.php:60
LocalFile\getQueryInfo
static getQueryInfo(array $options=[])
Return the tables, fields, and join conditions to be selected to create a new localfile object.
Definition: LocalFile.php:244
Title
Represents a title within MediaWiki.
Definition: Title.php:40
$options
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:1985
RecentChange\PRC_UNPATROLLED
const PRC_UNPATROLLED
Definition: RecentChange.php:78
NewFilesPager\getEndBody
getEndBody()
Hook into getBody() for the end of the list.
Definition: NewFilesPager.php:186
NewFilesPager\getIndexField
getIndexField()
This function should be overridden to return the name of the index fi- eld.
Definition: NewFilesPager.php:167
ImageGalleryBase\factory
static factory( $mode=false, IContextSource $context=null)
Get a new image gallery.
Definition: ImageGalleryBase.php:103
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
$time
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1802
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
User\getGroupsWithPermission
static getGroupsWithPermission( $role)
Get all the groups who have a given permission.
Definition: User.php:5042
$wgActorTableSchemaMigrationStage
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.
Definition: DefaultSettings.php:8979