From b37cec63892c7583d188ac365d7f2cd930753c61 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 13 Sep 2005 16:36:09 +0000 Subject: [PATCH] * Adding a nes specialpage - mimesearch --- includes/SpecialMIMEsearch.php | 154 +++++++++++++++++++++++++++++++++ languages/Language.php | 7 ++ 2 files changed, 161 insertions(+) create mode 100644 includes/SpecialMIMEsearch.php diff --git a/includes/SpecialMIMEsearch.php b/includes/SpecialMIMEsearch.php new file mode 100644 index 0000000000..ed2268a270 --- /dev/null +++ b/includes/SpecialMIMEsearch.php @@ -0,0 +1,154 @@ + + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later + */ + +/* */ +require_once 'QueryPage.php'; + +/** + * @package MediaWiki + * @subpackage SpecialPage + */ +class MIMEsearchPage extends QueryPage { + var $major, $minor; + + function MIMEsearchPage( $major, $minor ) { + $this->major = $major; + $this->minor = $minor; + } + + function getName() { return 'MIMEsearch'; } + + /** + * Due to this page relying upon extra fields being passed in the SELECT it + * will fail if it's set as expensive and misermode is on + */ + function isExpensive() { return false; } + function isSyndicated() { return false; } + + function linkParameters() { + $arr = array( $this->major, $this->minor ); + $mime = implode( '/', $arr ); + return array( 'mime' => $mime ); + } + + function getSQL() { + $dbr =& wfGetDB( DB_SLAVE ); + $image = $dbr->tableName( 'image' ); + $major = $dbr->addQuotes( $this->major ); + $minor = $dbr->addQuotes( $this->minor ); + + return + "SELECT 'MIMEsearch' AS type, + " . NS_IMAGE . " AS namespace, + img_name AS title, + img_major_mime AS value, + + img_size, + img_width, + img_height, + img_timestamp + FROM $image + WHERE img_major_mime = $major AND img_minor_mime = $minor + "; + } + + function formatResult( $skin, $result ) { + global $wgContLang, $wgLang; + + $nt = Title::makeTitle( $result->namespace, $result->title ); + $text = $wgContLang->convert( $nt->getPrefixedText() ); + $plink = $skin->makeLink( $nt->getPrefixedText(), $text ); + + $download = $skin->makeMediaLink( $nt->getText(), 'fuck me!', wfMsgHtml( 'download' ) ); + $bytes = wfMsg( 'nbytes', $wgLang->formatNum( $result->img_size ) ); + $dimensions = wfMsg( 'widthheight', $result->img_width, $result->img_height ); + $time = $wgLang->timeanddate( $result->img_timestamp ); + + return "($download) $plink .. $dimensions .. $bytes .. $time"; + } +} + +/** + * constructor + */ +function wfSpecialMIMEsearch() { + global $wgRequest, $wgTitle, $wgOut; + + $mime = $wgRequest->getText( 'mime' ); + + $wgOut->addHTML( + wfElement( 'form', + array( + 'id' => 'specialmimesearch', + 'method' => 'get', + 'action' => $wgTitle->escapeLocalUrl() + ), + null + ) . + wfOpenElement( 'label' ) . + wfMsgHtml( 'mimetype' ) . + wfElement( 'input', array( + 'type' => 'text', + 'size' => 20, + 'name' => 'mime', + 'value' => $mime + ), + '' + ) . + ' ' . + wfElement( 'input', array( + 'type' => 'submit', + 'value' => wfMsg( 'ilsubmit' ) + ), + '' + ) . + wfCloseElement( 'label' ) . + wfCloseElement( 'form' ) + ); + + list( $major, $minor ) = wfSpecialMIMEsearchParse( $mime ); + if ( $major == '' or $minor == '' or !wfSpecialMIMEsearchValidType( $major ) ) + return; + $wpp = new MIMEsearchPage( $major, $minor ); + + list( $limit, $offset ) = wfCheckLimits(); + $wpp->doQuery( $offset, $limit ); +} + +function wfSpecialMIMEsearchParse( $str ) { + wfSuppressWarnings(); + list( $major, $minor ) = explode( '/', $str, 2 ); + wfRestoreWarnings(); + + return array( + ltrim( $major, ' ' ), + rtrim( $minor, ' ' ) + ); +} + +function wfSpecialMIMEsearchValidType( $type ) { + // From maintenance/tables.sql => img_major_mime + $types = array( + 'unknown', + 'application', + 'audio', + 'image', + 'text', + 'video', + 'message', + 'model', + 'multipart' + ); + + return in_array( $type, $types ); +} +?> diff --git a/languages/Language.php b/languages/Language.php index e861eaf9be..916dacc967 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -461,6 +461,7 @@ See $1.', 'versionrequiredtext' => 'Version $1 of MediaWiki is required to use this page. See [[Special:Version]]', 'nbytes' => '$1 bytes', +'widthheight' => '$1x$2', 'ok' => 'OK', 'sitetitle' => '{{SITENAME}}', 'pagetitle' => '$1 - {{SITENAME}}', @@ -1069,6 +1070,12 @@ this old version, (rev) = revert to this old version. 'noimage-linktext' => 'upload it', 'uploadnewversion' => '[$1 Upload a new version of this file]', +# Mime search +# +'mimesearch' => 'MIME search', +'mimetype' => 'MIME type: ', +'download' => 'download', + # Statistics # 'statistics' => 'Statistics', -- 2.20.1