Adding $gallery field to NewFilesPager
[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 $out = $this->getOutput();
34 $pager = new NewFilesPager( $this->getContext(), $par );
35
36 if ( !$this->including() ) {
37 $out->addHTML( $pager->buildHTMLForm() );
38 }
39 $out->addHTML( $pager->getBody() );
40 if ( !$this->including() ) {
41 $out->addHTML( $pager->getNavigationBar() );
42 }
43 }
44 }
45
46
47 /**
48 * @ingroup SpecialPage Pager
49 */
50 class NewFilesPager extends ReverseChronologicalPager {
51
52 /**
53 * @var ImageGallery
54 */
55 var $gallery;
56
57 function __construct( IContextSource $context, $par = null ) {
58 $this->like = $context->getRequest()->getText( 'like' );
59 $this->showbots = $context->getRequest()->getBool( 'showbots' , 0 );
60
61 parent::__construct( $context );
62 }
63
64 function getQueryInfo() {
65 global $wgMiserMode;
66 $conds = $jconds = array();
67 $tables = array( 'image' );
68
69 if( !$this->showbots ) {
70 $tables[] = 'user_groups';
71 $conds[] = 'ug_group IS NULL';
72 $jconds['user_groups'] = array(
73 'LEFT JOIN',
74 array(
75 'ug_group' => User::getGroupsWithPermission( 'bot' ),
76 'ug_user = img_user'
77 )
78 );
79 }
80
81 if( !$wgMiserMode && $this->like !== null ){
82 $dbr = wfGetDB( DB_SLAVE );
83 $likeObj = Title::newFromURL( $this->like );
84 if( $likeObj instanceof Title ){
85 $like = $dbr->buildLike( $dbr->anyString(), strtolower( $likeObj->getDBkey() ), $dbr->anyString() );
86 $conds[] = "LOWER(img_name) $like";
87 }
88 }
89
90 $query = array(
91 'tables' => $tables,
92 'fields' => '*',
93 'join_conds' => $jconds,
94 'conds' => $conds
95 );
96
97 return $query;
98 }
99
100 function getIndexField(){
101 return 'img_timestamp';
102 }
103
104 function getStartBody(){
105 $this->gallery = new ImageGallery();
106 }
107
108 function getEndBody(){
109 return $this->gallery->toHTML();
110 }
111
112 function formatRow( $row ) {
113 $name = $row->img_name;
114 $user = User::newFromId( $row->img_user );
115
116 $title = Title::makeTitle( NS_FILE, $name );
117 $ul = Linker::link( $user->getUserpage(), $user->getName() );
118
119 $this->gallery->add(
120 $title,
121 "$ul<br />\n<i>"
122 . htmlspecialchars( $this->getLanguage()->timeanddate( $row->img_timestamp, true ) )
123 . "</i><br />\n"
124 );
125 }
126
127 protected function getHTMLFormFields() {
128 global $wgMiserMode;
129
130 $fields = array(
131 'like' => array(
132 'type' => 'text',
133 'label-message' => 'newimages-label',
134 'name' => 'like',
135 ),
136 'showbots' => array(
137 'type' => 'check',
138 'label' => wfMessage( 'showhidebots', wfMsg( 'show' ) ),
139 'name' => 'showbots',
140 ),
141 );
142
143 if( $wgMiserMode ){
144 unset( $fields['like'] );
145 }
146
147 return $fields;
148 }
149
150 protected function getHTMLFormLegend() {
151 return 'newimages-legend';
152 }
153
154 protected function getHTMLFormSubmit() {
155 return 'ilsubmit';
156 }
157 }