Switch some HTMLForms in special pages to OOUI
[lhc/web/wiklou.git] / includes / specials / SpecialNewimages.php
1 <?php
2 /**
3 * Implements Special:Newimages
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 class SpecialNewFiles extends IncludableSpecialPage {
25 public function __construct() {
26 parent::__construct( 'Newimages' );
27 }
28
29 public function execute( $par ) {
30 $this->setHeaders();
31 $this->outputHeader();
32
33 $out = $this->getOutput();
34 $this->addHelpLink( 'Help:New images' );
35
36 $pager = new NewFilesPager( $this->getContext(), $par );
37
38 if ( !$this->including() ) {
39 $this->setTopText();
40 $form = $pager->getForm();
41 $form->prepareForm();
42 $form->displayForm( '' );
43 }
44
45 $out->addHTML( $pager->getBody() );
46 if ( !$this->including() ) {
47 $out->addHTML( $pager->getNavigationBar() );
48 }
49 }
50
51 protected function getGroupName() {
52 return 'changes';
53 }
54
55 /**
56 * Send the text to be displayed above the options
57 */
58 function setTopText() {
59 global $wgContLang;
60
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"
67 ),
68 /* $lineStart */ false,
69 /* $interface */ false
70 );
71 }
72 }
73 }
74
75 /**
76 * @ingroup SpecialPage Pager
77 */
78 class NewFilesPager extends ReverseChronologicalPager {
79 /**
80 * @var ImageGallery
81 */
82 protected $gallery;
83
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 );
89 }
90
91 parent::__construct( $context );
92 }
93
94 function getQueryInfo() {
95 $conds = $jconds = array();
96 $tables = array( 'image' );
97
98 if ( !$this->showbots ) {
99 $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
100
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'
109 )
110 );
111 }
112 }
113
114 if ( !$this->getConfig()->get( 'MiserMode' ) && $this->like !== null ) {
115 $dbr = wfGetDB( DB_SLAVE );
116 $likeObj = Title::newFromURL( $this->like );
117 if ( $likeObj instanceof Title ) {
118 $like = $dbr->buildLike(
119 $dbr->anyString(),
120 strtolower( $likeObj->getDBkey() ),
121 $dbr->anyString()
122 );
123 $conds[] = "LOWER(img_name) $like";
124 }
125 }
126
127 $query = array(
128 'tables' => $tables,
129 'fields' => '*',
130 'join_conds' => $jconds,
131 'conds' => $conds
132 );
133
134 return $query;
135 }
136
137 function getIndexField() {
138 return 'img_timestamp';
139 }
140
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() );
150 }
151 }
152
153 return '';
154 }
155
156 function getEndBody() {
157 return $this->gallery->toHTML();
158 }
159
160 function formatRow( $row ) {
161 $name = $row->img_name;
162 $user = User::newFromId( $row->img_user );
163
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() );
167
168 $this->gallery->add(
169 $title,
170 "$ul<br />\n<i>"
171 . htmlspecialchars( $time )
172 . "</i><br />\n"
173 );
174 }
175
176 function getForm() {
177 $fields = array(
178 'like' => array(
179 'type' => 'text',
180 'label-message' => 'newimages-label',
181 'name' => 'like',
182 ),
183 'showbots' => array(
184 'type' => 'check',
185 'label-message' => 'newimages-showbots',
186 'name' => 'showbots',
187 ),
188 'limit' => array(
189 'type' => 'hidden',
190 'default' => $this->mLimit,
191 'name' => 'limit',
192 ),
193 'offset' => array(
194 'type' => 'hidden',
195 'default' => $this->getRequest()->getText( 'offset' ),
196 'name' => 'offset',
197 ),
198 );
199
200 if ( $this->getConfig()->get( 'MiserMode' ) ) {
201 unset( $fields['like'] );
202 }
203
204 $context = new DerivativeContext( $this->getContext() );
205 $context->setTitle( $this->getTitle() ); // Remove subpage
206 $form = new HTMLForm( $fields, $context );
207
208 $form->setSubmitTextMsg( 'ilsubmit' );
209 $form->setSubmitProgressive();
210
211 $form->setMethod( 'get' );
212 $form->setWrapperLegendMsg( 'newimages-legend' );
213
214 return $form;
215 }
216 }