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