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