Remove "related" searches
[mediawiki.git] / includes / specials / SpecialNewimages.php
blob546c1914055288bac020f15b49c73cba20a34909
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
24 class SpecialNewFiles extends IncludableSpecialPage {
25 public function __construct() {
26 parent::__construct( 'Newimages' );
29 public function execute( $par ) {
30 $this->setHeaders();
31 $this->outputHeader();
33 $pager = new NewFilesPager( $this->getContext(), $par );
35 if ( !$this->including() ) {
36 $this->setTopText();
37 $form = $pager->getForm();
38 $form->prepareForm();
39 $form->displayForm( '' );
42 $this->getOutput()->addHTML( $pager->getBody() );
43 if ( !$this->including() ) {
44 $this->getOutput()->addHTML( $pager->getNavigationBar() );
48 protected function getGroupName() {
49 return 'changes';
52 /**
53 * Send the text to be displayed above the options
55 function setTopText() {
56 global $wgContLang;
58 $message = $this->msg( 'newimagestext' )->inContentLanguage();
59 if ( !$message->isDisabled() ) {
60 $this->getOutput()->addWikiText(
61 Html::rawElement( 'p',
62 array( 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ),
63 "\n" . $message->plain() . "\n"
65 /* $lineStart */ false,
66 /* $interface */ false
72 /**
73 * @ingroup SpecialPage Pager
75 class NewFilesPager extends ReverseChronologicalPager {
76 /**
77 * @var ImageGallery
79 protected $gallery;
81 function __construct( IContextSource $context, $par = null ) {
82 $this->like = $context->getRequest()->getText( 'like' );
83 $this->showbots = $context->getRequest()->getBool( 'showbots', 0 );
84 if ( is_numeric( $par ) ) {
85 $this->setLimit( $par );
88 parent::__construct( $context );
91 function getQueryInfo() {
92 $conds = $jconds = array();
93 $tables = array( 'image' );
95 if ( !$this->showbots ) {
96 $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
98 if ( count( $groupsWithBotPermission ) ) {
99 $tables[] = 'user_groups';
100 $conds[] = 'ug_group IS NULL';
101 $jconds['user_groups'] = array(
102 'LEFT JOIN',
103 array(
104 'ug_group' => $groupsWithBotPermission,
105 'ug_user = img_user'
111 if ( !$this->getConfig()->get( 'MiserMode' ) && $this->like !== null ) {
112 $dbr = wfGetDB( DB_SLAVE );
113 $likeObj = Title::newFromURL( $this->like );
114 if ( $likeObj instanceof Title ) {
115 $like = $dbr->buildLike(
116 $dbr->anyString(),
117 strtolower( $likeObj->getDBkey() ),
118 $dbr->anyString()
120 $conds[] = "LOWER(img_name) $like";
124 $query = array(
125 'tables' => $tables,
126 'fields' => '*',
127 'join_conds' => $jconds,
128 'conds' => $conds
131 return $query;
134 function getIndexField() {
135 return 'img_timestamp';
138 function getStartBody() {
139 if ( !$this->gallery ) {
140 // Note that null for mode is taken to mean use default.
141 $mode = $this->getRequest()->getVal( 'gallerymode', null );
142 try {
143 $this->gallery = ImageGalleryBase::factory( $mode, $this->getContext() );
144 } catch ( MWException $e ) {
145 // User specified something invalid, fallback to default.
146 $this->gallery = ImageGalleryBase::factory( false, $this->getContext() );
150 return '';
153 function getEndBody() {
154 return $this->gallery->toHTML();
157 function formatRow( $row ) {
158 $name = $row->img_name;
159 $user = User::newFromId( $row->img_user );
161 $title = Title::makeTitle( NS_FILE, $name );
162 $ul = Linker::link( $user->getUserpage(), $user->getName() );
163 $time = $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() );
165 $this->gallery->add(
166 $title,
167 "$ul<br />\n<i>"
168 . htmlspecialchars( $time )
169 . "</i><br />\n"
173 function getForm() {
174 $fields = array(
175 'like' => array(
176 'type' => 'text',
177 'label-message' => 'newimages-label',
178 'name' => 'like',
180 'showbots' => array(
181 'type' => 'check',
182 'label-message' => 'newimages-showbots',
183 'name' => 'showbots',
185 'limit' => array(
186 'type' => 'hidden',
187 'default' => $this->mLimit,
188 'name' => 'limit',
190 'offset' => array(
191 'type' => 'hidden',
192 'default' => $this->getRequest()->getText( 'offset' ),
193 'name' => 'offset',
197 if ( $this->getConfig()->get( 'MiserMode' ) ) {
198 unset( $fields['like'] );
201 $context = new DerivativeContext( $this->getContext() );
202 $context->setTitle( $this->getTitle() ); // Remove subpage
203 $form = new HTMLForm( $fields, $context );
204 $form->setSubmitTextMsg( 'ilsubmit' );
205 $form->setMethod( 'get' );
206 $form->setWrapperLegendMsg( 'newimages-legend' );
208 return $form;