Merge "[LockManager] Memc lockmanager improvements."
[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 $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
72 if( count( $groupsWithBotPermission ) ) {
73 $tables[] = 'user_groups';
74 $conds[] = 'ug_group IS NULL';
75 $jconds['user_groups'] = array(
76 'LEFT JOIN',
77 array(
78 'ug_group' => $groupsWithBotPermission,
79 'ug_user = img_user'
80 )
81 );
82 }
83 }
84
85 if( !$wgMiserMode && $this->like !== null ){
86 $dbr = wfGetDB( DB_SLAVE );
87 $likeObj = Title::newFromURL( $this->like );
88 if( $likeObj instanceof Title ){
89 $like = $dbr->buildLike( $dbr->anyString(), strtolower( $likeObj->getDBkey() ), $dbr->anyString() );
90 $conds[] = "LOWER(img_name) $like";
91 }
92 }
93
94 $query = array(
95 'tables' => $tables,
96 'fields' => '*',
97 'join_conds' => $jconds,
98 'conds' => $conds
99 );
100
101 return $query;
102 }
103
104 function getIndexField(){
105 return 'img_timestamp';
106 }
107
108 function getStartBody(){
109 if ( !$this->gallery ) {
110 $this->gallery = new ImageGallery();
111 }
112 return '';
113 }
114
115 function getEndBody(){
116 return $this->gallery->toHTML();
117 }
118
119 function formatRow( $row ) {
120 $name = $row->img_name;
121 $user = User::newFromId( $row->img_user );
122
123 $title = Title::makeTitle( NS_FILE, $name );
124 $ul = Linker::link( $user->getUserpage(), $user->getName() );
125
126 $this->gallery->add(
127 $title,
128 "$ul<br />\n<i>"
129 . htmlspecialchars( $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() ) )
130 . "</i><br />\n"
131 );
132 }
133
134 function getForm() {
135 global $wgMiserMode;
136
137 $fields = array(
138 'like' => array(
139 'type' => 'text',
140 'label-message' => 'newimages-label',
141 'name' => 'like',
142 ),
143 'showbots' => array(
144 'type' => 'check',
145 'label' => $this->msg( 'showhidebots', $this->msg( 'show' )->plain() )->escaped(),
146 'name' => 'showbots',
147 # 'default' => $this->getRequest()->getBool( 'showbots', 0 ),
148 ),
149 'limit' => array(
150 'type' => 'hidden',
151 'default' => $this->getRequest()->getText( 'limit' ),
152 'name' => 'limit',
153 ),
154 'offset' => array(
155 'type' => 'hidden',
156 'default' => $this->getRequest()->getText( 'offset' ),
157 'name' => 'offset',
158 ),
159 );
160
161 if( $wgMiserMode ){
162 unset( $fields['like'] );
163 }
164
165 $form = new HTMLForm( $fields, $this->getContext() );
166 $form->setTitle( $this->getTitle() );
167 $form->setSubmitTextMsg( 'ilsubmit' );
168 $form->setMethod( 'get' );
169 $form->setWrapperLegendMsg( 'newimages-legend' );
170
171 return $form;
172 }
173 }