MediaWiki  1.27.2
NewFilesPager.php
Go to the documentation of this file.
1 <?php
26 
30  protected $gallery;
31 
35  protected $showBots;
36 
40  protected $hidePatrolled;
41 
42  function __construct( IContextSource $context, $par = null ) {
43  $this->like = $context->getRequest()->getText( 'like' );
44  $this->showBots = $context->getRequest()->getBool( 'showbots', 0 );
45  $this->hidePatrolled = $context->getRequest()->getBool( 'hidepatrolled', 0 );
46  if ( is_numeric( $par ) ) {
47  $this->setLimit( $par );
48  }
49 
50  parent::__construct( $context );
51  }
52 
53  function getQueryInfo() {
54  $conds = $jconds = [];
55  $tables = [ 'image' ];
56  $fields = [ 'img_name', 'img_user', 'img_timestamp' ];
57  $options = [];
58 
59  if ( !$this->showBots ) {
60  $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
61 
62  if ( count( $groupsWithBotPermission ) ) {
63  $tables[] = 'user_groups';
64  $conds[] = 'ug_group IS NULL';
65  $jconds['user_groups'] = [
66  'LEFT JOIN',
67  [
68  'ug_group' => $groupsWithBotPermission,
69  'ug_user = img_user'
70  ]
71  ];
72  }
73  }
74 
75  if ( $this->hidePatrolled ) {
76  $tables[] = 'recentchanges';
77  $conds['rc_type'] = RC_LOG;
78  $conds['rc_log_type'] = 'upload';
79  $conds['rc_patrolled'] = 0;
80  $conds['rc_namespace'] = NS_FILE;
81  $jconds['recentchanges'] = [
82  'INNER JOIN',
83  [
84  'rc_title = img_name',
85  'rc_user = img_user',
86  'rc_timestamp = img_timestamp'
87  ]
88  ];
89  // We're ordering by img_timestamp, so we have to make sure MariaDB queries `image` first.
90  // It sometimes decides to query `recentchanges` first and filesort the result set later
91  // to get the right ordering. T124205 / https://mariadb.atlassian.net/browse/MDEV-8880
92  $options[] = 'STRAIGHT_JOIN';
93  }
94 
95  if ( !$this->getConfig()->get( 'MiserMode' ) && $this->like !== null ) {
96  $dbr = wfGetDB( DB_SLAVE );
97  $likeObj = Title::newFromText( $this->like );
98  if ( $likeObj instanceof Title ) {
99  $like = $dbr->buildLike(
100  $dbr->anyString(),
101  strtolower( $likeObj->getDBkey() ),
102  $dbr->anyString()
103  );
104  $conds[] = "LOWER(img_name) $like";
105  }
106  }
107 
108  $query = [
109  'tables' => $tables,
110  'fields' => $fields,
111  'join_conds' => $jconds,
112  'conds' => $conds,
113  'options' => $options,
114  ];
115 
116  return $query;
117  }
118 
119  function getIndexField() {
120  return 'img_timestamp';
121  }
122 
123  function getStartBody() {
124  if ( !$this->gallery ) {
125  // Note that null for mode is taken to mean use default.
126  $mode = $this->getRequest()->getVal( 'gallerymode', null );
127  try {
128  $this->gallery = ImageGalleryBase::factory( $mode, $this->getContext() );
129  } catch ( Exception $e ) {
130  // User specified something invalid, fallback to default.
131  $this->gallery = ImageGalleryBase::factory( false, $this->getContext() );
132  }
133  }
134 
135  return '';
136  }
137 
138  function getEndBody() {
139  return $this->gallery->toHTML();
140  }
141 
142  function formatRow( $row ) {
143  $name = $row->img_name;
144  $user = User::newFromId( $row->img_user );
145 
147  $ul = Linker::link( $user->getUserPage(), $user->getName() );
148  $time = $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() );
149 
150  $this->gallery->add(
151  $title,
152  "$ul<br />\n<i>"
153  . htmlspecialchars( $time )
154  . "</i><br />\n"
155  );
156  }
157 
158  function getForm() {
159  $fields = [
160  'like' => [
161  'type' => 'text',
162  'label-message' => 'newimages-label',
163  'name' => 'like',
164  ],
165  'showbots' => [
166  'type' => 'check',
167  'label-message' => 'newimages-showbots',
168  'name' => 'showbots',
169  ],
170  'hidepatrolled' => [
171  'type' => 'check',
172  'label-message' => 'newimages-hidepatrolled',
173  'name' => 'hidepatrolled',
174  ],
175  'limit' => [
176  'type' => 'hidden',
177  'default' => $this->mLimit,
178  'name' => 'limit',
179  ],
180  'offset' => [
181  'type' => 'hidden',
182  'default' => $this->getRequest()->getText( 'offset' ),
183  'name' => 'offset',
184  ],
185  ];
186 
187  if ( $this->getConfig()->get( 'MiserMode' ) ) {
188  unset( $fields['like'] );
189  }
190 
191  if ( !$this->getUser()->useFilePatrol() ) {
192  unset( $fields['hidepatrolled'] );
193  }
194 
195  $context = new DerivativeContext( $this->getContext() );
196  $context->setTitle( $this->getTitle() ); // Remove subpage
197  $form = new HTMLForm( $fields, $context );
198 
199  $form->setSubmitTextMsg( 'ilsubmit' );
200  $form->setSubmitProgressive();
201 
202  $form->setMethod( 'get' );
203  $form->setWrapperLegendMsg( 'newimages-legend' );
204 
205  return $form;
206  }
207 }
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:1418
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:1932
An IContextSource implementation which will inherit context from another source but allow individual ...
IndexPager with a formatted navigation bar.
static newFromId($id)
Static factory method for creation from a given user ID.
Definition: User.php:591
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:277
Represents a title within MediaWiki.
Definition: Title.php:34
IContextSource $context
getTitle()
Get the Title object.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist & $tables
Definition: hooks.txt:965
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1612
getRequest()
Get the WebRequest object.
static factory($mode=false, IContextSource $context=null)
Get a new image gallery.
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:1004
getConfig()
Get the Config object.
getContext()
Get the base IContextSource object.
Object handling generic submission, CSRF protection, layout and other logic for UI forms...
Definition: HTMLForm.php:123
const DB_SLAVE
Definition: Defines.php:46
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
const NS_FILE
Definition: Defines.php:75
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:195
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
__construct(IContextSource $context, $par=null)
setLimit($limit)
Set the limit from an other source than the request.
Definition: IndexPager.php:254
ImageGallery $gallery
getUser()
Get the User object.
getRequest()
Get the WebRequest object.
static & makeTitle($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:524
static getGroupsWithPermission($role)
Get all the groups who have a given permission.
Definition: User.php:4529
const RC_LOG
Definition: Defines.php:171
For a write use something like
Definition: database.txt:26
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:310