Merge "Fix fatal in LocalRepo::findFiles()"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 17 Dec 2013 23:42:18 +0000 (23:42 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 17 Dec 2013 23:42:18 +0000 (23:42 +0000)
includes/job/JobQueueFederated.php
includes/specials/SpecialUserlogin.php
resources/jquery/jquery.suggestions.js
resources/mediawiki/mediawiki.searchSuggest.js
skins/common/commonInterface.css
skins/modern/main.css
tests/phpunit/includes/filebackend/FileBackendTest.php

index 589bed6..f4caac6 100644 (file)
@@ -150,21 +150,20 @@ class JobQueueFederated extends JobQueue {
                        return false;
                }
 
+               $empty = true;
+               $failed = 0;
                foreach ( $this->partitionQueues as $queue ) {
                        try {
-                               if ( !$queue->doIsEmpty() ) {
-                                       $this->cache->add( $key, 'false', self::CACHE_TTL_LONG );
-
-                                       return false;
-                               }
+                               $empty = $empty && $queue->doIsEmpty();
                        } catch ( JobQueueError $e ) {
+                               ++$failed;
                                MWExceptionHandler::logException( $e );
                        }
                }
+               $this->throwErrorIfAllPartitionsDown( $failed );
 
-               $this->cache->add( $key, 'true', self::CACHE_TTL_LONG );
-
-               return true;
+               $this->cache->add( $key, $empty ? 'true' : 'false', self::CACHE_TTL_LONG );
+               return !$empty;
        }
 
        protected function doGetSize() {
@@ -196,14 +195,16 @@ class JobQueueFederated extends JobQueue {
                        return $count;
                }
 
-               $count = 0;
+               $failed = 0;
                foreach ( $this->partitionQueues as $queue ) {
                        try {
                                $count += $queue->$method();
                        } catch ( JobQueueError $e ) {
+                               ++$failed;
                                MWExceptionHandler::logException( $e );
                        }
                }
+               $this->throwErrorIfAllPartitionsDown( $failed );
 
                $this->cache->set( $key, $count, self::CACHE_TTL_SHORT );
 
@@ -275,7 +276,7 @@ class JobQueueFederated extends JobQueue {
                        } else {
                                $partitionRing = $partitionRing->newWithoutLocation( $partition ); // blacklist
                                if ( !$partitionRing ) {
-                                       throw new JobQueueError( "Could not insert job(s), all partitions are down." );
+                                       throw new JobQueueError( "Could not insert job(s), no partitions available." );
                                }
                                $jobsLeft = array_merge( $jobsLeft, $jobBatch ); // not inserted
                        }
@@ -297,7 +298,7 @@ class JobQueueFederated extends JobQueue {
                        } else {
                                $partitionRing = $partitionRing->newWithoutLocation( $partition ); // blacklist
                                if ( !$partitionRing ) {
-                                       throw new JobQueueError( "Could not insert job(s), all partitions are down." );
+                                       throw new JobQueueError( "Could not insert job(s), no partitions available." );
                                }
                                $jobsLeft = array_merge( $jobsLeft, $jobBatch ); // not inserted
                        }
@@ -316,6 +317,7 @@ class JobQueueFederated extends JobQueue {
 
                $partitionsTry = $this->partitionMap; // (partition => weight)
 
+               $failed = 0;
                while ( count( $partitionsTry ) ) {
                        $partition = ArrayUtils::pickRandom( $partitionsTry );
                        if ( $partition === false ) {
@@ -327,8 +329,9 @@ class JobQueueFederated extends JobQueue {
                        try {
                                $job = $queue->pop();
                        } catch ( JobQueueError $e ) {
-                               $job = false;
+                               ++$failed;
                                MWExceptionHandler::logException( $e );
+                               $job = false;
                        }
                        if ( $job ) {
                                $job->metadata['QueuePartition'] = $partition;
@@ -338,6 +341,7 @@ class JobQueueFederated extends JobQueue {
                                unset( $partitionsTry[$partition] ); // blacklist partition
                        }
                }
+               $this->throwErrorIfAllPartitionsDown( $failed );
 
                $this->cache->set( $key, 'true', JobQueueDB::CACHE_TTL_LONG );
 
@@ -381,25 +385,32 @@ class JobQueueFederated extends JobQueue {
        }
 
        protected function doDelete() {
+               $failed = 0;
                /** @var JobQueue $queue */
                foreach ( $this->partitionQueues as $queue ) {
                        try {
                                $queue->doDelete();
                        } catch ( JobQueueError $e ) {
+                               ++$failed;
                                MWExceptionHandler::logException( $e );
                        }
                }
+               $this->throwErrorIfAllPartitionsDown( $failed );
+               return true;
        }
 
        protected function doWaitForBackups() {
+               $failed = 0;
                /** @var JobQueue $queue */
                foreach ( $this->partitionQueues as $queue ) {
                        try {
                                $queue->waitForBackups();
                        } catch ( JobQueueError $e ) {
+                               ++$failed;
                                MWExceptionHandler::logException( $e );
                        }
                }
+               $this->throwErrorIfAllPartitionsDown( $failed );
        }
 
        protected function doGetPeriodicTasks() {
@@ -463,6 +474,7 @@ class JobQueueFederated extends JobQueue {
        protected function doGetSiblingQueuesWithJobs( array $types ) {
                $result = array();
 
+               $failed = 0;
                /** @var JobQueue $queue */
                foreach ( $this->partitionQueues as $queue ) {
                        try {
@@ -476,16 +488,18 @@ class JobQueueFederated extends JobQueue {
                                        break; // short-circuit
                                }
                        } catch ( JobQueueError $e ) {
+                               ++$failed;
                                MWExceptionHandler::logException( $e );
                        }
                }
+               $this->throwErrorIfAllPartitionsDown( $failed );
 
                return array_values( $result );
        }
 
        protected function doGetSiblingQueueSizes( array $types ) {
                $result = array();
-
+               $failed = 0;
                /** @var JobQueue $queue */
                foreach ( $this->partitionQueues as $queue ) {
                        try {
@@ -498,13 +512,28 @@ class JobQueueFederated extends JobQueue {
                                        return null; // not supported on all partitions; bail
                                }
                        } catch ( JobQueueError $e ) {
+                               ++$failed;
                                MWExceptionHandler::logException( $e );
                        }
                }
+               $this->throwErrorIfAllPartitionsDown( $failed );
 
                return $result;
        }
 
+       /**
+        * Throw an error if no partitions available
+        *
+        * @param int $down The number of up partitions down
+        * @return void
+        * @throws JobQueueError
+        */
+       protected function throwErrorIfAllPartitionsDown( $down ) {
+               if ( $down >= count( $this->partitionQueues ) ) {
+                       throw new JobQueueError( 'No queue partitions available.' );
+               }
+       }
+
        public function setTestingPrefix( $key ) {
                /** @var JobQueue $queue */
                foreach ( $this->partitionQueues as $queue ) {
index e701e0f..3fc5ebb 100644 (file)
@@ -507,9 +507,12 @@ class LoginForm extends SpecialPage {
                $u->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 );
                $u->saveSettings();
 
-               # Update user count
+               // Update user count
                DeferredUpdates::addUpdate( new SiteStatsUpdate( 0, 0, 0, 0, 1 ) );
 
+               // Watch user's userpage and talk page
+               $u->addWatch( $u->getUserPage(), WatchedItem::IGNORE_USER_RIGHTS );
+
                return Status::newGood( $u );
        }
 
index 28e2afc..3774d0c 100644 (file)
@@ -61,6 +61,16 @@ $.suggestions = {
                }
        },
 
+       /**
+        * Hide the element with suggestions and clean up some state.
+        */
+       hide: function ( context ) {
+               // Remove any highlights, including on "special" items
+               context.data.$container.find( '.suggestions-result-current' ).removeClass( 'suggestions-result-current' );
+               // Hide the container
+               context.data.$container.hide();
+       },
+
        /**
         * Restore the text the user originally typed in the textbox, before it
         * was overwritten by highlight(). This restores the value the currently
@@ -83,7 +93,7 @@ $.suggestions = {
                // if the textbox is empty then clear the result div, but leave other settings intouched
                function maybeFetch() {
                        if ( context.data.$textbox.val().length === 0 ) {
-                               context.data.$container.hide();
+                               $.suggestions.hide( context );
                                context.data.prevText = '';
                        } else if (
                                context.data.$textbox.val() !== context.data.prevText ||
@@ -147,7 +157,7 @@ $.suggestions = {
                                if ( context.data !== undefined ) {
                                        if ( context.data.$textbox.val().length === 0 ) {
                                                // Hide the div when no suggestion exist
-                                               context.data.$container.hide();
+                                               $.suggestions.hide( context );
                                        } else {
                                                // Rebuild the suggestions list
                                                context.data.$container.show();
@@ -399,7 +409,7 @@ $.suggestions = {
                                break;
                        // Escape
                        case 27:
-                               context.data.$container.hide();
+                               $.suggestions.hide( context );
                                $.suggestions.restore( context );
                                $.suggestions.cancel( context );
                                context.data.$textbox.trigger( 'change' );
@@ -407,9 +417,9 @@ $.suggestions = {
                                break;
                        // Enter
                        case 13:
-                               context.data.$container.hide();
                                preventDefault = wasVisible;
                                selected = context.data.$container.find( '.suggestions-result-current' );
+                               $.suggestions.hide( context );
                                if ( selected.length === 0 || context.data.selectedWithMouse ) {
                                        // if nothing is selected OR if something was selected with the mouse,
                                        // cancel any current requests and submit the form
@@ -530,7 +540,7 @@ $.fn.suggestions = function () {
                                                        // do not interfere with non-left clicks or if modifier keys are pressed (e.g. ctrl-click)
                                                        if ( !( e.which !== 1 || e.altKey || e.ctrlKey || e.shiftKey || e.metaKey ) ) {
                                                                $.suggestions.highlight( context, $result, true );
-                                                               context.data.$container.hide();
+                                                               $.suggestions.hide( context );
                                                                if ( typeof context.config.result.select === 'function' ) {
                                                                        context.config.result.select.call( $result, context.data.$textbox );
                                                                }
@@ -557,7 +567,7 @@ $.fn.suggestions = function () {
                                                        }
                                                        // do not interfere with non-left clicks or if modifier keys are pressed (e.g. ctrl-click)
                                                        if ( !( e.which !== 1 || e.altKey || e.ctrlKey || e.shiftKey || e.metaKey ) ) {
-                                                               context.data.$container.hide();
+                                                               $.suggestions.hide( context );
                                                                if ( typeof context.config.special.select === 'function' ) {
                                                                        context.config.special.select.call( $special, context.data.$textbox );
                                                                }
@@ -617,7 +627,7 @@ $.fn.suggestions = function () {
                                        if ( context.data.mouseDownOn.length > 0 ) {
                                                return;
                                        }
-                                       context.data.$container.hide();
+                                       $.suggestions.hide( context );
                                        $.suggestions.cancel( context );
                                } );
                }
index 7f07862..8fd8496 100644 (file)
 
                // Compatibility map
                map = {
-                       browsers: {
-                               // Left-to-right languages
-                               ltr: {
-                                       // SimpleSearch is broken in Opera < 9.6
-                                       opera: [['>=', 9.6]],
-                                       docomo: false,
-                                       blackberry: false,
-                                       ipod: false,
-                                       iphone: false
-                               },
-                               // Right-to-left languages
-                               rtl: {
-                                       opera: [['>=', 9.6]],
-                                       docomo: false,
-                                       blackberry: false,
-                                       ipod: false,
-                                       iphone: false
-                               }
-                       }
+                       // SimpleSearch is broken in Opera < 9.6
+                       opera: [['>=', 9.6]],
+                       docomo: false,
+                       blackberry: false,
+                       ipod: false,
+                       iphone: false
                };
 
                if ( !$.client.test( map ) ) {
index af6665e..7eca070 100644 (file)
@@ -59,7 +59,7 @@
        font-size: 84%;
        line-height: 1.2em;
        margin: 0 0 1.4em 1em;
-       color: #7d7d7d;
+       color: #545454;
        width: auto;
 }
 span.subpages {
index 40fbfd7..5da7d5b 100644 (file)
@@ -303,7 +303,7 @@ hr {
 }
 
 #contentSub {
-       color: #888;
+       color: #545454;
        font-size: small;
        padding-left: 2em;
 }
index 072cb7c..13c906f 100644 (file)
@@ -1114,6 +1114,57 @@ class FileBackendTest extends MediaWikiTestCase {
                return $cases;
        }
 
+       /**
+        * @dataProvider provider_testGetFileStat
+        * @covers FileBackend::streamFile
+        */
+       public function testStreamFile( $path, $content, $alreadyExists ) {
+               $this->backend = $this->singleBackend;
+               $this->tearDownFiles();
+               $this->doTestStreamFile( $path, $content, $alreadyExists );
+               $this->tearDownFiles();
+       }
+
+       private function doTestStreamFile( $path, $content ) {
+               $backendName = $this->backendClass();
+
+               // Test doStreamFile() directly to avoid header madness
+               $class = new ReflectionClass( $this->backend );
+               $method = $class->getMethod( 'doStreamFile' );
+               $method->setAccessible( true );
+
+               if ( $content !== null ) {
+                       $this->prepare( array( 'dir' => dirname( $path ) ) );
+                       $status = $this->create( array( 'dst' => $path, 'content' => $content ) );
+                       $this->assertGoodStatus( $status,
+                               "Creation of file at $path succeeded ($backendName)." );
+
+                       ob_start();
+                       $method->invokeArgs( $this->backend, array( array( 'src' => $path ) ) );
+                       $data = ob_get_contents();
+                       ob_end_clean();
+
+                       $this->assertEquals( $content, $data, "Correct content streamed from '$path'" );
+               } else { // 404 case
+                       ob_start();
+                       $method->invokeArgs( $this->backend, array( array( 'src' => $path ) ) );
+                       $data = ob_get_contents();
+                       ob_end_clean();
+
+                       $this->assertEquals( '', $data, "Correct content streamed from '$path' ($backendName)" );
+               }
+       }
+
+       public static function provider_testStreamFile() {
+               $cases = array();
+
+               $base = self::baseStorePath();
+               $cases[] = array( "$base/unittest-cont1/e/b/z/some_file.txt", "some file contents" );
+               $cases[] = array( "$base/unittest-cont1/e/b/some-other_file.txt", null );
+
+               return $cases;
+       }
+
        /**
         * @dataProvider provider_testGetFileContents
         * @covers FileBackend::getFileContents