r70917 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70916‎ | r70917 | r70918 >
Date:21:23, 11 August 2010
Author:platonides
Status:ok (Comments)
Tags:
Comment:
Force $wgContLang to English at the entry point.
This avoids early Titles being localized.
Remove setupGlobals() from addArticle()
Make the upload dir global.
Make the fake uploads a bit saner.
Modified paths:
  • /trunk/phase3/maintenance/parserTests.inc (modified) (history)
  • /trunk/phase3/maintenance/tests/MediaWikiParserTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/parserTests.inc
@@ -41,7 +41,7 @@
4242 /**
4343 * boolean $useTemporaryTables Use temporary tables for the temporary database
4444 */
45 - private $useTemporaryTables = true;
 45+ private $useTemporaryTables = false;
4646
4747 /**
4848 * boolean $databaseSetupDone True if the database has been set up
@@ -145,6 +145,7 @@
146146 * Draw input from a set of test files
147147 */
148148 function fuzzTest( $filenames ) {
 149+ $GLOBALS['wgContLang'] = Language::factory( 'en' );
149150 $dict = $this->getFuzzInput( $filenames );
150151 $dictSize = strlen( $dict );
151152 $logMaxLength = log( $this->maxFuzzTestLength );
@@ -265,6 +266,7 @@
266267 * @return Boolean: true if passed all tests, false if any tests failed.
267268 */
268269 public function runTestsFromFiles( $filenames ) {
 270+ $GLOBALS['wgContLang'] = Language::factory( 'en' );
269271 $this->recorder->start();
270272 $this->setupDatabase();
271273 $ok = true;
@@ -486,9 +488,6 @@
487489 */
488490 private function setupGlobals( $opts = '', $config = '' ) {
489491 global $wgDBtype;
490 - if ( !isset( $this->uploadDir ) ) {
491 - $this->uploadDir = $this->setupUploadDir();
492 - }
493492
494493 # Find out values for some special options.
495494 $lang =
@@ -711,53 +710,14 @@
712711
713712
714713 if ( $wgDBtype == 'oracle' ) {
715 - # Insert 0 and 1 user_ids to prevent FK violations
 714+ # Insert 0 user to prevent FK violations
716715
717716 # Anonymous user
718717 $db->insert( 'user', array(
719718 'user_id' => 0,
720719 'user_name' => 'Anonymous' ) );
721 -
722 - # Hack-on-Hack: Insert a test user to be able to insert an image
723 - $db->insert( 'user', array(
724 - 'user_id' => 1,
725 - 'user_name' => 'Tester' ) );
726720 }
727721
728 - # Hack: Insert an image to work with
729 - $db->insert( 'image', array(
730 - 'img_name' => 'Foobar.jpg',
731 - 'img_size' => 12345,
732 - 'img_description' => 'Some lame file',
733 - 'img_user' => 1,
734 - 'img_user_text' => 'WikiSysop',
735 - 'img_timestamp' => $db->timestamp( '20010115123500' ),
736 - 'img_width' => 1941,
737 - 'img_height' => 220,
738 - 'img_bits' => 24,
739 - 'img_media_type' => MEDIATYPE_BITMAP,
740 - 'img_major_mime' => "image",
741 - 'img_minor_mime' => "jpeg",
742 - 'img_metadata' => serialize( array() ),
743 - ) );
744 -
745 - # This image will be blacklisted in [[MediaWiki:Bad image list]]
746 - $db->insert( 'image', array(
747 - 'img_name' => 'Bad.jpg',
748 - 'img_size' => 12345,
749 - 'img_description' => 'zomgnotcensored',
750 - 'img_user' => 1,
751 - 'img_user_text' => 'WikiSysop',
752 - 'img_timestamp' => $db->timestamp( '20010115123500' ),
753 - 'img_width' => 320,
754 - 'img_height' => 240,
755 - 'img_bits' => 24,
756 - 'img_media_type' => MEDIATYPE_BITMAP,
757 - 'img_major_mime' => "image",
758 - 'img_minor_mime' => "jpeg",
759 - 'img_metadata' => serialize( array() ),
760 - ) );
761 -
762722 # Update certain things in site_stats
763723 $db->insert( 'site_stats', array( 'ss_row_id' => 1, 'ss_images' => 2, 'ss_good_articles' => 1 ) );
764724
@@ -767,6 +727,31 @@
768728 # Make a new message cache
769729 global $wgMessageCache, $wgMemc;
770730 $wgMessageCache = new MessageCache( $wgMemc, true, 3600 );
 731+
 732+ $this->uploadDir = $this->setupUploadDir();
 733+ $user = User::createNew( 'WikiSysop' );
 734+ $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Foobar.jpg' ) );
 735+ $image->recordUpload2( '', 'Upload of some lame file', 'Some lame file', array(
 736+ 'width' => 1941,
 737+ 'height' => 220,
 738+ 'bits' => 24,
 739+ 'media_type' => MEDIATYPE_BITMAP,
 740+ 'mime' => 'image/jpeg',
 741+ 'metadata' => serialize( array() ),
 742+ 'fileExists' => true
 743+ ), $db->timestamp( '20010115123500' ), $user );
 744+
 745+ # This image will be blacklisted in [[MediaWiki:Bad image list]]
 746+ $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Bad.jpg' ) );
 747+ $image->recordUpload2( '', 'zomgnotcensored', 'Borderline image', array(
 748+ 'width' => 320,
 749+ 'height' => 240,
 750+ 'bits' => 24,
 751+ 'media_type' => MEDIATYPE_BITMAP,
 752+ 'mime' => 'image/jpeg',
 753+ 'metadata' => serialize( array() ),
 754+ 'fileExists' => true
 755+ ), $db->timestamp( '20010115123500' ), $user );
771756 }
772757
773758 /**
@@ -791,6 +776,8 @@
792777 if ( !$this->databaseSetupDone ) {
793778 return;
794779 }
 780+ $this->teardownUploadDir( $this->uploadDir );
 781+
795782 $this->changePrefix( $this->oldTablePrefix );
796783 $this->databaseSetupDone = false;
797784 if ( $this->useTemporaryTables ) {
@@ -825,14 +812,13 @@
826813 $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
827814 }
828815
829 - wfDebug( "Creating upload directory $dir\n" );
 816+ //wfDebug( "Creating upload directory $dir\n" );
830817 if ( file_exists( $dir ) ) {
831818 wfDebug( "Already exists!\n" );
832819 return $dir;
833820 }
834821 wfMkdirParents( $dir . '/3/3a' );
835822 copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
836 -
837823 wfMkdirParents( $dir . '/0/09' );
838824 copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
839825 return $dir;
@@ -848,10 +834,6 @@
849835 foreach ( $this->savedGlobals as $var => $val ) {
850836 $GLOBALS[$var] = $val;
851837 }
852 - if ( isset( $this->uploadDir ) ) {
853 - $this->teardownUploadDir( $this->uploadDir );
854 - unset( $this->uploadDir );
855 - }
856838 }
857839
858840 /**
@@ -1045,7 +1027,6 @@
10461028 * @param $line Integer: the input line number, for reporting errors
10471029 */
10481030 public function addArticle( $name, $text, $line ) {
1049 - $this->setupGlobals();
10501031 $title = Title::newFromText( $name );
10511032 if ( is_null( $title ) ) {
10521033 wfDie( "invalid title at line $line\n" );
@@ -1058,8 +1039,6 @@
10591040
10601041 $art = new Article( $title );
10611042 $art->insertNewArticle( $text, '', false, false );
1062 -
1063 - $this->teardownGlobals();
10641043 }
10651044
10661045 /**
@@ -1728,8 +1707,9 @@
17291708 $section = null;
17301709 continue;
17311710 }
 1711+ global $wgUseTeX;
17321712 if ( $this->parser &&
1733 - preg_match( '/\\bmath\\b/i', $data['options'] ) && !$this->parser->savedGlobals['wgUseTeX'] ) {
 1713+ preg_match( '/\\bmath\\b/i', $data['options'] ) && !$wgUseTeX ) {
17341714 # don't run math tests if $wgUseTeX is set to false in LocalSettings
17351715 $data = array();
17361716 $section = null;
Index: trunk/phase3/maintenance/tests/MediaWikiParserTest.php
@@ -17,7 +17,8 @@
1818 public function run( PHPUnit_Framework_TestResult $result = null, $filter = false,
1919 array $groups = array(), array $excludeGroups = array(), $processIsolation = false
2020 ) {
21 - global $IP;
 21+ global $IP, $wgContLang;
 22+ $wgContLang = Language::factory( 'en' );
2223 $this->backend->setupDatabase();
2324
2425 $iter = new TestFileIterator( "$IP/maintenance/parserTests.txt" );

Follow-up revisions

RevisionCommit summaryAuthorDate
r70918I didn't intend to change this in r70917platonides21:32, 11 August 2010
r70939size and sha1 cannot be null in the database layout....platonides12:00, 12 August 2010
r71383Move [[MediaWiki:bad image list]] to the beginning....platonides22:43, 20 August 2010
r71511Follow up r70917. Having $wgCapitalLinks = false; was what caused the errors.platonides21:33, 23 August 2010

Comments

#Comment by MarkAHershberger (talk | contribs)   04:55, 12 August 2010

the changes in parserTests.inc here cause failures for me on SQLite

#Comment by MarkAHershberger (talk | contribs)   04:58, 12 August 2010
PHPUnit 3.4.11 by Sebastian Bergmann.                                                                                          
                                                                                                                               
................................................A database query syntax error has occurred.                                    
The last attempted database query was:                                                                                         
"SELECT  *  FROM parsertest_user_properties  WHERE up_user = '1'  "                                                            
from within function "User::loadOptions".                                                                                      
Database returned error "1: no such table: parsertest_user_properties"        
#Comment by Platonides (talk | contribs)   09:21, 12 August 2010

Seem to be exposing an existing bug. Does it happen without temporary tables ?

r70899 touches code related to the tables, but it should follow the same path as it used to, for sqlite?

#Comment by Platonides (talk | contribs)   10:36, 12 August 2010

Errors about missing tables fixed in r70938. File parsedtests are failing, though.

#Comment by Platonides (talk | contribs)   12:01, 12 August 2010

Fixed in r70939.

#Comment by Simetrical (talk | contribs)   23:06, 12 August 2010

I'm getting tons of failures after this commit. I've pastebinned them: http://pastebin.com/KFhTxkUD

#Comment by Simetrical (talk | contribs)   18:42, 23 August 2010

Can you reproduce the errors with $wgCapitalLinks = false? That's what causes it for me.

#Comment by Platonides (talk | contribs)   21:36, 23 August 2010

Right. That was it. $wgCapitalLinks was active on the actual tests but not on article adding. Fixed in r71511.

#Comment by Simetrical (talk | contribs)   22:08, 23 August 2010

Confirmed the tests pass now.

#Comment by Hashar (talk | contribs)   20:14, 12 January 2011

marking ok, fixed by follow up.

Status & tagging log