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 ) {
62 global $wgRequest, $wgOut;
63 $mime = $par ?
$par : $wgRequest->getText( 'mime' );
66 $this->outputHeader();
68 Xml
::openElement( 'form', array( 'id' => 'specialmimesearch', 'method' => 'get', 'action' => SpecialPage
::getTitleFor( 'MIMEsearch' )->getLocalUrl() ) ) .
69 Xml
::openElement( 'fieldset' ) .
70 Html
::hidden( 'title', SpecialPage
::getTitleFor( 'MIMEsearch' )->getPrefixedText() ) .
71 Xml
::element( 'legend', null, wfMsg( 'mimesearch' ) ) .
72 Xml
::inputLabel( wfMsg( 'mimetype' ), 'mime', 'mime', 20, $mime ) . ' ' .
73 Xml
::submitButton( wfMsg( 'ilsubmit' ) ) .
74 Xml
::closeElement( 'fieldset' ) .
75 Xml
::closeElement( 'form' )
78 list( $this->major
, $this->minor
) = File
::splitMime( $mime );
79 if ( $this->major
== '' ||
$this->minor
== '' ||
$this->minor
== 'unknown' ||
80 !self
::isValidType( $this->major
) ) {
83 parent
::execute( $par );
87 function formatResult( $skin, $result ) {
88 global $wgContLang, $wgLang;
90 $nt = Title
::makeTitle( $result->namespace, $result->title
);
91 $text = $wgContLang->convert( $nt->getText() );
93 Title
::newFromText( $nt->getPrefixedText() ),
94 htmlspecialchars( $text )
97 $download = $skin->makeMediaLinkObj( $nt, wfMsgHtml( 'download' ) );
98 $bytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
99 $wgLang->formatNum( $result->img_size
) );
100 $dimensions = htmlspecialchars( wfMsg( 'widthheight',
101 $wgLang->formatNum( $result->img_width
),
102 $wgLang->formatNum( $result->img_height
)
104 $user = $skin->link( Title
::makeTitle( NS_USER
, $result->img_user_text
), htmlspecialchars( $result->img_user_text
) );
105 $time = htmlspecialchars( $wgLang->timeanddate( $result->img_timestamp
) );
107 return "($download) $plink . . $dimensions . . $bytes . . $user . . $time";
111 * @param $type string
114 protected static function isValidType( $type ) {
115 // From maintenance/tables.sql => img_major_mime
127 return in_array( $type, $types );