Follow-up r84814: revert redundant summary message addition.
[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 global $wgOut;
31
32 $this->setHeaders();
33 $this->outputHeader();
34
35 $pager = new NewFilesPager( $par );
36
37 $form = $pager->getForm();
38 $form->prepareForm();
39 $form->displayForm( '' );
40 $wgOut->addHTML( $pager->getBody() . $pager->getNavigationBar() );
41 }
42 }
43
44
45 /**
46 * @ingroup SpecialPage Pager
47 */
48 class NewFilesPager extends ReverseChronologicalPager {
49
50 function __construct( $par = null ) {
51 global $wgRequest, $wgUser;
52
53 $this->like = $wgRequest->getText( 'like' );
54 $this->showbots = $wgRequest->getBool( 'showbots' , 0 );
55 $this->skin = $wgUser->getSkin();
56
57 parent::__construct();
58 }
59
60 function getQueryInfo() {
61 global $wgMiserMode;
62 $conds = $jconds = array();
63 $tables = array( 'image' );
64
65 if( !$this->showbots ) {
66 $tables[] = 'user_groups';
67 $conds[] = 'ug_group IS NULL';
68 $jconds['user_groups'] = array(
69 'LEFT JOIN',
70 array(
71 'ug_group' => User::getGroupsWithPermission( 'bot' ),
72 'ug_user = img_user'
73 )
74 );
75 }
76
77 if( !$wgMiserMode && $this->like !== null ){
78 $dbr = wfGetDB( DB_SLAVE );
79 $likeObj = Title::newFromURL( $this->like );
80 if( $likeObj instanceof Title ){
81 $like = $dbr->buildLike( $dbr->anyString(), strtolower( $likeObj->getDBkey() ), $dbr->anyString() );
82 $conds[] = "LOWER(img_name) $like";
83 }
84 }
85
86 $query = array(
87 'tables' => $tables,
88 'fields' => '*',
89 'join_conds' => $jconds,
90 'conds' => $conds
91 );
92
93 return $query;
94 }
95
96 function getIndexField(){
97 return 'img_timestamp';
98 }
99
100 function getStartBody(){
101 $this->gallery = new ImageGallery();
102 }
103
104 function getEndBody(){
105 return $this->gallery->toHTML();
106 }
107
108 function formatRow( $row ) {
109 global $wgLang;
110
111 $name = $row->img_name;
112 $user = User::newFromId( $row->img_user );
113
114 $title = Title::newFromText( $name, NS_FILE );
115 $ul = $this->skin->link( $user->getUserpage(), $user->getName() );
116
117 $this->gallery->add(
118 $title,
119 "$ul<br />\n<i>"
120 . htmlspecialchars( $wgLang->timeanddate( $row->img_timestamp, true ) )
121 . "</i><br />\n"
122 );
123 }
124
125 function getForm() {
126 global $wgRequest, $wgMiserMode;
127
128 $fields = array(
129 'like' => array(
130 'type' => 'text',
131 'label-message' => 'newimages-label',
132 'name' => 'like',
133 ),
134 'showbots' => array(
135 'type' => 'check',
136 'label' => wfMessage( 'showhidebots', wfMsg( 'show' ) ),
137 'name' => 'showbots',
138 # 'default' => $wgRequest->getBool( 'showbots', 0 ),
139 ),
140 'limit' => array(
141 'type' => 'hidden',
142 'default' => $wgRequest->getText( 'limit' ),
143 'name' => 'limit',
144 ),
145 'offset' => array(
146 'type' => 'hidden',
147 'default' => $wgRequest->getText( 'offset' ),
148 'name' => 'offset',
149 ),
150 );
151
152 if( $wgMiserMode ){
153 unset( $fields['like'] );
154 }
155
156 $form = new HTMLForm( $fields );
157 $form->setTitle( $this->getTitle() );
158 $form->setSubmitText( wfMsg( 'ilsubmit' ) );
159 $form->setMethod( 'get' );
160 $form->setWrapperLegend( wfMsg( 'newimages-legend' ) );
161
162 return $form;
163 }
164 }