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