Merge "Don't purge thumbs for old versions of an image during ?action=purge"
[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 $this->gallery = new ImageGallery();
121 }
122
123 return '';
124 }
125
126 function getEndBody() {
127 return $this->gallery->toHTML();
128 }
129
130 function formatRow( $row ) {
131 $name = $row->img_name;
132 $user = User::newFromId( $row->img_user );
133
134 $title = Title::makeTitle( NS_FILE, $name );
135 $ul = Linker::link( $user->getUserpage(), $user->getName() );
136 $time = $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() );
137
138 $this->gallery->add(
139 $title,
140 "$ul<br />\n<i>"
141 . htmlspecialchars( $time )
142 . "</i><br />\n"
143 );
144 }
145
146 function getForm() {
147 global $wgMiserMode;
148
149 $fields = array(
150 'like' => array(
151 'type' => 'text',
152 'label-message' => 'newimages-label',
153 'name' => 'like',
154 ),
155 'showbots' => array(
156 'type' => 'check',
157 'label' => $this->msg( 'showhidebots', $this->msg( 'show' )->plain() )->escaped(),
158 'name' => 'showbots',
159 ),
160 'limit' => array(
161 'type' => 'hidden',
162 'default' => $this->mLimit,
163 'name' => 'limit',
164 ),
165 'offset' => array(
166 'type' => 'hidden',
167 'default' => $this->getRequest()->getText( 'offset' ),
168 'name' => 'offset',
169 ),
170 );
171
172 if ( $wgMiserMode ) {
173 unset( $fields['like'] );
174 }
175
176 $form = new HTMLForm( $fields, $this->getContext() );
177 $form->setTitle( $this->getTitle() );
178 $form->setSubmitTextMsg( 'ilsubmit' );
179 $form->setMethod( 'get' );
180 $form->setWrapperLegendMsg( 'newimages-legend' );
181
182 return $form;
183 }
184 }