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