3 * Implements Special:MIMESearch
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
21 * @ingroup SpecialPage
22 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
26 * Searches the database for files of the requested MIME type, comparing this with the
27 * 'img_major_mime' and 'img_minor_mime' fields in the image table.
28 * @ingroup SpecialPage
30 class MIMEsearchPage
extends QueryPage
{
31 protected $major, $minor;
33 function __construct( $name = 'MIMEsearch' ) {
34 parent
::__construct( $name );
37 function isExpensive() { return true; }
38 function isSyndicated() { return false; }
39 function isCacheable() { return false; }
41 function linkParameters() {
42 return array( 'mime' => "{$this->major}/{$this->minor}" );
45 public function getQueryInfo() {
47 'tables' => array( 'image' ),
48 'fields' => array( "'" . NS_FILE
. "' AS namespace",
50 'img_major_mime AS value',
56 'conds' => array( 'img_major_mime' => $this->major
,
57 'img_minor_mime' => $this->minor
)
61 function execute( $par ) {
64 $mime = $par ?
$par : $this->getRequest()->getText( 'mime' );
67 $this->outputHeader();
68 $this->getOutput()->addHTML(
69 Xml
::openElement( 'form', array( 'id' => 'specialmimesearch', 'method' => 'get', 'action' => $wgScript ) ) .
70 Xml
::openElement( 'fieldset' ) .
71 Html
::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
72 Xml
::element( 'legend', null, $this->msg( 'mimesearch' )->text() ) .
73 Xml
::inputLabel( $this->msg( 'mimetype' )->text(), 'mime', 'mime', 20, $mime ) . ' ' .
74 Xml
::submitButton( $this->msg( 'ilsubmit' )->text() ) .
75 Xml
::closeElement( 'fieldset' ) .
76 Xml
::closeElement( 'form' )
79 list( $this->major
, $this->minor
) = File
::splitMime( $mime );
80 if ( $this->major
== '' ||
$this->minor
== '' ||
$this->minor
== 'unknown' ||
81 !self
::isValidType( $this->major
) ) {
84 parent
::execute( $par );
88 function formatResult( $skin, $result ) {
91 $nt = Title
::makeTitle( $result->namespace, $result->title
);
92 $text = $wgContLang->convert( $nt->getText() );
93 $plink = Linker
::link(
94 Title
::newFromText( $nt->getPrefixedText() ),
95 htmlspecialchars( $text )
98 $download = Linker
::makeMediaLinkObj( $nt, $this->msg( 'download' )->escaped() );
99 $lang = $this->getLanguage();
100 $bytes = htmlspecialchars( $lang->formatSize( $result->img_size
) );
101 $dimensions = $this->msg( 'widthheight' )->numParams( $result->img_width
,
102 $result->img_height
)->escaped();
103 $user = Linker
::link( Title
::makeTitle( NS_USER
, $result->img_user_text
), htmlspecialchars( $result->img_user_text
) );
104 $time = htmlspecialchars( $lang->userTimeAndDate( $result->img_timestamp
, $this->getUser() ) );
106 return "($download) $plink . . $dimensions . . $bytes . . $user . . $time";
110 * @param $type string
113 protected static function isValidType( $type ) {
114 // From maintenance/tables.sql => img_major_mime
126 return in_array( $type, $types );