Index: trunk/phase3/tests/phpunit/includes/GlobalFunctions/GlobalTest.php |
— | — | @@ -935,6 +935,28 @@ |
936 | 936 | ); |
937 | 937 | } |
938 | 938 | |
| 939 | + /** |
| 940 | + * @dataProvider provideWfIsBadImageList |
| 941 | + */ |
| 942 | + function testWfIsBadImage( $name, $title, $blacklist, $expected, $desc ) { |
| 943 | + $this->assertEquals( $expected, wfIsBadImage( $name, $title, $blacklist ), $desc ); |
| 944 | + } |
| 945 | + |
| 946 | + function provideWfIsBadImageList() { |
| 947 | + $blacklist = '* [[File:Bad.jpg]] except [[Nasty page]]'; |
| 948 | + return array( |
| 949 | + array( 'Bad.jpg', false, $blacklist, true, |
| 950 | + 'Called on a bad image' ), |
| 951 | + array( 'Bad.jpg', Title::makeTitle( NS_MAIN, 'A page' ), $blacklist, true, |
| 952 | + 'Called on a bad image' ), |
| 953 | + array( 'NotBad.jpg', false, $blacklist, false, |
| 954 | + 'Called on a non-bad image' ), |
| 955 | + array( 'Bad.jpg', Title::makeTitle( NS_MAIN, 'Nasty page' ), $blacklist, false, |
| 956 | + 'Called on a bad image but is on a whitelisted page' ), |
| 957 | + array( 'File:Bad.jpg', false, $blacklist, false, |
| 958 | + 'Called on a bad image with File:' ), |
| 959 | + ); |
| 960 | + } |
939 | 961 | /* TODO: many more! */ |
940 | 962 | } |
941 | 963 | |
Index: trunk/phase3/includes/ImageFunctions.php |
— | — | @@ -16,10 +16,11 @@ |
17 | 17 | * |
18 | 18 | * @param $name string the image name to check |
19 | 19 | * @param $contextTitle Title|bool the page on which the image occurs, if known |
| 20 | + * @param $blacklist string wikitext of a file blacklist |
20 | 21 | * @return bool |
21 | 22 | */ |
22 | | -function wfIsBadImage( $name, $contextTitle = false ) { |
23 | | - static $badImages = null; |
| 23 | +function wfIsBadImage( $name, $contextTitle = false, $blacklist = null ) { |
| 24 | + static $badImageCache = null; // based on bad_image_list msg |
24 | 25 | wfProfileIn( __METHOD__ ); |
25 | 26 | |
26 | 27 | # Handle redirects |
— | — | @@ -34,11 +35,17 @@ |
35 | 36 | wfProfileOut( __METHOD__ ); |
36 | 37 | return $bad; |
37 | 38 | } |
38 | | - |
39 | | - if( $badImages === null ) { |
| 39 | + |
| 40 | + $cacheable = ( $blacklist === null ); |
| 41 | + if( $cacheable && $badImageCache !== null ) { |
| 42 | + $badImages = $badImageCache; |
| 43 | + } else { // cache miss |
| 44 | + if ( $blacklist === null ) { |
| 45 | + $blacklist = wfMsgForContentNoTrans( 'bad_image_list' ); // site list |
| 46 | + } |
40 | 47 | # Build the list now |
41 | 48 | $badImages = array(); |
42 | | - $lines = explode( "\n", wfMsgForContentNoTrans( 'bad_image_list' ) ); |
| 49 | + $lines = explode( "\n", $blacklist ); |
43 | 50 | foreach( $lines as $line ) { |
44 | 51 | # List items only |
45 | 52 | if ( substr( $line, 0, 1 ) !== '*' ) { |
— | — | @@ -68,6 +75,9 @@ |
69 | 76 | $badImages[$imageDBkey] = $exceptions; |
70 | 77 | } |
71 | 78 | } |
| 79 | + if ( $cacheable ) { |
| 80 | + $badImageCache = $badImages; |
| 81 | + } |
72 | 82 | } |
73 | 83 | |
74 | 84 | $contextKey = $contextTitle ? $contextTitle->getPrefixedDBkey() : false; |