r100915 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100914‎ | r100915 | r100916 >
Date:00:23, 27 October 2011
Author:aaron
Status:resolved (Comments)
Tags:
Comment:
* Allow passing in a blacklist into wfIsBadImage()
* Added wfIsBadImage() unit tests
Modified paths:
  • /trunk/phase3/includes/ImageFunctions.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/GlobalFunctions/GlobalTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/GlobalFunctions/GlobalTest.php
@@ -935,6 +935,28 @@
936936 );
937937 }
938938
 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+ }
939961 /* TODO: many more! */
940962 }
941963
Index: trunk/phase3/includes/ImageFunctions.php
@@ -16,10 +16,11 @@
1717 *
1818 * @param $name string the image name to check
1919 * @param $contextTitle Title|bool the page on which the image occurs, if known
 20+ * @param $blacklist string wikitext of a file blacklist
2021 * @return bool
2122 */
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
2425 wfProfileIn( __METHOD__ );
2526
2627 # Handle redirects
@@ -34,11 +35,17 @@
3536 wfProfileOut( __METHOD__ );
3637 return $bad;
3738 }
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+ }
4047 # Build the list now
4148 $badImages = array();
42 - $lines = explode( "\n", wfMsgForContentNoTrans( 'bad_image_list' ) );
 49+ $lines = explode( "\n", $blacklist );
4350 foreach( $lines as $line ) {
4451 # List items only
4552 if ( substr( $line, 0, 1 ) !== '*' ) {
@@ -68,6 +75,9 @@
6976 $badImages[$imageDBkey] = $exceptions;
7077 }
7178 }
 79+ if ( $cacheable ) {
 80+ $badImageCache = $badImages;
 81+ }
7282 }
7383
7484 $contextKey = $contextTitle ? $contextTitle->getPrefixedDBkey() : false;

Follow-up revisions

RevisionCommit summaryAuthorDate
r100932Disabled "bad image" tests which made totally broken assumptions about how/wh...aaron01:36, 27 October 2011
r101049FU r100915: split out GlobalWithDBTest (tests which need the DB)aaron20:54, 27 October 2011

Comments

#Comment by Platonides (talk | contribs)   15:08, 27 October 2011

The RepoGroup::singleton()->checkRedirect of wfIsBadImage() fails in tests with no database.

#Comment by Aaron Schulz (talk | contribs)   17:07, 27 October 2011

What test parameters are you running to get that. run-tests works fine for me.

#Comment by Hashar (talk | contribs)   17:46, 27 October 2011

Platonides, at r100915 I can't reproduce the issue you are describing: make databaseless works for me as well as:

./phpunit.php --filter testWfIsBadImage

Is that because you are running the test suite without a database backend? If so that would mean we need to tag this tests with @group Database.

#Comment by Aaron Schulz (talk | contribs)   17:48, 27 October 2011

Maybe it should be moved to it's own file with @group, that way the other tests won't need create DB tables.

#Comment by Platonides (talk | contribs)   20:00, 27 October 2011

Precisely, databaseless should be able to run without a database. :)

Status & tagging log