Merge "Remove not used private member variable mParserWarnings from OutputPage"
[mediawiki.git] / includes / specials / SpecialNewimages.php
blob6b7c0387b620327608fd092cf1411869c637ca25
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 function __construct( IContextSource $context, $par = null ) {
85 $this->like = $context->getRequest()->getText( 'like' );
86 $this->showbots = $context->getRequest()->getBool( 'showbots', 0 );
87 if ( is_numeric( $par ) ) {
88 $this->setLimit( $par );
91 parent::__construct( $context );
94 function getQueryInfo() {
95 $conds = $jconds = array();
96 $tables = array( 'image' );
98 if ( !$this->showbots ) {
99 $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
101 if ( count( $groupsWithBotPermission ) ) {
102 $tables[] = 'user_groups';
103 $conds[] = 'ug_group IS NULL';
104 $jconds['user_groups'] = array(
105 'LEFT JOIN',
106 array(
107 'ug_group' => $groupsWithBotPermission,
108 'ug_user = img_user'
114 if ( !$this->getConfig()->get( 'MiserMode' ) && $this->like !== null ) {
115 $dbr = wfGetDB( DB_SLAVE );
116 $likeObj = Title::newFromText( $this->like );
117 if ( $likeObj instanceof Title ) {
118 $like = $dbr->buildLike(
119 $dbr->anyString(),
120 strtolower( $likeObj->getDBkey() ),
121 $dbr->anyString()
123 $conds[] = "LOWER(img_name) $like";
127 $query = array(
128 'tables' => $tables,
129 'fields' => '*',
130 'join_conds' => $jconds,
131 'conds' => $conds
134 return $query;
137 function getIndexField() {
138 return 'img_timestamp';
141 function getStartBody() {
142 if ( !$this->gallery ) {
143 // Note that null for mode is taken to mean use default.
144 $mode = $this->getRequest()->getVal( 'gallerymode', null );
145 try {
146 $this->gallery = ImageGalleryBase::factory( $mode, $this->getContext() );
147 } catch ( Exception $e ) {
148 // User specified something invalid, fallback to default.
149 $this->gallery = ImageGalleryBase::factory( false, $this->getContext() );
153 return '';
156 function getEndBody() {
157 return $this->gallery->toHTML();
160 function formatRow( $row ) {
161 $name = $row->img_name;
162 $user = User::newFromId( $row->img_user );
164 $title = Title::makeTitle( NS_FILE, $name );
165 $ul = Linker::link( $user->getUserpage(), $user->getName() );
166 $time = $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() );
168 $this->gallery->add(
169 $title,
170 "$ul<br />\n<i>"
171 . htmlspecialchars( $time )
172 . "</i><br />\n"
176 function getForm() {
177 $fields = array(
178 'like' => array(
179 'type' => 'text',
180 'label-message' => 'newimages-label',
181 'name' => 'like',
183 'showbots' => array(
184 'type' => 'check',
185 'label-message' => 'newimages-showbots',
186 'name' => 'showbots',
188 'limit' => array(
189 'type' => 'hidden',
190 'default' => $this->mLimit,
191 'name' => 'limit',
193 'offset' => array(
194 'type' => 'hidden',
195 'default' => $this->getRequest()->getText( 'offset' ),
196 'name' => 'offset',
200 if ( $this->getConfig()->get( 'MiserMode' ) ) {
201 unset( $fields['like'] );
204 $context = new DerivativeContext( $this->getContext() );
205 $context->setTitle( $this->getTitle() ); // Remove subpage
206 $form = new HTMLForm( $fields, $context );
208 $form->setSubmitTextMsg( 'ilsubmit' );
209 $form->setSubmitProgressive();
211 $form->setMethod( 'get' );
212 $form->setWrapperLegendMsg( 'newimages-legend' );
214 return $form;