3 * Global functions related to images
9 * Determine if an image exists on the 'bad image list'.
11 * The format of MediaWiki:Bad_image_list is as follows:
12 * * Only list items (lines starting with "*") are considered
13 * * The first link on a line must be a link to a bad image
14 * * Any subsequent links on the same line are considered to be exceptions,
15 * i.e. articles where the image may occur inline.
17 * @param $name string the image name to check
18 * @param $contextTitle Title: the page on which the image occurs, if known
21 function wfIsBadImage( $name, $contextTitle = false ) {
22 static $badImages = false;
23 wfProfileIn( __METHOD__
);
26 $redirectTitle = RepoGroup
::singleton()->checkRedirect( Title
::makeTitle( NS_FILE
, $name ) );
27 if( $redirectTitle ) {
28 $name = $redirectTitle->getDbKey();
31 # Run the extension hook
33 if( !wfRunHooks( 'BadImage', array( $name, &$bad ) ) ) {
34 wfProfileOut( __METHOD__
);
41 $lines = explode( "\n", wfMsgForContentNoTrans( 'bad_image_list' ) );
42 foreach( $lines as $line ) {
44 if ( substr( $line, 0, 1 ) !== '*' ) {
50 if ( !preg_match_all( '/\[\[:?(.*?)\]\]/', $line, $m ) ) {
54 $exceptions = array();
56 foreach ( $m[1] as $i => $titleText ) {
57 $title = Title
::newFromText( $titleText );
58 if ( !is_null( $title ) ) {
60 $imageDBkey = $title->getDBkey();
62 $exceptions[$title->getPrefixedDBkey()] = true;
67 if ( $imageDBkey !== false ) {
68 $badImages[$imageDBkey] = $exceptions;
73 $contextKey = $contextTitle ?
$contextTitle->getPrefixedDBkey() : false;
74 $bad = isset( $badImages[$name] ) && !isset( $badImages[$name][$contextKey] );
75 wfProfileOut( __METHOD__
);
80 * Calculate the largest thumbnail width for a given original file size
81 * such that the thumbnail's height is at most $maxHeight.
82 * @param $boxWidth Integer Width of the thumbnail box.
83 * @param $boxHeight Integer Height of the thumbnail box.
84 * @param $maxHeight Integer Maximum height expected for the thumbnail.
87 function wfFitBoxWidth( $boxWidth, $boxHeight, $maxHeight ) {
88 $idealWidth = $boxWidth * $maxHeight / $boxHeight;
89 $roundedUp = ceil( $idealWidth );
90 if( round( $roundedUp * $boxHeight / $boxWidth ) > $maxHeight )
91 return floor( $idealWidth );