Add checks of $wgEnableBotPasswords in more places
[mediawiki.git] / includes / specials / SpecialNewimages.php
blob53fb45e7076702764a5994cd4d77db36f5703a12
1 <?php
2 /**
3 * Implements Special:Newimages
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup SpecialPage
24 class SpecialNewFiles extends IncludableSpecialPage {
25 public function __construct() {
26 parent::__construct( 'Newimages' );
29 public function execute( $par ) {
30 $this->setHeaders();
31 $this->outputHeader();
33 $out = $this->getOutput();
34 $this->addHelpLink( 'Help:New images' );
36 $pager = new NewFilesPager( $this->getContext(), $par );
38 if ( !$this->including() ) {
39 $this->setTopText();
40 $form = $pager->getForm();
41 $form->prepareForm();
42 $form->displayForm( '' );
45 $out->addHTML( $pager->getBody() );
46 if ( !$this->including() ) {
47 $out->addHTML( $pager->getNavigationBar() );
51 protected function getGroupName() {
52 return 'changes';
55 /**
56 * Send the text to be displayed above the options
58 function setTopText() {
59 global $wgContLang;
61 $message = $this->msg( 'newimagestext' )->inContentLanguage();
62 if ( !$message->isDisabled() ) {
63 $this->getOutput()->addWikiText(
64 Html::rawElement( 'p',
65 array( 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ),
66 "\n" . $message->plain() . "\n"
68 /* $lineStart */ false,
69 /* $interface */ false
75 /**
76 * @ingroup SpecialPage Pager
78 class NewFilesPager extends ReverseChronologicalPager {
79 /**
80 * @var ImageGallery
82 protected $gallery;
84 /**
85 * @var bool
87 protected $showBots;
89 /**
90 * @var bool
92 protected $hidePatrolled;
94 function __construct( IContextSource $context, $par = null ) {
95 $this->like = $context->getRequest()->getText( 'like' );
96 $this->showBots = $context->getRequest()->getBool( 'showbots', 0 );
97 $this->hidePatrolled = $context->getRequest()->getBool( 'hidepatrolled', 0 );
98 if ( is_numeric( $par ) ) {
99 $this->setLimit( $par );
102 parent::__construct( $context );
105 function getQueryInfo() {
106 $conds = $jconds = array();
107 $tables = array( 'image' );
109 if ( !$this->showBots ) {
110 $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
112 if ( count( $groupsWithBotPermission ) ) {
113 $tables[] = 'user_groups';
114 $conds[] = 'ug_group IS NULL';
115 $jconds['user_groups'] = array(
116 'LEFT JOIN',
117 array(
118 'ug_group' => $groupsWithBotPermission,
119 'ug_user = img_user'
125 if ( $this->hidePatrolled ) {
126 $tables[] = 'recentchanges';
127 $conds['rc_type'] = RC_LOG;
128 $conds['rc_log_type'] = 'upload';
129 $conds['rc_patrolled'] = 0;
130 $jconds['recentchanges'] = array(
131 'INNER JOIN',
132 array(
133 'rc_title = img_name',
134 'rc_user = img_user',
135 'rc_timestamp = img_timestamp'
140 if ( !$this->getConfig()->get( 'MiserMode' ) && $this->like !== null ) {
141 $dbr = wfGetDB( DB_SLAVE );
142 $likeObj = Title::newFromText( $this->like );
143 if ( $likeObj instanceof Title ) {
144 $like = $dbr->buildLike(
145 $dbr->anyString(),
146 strtolower( $likeObj->getDBkey() ),
147 $dbr->anyString()
149 $conds[] = "LOWER(img_name) $like";
153 $query = array(
154 'tables' => $tables,
155 'fields' => '*',
156 'join_conds' => $jconds,
157 'conds' => $conds
160 return $query;
163 function getIndexField() {
164 return 'img_timestamp';
167 function getStartBody() {
168 if ( !$this->gallery ) {
169 // Note that null for mode is taken to mean use default.
170 $mode = $this->getRequest()->getVal( 'gallerymode', null );
171 try {
172 $this->gallery = ImageGalleryBase::factory( $mode, $this->getContext() );
173 } catch ( Exception $e ) {
174 // User specified something invalid, fallback to default.
175 $this->gallery = ImageGalleryBase::factory( false, $this->getContext() );
179 return '';
182 function getEndBody() {
183 return $this->gallery->toHTML();
186 function formatRow( $row ) {
187 $name = $row->img_name;
188 $user = User::newFromId( $row->img_user );
190 $title = Title::makeTitle( NS_FILE, $name );
191 $ul = Linker::link( $user->getUserpage(), $user->getName() );
192 $time = $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() );
194 $this->gallery->add(
195 $title,
196 "$ul<br />\n<i>"
197 . htmlspecialchars( $time )
198 . "</i><br />\n"
202 function getForm() {
203 $fields = array(
204 'like' => array(
205 'type' => 'text',
206 'label-message' => 'newimages-label',
207 'name' => 'like',
209 'showbots' => array(
210 'type' => 'check',
211 'label-message' => 'newimages-showbots',
212 'name' => 'showbots',
214 'hidepatrolled' => array(
215 'type' => 'check',
216 'label-message' => 'newimages-hidepatrolled',
217 'name' => 'hidepatrolled',
219 'limit' => array(
220 'type' => 'hidden',
221 'default' => $this->mLimit,
222 'name' => 'limit',
224 'offset' => array(
225 'type' => 'hidden',
226 'default' => $this->getRequest()->getText( 'offset' ),
227 'name' => 'offset',
231 if ( $this->getConfig()->get( 'MiserMode' ) ) {
232 unset( $fields['like'] );
235 if ( !$this->getUser()->useFilePatrol() ) {
236 unset( $fields['hidepatrolled'] );
239 $context = new DerivativeContext( $this->getContext() );
240 $context->setTitle( $this->getTitle() ); // Remove subpage
241 $form = new HTMLForm( $fields, $context );
243 $form->setSubmitTextMsg( 'ilsubmit' );
244 $form->setSubmitProgressive();
246 $form->setMethod( 'get' );
247 $form->setWrapperLegendMsg( 'newimages-legend' );
249 return $form;