Revert r104353, r104354, r104356, r104358, r104383: changes to pagers breaking...
[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( $this->getContext(), $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 /**
54 * @var ImageGallery
55 */
56 var $gallery;
57
58 function __construct( IContextSource $context, $par = null ) {
59 $this->like = $context->getRequest()->getText( 'like' );
60 $this->showbots = $context->getRequest()->getBool( 'showbots' , 0 );
61
62 parent::__construct( $context );
63 }
64
65 function getQueryInfo() {
66 global $wgMiserMode;
67 $conds = $jconds = array();
68 $tables = array( 'image' );
69
70 if( !$this->showbots ) {
71 $tables[] = 'user_groups';
72 $conds[] = 'ug_group IS NULL';
73 $jconds['user_groups'] = array(
74 'LEFT JOIN',
75 array(
76 'ug_group' => User::getGroupsWithPermission( 'bot' ),
77 'ug_user = img_user'
78 )
79 );
80 }
81
82 if( !$wgMiserMode && $this->like !== null ){
83 $dbr = wfGetDB( DB_SLAVE );
84 $likeObj = Title::newFromURL( $this->like );
85 if( $likeObj instanceof Title ){
86 $like = $dbr->buildLike( $dbr->anyString(), strtolower( $likeObj->getDBkey() ), $dbr->anyString() );
87 $conds[] = "LOWER(img_name) $like";
88 }
89 }
90
91 $query = array(
92 'tables' => $tables,
93 'fields' => '*',
94 'join_conds' => $jconds,
95 'conds' => $conds
96 );
97
98 return $query;
99 }
100
101 function getIndexField(){
102 return 'img_timestamp';
103 }
104
105 function getStartBody(){
106 $this->gallery = new ImageGallery();
107 }
108
109 function getEndBody(){
110 return $this->gallery->toHTML();
111 }
112
113 function formatRow( $row ) {
114 $name = $row->img_name;
115 $user = User::newFromId( $row->img_user );
116
117 $title = Title::makeTitle( NS_FILE, $name );
118 $ul = Linker::link( $user->getUserpage(), $user->getName() );
119
120 $this->gallery->add(
121 $title,
122 "$ul<br />\n<i>"
123 . htmlspecialchars( $this->getLanguage()->timeanddate( $row->img_timestamp, true ) )
124 . "</i><br />\n"
125 );
126 }
127
128 function getForm() {
129 global $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' => $this->getRequest()->getBool( 'showbots', 0 ),
142 ),
143 'limit' => array(
144 'type' => 'hidden',
145 'default' => $this->getRequest()->getText( 'limit' ),
146 'name' => 'limit',
147 ),
148 'offset' => array(
149 'type' => 'hidden',
150 'default' => $this->getRequest()->getText( 'offset' ),
151 'name' => 'offset',
152 ),
153 );
154
155 if( $wgMiserMode ){
156 unset( $fields['like'] );
157 }
158
159 $form = new HTMLForm( $fields, $this->getContext() );
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 }