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