Merge "Make HTTPS port configurable"
[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 $pager = new NewFilesPager( $this->getContext(), $par );
34
35 if ( !$this->including() ) {
36 $this->setTopText();
37 $form = $pager->getForm();
38 $form->prepareForm();
39 $form->displayForm( '' );
40 }
41
42 $this->getOutput()->addHTML( $pager->getBody() );
43 if ( !$this->including() ) {
44 $this->getOutput()->addHTML( $pager->getNavigationBar() );
45 }
46 }
47
48 protected function getGroupName() {
49 return 'changes';
50 }
51
52 /**
53 * Send the text to be displayed above the options
54 */
55 function setTopText() {
56 global $wgContLang;
57
58 $message = $this->msg( 'newimagestext' )->inContentLanguage();
59 if ( !$message->isDisabled() ) {
60 $this->getOutput()->addWikiText(
61 Html::rawElement( 'p',
62 array( 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ),
63 "\n" . $message->plain() . "\n"
64 ),
65 /* $lineStart */ false,
66 /* $interface */ false
67 );
68 }
69 }
70 }
71
72 /**
73 * @ingroup SpecialPage Pager
74 */
75 class NewFilesPager extends ReverseChronologicalPager {
76 /**
77 * @var ImageGallery
78 */
79 protected $gallery;
80
81 function __construct( IContextSource $context, $par = null ) {
82 $this->like = $context->getRequest()->getText( 'like' );
83 $this->showbots = $context->getRequest()->getBool( 'showbots', 0 );
84 if ( is_numeric( $par ) ) {
85 $this->setLimit( $par );
86 }
87
88 parent::__construct( $context );
89 }
90
91 function getQueryInfo() {
92 global $wgMiserMode;
93 $conds = $jconds = array();
94 $tables = array( 'image' );
95
96 if ( !$this->showbots ) {
97 $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
98
99 if ( count( $groupsWithBotPermission ) ) {
100 $tables[] = 'user_groups';
101 $conds[] = 'ug_group IS NULL';
102 $jconds['user_groups'] = array(
103 'LEFT JOIN',
104 array(
105 'ug_group' => $groupsWithBotPermission,
106 'ug_user = img_user'
107 )
108 );
109 }
110 }
111
112 if ( !$wgMiserMode && $this->like !== null ) {
113 $dbr = wfGetDB( DB_SLAVE );
114 $likeObj = Title::newFromURL( $this->like );
115 if ( $likeObj instanceof Title ) {
116 $like = $dbr->buildLike(
117 $dbr->anyString(),
118 strtolower( $likeObj->getDBkey() ),
119 $dbr->anyString()
120 );
121 $conds[] = "LOWER(img_name) $like";
122 }
123 }
124
125 $query = array(
126 'tables' => $tables,
127 'fields' => '*',
128 'join_conds' => $jconds,
129 'conds' => $conds
130 );
131
132 return $query;
133 }
134
135 function getIndexField() {
136 return 'img_timestamp';
137 }
138
139 function getStartBody() {
140 if ( !$this->gallery ) {
141 // Note that null for mode is taken to mean use default.
142 $mode = $this->getRequest()->getVal( 'gallerymode', null );
143 try {
144 $this->gallery = ImageGalleryBase::factory( $mode );
145 } catch ( MWException $e ) {
146 // User specified something invalid, fallback to default.
147 $this->gallery = ImageGalleryBase::factory();
148 }
149 $this->gallery->setContext( $this->getContext() );
150 }
151
152 return '';
153 }
154
155 function getEndBody() {
156 return $this->gallery->toHTML();
157 }
158
159 function formatRow( $row ) {
160 $name = $row->img_name;
161 $user = User::newFromId( $row->img_user );
162
163 $title = Title::makeTitle( NS_FILE, $name );
164 $ul = Linker::link( $user->getUserpage(), $user->getName() );
165 $time = $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() );
166
167 $this->gallery->add(
168 $title,
169 "$ul<br />\n<i>"
170 . htmlspecialchars( $time )
171 . "</i><br />\n"
172 );
173 }
174
175 function getForm() {
176 global $wgMiserMode;
177
178 $fields = array(
179 'like' => array(
180 'type' => 'text',
181 'label-message' => 'newimages-label',
182 'name' => 'like',
183 ),
184 'showbots' => array(
185 'type' => 'check',
186 'label-message' => 'newimages-showbots',
187 'name' => 'showbots',
188 ),
189 'limit' => array(
190 'type' => 'hidden',
191 'default' => $this->mLimit,
192 'name' => 'limit',
193 ),
194 'offset' => array(
195 'type' => 'hidden',
196 'default' => $this->getRequest()->getText( 'offset' ),
197 'name' => 'offset',
198 ),
199 );
200
201 if ( $wgMiserMode ) {
202 unset( $fields['like'] );
203 }
204
205 $context = new DerivativeContext( $this->getContext() );
206 $context->setTitle( $this->getTitle() ); // Remove subpage
207 $form = new HTMLForm( $fields, $context );
208 $form->setSubmitTextMsg( 'ilsubmit' );
209 $form->setMethod( 'get' );
210 $form->setWrapperLegendMsg( 'newimages-legend' );
211
212 return $form;
213 }
214 }