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