MediaWiki  1.28.1
NewFilesPager.php
Go to the documentation of this file.
1 <?php
26 
30  protected $gallery;
31 
35  protected $opts;
36 
42  $this->opts = $opts;
43 
44  $this->setLimit( $opts->getValue( 'limit' ) );
45 
46  parent::__construct( $context );
47  }
48 
49  function getQueryInfo() {
51  $conds = $jconds = [];
52  $tables = [ 'image' ];
53  $fields = [ 'img_name', 'img_user', 'img_timestamp' ];
54  $options = [];
55 
56  if ( !$opts->getValue( 'showbots' ) ) {
57  $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
58 
59  if ( count( $groupsWithBotPermission ) ) {
60  $tables[] = 'user_groups';
61  $conds[] = 'ug_group IS NULL';
62  $jconds['user_groups'] = [
63  'LEFT JOIN',
64  [
65  'ug_group' => $groupsWithBotPermission,
66  'ug_user = img_user'
67  ]
68  ];
69  }
70  }
71 
72  if ( $opts->getValue( 'hidepatrolled' ) ) {
73  $tables[] = 'recentchanges';
74  $conds['rc_type'] = RC_LOG;
75  $conds['rc_log_type'] = 'upload';
76  $conds['rc_patrolled'] = 0;
77  $conds['rc_namespace'] = NS_FILE;
78  $jconds['recentchanges'] = [
79  'INNER JOIN',
80  [
81  'rc_title = img_name',
82  'rc_user = img_user',
83  'rc_timestamp = img_timestamp'
84  ]
85  ];
86  // We're ordering by img_timestamp, so we have to make sure MariaDB queries `image` first.
87  // It sometimes decides to query `recentchanges` first and filesort the result set later
88  // to get the right ordering. T124205 / https://mariadb.atlassian.net/browse/MDEV-8880
89  $options[] = 'STRAIGHT_JOIN';
90  }
91 
92  $likeVal = $opts->getValue( 'like' );
93  if ( !$this->getConfig()->get( 'MiserMode' ) && $likeVal !== '' ) {
94  $dbr = wfGetDB( DB_REPLICA );
95  $likeObj = Title::newFromText( $likeVal );
96  if ( $likeObj instanceof Title ) {
97  $like = $dbr->buildLike(
98  $dbr->anyString(),
99  strtolower( $likeObj->getDBkey() ),
100  $dbr->anyString()
101  );
102  $conds[] = "LOWER(img_name) $like";
103  }
104  }
105 
106  $query = [
107  'tables' => $tables,
108  'fields' => $fields,
109  'join_conds' => $jconds,
110  'conds' => $conds,
111  'options' => $options,
112  ];
113 
114  return $query;
115  }
116 
117  function getIndexField() {
118  return 'img_timestamp';
119  }
120 
121  function getStartBody() {
122  if ( !$this->gallery ) {
123  // Note that null for mode is taken to mean use default.
124  $mode = $this->getRequest()->getVal( 'gallerymode', null );
125  try {
126  $this->gallery = ImageGalleryBase::factory( $mode, $this->getContext() );
127  } catch ( Exception $e ) {
128  // User specified something invalid, fallback to default.
129  $this->gallery = ImageGalleryBase::factory( false, $this->getContext() );
130  }
131  }
132 
133  return '';
134  }
135 
136  function getEndBody() {
137  return $this->gallery->toHTML();
138  }
139 
140  function formatRow( $row ) {
141  $name = $row->img_name;
142  $user = User::newFromId( $row->img_user );
143 
145  $ul = Linker::link( $user->getUserPage(), $user->getName() );
146  $time = $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() );
147 
148  $this->gallery->add(
149  $title,
150  "$ul<br />\n<i>"
151  . htmlspecialchars( $time )
152  . "</i><br />\n"
153  );
154  }
155 }
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
Interface for objects which can provide a MediaWiki context on request.
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
null for the local 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:1555
getLanguage()
Get the Language object.
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
Definition: hooks.txt:2102
FormOptions $opts
IndexPager with a formatted navigation bar.
static newFromId($id)
Static factory method for creation from a given user ID.
Definition: User.php:548
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:262
IContextSource $context
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist & $tables
Definition: hooks.txt:1007
getRequest()
Get the WebRequest object.
static factory($mode=false, IContextSource $context=null)
Get a new image gallery.
__construct(IContextSource $context, FormOptions $opts)
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist 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:1046
getConfig()
Get the Config object.
getValue($name)
Get the value for the given option name.
getContext()
Get the base IContextSource object.
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:953
const NS_FILE
Definition: Defines.php:62
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 local account $user
Definition: hooks.txt:242
static link($target, $html=null, $customAttribs=[], $query=[], $options=[])
This function returns an HTML link to the given target.
Definition: Linker.php:203
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
setLimit($limit)
Set the limit from an other source than the request.
Definition: IndexPager.php:254
const DB_REPLICA
Definition: defines.php:22
ImageGallery $gallery
static makeTitle($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:511
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1749
static getGroupsWithPermission($role)
Get all the groups who have a given permission.
Definition: User.php:4602
const RC_LOG
Definition: Defines.php:138
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:300