7954795b6be56b85e96187355375ebc9934bf90c
[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
47 /**
48 * @ingroup SpecialPage Pager
49 */
50 class NewFilesPager extends ReverseChronologicalPager {
51
52 /**
53 * @var ImageGallery
54 */
55 var $gallery;
56
57 function __construct( IContextSource $context, $par = null ) {
58 $this->like = $context->getRequest()->getText( 'like' );
59 $this->showbots = $context->getRequest()->getBool( 'showbots', 0 );
60 if ( is_numeric( $par ) ) {
61 $this->setLimit( $par );
62 }
63
64 parent::__construct( $context );
65 }
66
67 function getQueryInfo() {
68 global $wgMiserMode;
69 $conds = $jconds = array();
70 $tables = array( 'image' );
71
72 if( !$this->showbots ) {
73 $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
74 if( count( $groupsWithBotPermission ) ) {
75 $tables[] = 'user_groups';
76 $conds[] = 'ug_group IS NULL';
77 $jconds['user_groups'] = array(
78 'LEFT JOIN',
79 array(
80 'ug_group' => $groupsWithBotPermission,
81 'ug_user = img_user'
82 )
83 );
84 }
85 }
86
87 if( !$wgMiserMode && $this->like !== null ) {
88 $dbr = wfGetDB( DB_SLAVE );
89 $likeObj = Title::newFromURL( $this->like );
90 if( $likeObj instanceof Title ) {
91 $like = $dbr->buildLike( $dbr->anyString(), strtolower( $likeObj->getDBkey() ), $dbr->anyString() );
92 $conds[] = "LOWER(img_name) $like";
93 }
94 }
95
96 $query = array(
97 'tables' => $tables,
98 'fields' => '*',
99 'join_conds' => $jconds,
100 'conds' => $conds
101 );
102
103 return $query;
104 }
105
106 function getIndexField() {
107 return 'img_timestamp';
108 }
109
110 function getStartBody() {
111 if ( !$this->gallery ) {
112 $this->gallery = new ImageGallery();
113 }
114 return '';
115 }
116
117 function getEndBody() {
118 return $this->gallery->toHTML();
119 }
120
121 function formatRow( $row ) {
122 $name = $row->img_name;
123 $user = User::newFromId( $row->img_user );
124
125 $title = Title::makeTitle( NS_FILE, $name );
126 $ul = Linker::link( $user->getUserpage(), $user->getName() );
127
128 $this->gallery->add(
129 $title,
130 "$ul<br />\n<i>"
131 . htmlspecialchars( $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() ) )
132 . "</i><br />\n"
133 );
134 }
135
136 function getForm() {
137 global $wgMiserMode;
138
139 $fields = array(
140 'like' => array(
141 'type' => 'text',
142 'label-message' => 'newimages-label',
143 'name' => 'like',
144 ),
145 'showbots' => array(
146 'type' => 'check',
147 'label' => $this->msg( 'showhidebots', $this->msg( 'show' )->plain() )->escaped(),
148 'name' => 'showbots',
149 # 'default' => $this->getRequest()->getBool( 'showbots', 0 ),
150 ),
151 'limit' => array(
152 'type' => 'hidden',
153 'default' => $this->mLimit,
154 'name' => 'limit',
155 ),
156 'offset' => array(
157 'type' => 'hidden',
158 'default' => $this->getRequest()->getText( 'offset' ),
159 'name' => 'offset',
160 ),
161 );
162
163 if( $wgMiserMode ) {
164 unset( $fields['like'] );
165 }
166
167 $form = new HTMLForm( $fields, $this->getContext() );
168 $form->setTitle( $this->getTitle() );
169 $form->setSubmitTextMsg( 'ilsubmit' );
170 $form->setMethod( 'get' );
171 $form->setWrapperLegendMsg( 'newimages-legend' );
172
173 return $form;
174 }
175 }