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