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