X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSpecialMIMEsearch.php;h=82ee4be6e1181c6489e2dccc129dbd6dbfcb32bc;hb=40589a98d7743ae0726de1321f0933f4aae8720f;hp=ed2268a2701f8517925ba5123422e3ab3c97e808;hpb=b37cec63892c7583d188ac365d7f2cd930753c61;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SpecialMIMEsearch.php b/includes/SpecialMIMEsearch.php index ed2268a270..82ee4be6e1 100644 --- a/includes/SpecialMIMEsearch.php +++ b/includes/SpecialMIMEsearch.php @@ -3,19 +3,17 @@ * A special page to search for files by MIME type as defined in the * img_major_mime and img_minor_mime fields in the image table * - * @package MediaWiki - * @subpackage SpecialPage + * @file + * @ingroup SpecialPage * * @author Ævar Arnfjörð Bjarmason * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later */ -/* */ -require_once 'QueryPage.php'; - /** - * @package MediaWiki - * @subpackage SpecialPage + * Searches the database for files of the requested MIME type, comparing this with the + * 'img_major_mime' and 'img_minor_mime' fields in the image table. + * @ingroup SpecialPage */ class MIMEsearchPage extends QueryPage { var $major, $minor; @@ -24,16 +22,16 @@ class MIMEsearchPage extends QueryPage { $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 isExpensive() { return true; } function isSyndicated() { return false; } - + function linkParameters() { $arr = array( $this->major, $this->minor ); $mime = implode( '/', $arr ); @@ -41,20 +39,21 @@ class MIMEsearchPage extends QueryPage { } function getSQL() { - $dbr =& wfGetDB( DB_SLAVE ); + $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_user_text, img_timestamp FROM $image WHERE img_major_mime = $major AND img_minor_mime = $minor @@ -65,69 +64,55 @@ class MIMEsearchPage extends QueryPage { global $wgContLang, $wgLang; $nt = Title::makeTitle( $result->namespace, $result->title ); - $text = $wgContLang->convert( $nt->getPrefixedText() ); + $text = $wgContLang->convert( $nt->getText() ); $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 ); + $download = $skin->makeMediaLinkObj( $nt, wfMsgHtml( 'download' ) ); + $bytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape'), + $wgLang->formatNum( $result->img_size ) ); + $dimensions = wfMsgHtml( 'widthheight', $wgLang->formatNum( $result->img_width ), + $wgLang->formatNum( $result->img_height ) ); + $user = $skin->makeLinkObj( Title::makeTitle( NS_USER, $result->img_user_text ), $result->img_user_text ); $time = $wgLang->timeanddate( $result->img_timestamp ); - - return "($download) $plink .. $dimensions .. $bytes .. $time"; + + return "($download) $plink . . $dimensions . . $bytes . . $user . . $time"; } } /** - * constructor + * Output the HTML search form, and constructs the MIMEsearchPage object. */ -function wfSpecialMIMEsearch() { +function wfSpecialMIMEsearch( $par = null ) { global $wgRequest, $wgTitle, $wgOut; - $mime = $wgRequest->getText( 'mime' ); + $mime = isset( $par ) ? $par : $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' ) + Xml::openElement( 'form', array( 'id' => 'specialmimesearch', 'method' => 'get', 'action' => $wgTitle->getLocalUrl() ) ) . + Xml::openElement( 'fieldset' ) . + Xml::element( 'legend', null, wfMsg( 'mimesearch' ) ) . + Xml::inputLabel( wfMsg( 'mimetype' ), 'mime', 'mime', 20, $mime ) . ' ' . + Xml::submitButton( wfMsg( 'ilsubmit' ) ) . + Xml::closeElement( 'fieldset' ) . + Xml::closeElement( '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(); + // searched for an invalid MIME type. + if( strpos( $str, '/' ) === false) { + return array ('', ''); + } + list( $major, $minor ) = explode( '/', $str, 2 ); - wfRestoreWarnings(); return array( ltrim( $major, ' ' ), @@ -151,4 +136,3 @@ function wfSpecialMIMEsearchValidType( $type ) { return in_array( $type, $types ); } -?>