MediaWiki  REL1_19
ImageFunctions.php
Go to the documentation of this file.
00001 <?php
00022 function wfIsBadImage( $name, $contextTitle = false, $blacklist = null ) {
00023         static $badImageCache = null; // based on bad_image_list msg
00024         wfProfileIn( __METHOD__ );
00025 
00026         # Handle redirects
00027         $redirectTitle = RepoGroup::singleton()->checkRedirect( Title::makeTitle( NS_FILE, $name ) );
00028         if( $redirectTitle ) {
00029                 $name = $redirectTitle->getDbKey();
00030         }
00031 
00032         # Run the extension hook
00033         $bad = false;
00034         if( !wfRunHooks( 'BadImage', array( $name, &$bad ) ) ) {
00035                 wfProfileOut( __METHOD__ );
00036                 return $bad;
00037         }
00038  
00039         $cacheable = ( $blacklist === null );
00040         if( $cacheable && $badImageCache !== null ) {
00041                 $badImages = $badImageCache;
00042         } else { // cache miss
00043                 if ( $blacklist === null ) {
00044                         $blacklist = wfMsgForContentNoTrans( 'bad_image_list' ); // site list
00045                 }
00046                 # Build the list now
00047                 $badImages = array();
00048                 $lines = explode( "\n", $blacklist );
00049                 foreach( $lines as $line ) {
00050                         # List items only
00051                         if ( substr( $line, 0, 1 ) !== '*' ) {
00052                                 continue;
00053                         }
00054 
00055                         # Find all links
00056                         $m = array();
00057                         if ( !preg_match_all( '/\[\[:?(.*?)\]\]/', $line, $m ) ) {
00058                                 continue;
00059                         }
00060 
00061                         $exceptions = array();
00062                         $imageDBkey = false;
00063                         foreach ( $m[1] as $i => $titleText ) {
00064                                 $title = Title::newFromText( $titleText );
00065                                 if ( !is_null( $title ) ) {
00066                                         if ( $i == 0 ) {
00067                                                 $imageDBkey = $title->getDBkey();
00068                                         } else {
00069                                                 $exceptions[$title->getPrefixedDBkey()] = true;
00070                                         }
00071                                 }
00072                         }
00073 
00074                         if ( $imageDBkey !== false ) {
00075                                 $badImages[$imageDBkey] = $exceptions;
00076                         }
00077                 }
00078                 if ( $cacheable ) {
00079                         $badImageCache = $badImages;
00080                 }
00081         }
00082 
00083         $contextKey = $contextTitle ? $contextTitle->getPrefixedDBkey() : false;
00084         $bad = isset( $badImages[$name] ) && !isset( $badImages[$name][$contextKey] );
00085         wfProfileOut( __METHOD__ );
00086         return $bad;
00087 }