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