Merge "Add TitleQuickPermissions hook to Title::checkQuickPermissions"
[mediawiki.git] / includes / specials / SpecialNewimages.php
blob8e92e4ae1062b6f27ad3074aa7b180d113fe0227
1 <?php
2 /**
3 * Implements Special:Newimages
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.
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.
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
20 * @file
21 * @ingroup SpecialPage
23 class SpecialNewFiles extends IncludableSpecialPage {
24 public function __construct() {
25 parent::__construct( 'Newimages' );
28 public function execute( $par ) {
29 $this->setHeaders();
30 $this->outputHeader();
32 $pager = new NewFilesPager( $this->getContext(), $par );
34 if ( !$this->including() ) {
35 $form = $pager->getForm();
36 $form->prepareForm();
37 $form->displayForm( '' );
40 $this->getOutput()->addHTML( $pager->getBody() );
41 if ( !$this->including() ) {
42 $this->getOutput()->addHTML( $pager->getNavigationBar() );
46 protected function getGroupName() {
47 return 'changes';
51 /**
52 * @ingroup SpecialPage Pager
54 class NewFilesPager extends ReverseChronologicalPager {
55 /**
56 * @var ImageGallery
58 var $gallery;
60 function __construct( IContextSource $context, $par = null ) {
61 $this->like = $context->getRequest()->getText( 'like' );
62 $this->showbots = $context->getRequest()->getBool( 'showbots', 0 );
63 if ( is_numeric( $par ) ) {
64 $this->setLimit( $par );
67 parent::__construct( $context );
70 function getQueryInfo() {
71 global $wgMiserMode;
72 $conds = $jconds = array();
73 $tables = array( 'image' );
75 if ( !$this->showbots ) {
76 $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
78 if ( count( $groupsWithBotPermission ) ) {
79 $tables[] = 'user_groups';
80 $conds[] = 'ug_group IS NULL';
81 $jconds['user_groups'] = array(
82 'LEFT JOIN',
83 array(
84 'ug_group' => $groupsWithBotPermission,
85 'ug_user = img_user'
91 if ( !$wgMiserMode && $this->like !== null ) {
92 $dbr = wfGetDB( DB_SLAVE );
93 $likeObj = Title::newFromURL( $this->like );
94 if ( $likeObj instanceof Title ) {
95 $like = $dbr->buildLike(
96 $dbr->anyString(),
97 strtolower( $likeObj->getDBkey() ),
98 $dbr->anyString()
100 $conds[] = "LOWER(img_name) $like";
104 $query = array(
105 'tables' => $tables,
106 'fields' => '*',
107 'join_conds' => $jconds,
108 'conds' => $conds
111 return $query;
114 function getIndexField() {
115 return 'img_timestamp';
118 function getStartBody() {
119 if ( !$this->gallery ) {
120 $this->gallery = new ImageGallery();
123 return '';
126 function getEndBody() {
127 return $this->gallery->toHTML();
130 function formatRow( $row ) {
131 $name = $row->img_name;
132 $user = User::newFromId( $row->img_user );
134 $title = Title::makeTitle( NS_FILE, $name );
135 $ul = Linker::link( $user->getUserpage(), $user->getName() );
136 $time = $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() );
138 $this->gallery->add(
139 $title,
140 "$ul<br />\n<i>"
141 . htmlspecialchars( $time )
142 . "</i><br />\n"
146 function getForm() {
147 global $wgMiserMode;
149 $fields = array(
150 'like' => array(
151 'type' => 'text',
152 'label-message' => 'newimages-label',
153 'name' => 'like',
155 'showbots' => array(
156 'type' => 'check',
157 'label' => $this->msg( 'showhidebots', $this->msg( 'show' )->plain() )->escaped(),
158 'name' => 'showbots',
160 'limit' => array(
161 'type' => 'hidden',
162 'default' => $this->mLimit,
163 'name' => 'limit',
165 'offset' => array(
166 'type' => 'hidden',
167 'default' => $this->getRequest()->getText( 'offset' ),
168 'name' => 'offset',
172 if ( $wgMiserMode ) {
173 unset( $fields['like'] );
176 $form = new HTMLForm( $fields, $this->getContext() );
177 $form->setTitle( $this->getTitle() );
178 $form->setSubmitTextMsg( 'ilsubmit' );
179 $form->setMethod( 'get' );
180 $form->setWrapperLegendMsg( 'newimages-legend' );
182 return $form;