Merge "Protected function UploadBase->validateName changed to public"
[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
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 $form = $pager->getForm();
37 $form->prepareForm();
38 $form->displayForm( '' );
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 /**
57 * @var ImageGallery
58 */
59 var $gallery;
60
61 function __construct( IContextSource $context, $par = null ) {
62 $this->like = $context->getRequest()->getText( 'like' );
63 $this->showbots = $context->getRequest()->getBool( 'showbots', 0 );
64 if ( is_numeric( $par ) ) {
65 $this->setLimit( $par );
66 }
67
68 parent::__construct( $context );
69 }
70
71 function getQueryInfo() {
72 global $wgMiserMode;
73 $conds = $jconds = array();
74 $tables = array( 'image' );
75
76 if( !$this->showbots ) {
77 $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
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( $dbr->anyString(), strtolower( $likeObj->getDBkey() ), $dbr->anyString() );
96 $conds[] = "LOWER(img_name) $like";
97 }
98 }
99
100 $query = array(
101 'tables' => $tables,
102 'fields' => '*',
103 'join_conds' => $jconds,
104 'conds' => $conds
105 );
106
107 return $query;
108 }
109
110 function getIndexField() {
111 return 'img_timestamp';
112 }
113
114 function getStartBody() {
115 if ( !$this->gallery ) {
116 $this->gallery = new ImageGallery();
117 }
118 return '';
119 }
120
121 function getEndBody() {
122 return $this->gallery->toHTML();
123 }
124
125 function formatRow( $row ) {
126 $name = $row->img_name;
127 $user = User::newFromId( $row->img_user );
128
129 $title = Title::makeTitle( NS_FILE, $name );
130 $ul = Linker::link( $user->getUserpage(), $user->getName() );
131
132 $this->gallery->add(
133 $title,
134 "$ul<br />\n<i>"
135 . htmlspecialchars( $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() ) )
136 . "</i><br />\n"
137 );
138 }
139
140 function getForm() {
141 global $wgMiserMode;
142
143 $fields = array(
144 'like' => array(
145 'type' => 'text',
146 'label-message' => 'newimages-label',
147 'name' => 'like',
148 ),
149 'showbots' => array(
150 'type' => 'check',
151 'label' => $this->msg( 'showhidebots', $this->msg( 'show' )->plain() )->escaped(),
152 'name' => 'showbots',
153 # 'default' => $this->getRequest()->getBool( 'showbots', 0 ),
154 ),
155 'limit' => array(
156 'type' => 'hidden',
157 'default' => $this->mLimit,
158 'name' => 'limit',
159 ),
160 'offset' => array(
161 'type' => 'hidden',
162 'default' => $this->getRequest()->getText( 'offset' ),
163 'name' => 'offset',
164 ),
165 );
166
167 if( $wgMiserMode ) {
168 unset( $fields['like'] );
169 }
170
171 $form = new HTMLForm( $fields, $this->getContext() );
172 $form->setTitle( $this->getTitle() );
173 $form->setSubmitTextMsg( 'ilsubmit' );
174 $form->setMethod( 'get' );
175 $form->setWrapperLegendMsg( 'newimages-legend' );
176
177 return $form;
178 }
179 }