Merge "Add some LocalRepo integration tests"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 30 Aug 2019 11:42:55 +0000 (11:42 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 30 Aug 2019 11:42:55 +0000 (11:42 +0000)
137 files changed:
Gruntfile.js
RELEASE-NOTES-1.34
autoload.php
includes/DefaultSettings.php
includes/EditPage.php
includes/OutputPage.php
includes/Permissions/PermissionManager.php
includes/Storage/BlobStore.php
includes/Storage/SqlBlobStore.php
includes/TemplatesOnThisPageFormatter.php
includes/actions/pagers/HistoryPager.php
includes/api/ApiFeedContributions.php
includes/api/ApiQueryAllUsers.php
includes/api/ApiQueryContributors.php
includes/block/AbstractBlock.php
includes/block/CompositeBlock.php
includes/block/DatabaseBlock.php
includes/block/SystemBlock.php
includes/cache/MessageCache.php
includes/changes/ChangesList.php
includes/content/UnknownContent.php [new file with mode: 0644]
includes/content/UnknownContentHandler.php [new file with mode: 0644]
includes/db/MWLBFactory.php
includes/diff/DifferenceEngine.php
includes/diff/SlotDiffRenderer.php
includes/diff/TextSlotDiffRenderer.php
includes/diff/UnsupportedSlotDiffRenderer.php [new file with mode: 0644]
includes/filebackend/FileBackendGroup.php
includes/filerepo/FileRepo.php
includes/filerepo/file/LocalFile.php
includes/libs/HashRing.php
includes/libs/filebackend/FSFileBackend.php
includes/libs/filebackend/FileBackend.php
includes/libs/filebackend/FileBackendStore.php
includes/libs/filebackend/MemoryFileBackend.php
includes/libs/filebackend/SwiftFileBackend.php
includes/libs/filebackend/filejournal/FileJournal.php
includes/libs/mime/MSCompoundFileReader.php
includes/logging/LogEventsList.php
includes/objectcache/ObjectCache.php
includes/page/Article.php
includes/page/ImageHistoryList.php
includes/page/ImagePage.php
includes/profiler/Profiler.php
includes/profiler/output/ProfilerOutput.php
includes/profiler/output/ProfilerOutputText.php
includes/skins/Skin.php
includes/skins/SkinTemplate.php
includes/specialpage/WantedQueryPage.php
includes/specials/SpecialContributions.php
includes/specials/SpecialDeletedContributions.php
includes/specials/SpecialMovepage.php
includes/specials/SpecialNewimages.php
includes/specials/SpecialSearch.php
includes/specials/pagers/ContribsPager.php
includes/specials/pagers/NewFilesPager.php
includes/upload/UploadFromChunks.php
includes/user/User.php
languages/i18n/en.json
languages/i18n/exif/qqq.json
languages/i18n/qqq.json
load.php
maintenance/Maintenance.php
maintenance/categoryChangesAsRdf.php
package-lock.json
resources/Resources.php
resources/src/jquery/jquery.highlightText.js
resources/src/jquery/jquery.suggestions.js
resources/src/mediawiki.pulsatingdot/mediawiki.pulsatingdot.less [new file with mode: 0644]
resources/src/mediawiki.widgets/mw.widgets.DateInputWidget.js
resources/src/startup/mediawiki.js
resources/src/startup/startup.js
tests/common/TestsAutoLoader.php
tests/parser/parserTests.txt
tests/phpunit/MediaWikiIntegrationTestCase.php
tests/phpunit/MediaWikiTestCaseTrait.php
tests/phpunit/MediaWikiUnitTestCase.php
tests/phpunit/data/categoriesrdf/delete.sparql
tests/phpunit/data/categoriesrdf/edit.sparql
tests/phpunit/data/categoriesrdf/move.sparql
tests/phpunit/includes/ActorMigrationTest.php
tests/phpunit/includes/ContentSecurityPolicyTest.php
tests/phpunit/includes/GlobalFunctions/GlobalTest.php
tests/phpunit/includes/GlobalFunctions/GlobalWithDBTest.php
tests/phpunit/includes/MessageTest.php
tests/phpunit/includes/MovePageTest.php
tests/phpunit/includes/Permissions/PermissionManagerTest.php
tests/phpunit/includes/PrefixSearchTest.php
tests/phpunit/includes/Rest/BasicAccess/MWBasicRequestAuthorizerTest.php
tests/phpunit/includes/Revision/RevisionQueryInfoTest.php
tests/phpunit/includes/Revision/RevisionStoreDbTestBase.php
tests/phpunit/includes/RevisionDbTestBase.php
tests/phpunit/includes/RevisionTest.php
tests/phpunit/includes/Storage/SqlBlobStoreTest.php
tests/phpunit/includes/TitlePermissionTest.php
tests/phpunit/includes/TitleTest.php
tests/phpunit/includes/api/ApiBlockTest.php
tests/phpunit/includes/api/ApiDeleteTest.php
tests/phpunit/includes/api/ApiEditPageTest.php
tests/phpunit/includes/api/ApiMainTest.php
tests/phpunit/includes/api/ApiMoveTest.php
tests/phpunit/includes/api/ApiOptionsTest.php
tests/phpunit/includes/api/ApiParseTest.php
tests/phpunit/includes/api/ApiQuerySiteinfoTest.php
tests/phpunit/includes/api/ApiUserrightsTest.php
tests/phpunit/includes/api/query/ApiQueryUserContribsTest.php
tests/phpunit/includes/auth/AuthManagerTest.php
tests/phpunit/includes/block/BlockManagerTest.php
tests/phpunit/includes/cache/MessageCacheTest.php
tests/phpunit/includes/content/UnknownContentHandlerTest.php [new file with mode: 0644]
tests/phpunit/includes/content/UnknownContentTest.php [new file with mode: 0644]
tests/phpunit/includes/diff/DifferenceEngineTest.php
tests/phpunit/includes/diff/TextSlotDiffRendererTest.php
tests/phpunit/includes/diff/UnsupportedSlotDiffRendererTest.php [new file with mode: 0644]
tests/phpunit/includes/filebackend/FileBackendGroupIntegrationTest.php [new file with mode: 0644]
tests/phpunit/includes/filerepo/RepoGroupTest.php
tests/phpunit/includes/interwiki/InterwikiTest.php
tests/phpunit/includes/objectcache/ObjectCacheTest.php
tests/phpunit/includes/page/PageArchiveTestBase.php
tests/phpunit/includes/page/WikiPageDbTestBase.php
tests/phpunit/includes/resourceloader/ResourceLoaderTest.php
tests/phpunit/includes/search/SearchEnginePrefixTest.php
tests/phpunit/includes/specialpage/ChangesListSpecialPageTest.php
tests/phpunit/includes/specialpage/SpecialPageFactoryTest.php
tests/phpunit/includes/title/NamespaceInfoTest.php
tests/phpunit/includes/user/UserGroupMembershipTest.php
tests/phpunit/includes/user/UserTest.php
tests/phpunit/includes/watcheditem/WatchedItemStoreUnitTest.php
tests/phpunit/languages/LanguageFallbackStaticMethodsTest.php [new file with mode: 0644]
tests/phpunit/structure/AvailableRightsTest.php
tests/phpunit/tests/MediaWikiTestCaseTest.php
tests/phpunit/unit/includes/filebackend/FileBackendGroupTestTrait.php [new file with mode: 0644]
tests/phpunit/unit/includes/filebackend/lockmanager/LockManagerGroupFactoryTest.php
tests/phpunit/unit/includes/language/LanguageFallbackTestTrait.php [new file with mode: 0644]
tests/qunit/suites/resources/mediawiki/mediawiki.Uri.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.loader.test.js
tests/qunit/suites/resources/startup.test.js

index f3950f6..8115ea2 100644 (file)
@@ -26,7 +26,7 @@ module.exports = function ( grunt ) {
                                cache: true
                        },
                        all: [
-                               '**/*.js{,on}',
+                               '**/*.{js,json}',
                                '!docs/**',
                                '!node_modules/**',
                                '!resources/lib/**',
index 932122d..e57dacc 100644 (file)
@@ -81,6 +81,7 @@ For notes on 1.33.x and older releases, see HISTORY.
   password setups and deprecated since 1.24, is now removed.
 * $wgDBOracleDRCP - If you must use persistent connections, set DBO_PERSISTENT
   in the 'flags' field for servers in $wgDBServers (or $wgLBFactoryConf).
+* $wgMemCachedDebug - Set the cache "debug" field in $wgObjectCaches instead.
 
 === New user-facing features in 1.34 ===
 * Special:Mute has been added as a quick way for users to block unwanted emails
@@ -476,6 +477,7 @@ because of Phabricator reports.
   SearchResult::newFromTitle(). This class is being refactored into an abstract
   class. If you extend this class please be sure to override all its methods
   or extend RevisionSearchResult.
+* Skin::getSkinNameMessages() is deprecated and no longer used.
 
 === Other changes in 1.34 ===
 * â€¦
index 35c9b0a..eb54f7c 100644 (file)
@@ -1521,9 +1521,12 @@ $wgAutoloadLocalClasses = [
        'UncategorizedTemplatesPage' => __DIR__ . '/includes/specials/SpecialUncategorizedtemplates.php',
        'Undelete' => __DIR__ . '/maintenance/undelete.php',
        'UnifiedDiffFormatter' => __DIR__ . '/includes/diff/UnifiedDiffFormatter.php',
+       'UnknownContent' => __DIR__ . '/includes/content/UnknownContent.php',
+       'UnknownContentHandler' => __DIR__ . '/includes/content/UnknownContentHandler.php',
        'UnlistedSpecialPage' => __DIR__ . '/includes/specialpage/UnlistedSpecialPage.php',
        'UnprotectAction' => __DIR__ . '/includes/actions/UnprotectAction.php',
        'UnregisteredLocalFile' => __DIR__ . '/includes/filerepo/file/UnregisteredLocalFile.php',
+       'UnsupportedSlotDiffRenderer' => __DIR__ . '/includes/diff/UnsupportedSlotDiffRenderer.php',
        'UnusedCategoriesPage' => __DIR__ . '/includes/specials/SpecialUnusedcategories.php',
        'UnusedimagesPage' => __DIR__ . '/includes/specials/SpecialUnusedimages.php',
        'UnusedtemplatesPage' => __DIR__ . '/includes/specials/SpecialUnusedtemplates.php',
index 93a5919..9577a48 100644 (file)
@@ -2554,11 +2554,6 @@ $wgPHPSessionHandling = 'enable';
  */
 $wgSessionPbkdf2Iterations = 10001;
 
-/**
- * If enabled, will send MemCached debugging information to $wgDebugLogFile
- */
-$wgMemCachedDebug = false;
-
 /**
  * The list of MemCached servers and port numbers
  */
index d0a5080..e51fc52 100644 (file)
@@ -689,10 +689,6 @@ class EditPage {
                # checking, etc.
                if ( $this->formtype == 'initial' || $this->firsttime ) {
                        if ( $this->initialiseForm() === false ) {
-                               $out = $this->context->getOutput();
-                               if ( $out->getRedirect() === '' ) { // mcrundo hack redirects, don't override it
-                                       $this->noSuchSectionPage();
-                               }
                                return;
                        }
 
@@ -1145,8 +1141,26 @@ class EditPage {
 
                $content = $this->getContentObject( false ); # TODO: track content object?!
                if ( $content === false ) {
+                       $out = $this->context->getOutput();
+                       if ( $out->getRedirect() === '' ) { // mcrundo hack redirects, don't override it
+                               $this->noSuchSectionPage();
+                       }
+                       return false;
+               }
+
+               if ( !$this->isSupportedContentModel( $content->getModel() ) ) {
+                       $modelMsg = $this->getContext()->msg( 'content-model-' . $content->getModel() );
+                       $modelName = $modelMsg->exists() ? $modelMsg->text() : $content->getModel();
+
+                       $out = $this->context->getOutput();
+                       $out->showErrorPage(
+                               'modeleditnotsupported-title',
+                               'modeleditnotsupported-text',
+                               $modelName
+                       );
                        return false;
                }
+
                $this->textbox1 = $this->toEditText( $content );
 
                $user = $this->context->getUser();
index b2ca53a..9af16d3 100644 (file)
@@ -3311,12 +3311,10 @@ class OutputPage extends ContextSource {
                        $vars['wgUserVariant'] = $contLang->getPreferredVariant();
                }
                // Same test as SkinTemplate
-               $vars['wgIsProbablyEditable'] = $title->quickUserCan( 'edit', $user )
-                       && ( $title->exists() || $title->quickUserCan( 'create', $user ) );
+               $vars['wgIsProbablyEditable'] = $this->userCanEditOrCreate( $user, $title );
 
-               $vars['wgRelevantPageIsProbablyEditable'] = $relevantTitle
-                       && $relevantTitle->quickUserCan( 'edit', $user )
-                       && ( $relevantTitle->exists() || $relevantTitle->quickUserCan( 'create', $user ) );
+               $vars['wgRelevantPageIsProbablyEditable'] = $relevantTitle &&
+                       $this->userCanEditOrCreate( $user, $relevantTitle );
 
                foreach ( $title->getRestrictionTypes() as $type ) {
                        // Following keys are set in $vars:
@@ -3383,6 +3381,21 @@ class OutputPage extends ContextSource {
                return true;
        }
 
+       /**
+        * @param User $user
+        * @param LinkTarget $title
+        * @return bool
+        */
+       private function userCanEditOrCreate(
+               User $user,
+               LinkTarget $title
+       ) {
+               $pm = MediaWikiServices::getInstance()->getPermissionManager();
+               return $pm->quickUserCan( 'edit', $user, $title )
+               && ( $this->getTitle()->exists() ||
+                        $pm->quickUserCan( 'create', $user, $title ) );
+       }
+
        /**
         * @return array Array in format "link name or number => 'link html'".
         */
@@ -3447,11 +3460,7 @@ class OutputPage extends ContextSource {
 
                # Universal edit button
                if ( $config->get( 'UniversalEditButton' ) && $this->isArticleRelated() ) {
-                       $user = $this->getUser();
-                       if ( $this->getTitle()->quickUserCan( 'edit', $user )
-                               && ( $this->getTitle()->exists() ||
-                                       $this->getTitle()->quickUserCan( 'create', $user ) )
-                       ) {
+                       if ( $this->userCanEditOrCreate( $this->getUser(), $this->getTitle() ) ) {
                                // Original UniversalEditButton
                                $msg = $this->msg( 'edit' )->text();
                                $tags['universal-edit-button'] = Html::element( 'link', [
index 43d57a7..37791d0 100644 (file)
@@ -231,6 +231,25 @@ class PermissionManager {
                return !count( $this->getPermissionErrorsInternal( $action, $user, $page, $rigor, true ) );
        }
 
+       /**
+        * A convenience method for calling PermissionManager::userCan
+        * with PermissionManager::RIGOR_QUICK
+        *
+        * Suitable for use for nonessential UI controls in common cases, but
+        * _not_ for functional access control.
+        * May provide false positives, but should never provide a false negative.
+        *
+        * @see PermissionManager::userCan()
+        *
+        * @param string $action
+        * @param User $user
+        * @param LinkTarget $page
+        * @return bool
+        */
+       public function quickUserCan( $action, User $user, LinkTarget $page ) {
+               return $this->userCan( $action, $user, $page, self::RIGOR_QUICK );
+       }
+
        /**
         * Can $user perform $action on a page?
         *
@@ -1244,11 +1263,12 @@ class PermissionManager {
         */
        public function getUserPermissions( UserIdentity $user ) {
                $user = User::newFromIdentity( $user );
-               if ( !isset( $this->usersRights[ $user->getId() ] ) ) {
-                       $this->usersRights[ $user->getId() ] = $this->getGroupPermissions(
+               $rightsCacheKey = $this->getRightsCacheKey( $user );
+               if ( !isset( $this->usersRights[ $rightsCacheKey ] ) ) {
+                       $this->usersRights[ $rightsCacheKey ] = $this->getGroupPermissions(
                                $user->getEffectiveGroups()
                        );
-                       Hooks::run( 'UserGetRights', [ $user, &$this->usersRights[ $user->getId() ] ] );
+                       Hooks::run( 'UserGetRights', [ $user, &$this->usersRights[ $rightsCacheKey ] ] );
 
                        // Deny any rights denied by the user's session, unless this
                        // endpoint has no sessions.
@@ -1256,17 +1276,17 @@ class PermissionManager {
                                // FIXME: $user->getRequest().. need to be replaced with something else
                                $allowedRights = $user->getRequest()->getSession()->getAllowedUserRights();
                                if ( $allowedRights !== null ) {
-                                       $this->usersRights[ $user->getId() ] = array_intersect(
-                                               $this->usersRights[ $user->getId() ],
+                                       $this->usersRights[ $rightsCacheKey ] = array_intersect(
+                                               $this->usersRights[ $rightsCacheKey ],
                                                $allowedRights
                                        );
                                }
                        }
 
-                       Hooks::run( 'UserGetRightsRemove', [ $user, &$this->usersRights[ $user->getId() ] ] );
+                       Hooks::run( 'UserGetRightsRemove', [ $user, &$this->usersRights[ $rightsCacheKey ] ] );
                        // Force reindexation of rights when a hook has unset one of them
-                       $this->usersRights[ $user->getId() ] = array_values(
-                               array_unique( $this->usersRights[ $user->getId() ] )
+                       $this->usersRights[ $rightsCacheKey ] = array_values(
+                               array_unique( $this->usersRights[ $rightsCacheKey ] )
                        );
 
                        if (
@@ -1275,13 +1295,13 @@ class PermissionManager {
                                $user->getBlock()
                        ) {
                                $anon = new User;
-                               $this->usersRights[ $user->getId() ] = array_intersect(
-                                       $this->usersRights[ $user->getId() ],
+                               $this->usersRights[ $rightsCacheKey ] = array_intersect(
+                                       $this->usersRights[ $rightsCacheKey ],
                                        $this->getUserPermissions( $anon )
                                );
                        }
                }
-               $rights = $this->usersRights[ $user->getId() ];
+               $rights = $this->usersRights[ $rightsCacheKey ];
                foreach ( $this->temporaryUserRights[ $user->getId() ] ?? [] as $overrides ) {
                        $rights = array_values( array_unique( array_merge( $rights, $overrides ) ) );
                }
@@ -1298,14 +1318,24 @@ class PermissionManager {
         */
        public function invalidateUsersRightsCache( $user = null ) {
                if ( $user !== null ) {
-                       if ( isset( $this->usersRights[ $user->getId() ] ) ) {
-                               unset( $this->usersRights[$user->getId()] );
+                       $rightsCacheKey = $this->getRightsCacheKey( $user );
+                       if ( isset( $this->usersRights[ $rightsCacheKey ] ) ) {
+                               unset( $this->usersRights[ $rightsCacheKey ] );
                        }
                } else {
                        $this->usersRights = null;
                }
        }
 
+       /**
+        * Gets a unique key for user rights cache.
+        * @param UserIdentity $user
+        * @return string
+        */
+       private function getRightsCacheKey( UserIdentity $user ) {
+               return $user->isRegistered() ? "u:{$user->getId()}" : "anon:{$user->getName()}";
+       }
+
        /**
         * Check, if the given group has the given permission
         *
@@ -1583,7 +1613,8 @@ class PermissionManager {
                if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
                        throw new Exception( __METHOD__ . ' can not be called outside of tests' );
                }
-               $this->usersRights[ $user->getId() ] = is_array( $rights ) ? $rights : [ $rights ];
+               $this->usersRights[ $this->getRightsCacheKey( $user ) ] =
+                       is_array( $rights ) ? $rights : [ $rights ];
        }
 
 }
index 8b1112b..78885db 100644 (file)
@@ -22,6 +22,8 @@
 
 namespace MediaWiki\Storage;
 
+use StatusValue;
+
 /**
  * Service for loading and storing data blobs.
  *
@@ -95,6 +97,19 @@ interface BlobStore {
         */
        public function getBlob( $blobAddress, $queryFlags = 0 );
 
+       /**
+        * A batched version of BlobStore::getBlob.
+        *
+        * @param string[] $blobAddresses An array of blob addresses.
+        * @param int $queryFlags See IDBAccessObject.
+        * @throws BlobAccessException
+        * @return StatusValue A status with a map of blobAddress => binary blob data or null
+        *         if fetching the blob has failed. Fetch failures errors are the
+        *         warnings in the status object.
+        * @since 1.34
+        */
+       public function getBlobBatch( $blobAddresses, $queryFlags = 0 );
+
        /**
         * Stores an arbitrary blob of data and returns an address that can be used with
         * getBlob() to retrieve the same blob of data,
index d1b688b..8c011df 100644 (file)
 
 namespace MediaWiki\Storage;
 
+use AppendIterator;
 use DBAccessObjectUtils;
 use IDBAccessObject;
 use IExpiringStore;
 use InvalidArgumentException;
 use Language;
 use MWException;
+use StatusValue;
 use WANObjectCache;
 use ExternalStoreAccess;
 use Wikimedia\Assert\Assert;
@@ -277,92 +279,170 @@ class SqlBlobStore implements IDBAccessObject, BlobStore {
        public function getBlob( $blobAddress, $queryFlags = 0 ) {
                Assert::parameterType( 'string', $blobAddress, '$blobAddress' );
 
-               // No negative caching; negative hits on text rows may be due to corrupted replica DBs
+               $error = null;
                $blob = $this->cache->getWithSetCallback(
                        $this->getCacheKey( $blobAddress ),
                        $this->getCacheTTL(),
-                       function ( $unused, &$ttl, &$setOpts ) use ( $blobAddress, $queryFlags ) {
+                       function ( $unused, &$ttl, &$setOpts ) use ( $blobAddress, $queryFlags, &$error ) {
                                // Ignore $setOpts; blobs are immutable and negatives are not cached
-                               return $this->fetchBlob( $blobAddress, $queryFlags );
+                               list( $result, $errors ) = $this->fetchBlobs( [ $blobAddress ], $queryFlags );
+                               // No negative caching; negative hits on text rows may be due to corrupted replica DBs
+                               $error = $errors[$blobAddress] ?? null;
+                               return $result[$blobAddress];
                        },
                        [ 'pcGroup' => self::TEXT_CACHE_GROUP, 'pcTTL' => IExpiringStore::TTL_PROC_LONG ]
                );
 
-               if ( $blob === false ) {
-                       throw new BlobAccessException( 'Failed to load blob from address ' . $blobAddress );
+               if ( $error ) {
+                       throw new BlobAccessException( $error );
                }
 
+               Assert::postcondition( is_string( $blob ), 'Blob must not be null' );
                return $blob;
        }
 
+       /**
+        * A batched version of BlobStore::getBlob.
+        *
+        * @param string[] $blobAddresses An array of blob addresses.
+        * @param int $queryFlags See IDBAccessObject.
+        * @throws BlobAccessException
+        * @return StatusValue A status with a map of blobAddress => binary blob data or null
+        *         if fetching the blob has failed. Fetch failures errors are the
+        *         warnings in the status object.
+        * @since 1.34
+        */
+       public function getBlobBatch( $blobAddresses, $queryFlags = 0 ) {
+               $errors = null;
+               $addressByCacheKey = $this->cache->makeMultiKeys(
+                       $blobAddresses,
+                       function ( $blobAddress ) {
+                               return $this->getCacheKey( $blobAddress );
+                       }
+               );
+               $blobsByCacheKey = $this->cache->getMultiWithUnionSetCallback(
+                       $addressByCacheKey,
+                       $this->getCacheTTL(),
+                       function ( array $blobAddresses, array &$ttls, array &$setOpts ) use ( $queryFlags, &$errors ) {
+                               // Ignore $setOpts; blobs are immutable and negatives are not cached
+                               list( $result, $errors ) = $this->fetchBlobs( $blobAddresses, $queryFlags );
+                               return $result;
+                       },
+                       [ 'pcGroup' => self::TEXT_CACHE_GROUP, 'pcTTL' => IExpiringStore::TTL_PROC_LONG ]
+               );
+
+               // Remap back to incoming blob addresses. The return value of the
+               // WANObjectCache::getMultiWithUnionSetCallback is keyed on the internal
+               // keys from WANObjectCache::makeMultiKeys, so we need to remap them
+               // before returning to the client.
+               $blobsByAddress = [];
+               foreach ( $blobsByCacheKey as $cacheKey => $blob ) {
+                       $blobsByAddress[ $addressByCacheKey[ $cacheKey ] ] = $blob !== false ? $blob : null;
+               }
+
+               $result = StatusValue::newGood( $blobsByAddress );
+               if ( $errors ) {
+                       foreach ( $errors as $error ) {
+                               $result->warning( 'internalerror', $error );
+                       }
+               }
+               return $result;
+       }
+
        /**
         * MCR migration note: this corresponds to Revision::fetchText
         *
-        * @param string $blobAddress
+        * @param string[] $blobAddresses
         * @param int $queryFlags
         *
         * @throws BlobAccessException
-        * @return string|false
-        */
-       private function fetchBlob( $blobAddress, $queryFlags ) {
-               list( $schema, $id, ) = self::splitBlobAddress( $blobAddress );
+        * @return array [ $result, $errors ] A map of blob addresses to successfully fetched blobs
+        *         or false if fetch failed, plus and array of errors
+        */
+       private function fetchBlobs( $blobAddresses, $queryFlags ) {
+               $textIdToBlobAddress = [];
+               $result = [];
+               $errors = [];
+               foreach ( $blobAddresses as $blobAddress ) {
+                       list( $schema, $id ) = self::splitBlobAddress( $blobAddress );
+                       //TODO: MCR: also support 'ex' schema with ExternalStore URLs, plus flags encoded in the URL!
+                       if ( $schema === 'tt' ) {
+                               $textId = intval( $id );
+                               $textIdToBlobAddress[$textId] = $blobAddress;
+                       } else {
+                               $errors[$blobAddress] = "Unknown blob address schema: $schema";
+                               $result[$blobAddress] = false;
+                               continue;
+                       }
 
-               //TODO: MCR: also support 'ex' schema with ExternalStore URLs, plus flags encoded in the URL!
-               if ( $schema === 'tt' ) {
-                       $textId = intval( $id );
-               } else {
-                       // XXX: change to better exceptions! That makes migration more difficult, though.
-                       throw new BlobAccessException( "Unknown blob address schema: $schema" );
+                       if ( !$textId || $id !== (string)$textId ) {
+                               $errors[$blobAddress] = "Bad blob address: $blobAddress";
+                               $result[$blobAddress] = false;
+                       }
                }
 
-               if ( !$textId || $id !== (string)$textId ) {
-                       // XXX: change to better exceptions! That makes migration more difficult, though.
-                       throw new BlobAccessException( "Bad blob address: $blobAddress" );
+               $textIds = array_keys( $textIdToBlobAddress );
+               if ( !$textIds ) {
+                       return [ $result, $errors ];
                }
-
                // Callers doing updates will pass in READ_LATEST as usual. Since the text/blob tables
                // do not normally get rows changed around, set READ_LATEST_IMMUTABLE in those cases.
                $queryFlags |= DBAccessObjectUtils::hasFlags( $queryFlags, self::READ_LATEST )
                        ? self::READ_LATEST_IMMUTABLE
                        : 0;
-
                list( $index, $options, $fallbackIndex, $fallbackOptions ) =
                        DBAccessObjectUtils::getDBOptions( $queryFlags );
-
                // Text data is immutable; check replica DBs first.
-               $row = $this->getDBConnection( $index )->selectRow(
+               $dbConnection = $this->getDBConnection( $index );
+               $rows = $dbConnection->select(
                        'text',
-                       [ 'old_text', 'old_flags' ],
-                       [ 'old_id' => $textId ],
+                       [ 'old_id', 'old_text', 'old_flags' ],
+                       [ 'old_id' => $textIds ],
                        __METHOD__,
                        $options
                );
 
-               // Fallback to DB_MASTER in some cases if the row was not found, using the appropriate
+               // Fallback to DB_MASTER in some cases if not all the rows were found, using the appropriate
                // options, such as FOR UPDATE to avoid missing rows due to REPEATABLE-READ.
-               if ( !$row && $fallbackIndex !== null ) {
-                       $row = $this->getDBConnection( $fallbackIndex )->selectRow(
+               if ( $dbConnection->numRows( $rows ) !== count( $textIds ) && $fallbackIndex !== null ) {
+                       $fetchedTextIds = [];
+                       foreach ( $rows as $row ) {
+                               $fetchedTextIds[] = $row->old_id;
+                       }
+                       $missingTextIds = array_diff( $textIds, $fetchedTextIds );
+                       $dbConnection = $this->getDBConnection( $fallbackIndex );
+                       $rowsFromFallback = $dbConnection->select(
                                'text',
-                               [ 'old_text', 'old_flags' ],
-                               [ 'old_id' => $textId ],
+                               [ 'old_id', 'old_text', 'old_flags' ],
+                               [ 'old_id' => $missingTextIds ],
                                __METHOD__,
                                $fallbackOptions
                        );
+                       $appendIterator = new AppendIterator();
+                       $appendIterator->append( $rows );
+                       $appendIterator->append( $rowsFromFallback );
+                       $rows = $appendIterator;
                }
 
-               if ( !$row ) {
-                       wfWarn( __METHOD__ . ": No text row with ID $textId." );
-                       return false;
+               foreach ( $rows as $row ) {
+                       $blobAddress = $textIdToBlobAddress[$row->old_id];
+                       $blob = $this->expandBlob( $row->old_text, $row->old_flags, $blobAddress );
+                       if ( $blob === false ) {
+                               $errors[$blobAddress] = "Bad data in text row {$row->old_id}.";
+                       }
+                       $result[$blobAddress] = $blob;
                }
 
-               $blob = $this->expandBlob( $row->old_text, $row->old_flags, $blobAddress );
-
-               if ( $blob === false ) {
-                       wfLogWarning( __METHOD__ . ": Bad data in text row $textId." );
-                       return false;
+               // If we're still missing some of the rows, set errors for missing blobs.
+               if ( count( $result ) !== count( $blobAddresses ) ) {
+                       foreach ( $blobAddresses as $blobAddress ) {
+                               if ( !isset( $result[$blobAddress ] ) ) {
+                                       $errors[$blobAddress] = "Unable to fetch blob at $blobAddress";
+                                       $result[$blobAddress] = false;
+                               }
+                       }
                }
-
-               return $blob;
+               return [ $result, $errors ];
        }
 
        /**
index bca1ef6..215e4ec 100644 (file)
@@ -20,6 +20,7 @@
 
 use MediaWiki\Linker\LinkRenderer;
 use MediaWiki\Linker\LinkTarget;
+use MediaWiki\MediaWikiServices;
 
 /**
  * Handles formatting for the "templates used on this page"
@@ -158,11 +159,13 @@ class TemplatesOnThisPageFormatter {
         * Return a link to the edit page, with the text
         * saying "view source" if the user can't edit the page
         *
-        * @param Title $titleObj
+        * @param LinkTarget $titleObj
         * @return string
         */
-       private function buildEditLink( Title $titleObj ) {
-               if ( $titleObj->quickUserCan( 'edit', $this->context->getUser() ) ) {
+       private function buildEditLink( LinkTarget $titleObj ) {
+               if ( MediaWikiServices::getInstance()->getPermissionManager()
+                               ->quickUserCan( 'edit', $this->context->getUser(), $titleObj )
+               ) {
                        $linkMsg = 'editlink';
                } else {
                        $linkMsg = 'viewsourcelink';
index fd2fbd0..f178911 100644 (file)
@@ -401,8 +401,11 @@ class HistoryPager extends ReverseChronologicalPager {
                $tools = [];
 
                # Rollback and undo links
-               if ( $prevRev && $this->getTitle()->quickUserCan( 'edit', $user ) ) {
-                       if ( $latest && $this->getTitle()->quickUserCan( 'rollback', $user ) ) {
+
+               if ( $prevRev && $permissionManager->quickUserCan( 'edit', $user, $this->getTitle() ) ) {
+                       if ( $latest && $permissionManager->quickUserCan( 'rollback',
+                                       $user, $this->getTitle() )
+                       ) {
                                // Get a rollback link without the brackets
                                $rollbackLink = Linker::generateRollback(
                                        $rev,
index 28b0a4b..fabe4a2 100644 (file)
@@ -71,18 +71,15 @@ class ApiFeedContributions extends ApiBase {
                        ' [' . $config->get( 'LanguageCode' ) . ']';
                $feedUrl = SpecialPage::getTitleFor( 'Contributions', $params['user'] )->getFullURL();
 
-               $target = 'newbies';
-               if ( $params['user'] != 'newbies' ) {
-                       try {
-                               $target = $this->titleParser
-                                       ->parseTitle( $params['user'], NS_USER )
-                                       ->getText();
-                       } catch ( MalformedTitleException $e ) {
-                               $this->dieWithError(
-                                       [ 'apierror-baduser', 'user', wfEscapeWikiText( $params['user'] ) ],
-                                       'baduser_' . $this->encodeParamName( 'user' )
-                               );
-                       }
+               try {
+                       $target = $this->titleParser
+                               ->parseTitle( $params['user'], NS_USER )
+                               ->getText();
+               } catch ( MalformedTitleException $e ) {
+                       $this->dieWithError(
+                               [ 'apierror-baduser', 'user', wfEscapeWikiText( $params['user'] ) ],
+                               'baduser_' . $this->encodeParamName( 'user' )
+                       );
                }
 
                $feed = new $feedClasses[$params['feedformat']] (
index 023b88f..e0513e2 100644 (file)
@@ -356,7 +356,7 @@ class ApiQueryAllUsers extends ApiQueryBase {
                                ApiBase::PARAM_ISMULTI => true,
                        ],
                        'rights' => [
-                               ApiBase::PARAM_TYPE => User::getAllRights(),
+                               ApiBase::PARAM_TYPE => $this->getPermissionManager()->getAllPermissions(),
                                ApiBase::PARAM_ISMULTI => true,
                        ],
                        'prop' => [
index fd2d199..a1945c4 100644 (file)
@@ -231,7 +231,7 @@ class ApiQueryContributors extends ApiQueryBase {
 
        public function getAllowedParams() {
                $userGroups = User::getAllGroups();
-               $userRights = User::getAllRights();
+               $userRights = $this->getPermissionManager()->getAllPermissions();
 
                return [
                        'group' => [
index fcc624e..4d4bb07 100644 (file)
@@ -90,13 +90,13 @@ abstract class AbstractBlock {
        /**
         * Create a new block with specified parameters on a user, IP or IP range.
         *
-        * @param array $options Parameters of the block:
-        *     address string|User  Target user name, User object, IP address or IP range
-        *     by int               User ID of the blocker
-        *     reason string        Reason of the block
-        *     timestamp string     The time at which the block comes into effect
-        *     byText string        Username of the blocker (for foreign users)
-        *     hideName bool        Hide the target user name
+        * @param array $options Parameters of the block, with supported options:
+        *  - address: (string|User) Target user name, User object, IP address or IP range
+        *  - by: (int) User ID of the blocker
+        *  - reason: (string) Reason of the block
+        *  - timestamp: (string) The time at which the block comes into effect
+        *  - byText: (string) Username of the blocker (for foreign users)
+        *  - hideName: (bool) Hide the target user name
         */
        public function __construct( array $options = [] ) {
                $defaults = [
index 45a6301..3f3e2d3 100644 (file)
@@ -40,8 +40,9 @@ class CompositeBlock extends AbstractBlock {
        /**
         * Create a new block with specified parameters on a user, IP or IP range.
         *
-        * @param array $options Parameters of the block:
-        *     originalBlocks Block[] Blocks that this block is composed from
+        * @param array $options Parameters of the block, with options supported by
+        *  `AbstractBlock::__construct`, and also:
+        *  - originalBlocks: (Block[]) Blocks that this block is composed from
         */
        public function __construct( array $options = [] ) {
                parent::__construct( $options );
index 79286c5..6007abd 100644 (file)
@@ -86,18 +86,18 @@ class DatabaseBlock extends AbstractBlock {
        /**
         * Create a new block with specified option parameters on a user, IP or IP range.
         *
-        * @param array $options Parameters of the block:
-        *     user int             Override target user ID (for foreign users)
-        *     auto bool            Is this an automatic block?
-        *     expiry string        Timestamp of expiration of the block or 'infinity'
-        *     anonOnly bool        Only disallow anonymous actions
-        *     createAccount bool   Disallow creation of new accounts
-        *     enableAutoblock bool Enable automatic blocking
-        *     blockEmail bool      Disallow sending emails
-        *     allowUsertalk bool   Allow the target to edit its own talk page
-        *     sitewide bool        Disallow editing all pages and all contribution
-        *                          actions, except those specifically allowed by
-        *                          other block flags
+        * @param array $options Parameters of the block, with options supported by
+        *  `AbstractBlock::__construct`, and also:
+        *  - user: (int) Override target user ID (for foreign users)
+        *  - auto: (bool) Is this an automatic block?
+        *  - expiry: (string) Timestamp of expiration of the block or 'infinity'
+        *  - anonOnly: (bool) Only disallow anonymous actions
+        *  - createAccount: (bool) Disallow creation of new accounts
+        *  - enableAutoblock: (bool) Enable automatic blocking
+        *  - blockEmail: (bool) Disallow sending emails
+        *  - allowUsertalk: (bool) Allow the target to edit its own talk page
+        *  - sitewide: (bool) Disallow editing all pages and all contribution actions,
+        *    except those specifically allowed by other block flags
         *
         * @since 1.26 $options array
         */
index 0cbf125..494a7b9 100644 (file)
@@ -39,11 +39,11 @@ class SystemBlock extends AbstractBlock {
        /**
         * Create a new block with specified parameters on a user, IP or IP range.
         *
-        * @param array $options Parameters of the block:
-        *     systemBlock string   Indicate that this block is automatically
-        *                          created by MediaWiki rather than being stored
-        *                          in the database. Value is a string to return
-        *                          from self::getSystemBlockType().
+        * @param array $options Parameters of the block, with options supported by
+        *  `AbstractBlock::__construct`, and also:
+        *  - systemBlock: (string) Indicate that this block is automatically created by
+        *    MediaWiki rather than being stored in the database. Value is a string to
+        *    return from self::getSystemBlockType().
         */
        public function __construct( array $options = [] ) {
                parent::__construct( $options );
index dfbc50a..3a6d892 100644 (file)
@@ -165,8 +165,8 @@ class MessageCache {
                global $wgUser;
 
                if ( !$this->mParserOptions ) {
-                       if ( !$wgUser->isSafeToLoad() ) {
-                               // $wgUser isn't unstubbable yet, so don't try to get a
+                       if ( !$wgUser || !$wgUser->isSafeToLoad() ) {
+                               // $wgUser isn't available yet, so don't try to get a
                                // ParserOptions for it. And don't cache this ParserOptions
                                // either.
                                $po = ParserOptions::newFromAnon();
index 7807877..0382d73 100644 (file)
@@ -716,7 +716,9 @@ class ChangesList extends ContextSource {
                        /** Check for rollback permissions, disallow special pages, and only
                         * show a link on the top-most revision
                         */
-                       if ( $title->quickUserCan( 'rollback', $this->getUser() ) ) {
+                       if ( MediaWikiServices::getInstance()->getPermissionManager()
+                               ->quickUserCan( 'rollback', $this->getUser(), $title )
+                       ) {
                                $rev = new Revision( [
                                        'title' => $title,
                                        'id' => $rc->mAttribs['rc_this_oldid'],
diff --git a/includes/content/UnknownContent.php b/includes/content/UnknownContent.php
new file mode 100644 (file)
index 0000000..27199a0
--- /dev/null
@@ -0,0 +1,149 @@
+<?php
+/**
+ * Content object implementation for representing unknown content.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @since 1.34
+ *
+ * @file
+ * @ingroup Content
+ *
+ * @author Daniel Kinzler
+ */
+
+/**
+ * Content object implementation representing unknown content.
+ *
+ * This can be used to handle content for which no ContentHandler exists on the system,
+ * perhaps because the extension that provided it has been removed.
+ *
+ * UnknownContent instances are immutable.
+ *
+ * @ingroup Content
+ */
+class UnknownContent extends AbstractContent {
+
+       /** @var string */
+       private $data;
+
+       /**
+        * @param string $data
+        * @param string $model_id The model ID to handle
+        */
+       public function __construct( $data, $model_id ) {
+               parent::__construct( $model_id );
+
+               $this->data = $data;
+       }
+
+       /**
+        * @return Content $this
+        */
+       public function copy() {
+               // UnknownContent is immutable, so no need to copy.
+               return $this;
+       }
+
+       /**
+        * Returns an empty string.
+        *
+        * @param int $maxlength
+        *
+        * @return string
+        */
+       public function getTextForSummary( $maxlength = 250 ) {
+               return '';
+       }
+
+       /**
+        * Returns the data size in bytes.
+        *
+        * @return int
+        */
+       public function getSize() {
+               return strlen( $this->data );
+       }
+
+       /**
+        * Returns false.
+        *
+        * @param bool|null $hasLinks If it is known whether this content contains links,
+        * provide this information here, to avoid redundant parsing to find out.
+        *
+        * @return bool
+        */
+       public function isCountable( $hasLinks = null ) {
+               return false;
+       }
+
+       /**
+        * @return string data of unknown format and meaning
+        */
+       public function getNativeData() {
+               return $this->getData();
+       }
+
+       /**
+        * @return string data of unknown format and meaning
+        */
+       public function getData() {
+               return $this->data;
+       }
+
+       /**
+        * Returns an empty string.
+        *
+        * @return string The raw text.
+        */
+       public function getTextForSearchIndex() {
+               return '';
+       }
+
+       /**
+        * Returns false.
+        */
+       public function getWikitextForTransclusion() {
+               return false;
+       }
+
+       /**
+        * Fills the ParserOutput with an error message.
+        */
+       protected function fillParserOutput( Title $title, $revId,
+               ParserOptions $options, $generateHtml, ParserOutput &$output
+       ) {
+               $msg = wfMessage( 'unsupported-content-model', [ $this->getModel() ] );
+               $html = Html::rawElement( 'div', [ 'class' => 'error' ], $msg->inContentLanguage()->parse() );
+               $output->setText( $html );
+       }
+
+       /**
+        * Returns false.
+        */
+       public function convert( $toModel, $lossy = '' ) {
+               return false;
+       }
+
+       protected function equalsInternal( Content $that ) {
+               if ( !$that instanceof UnknownContent ) {
+                       return false;
+               }
+
+               return $this->getData() == $that->getData();
+       }
+
+}
diff --git a/includes/content/UnknownContentHandler.php b/includes/content/UnknownContentHandler.php
new file mode 100644 (file)
index 0000000..1427e2b
--- /dev/null
@@ -0,0 +1,114 @@
+<?php
+/**
+ * Base content handler class for flat text contents.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @since 1.34
+ *
+ * @file
+ * @ingroup Content
+ */
+
+/**
+ * Content handler implementation for unknown content.
+ *
+ * This can be used to handle content for which no ContentHandler exists on the system,
+ * perhaps because the extension that provided it has been removed.
+ *
+ * @ingroup Content
+ */
+class UnknownContentHandler extends ContentHandler {
+
+       /**
+        * Constructs an UnknownContentHandler. Since UnknownContentHandler can be registered
+        * for multiple model IDs on a system, multiple instances of UnknownContentHandler may
+        * coexist.
+        *
+        * To preserve the serialization format of the original content model, it must be supplied
+        * to the constructor via the $formats parameter. If not given, the default format is
+        * reported as 'application/octet-stream'.
+        *
+        * @param string $modelId
+        * @param string[]|null $formats
+        */
+       public function __construct( $modelId, $formats = null ) {
+               parent::__construct(
+                       $modelId,
+                       $formats ?? [
+                               'application/octet-stream',
+                               'application/unknown',
+                               'application/x-binary',
+                               'text/unknown',
+                               'unknown/unknown',
+                       ]
+               );
+       }
+
+       /**
+        * Returns the content's data as-is.
+        *
+        * @param Content $content
+        * @param string|null $format The serialization format to check
+        *
+        * @return mixed
+        */
+       public function serializeContent( Content $content, $format = null ) {
+               /** @var UnknownContent $content */
+               return $content->getData();
+       }
+
+       /**
+        * Constructs an UnknownContent instance wrapping the given data.
+        *
+        * @since 1.21
+        *
+        * @param string $blob serialized content in an unknown format
+        * @param string|null $format ignored
+        *
+        * @return Content The UnknownContent object wrapping $data
+        */
+       public function unserializeContent( $blob, $format = null ) {
+               return new UnknownContent( $blob, $this->getModelID() );
+       }
+
+       /**
+        * Creates an empty UnknownContent object.
+        *
+        * @since 1.21
+        *
+        * @return Content A new UnknownContent object with empty text.
+        */
+       public function makeEmptyContent() {
+               return $this->unserializeContent( '' );
+       }
+
+       /**
+        * @return false
+        */
+       public function supportsDirectEditing() {
+               return false;
+       }
+
+       /**
+        * @param IContextSource $context
+        *
+        * @return SlotDiffRenderer
+        */
+       protected function getSlotDiffRendererInternal( IContextSource $context ) {
+               return new UnsupportedSlotDiffRenderer( $context );
+       }
+}
index 80eb2f7..1803009 100644 (file)
@@ -66,7 +66,7 @@ abstract class MWLBFactory {
         * @param array $lbConf Config for LBFactory::__construct()
         * @param ServiceOptions $options
         * @param ConfiguredReadOnlyMode $readOnlyMode
-        * @param BagOStuff $srvCace
+        * @param BagOStuff $srvCache
         * @param BagOStuff $mainStash
         * @param WANObjectCache $wanCache
         * @return array
@@ -76,7 +76,7 @@ abstract class MWLBFactory {
                array $lbConf,
                ServiceOptions $options,
                ConfiguredReadOnlyMode $readOnlyMode,
-               BagOStuff $srvCace,
+               BagOStuff $srvCache,
                BagOStuff $mainStash,
                WANObjectCache $wanCache
        ) {
@@ -159,7 +159,7 @@ abstract class MWLBFactory {
                        $options->get( 'DBprefix' )
                );
 
-               $lbConf = self::injectObjectCaches( $lbConf, $srvCace, $mainStash, $wanCache );
+               $lbConf = self::injectObjectCaches( $lbConf, $srvCache, $mainStash, $wanCache );
 
                return $lbConf;
        }
@@ -222,6 +222,11 @@ abstract class MWLBFactory {
        private static function injectObjectCaches(
                array $lbConf, BagOStuff $sCache, BagOStuff $mStash, WANObjectCache $wCache
        ) {
+               // Fallback if APC style caching is not an option
+               if ( $sCache instanceof EmptyBagOStuff ) {
+                       $sCache = new HashBagOStuff( [ 'maxKeys' => 100 ] );
+               }
+
                // Use APC/memcached style caching, but avoids loops with CACHE_DB (T141804)
                if ( $sCache->getQoS( $sCache::ATTR_EMULATION ) > $sCache::QOS_EMULATION_SQL ) {
                        $lbConf['srvCache'] = $sCache;
index 1d3b402..b8697e5 100644 (file)
@@ -22,7 +22,6 @@
  */
 
 use MediaWiki\MediaWikiServices;
-use MediaWiki\Permissions\PermissionManager;
 use MediaWiki\Revision\RevisionRecord;
 use MediaWiki\Revision\SlotRecord;
 use MediaWiki\Storage\NameTableAccessException;
@@ -542,8 +541,8 @@ class DifferenceEngine extends ContextSource {
 
                        $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
 
-                       if ( $samePage && $this->mNewPage && $permissionManager->userCan(
-                               'edit', $user, $this->mNewPage, PermissionManager::RIGOR_QUICK
+                       if ( $samePage && $this->mNewPage && $permissionManager->quickUserCan(
+                               'edit', $user, $this->mNewPage
                        ) ) {
                                if ( $this->mNewRev->isCurrent() && $permissionManager->userCan(
                                        'rollback', $user, $this->mNewPage
@@ -556,8 +555,8 @@ class DifferenceEngine extends ContextSource {
                                        }
                                }
 
-                               if ( !$this->mOldRev->isDeleted( RevisionRecord::DELETED_TEXT ) &&
-                                       !$this->mNewRev->isDeleted( RevisionRecord::DELETED_TEXT )
+                               if ( $this->userCanEdit( $this->mOldRev ) &&
+                                       $this->userCanEdit( $this->mNewRev )
                                ) {
                                        $undoLink = Html::element( 'a', [
                                                        'href' => $this->mNewPage->getLocalURL( [
@@ -766,12 +765,14 @@ class DifferenceEngine extends ContextSource {
        protected function getMarkPatrolledLinkInfo() {
                $user = $this->getUser();
                $config = $this->getConfig();
+               $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
 
                // Prepare a change patrol link, if applicable
                if (
                        // Is patrolling enabled and the user allowed to?
                        $config->get( 'UseRCPatrol' ) &&
-                       $this->mNewPage && $this->mNewPage->quickUserCan( 'patrol', $user ) &&
+                       $this->mNewPage &&
+                       $permissionManager->quickUserCan( 'patrol', $user, $this->mNewPage ) &&
                        // Only do this if the revision isn't more than 6 hours older
                        // than the Max RC age (6h because the RC might not be cleaned out regularly)
                        RecentChange::isInRCLifespan( $this->mNewRev->getTimestamp(), 21600 )
@@ -804,8 +805,7 @@ class DifferenceEngine extends ContextSource {
                        // Build the link
                        if ( $rcid ) {
                                $this->getOutput()->preventClickjacking();
-                               if ( MediaWikiServices::getInstance()->getPermissionManager()
-                                               ->userHasRight( $user, 'writeapi' ) ) {
+                               if ( $permissionManager->userHasRight( $user, 'writeapi' ) ) {
                                        $this->getOutput()->addModules( 'mediawiki.page.patrol.ajax' );
                                }
 
@@ -900,7 +900,11 @@ class DifferenceEngine extends ContextSource {
                                        ) {
                                                $out->addParserOutput( $parserOutput, [
                                                        'enableSectionEditLinks' => $this->mNewRev->isCurrent()
-                                                               && $this->mNewRev->getTitle()->quickUserCan( 'edit', $this->getUser() ),
+                                                               && MediaWikiServices::getInstance()->getPermissionManager()->quickUserCan(
+                                                                       'edit',
+                                                                       $this->getUser(),
+                                                                       $this->mNewRev->getTitle()
+                                                               )
                                                ] );
                                        }
                                }
@@ -1500,6 +1504,24 @@ class DifferenceEngine extends ContextSource {
                return wfMessage( $msg )->numParams( $numEdits, $numUsers )->parse();
        }
 
+       /**
+        * @param Revision $rev
+        * @return bool whether the user can see and edit the revision.
+        */
+       private function userCanEdit( Revision $rev ) {
+               $user = $this->getUser();
+
+               if ( !$rev->getContentHandler()->supportsDirectEditing() ) {
+                       return false;
+               }
+
+               if ( !$rev->userCan( RevisionRecord::DELETED_TEXT, $user ) ) {
+                       return false;
+               }
+
+               return true;
+       }
+
        /**
         * Get a header for a specified revision.
         *
@@ -1533,13 +1555,14 @@ class DifferenceEngine extends ContextSource {
                $header = Linker::linkKnown( $title, $header, [],
                        [ 'oldid' => $rev->getId() ] );
 
-               if ( $rev->userCan( RevisionRecord::DELETED_TEXT, $user ) ) {
+               if ( $this->userCanEdit( $rev ) ) {
                        $editQuery = [ 'action' => 'edit' ];
                        if ( !$rev->isCurrent() ) {
                                $editQuery['oldid'] = $rev->getId();
                        }
 
-                       $key = $title->quickUserCan( 'edit', $user ) ? 'editold' : 'viewsourceold';
+                       $key = MediaWikiServices::getInstance()->getPermissionManager()
+                               ->quickUserCan( 'edit', $user, $title ) ? 'editold' : 'viewsourceold';
                        $msg = $this->msg( $key )->escaped();
                        $editLink = $this->msg( 'parentheses' )->rawParams(
                                Linker::linkKnown( $title, $msg, [], $editQuery ) )->escaped();
index 969e0ba..c58502b 100644 (file)
@@ -44,7 +44,7 @@ abstract class SlotDiffRenderer {
         * must have the same content model that was used to obtain this diff renderer.
         * @param Content|null $oldContent
         * @param Content|null $newContent
-        * @return string
+        * @return string HTML, one or more <tr> tags.
         */
        abstract public function getDiff( Content $oldContent = null, Content $newContent = null );
 
index 510465b..935172a 100644 (file)
@@ -112,7 +112,7 @@ class TextSlotDiffRenderer extends SlotDiffRenderer {
         * Diff the text representations of two content objects (or just two pieces of text in general).
         * @param string $oldText
         * @param string $newText
-        * @return string
+        * @return string HTML, one or more <tr> tags.
         */
        public function getTextDiff( $oldText, $newText ) {
                Assert::parameterType( 'string', $oldText, '$oldText' );
diff --git a/includes/diff/UnsupportedSlotDiffRenderer.php b/includes/diff/UnsupportedSlotDiffRenderer.php
new file mode 100644 (file)
index 0000000..db1b868
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+/**
+ * Renders a slot diff by doing a text diff on the native representation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup DifferenceEngine
+ */
+
+/**
+ * Produces a warning message about not being able to render a slot diff.
+ *
+ * @since 1.34
+ *
+ * @ingroup DifferenceEngine
+ */
+class UnsupportedSlotDiffRenderer extends SlotDiffRenderer {
+
+       /**
+        * @var MessageLocalizer
+        */
+       private $localizer;
+
+       /**
+        * UnsupportedSlotDiffRenderer constructor.
+        *
+        * @param MessageLocalizer $localizer
+        */
+       public function __construct( MessageLocalizer $localizer ) {
+               $this->localizer = $localizer;
+       }
+
+       /** @inheritDoc */
+       public function getDiff( Content $oldContent = null, Content $newContent = null ) {
+               $this->normalizeContents( $oldContent, $newContent );
+
+               $oldModel = $oldContent->getModel();
+               $newModel = $newContent->getModel();
+
+               if ( $oldModel !== $newModel ) {
+                       $msg = $this->localizer->msg( 'unsupported-content-diff2', $oldModel, $newModel );
+               } else {
+                       $msg = $this->localizer->msg( 'unsupported-content-diff', $oldModel );
+               }
+
+               return Html::rawElement(
+                       'tr',
+                       [],
+                       Html::rawElement(
+                               'td',
+                               [ 'colspan' => 4, 'class' => 'error' ],
+                               $msg->parse()
+                       )
+               );
+       }
+
+}
index 8b31f05..9e04d09 100644 (file)
@@ -150,6 +150,7 @@ class FileBackendGroup {
 
                        $class = $config['class'];
                        if ( $class === FileBackendMultiWrite::class ) {
+                               // @todo How can we test this? What's the intended use-case?
                                foreach ( $config['backends'] as $index => $beConfig ) {
                                        if ( isset( $beConfig['template'] ) ) {
                                                // Config is just a modified version of a registered backend's.
index 60f1607..42e78ff 100644 (file)
@@ -899,20 +899,15 @@ class FileRepo {
                        }
 
                        // Resolve source to a storage path if virtual
-                       $srcPath = $this->resolveToStoragePath( $srcPath );
+                       $srcPath = $this->resolveToStoragePathIfVirtual( $srcPath );
 
-                       // Get the appropriate file operation
-                       if ( FileBackend::isStoragePath( $srcPath ) ) {
-                               $opName = 'copy';
-                       } else {
-                               $opName = 'store';
-                       }
+                       // Copy the source file to the destination
                        $operations[] = [
-                               'op' => $opName,
-                               'src' => $srcPath,
+                               'op' => FileBackend::isStoragePath( $srcPath ) ? 'copy' : 'store',
+                               'src' => $srcPath, // storage path (copy) or local file path (store)
                                'dst' => $dstPath,
-                               'overwrite' => $flags & self::OVERWRITE,
-                               'overwriteSame' => $flags & self::OVERWRITE_SAME,
+                               'overwrite' => ( $flags & self::OVERWRITE ) ? true : false,
+                               'overwriteSame' => ( $flags & self::OVERWRITE_SAME ) ? true : false,
                        ];
                }
 
@@ -949,7 +944,7 @@ class FileRepo {
                                $path = $this->getZonePath( $zone ) . "/$rel";
                        } else {
                                // Resolve source to a storage path if virtual
-                               $path = $this->resolveToStoragePath( $path );
+                               $path = $this->resolveToStoragePathIfVirtual( $path );
                        }
                        $operations[] = [ 'op' => 'delete', 'src' => $path ];
                }
@@ -1002,7 +997,7 @@ class FileRepo {
        public function quickCleanDir( $dir ) {
                $status = $this->newGood();
                $status->merge( $this->backend->clean(
-                       [ 'dir' => $this->resolveToStoragePath( $dir ) ] ) );
+                       [ 'dir' => $this->resolveToStoragePathIfVirtual( $dir ) ] ) );
 
                return $status;
        }
@@ -1027,10 +1022,10 @@ class FileRepo {
                        if ( $src instanceof FSFile ) {
                                $op = 'store';
                        } else {
-                               $src = $this->resolveToStoragePath( $src );
+                               $src = $this->resolveToStoragePathIfVirtual( $src );
                                $op = FileBackend::isStoragePath( $src ) ? 'copy' : 'store';
                        }
-                       $dst = $this->resolveToStoragePath( $dst );
+                       $dst = $this->resolveToStoragePathIfVirtual( $dst );
 
                        if ( !isset( $triple[2] ) ) {
                                $headers = [];
@@ -1070,7 +1065,7 @@ class FileRepo {
                foreach ( $paths as $path ) {
                        $operations[] = [
                                'op' => 'delete',
-                               'src' => $this->resolveToStoragePath( $path ),
+                               'src' => $this->resolveToStoragePathIfVirtual( $path ),
                                'ignoreMissingSource' => true
                        ];
                }
@@ -1139,7 +1134,7 @@ class FileRepo {
                $sources = [];
                foreach ( $srcPaths as $srcPath ) {
                        // Resolve source to a storage path if virtual
-                       $source = $this->resolveToStoragePath( $srcPath );
+                       $source = $this->resolveToStoragePathIfVirtual( $srcPath );
                        $sources[] = $source; // chunk to merge
                }
 
@@ -1226,7 +1221,7 @@ class FileRepo {
 
                        $options = $ntuple[3] ?? [];
                        // Resolve source to a storage path if virtual
-                       $srcPath = $this->resolveToStoragePath( $srcPath );
+                       $srcPath = $this->resolveToStoragePathIfVirtual( $srcPath );
                        if ( !$this->validateFilename( $dstRel ) ) {
                                throw new MWException( 'Validation error in $dstRel' );
                        }
@@ -1266,27 +1261,17 @@ class FileRepo {
 
                        // Copy (or move) the source file to the destination
                        if ( FileBackend::isStoragePath( $srcPath ) ) {
-                               if ( $flags & self::DELETE_SOURCE ) {
-                                       $operations[] = [
-                                               'op' => 'move',
-                                               'src' => $srcPath,
-                                               'dst' => $dstPath,
-                                               'overwrite' => true, // replace current
-                                               'headers' => $headers
-                                       ];
-                               } else {
-                                       $operations[] = [
-                                               'op' => 'copy',
-                                               'src' => $srcPath,
-                                               'dst' => $dstPath,
-                                               'overwrite' => true, // replace current
-                                               'headers' => $headers
-                                       ];
-                               }
-                       } else { // FS source path
+                               $operations[] = [
+                                       'op' => ( $flags & self::DELETE_SOURCE ) ? 'move' : 'copy',
+                                       'src' => $srcPath,
+                                       'dst' => $dstPath,
+                                       'overwrite' => true, // replace current
+                                       'headers' => $headers
+                               ];
+                       } else {
                                $operations[] = [
                                        'op' => 'store',
-                                       'src' => $src, // prefer FSFile objects
+                                       'src' => $src, // FSFile (preferred) or local file path
                                        'dst' => $dstPath,
                                        'overwrite' => true, // replace current
                                        'headers' => $headers
@@ -1327,7 +1312,7 @@ class FileRepo {
         * @return Status
         */
        protected function initDirectory( $dir ) {
-               $path = $this->resolveToStoragePath( $dir );
+               $path = $this->resolveToStoragePathIfVirtual( $dir );
                list( , $container, ) = FileBackend::splitStoragePath( $path );
 
                $params = [ 'dir' => $path ];
@@ -1357,7 +1342,7 @@ class FileRepo {
 
                $status = $this->newGood();
                $status->merge( $this->backend->clean(
-                       [ 'dir' => $this->resolveToStoragePath( $dir ) ] ) );
+                       [ 'dir' => $this->resolveToStoragePathIfVirtual( $dir ) ] ) );
 
                return $status;
        }
@@ -1381,12 +1366,12 @@ class FileRepo {
         * @return array Map of files and existence flags, or false
         */
        public function fileExistsBatch( array $files ) {
-               $paths = array_map( [ $this, 'resolveToStoragePath' ], $files );
+               $paths = array_map( [ $this, 'resolveToStoragePathIfVirtual' ], $files );
                $this->backend->preloadFileStat( [ 'srcs' => $paths ] );
 
                $result = [];
                foreach ( $files as $key => $file ) {
-                       $path = $this->resolveToStoragePath( $file );
+                       $path = $this->resolveToStoragePathIfVirtual( $file );
                        $result[$key] = $this->backend->fileExists( [ 'src' => $path ] );
                }
 
@@ -1517,7 +1502,7 @@ class FileRepo {
         * @return string
         * @throws MWException
         */
-       protected function resolveToStoragePath( $path ) {
+       protected function resolveToStoragePathIfVirtual( $path ) {
                if ( self::isVirtualUrl( $path ) ) {
                        return $this->resolveVirtualUrl( $path );
                }
@@ -1533,7 +1518,7 @@ class FileRepo {
         * @return TempFSFile|null Returns null on failure
         */
        public function getLocalCopy( $virtualUrl ) {
-               $path = $this->resolveToStoragePath( $virtualUrl );
+               $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
 
                return $this->backend->getLocalCopy( [ 'src' => $path ] );
        }
@@ -1547,7 +1532,7 @@ class FileRepo {
         * @return FSFile|null Returns null on failure.
         */
        public function getLocalReference( $virtualUrl ) {
-               $path = $this->resolveToStoragePath( $virtualUrl );
+               $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
 
                return $this->backend->getLocalReference( [ 'src' => $path ] );
        }
@@ -1578,7 +1563,7 @@ class FileRepo {
         * @return string|bool False on failure
         */
        public function getFileTimestamp( $virtualUrl ) {
-               $path = $this->resolveToStoragePath( $virtualUrl );
+               $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
 
                return $this->backend->getFileTimestamp( [ 'src' => $path ] );
        }
@@ -1590,7 +1575,7 @@ class FileRepo {
         * @return int|bool False on failure
         */
        public function getFileSize( $virtualUrl ) {
-               $path = $this->resolveToStoragePath( $virtualUrl );
+               $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
 
                return $this->backend->getFileSize( [ 'src' => $path ] );
        }
@@ -1602,7 +1587,7 @@ class FileRepo {
         * @return string|bool
         */
        public function getFileSha1( $virtualUrl ) {
-               $path = $this->resolveToStoragePath( $virtualUrl );
+               $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
 
                return $this->backend->getFileSha1Base36( [ 'src' => $path ] );
        }
@@ -1617,7 +1602,7 @@ class FileRepo {
         * @since 1.27
         */
        public function streamFileWithStatus( $virtualUrl, $headers = [], $optHeaders = [] ) {
-               $path = $this->resolveToStoragePath( $virtualUrl );
+               $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
                $params = [ 'src' => $path, 'headers' => $headers, 'options' => $optHeaders ];
 
                // T172851: HHVM does not flush the output properly, causing OOM
index 54fc251..6143c31 100644 (file)
@@ -1923,10 +1923,9 @@ class LocalFile extends File {
 
                wfDebugLog( 'imagemove', "Finished moving {$this->name}" );
 
-               // Purge the source and target files...
+               // Purge the source and target files outside the transaction...
                $oldTitleFile = $localRepo->newFile( $this->title );
                $newTitleFile = $localRepo->newFile( $target );
-               // To avoid slow purges in the transaction, move them outside...
                DeferredUpdates::addUpdate(
                        new AutoCommitUpdate(
                                $this->getRepo()->getMasterDB(),
@@ -1934,6 +1933,7 @@ class LocalFile extends File {
                                function () use ( $oldTitleFile, $newTitleFile, $archiveNames ) {
                                        $oldTitleFile->purgeEverything();
                                        foreach ( $archiveNames as $archiveName ) {
+                                               /** @var OldLocalFile $oldTitleFile */
                                                $oldTitleFile->purgeOldThumbnails( $archiveName );
                                        }
                                        $newTitleFile->purgeEverything();
index 251fa88..f8ab6a3 100644 (file)
@@ -44,9 +44,9 @@ class HashRing implements Serializable {
        /** @var int[] Map of (location => UNIX timestamp) */
        protected $ejectExpiryByLocation;
 
-       /** @var array[] Non-empty list of (float, node name, location name) */
+       /** @var array[] Non-empty position-ordered list of (position, location name) */
        protected $baseRing;
-       /** @var array[] Non-empty list of (float, node name, location name) */
+       /** @var array[] Non-empty position-ordered list of (position, location name) */
        protected $liveRing;
 
        /** @var float Number of positions on the ring */
@@ -96,7 +96,7 @@ class HashRing implements Serializable {
                $this->algo = $algo;
                $this->weightByLocation = $weightByLocation;
                $this->ejectExpiryByLocation = $ejections;
-               $this->baseRing = $this->buildLocationRing( $this->weightByLocation, $this->algo );
+               $this->baseRing = $this->buildLocationRing( $this->weightByLocation );
        }
 
        /**
@@ -111,12 +111,13 @@ class HashRing implements Serializable {
        }
 
        /**
-        * Get the location of an item on the ring, as well as the next locations
+        * Get the location of an item on the ring followed by the next ring locations
         *
         * @param string $item
         * @param int $limit Maximum number of locations to return
         * @param int $from One of the RING_* class constants
         * @return string[] List of locations
+        * @throws InvalidArgumentException
         * @throws UnexpectedValueException
         */
        public function getLocations( $item, $limit, $from = self::RING_ALL ) {
@@ -128,22 +129,25 @@ class HashRing implements Serializable {
                        throw new InvalidArgumentException( "Invalid ring source specified." );
                }
 
-               // Locate this item's position on the hash ring
-               $position = $this->getItemPosition( $item );
-               $itemNodeIndex = $this->findNodeIndexForPosition( $position, $ring );
+               // Locate the node index for this item's position on the hash ring
+               $itemIndex = $this->findNodeIndexForPosition( $this->getItemPosition( $item ), $ring );
 
                $locations = [];
-               $currentIndex = $itemNodeIndex;
+               $currentIndex = null;
                while ( count( $locations ) < $limit ) {
+                       if ( $currentIndex === null ) {
+                               $currentIndex = $itemIndex;
+                       } else {
+                               $currentIndex = $this->getNextClockwiseNodeIndex( $currentIndex, $ring );
+                               if ( $currentIndex === $itemIndex ) {
+                                       break; // all nodes visited
+                               }
+                       }
                        $nodeLocation = $ring[$currentIndex][self::KEY_LOCATION];
                        if ( !in_array( $nodeLocation, $locations, true ) ) {
                                // Ignore other nodes for the same locations already added
                                $locations[] = $nodeLocation;
                        }
-                       $currentIndex = $this->getNextClockwiseNodeIndex( $currentIndex, $ring );
-                       if ( $currentIndex === $itemNodeIndex ) {
-                               break; // all nodes visited
-                       }
                }
 
                return $locations;
@@ -159,18 +163,22 @@ class HashRing implements Serializable {
                if ( $count === 0 ) {
                        return null;
                }
+
+               $index = null;
                $lowPos = 0;
                $highPos = $count;
                while ( true ) {
-                       $midPos = intval( ( $lowPos + $highPos ) / 2 );
+                       $midPos = (int)( ( $lowPos + $highPos ) / 2 );
                        if ( $midPos === $count ) {
-                               return 0;
+                               $index = 0;
+                               break;
                        }
-                       $midVal = $ring[$midPos][self::KEY_POS];
-                       $midMinusOneVal = $midPos === 0 ? 0 : $ring[$midPos - 1][self::KEY_POS];
 
+                       $midVal = $ring[$midPos][self::KEY_POS];
+                       $midMinusOneVal = ( $midPos === 0 ) ? 0 : $ring[$midPos - 1][self::KEY_POS];
                        if ( $position <= $midVal && $position > $midMinusOneVal ) {
-                               return $midPos;
+                               $index = $midPos;
+                               break;
                        }
 
                        if ( $midVal < $position ) {
@@ -180,9 +188,12 @@ class HashRing implements Serializable {
                        }
 
                        if ( $lowPos > $highPos ) {
-                               return 0;
+                               $index = 0;
+                               break;
                        }
                }
+
+               return $index;
        }
 
        /**
@@ -260,10 +271,9 @@ class HashRing implements Serializable {
 
        /**
         * @param int[] $weightByLocation
-        * @param string $algo Hashing algorithm
         * @return array[]
         */
-       private function buildLocationRing( array $weightByLocation, $algo ) {
+       private function buildLocationRing( array $weightByLocation ) {
                $locationCount = count( $weightByLocation );
                $totalWeight = array_sum( $weightByLocation );
 
@@ -323,7 +333,14 @@ class HashRing implements Serializable {
                        throw new UnexpectedValueException( __METHOD__ . ": {$this->algo} is < 32 bits." );
                }
 
-               return (float)sprintf( '%u', unpack( 'V', $octets )[1] );
+               $pos = unpack( 'V', $octets )[1];
+               if ( $pos < 0 ) {
+                       // Most-significant-bit is set, causing unpack() to return a negative integer due
+                       // to the fact that it returns a signed int. Cast it to an unsigned integer string.
+                       $pos = sprintf( '%u', $pos );
+               }
+
+               return (float)$pos;
        }
 
        /**
index c05dc28..c1a796f 100644 (file)
@@ -593,7 +593,7 @@ class FSFileBackend extends FileBackendStore {
                } elseif ( !$hadError ) {
                        return false; // file does not exist
                } else {
-                       return null; // failure
+                       return self::UNKNOWN; // failure
                }
        }
 
@@ -610,7 +610,7 @@ class FSFileBackend extends FileBackendStore {
                $exists = is_dir( $dir );
                $hadError = $this->untrapWarnings();
 
-               return $hadError ? null : $exists;
+               return $hadError ? self::UNKNOWN : $exists;
        }
 
        /**
@@ -632,7 +632,7 @@ class FSFileBackend extends FileBackendStore {
                } elseif ( !is_readable( $dir ) ) {
                        $this->logger->warning( __METHOD__ . "() given directory is unreadable: '$dir'\n" );
 
-                       return null; // bad permissions?
+                       return self::UNKNOWN; // bad permissions?
                }
 
                return new FSFileBackendDirList( $dir, $params );
@@ -657,7 +657,7 @@ class FSFileBackend extends FileBackendStore {
                } elseif ( !is_readable( $dir ) ) {
                        $this->logger->warning( __METHOD__ . "() given directory is unreadable: '$dir'\n" );
 
-                       return null; // bad permissions?
+                       return self::UNKNOWN; // bad permissions?
                }
 
                return new FSFileBackendFileList( $dir, $params );
index 4cacb7a..905e925 100644 (file)
@@ -131,6 +131,9 @@ abstract class FileBackend implements LoggerAwareInterface {
        const ATTR_METADATA = 2; // files can be stored with metadata key/values
        const ATTR_UNICODE_PATHS = 4; // files can have Unicode paths (not just ASCII)
 
+       /** @var null Idiom for "could not determine due to I/O errors" */
+       const UNKNOWN = null;
+
        /**
         * Create a new backend instance from configuration.
         * This should only be called from within FileBackendGroup.
@@ -209,7 +212,8 @@ abstract class FileBackend implements LoggerAwareInterface {
        }
 
        /**
-        * Get the unique backend name.
+        * Get the unique backend name
+        *
         * We may have multiple different backends of the same type.
         * For example, we can have two Swift backends using different proxies.
         *
@@ -231,6 +235,7 @@ abstract class FileBackend implements LoggerAwareInterface {
 
        /**
         * Alias to getDomainId()
+        *
         * @return string
         * @since 1.20
         * @deprecated Since 1.34 Use getDomainId()
@@ -1164,21 +1169,34 @@ abstract class FileBackend implements LoggerAwareInterface {
        abstract public function getFileHttpUrl( array $params );
 
        /**
-        * Check if a directory exists at a given storage path.
-        * Backends using key/value stores will check if the path is a
-        * virtual directory, meaning there are files under the given directory.
+        * Check if a directory exists at a given storage path
+        *
+        * For backends using key/value stores, a directory is said to exist whenever
+        * there exist any files with paths using the given directory path as a prefix
+        * followed by a forward slash. For example, if there is a file called
+        * "mwstore://backend/container/dir/path.svg" then directories are said to exist
+        * at "mwstore://backend/container" and "mwstore://backend/container/dir". These
+        * can be thought of as "virtual" directories.
+        *
+        * Backends that directly use a filesystem layer might enumerate empty directories.
+        * The clean() method should always be used when files are deleted or moved if this
+        * is a concern. This is a trade-off to avoid write amplication/contention on file
+        * changes or read amplification when calling this method.
         *
         * Storage backends with eventual consistency might return stale data.
         *
+        * @see FileBackend::clean()
+        *
         * @param array $params Parameters include:
         *   - dir : storage directory
-        * @return bool|null Returns null on failure
+        * @return bool|null Whether a directory exists or null on failure
         * @since 1.20
         */
        abstract public function directoryExists( array $params );
 
        /**
-        * Get an iterator to list *all* directories under a storage directory.
+        * Get an iterator to list *all* directories under a storage directory
+        *
         * If the directory is of the form "mwstore://backend/container",
         * then all directories in the container will be listed.
         * If the directory is of form "mwstore://backend/container/dir",
@@ -1189,10 +1207,12 @@ abstract class FileBackend implements LoggerAwareInterface {
         *
         * Failures during iteration can result in FileBackendError exceptions (since 1.22).
         *
+        * @see FileBackend::directoryExists()
+        *
         * @param array $params Parameters include:
         *   - dir     : storage directory
         *   - topOnly : only return direct child dirs of the directory
-        * @return Traversable|array|null Returns null on failure
+        * @return Traversable|array|null Directory list enumerator null on failure
         * @since 1.20
         */
        abstract public function getDirectoryList( array $params );
@@ -1205,9 +1225,11 @@ abstract class FileBackend implements LoggerAwareInterface {
         *
         * Failures during iteration can result in FileBackendError exceptions (since 1.22).
         *
+        * @see FileBackend::directoryExists()
+        *
         * @param array $params Parameters include:
         *   - dir : storage directory
-        * @return Traversable|array|null Returns null on failure
+        * @return Traversable|array|null Directory list enumerator or null on failure
         * @since 1.20
         */
        final public function getTopDirectoryList( array $params ) {
@@ -1215,12 +1237,12 @@ abstract class FileBackend implements LoggerAwareInterface {
        }
 
        /**
-        * Get an iterator to list *all* stored files under a storage directory.
-        * If the directory is of the form "mwstore://backend/container",
-        * then all files in the container will be listed.
-        * If the directory is of form "mwstore://backend/container/dir",
-        * then all files under that directory will be listed.
-        * Results will be storage paths relative to the given directory.
+        * Get an iterator to list *all* stored files under a storage directory
+        *
+        * If the directory is of the form "mwstore://backend/container", then all
+        * files in the container will be listed. If the directory is of form
+        * "mwstore://backend/container/dir", then all files under that directory will
+        * be listed. Results will be storage paths relative to the given directory.
         *
         * Storage backends with eventual consistency might return stale data.
         *
@@ -1230,7 +1252,7 @@ abstract class FileBackend implements LoggerAwareInterface {
         *   - dir        : storage directory
         *   - topOnly    : only return direct child files of the directory (since 1.20)
         *   - adviseStat : set to true if stat requests will be made on the files (since 1.22)
-        * @return Traversable|array|null Returns null on failure
+        * @return Traversable|array|null File list enumerator or null on failure
         */
        abstract public function getFileList( array $params );
 
@@ -1245,7 +1267,7 @@ abstract class FileBackend implements LoggerAwareInterface {
         * @param array $params Parameters include:
         *   - dir        : storage directory
         *   - adviseStat : set to true if stat requests will be made on the files (since 1.22)
-        * @return Traversable|array|null Returns null on failure
+        * @return Traversable|array|null File list enumerator or null on failure
         * @since 1.20
         */
        final public function getTopFileList( array $params ) {
@@ -1283,7 +1305,7 @@ abstract class FileBackend implements LoggerAwareInterface {
         * @param array $params Parameters include:
         *   - srcs        : list of source storage paths
         *   - latest      : use the latest available data
-        * @return bool All requests proceeded without I/O errors (since 1.24)
+        * @return bool Whether all requests proceeded without I/O errors (since 1.24)
         * @since 1.23
         */
        abstract public function preloadFileStat( array $params );
@@ -1526,7 +1548,7 @@ abstract class FileBackend implements LoggerAwareInterface {
         *
         * @param string $type One of (attachment, inline)
         * @param string $filename Suggested file name (should not contain slashes)
-        * @throws FileBackendError
+        * @throws InvalidArgumentException
         * @return string
         * @since 1.20
         */
index aa95ee4..9b901dd 100644 (file)
@@ -604,7 +604,7 @@ abstract class FileBackendStore extends FileBackend {
                $ps = $this->scopedProfileSection( __METHOD__ . "-{$this->name}" );
                $stat = $this->getFileStat( $params );
 
-               return ( $stat === null ) ? null : (bool)$stat; // null => failure
+               return ( $stat === self::UNKNOWN ) ? self::UNKNOWN : (bool)$stat;
        }
 
        final public function getFileTimestamp( array $params ) {
@@ -637,7 +637,7 @@ abstract class FileBackendStore extends FileBackend {
                        // cache entries from mass object listings that do not include the SHA-1. In that
                        // case, loading the persistent stat cache will likely yield the SHA-1.
                        if (
-                               $stat === null ||
+                               $stat === self::UNKNOWN ||
                                ( $requireSHA1 && is_array( $stat ) && !isset( $stat['sha1'] ) )
                        ) {
                                $this->primeFileCache( [ $path ] ); // check persistent cache
@@ -936,7 +936,7 @@ abstract class FileBackendStore extends FileBackend {
                                        $res = true;
                                        break; // found one!
                                } elseif ( $exists === null ) { // error?
-                                       $res = null; // if we don't find anything, it is indeterminate
+                                       $res = self::UNKNOWN; // if we don't find anything, it is indeterminate
                                }
                        }
 
@@ -957,7 +957,7 @@ abstract class FileBackendStore extends FileBackend {
        final public function getDirectoryList( array $params ) {
                list( $fullCont, $dir, $shard ) = $this->resolveStoragePath( $params['dir'] );
                if ( $dir === null ) { // invalid storage path
-                       return null;
+                       return self::UNKNOWN;
                }
                if ( $shard !== null ) {
                        // File listing is confined to a single container/shard
@@ -987,7 +987,7 @@ abstract class FileBackendStore extends FileBackend {
        final public function getFileList( array $params ) {
                list( $fullCont, $dir, $shard ) = $this->resolveStoragePath( $params['dir'] );
                if ( $dir === null ) { // invalid storage path
-                       return null;
+                       return self::UNKNOWN;
                }
                if ( $shard !== null ) {
                        // File listing is confined to a single container/shard
index f0cbf3b..88b281e 100644 (file)
@@ -148,7 +148,7 @@ class MemoryFileBackend extends FileBackendStore {
        protected function doGetFileStat( array $params ) {
                $src = $this->resolveHashKey( $params['src'] );
                if ( $src === null ) {
-                       return null;
+                       return false; // invalid path
                }
 
                if ( isset( $this->files[$src] ) ) {
index afd1688..e576c64 100644 (file)
@@ -593,7 +593,7 @@ class SwiftFileBackend extends FileBackendStore {
                $stat = $this->getContainerStat( $fullCont );
                if ( is_array( $stat ) ) {
                        return $status; // already there
-               } elseif ( $stat === null ) {
+               } elseif ( $stat === self::UNKNOWN ) {
                        $status->fatal( 'backend-fail-internal', $this->name );
                        $this->logger->error( __METHOD__ . ': cannot get container stat' );
 
@@ -832,7 +832,7 @@ class SwiftFileBackend extends FileBackendStore {
                        return ( count( $status->value ) ) > 0;
                }
 
-               return null; // error
+               return self::UNKNOWN; // error
        }
 
        /**
@@ -1401,7 +1401,7 @@ class SwiftFileBackend extends FileBackendStore {
                if ( !$this->containerStatCache->hasField( $container, 'stat' ) ) {
                        $auth = $this->getAuthentication();
                        if ( !$auth ) {
-                               return null;
+                               return self::UNKNOWN;
                        }
 
                        list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $this->http->run( [
@@ -1427,7 +1427,7 @@ class SwiftFileBackend extends FileBackendStore {
                                $this->onError( null, __METHOD__,
                                        [ 'cont' => $container ], $rerr, $rcode, $rdesc );
 
-                               return null;
+                               return self::UNKNOWN;
                        }
                }
 
@@ -1599,7 +1599,7 @@ class SwiftFileBackend extends FileBackendStore {
                                $stats[$path] = false;
                                continue; // invalid storage path
                        } elseif ( !$auth ) {
-                               $stats[$path] = null;
+                               $stats[$path] = self::UNKNOWN;
                                continue;
                        }
 
@@ -1609,7 +1609,7 @@ class SwiftFileBackend extends FileBackendStore {
                                $stats[$path] = false;
                                continue; // ok, nothing to do
                        } elseif ( !is_array( $cstat ) ) {
-                               $stats[$path] = null;
+                               $stats[$path] = self::UNKNOWN;
                                continue;
                        }
 
@@ -1642,7 +1642,7 @@ class SwiftFileBackend extends FileBackendStore {
                        } elseif ( $rcode === 404 ) {
                                $stat = false;
                        } else {
-                               $stat = null;
+                               $stat = self::UNKNOWN;
                                $this->onError( null, __METHOD__, $params, $rerr, $rcode, $rdesc );
                        }
                        $stats[$path] = $stat;
index dc007a0..e512423 100644 (file)
@@ -26,6 +26,7 @@
  * @ingroup FileJournal
  */
 
+use Wikimedia\ObjectFactory;
 use Wikimedia\Timestamp\ConvertibleTimestamp;
 
 /**
@@ -43,12 +44,12 @@ abstract class FileJournal {
        protected $ttlDays;
 
        /**
-        * Construct a new instance from configuration.
+        * Construct a new instance from configuration. Do not call this directly, use factory().
         *
         * @param array $config Includes:
         *     'ttlDays' : days to keep log entries around (false means "forever")
         */
-       protected function __construct( array $config ) {
+       public function __construct( array $config ) {
                $this->ttlDays = $config['ttlDays'] ?? false;
        }
 
@@ -61,11 +62,10 @@ abstract class FileJournal {
         * @return FileJournal
         */
        final public static function factory( array $config, $backend ) {
-               $class = $config['class'];
-               $jrn = new $class( $config );
-               if ( !$jrn instanceof self ) {
-                       throw new InvalidArgumentException( "$class is not an instance of " . __CLASS__ );
-               }
+               $jrn = ObjectFactory::getObjectFromSpec(
+                       $config,
+                       [ 'specIsArg' => true, 'assertClass' => __CLASS__ ]
+               );
                $jrn->backend = $backend;
 
                return $jrn;
index 8afaa38..0383def 100644 (file)
@@ -182,11 +182,6 @@ class MSCompoundFileReader {
                return $this->unpack( $block, 0, $struct );
        }
 
-       private function unpackSector( $sectorNumber, $struct ) {
-               $offset = $this->sectorOffset( $sectorNumber );
-               return $this->unpackOffset( $offset, array_sum( $struct ) );
-       }
-
        private function unpack( $block, $offset, $struct ) {
                $data = [];
                foreach ( $struct as $key => $length ) {
index 66be436..6791503 100644 (file)
@@ -36,6 +36,7 @@ class LogEventsList extends ContextSource {
 
        /**
         * @var array
+        * @deprecated since 1.34, no longer used.
         */
        protected $mDefaultQuery;
 
@@ -220,21 +221,6 @@ class LogEventsList extends ContextSource {
                ];
        }
 
-       private function getDefaultQuery() {
-               if ( !isset( $this->mDefaultQuery ) ) {
-                       $this->mDefaultQuery = $this->getRequest()->getQueryValues();
-                       unset( $this->mDefaultQuery['title'] );
-                       unset( $this->mDefaultQuery['dir'] );
-                       unset( $this->mDefaultQuery['offset'] );
-                       unset( $this->mDefaultQuery['limit'] );
-                       unset( $this->mDefaultQuery['order'] );
-                       unset( $this->mDefaultQuery['month'] );
-                       unset( $this->mDefaultQuery['year'] );
-               }
-
-               return $this->mDefaultQuery;
-       }
-
        /**
         * @param array $queryTypes
         * @return array Form descriptor
index ad0f67e..8ffe824 100644 (file)
@@ -204,9 +204,6 @@ class ObjectCache {
                                if ( !isset( $params['servers'] ) ) {
                                        $params['servers'] = $GLOBALS['wgMemCachedServers'];
                                }
-                               if ( !isset( $params['debug'] ) ) {
-                                       $params['debug'] = $GLOBALS['wgMemCachedDebug'];
-                               }
                                if ( !isset( $params['persistent'] ) ) {
                                        $params['persistent'] = $GLOBALS['wgMemCachedPersistent'];
                                }
@@ -393,12 +390,19 @@ class ObjectCache {
         */
        public static function detectLocalServerCache() {
                if ( function_exists( 'apcu_fetch' ) ) {
-                       return 'apcu';
+                       // Make sure the APCu methods actually store anything
+                       if ( PHP_SAPI !== 'cli' || ini_get( 'apc.enable_cli' ) ) {
+                               return 'apcu';
+                       }
                } elseif ( function_exists( 'apc_fetch' ) ) {
-                       return 'apc';
+                       // Make sure the APC methods actually store anything
+                       if ( PHP_SAPI !== 'cli' || ini_get( 'apc.enable_cli' ) ) {
+                               return 'apc';
+                       }
                } elseif ( function_exists( 'wincache_ucache_get' ) ) {
                        return 'wincache';
                }
+
                return CACHE_NONE;
        }
 }
index fcfb83d..d8cd1c5 100644 (file)
@@ -635,8 +635,9 @@ class Article implements Page {
                if ( $outputPage->isPrintable() ) {
                        $parserOptions->setIsPrintable( true );
                        $poOptions['enableSectionEditLinks'] = false;
-               } elseif ( $this->viewIsRenderAction
-                       || !$this->isCurrent() || !$this->getTitle()->quickUserCan( 'edit', $user )
+               } elseif ( $this->viewIsRenderAction || !$this->isCurrent() ||
+                       !MediaWikiServices::getInstance()->getPermissionManager()
+                               ->quickUserCan( 'edit', $user, $this->getTitle() )
                ) {
                        $poOptions['enableSectionEditLinks'] = false;
                }
@@ -1181,7 +1182,8 @@ class Article implements Page {
                $title = $this->getTitle();
                $rc = false;
 
-               if ( !$title->quickUserCan( 'patrol', $user )
+               if ( !MediaWikiServices::getInstance()->getPermissionManager()
+                               ->quickUserCan( 'patrol', $user, $title )
                        || !( $wgUseRCPatrol || $wgUseNPPatrol
                                || ( $wgUseFilePatrol && $title->inNamespace( NS_FILE ) ) )
                ) {
@@ -1450,6 +1452,7 @@ class Article implements Page {
 
                # Show error message
                $oldid = $this->getOldID();
+               $pm = MediaWikiServices::getInstance()->getPermissionManager();
                if ( !$oldid && $title->getNamespace() === NS_MEDIAWIKI && $title->hasSourceText() ) {
                        // use fake Content object for system message
                        $parserOptions = ParserOptions::newCanonical( 'canonical' );
@@ -1457,8 +1460,8 @@ class Article implements Page {
                } else {
                        if ( $oldid ) {
                                $text = wfMessage( 'missing-revision', $oldid )->plain();
-                       } elseif ( $title->quickUserCan( 'create', $this->getContext()->getUser() )
-                               && $title->quickUserCan( 'edit', $this->getContext()->getUser() )
+                       } elseif ( $pm->quickUserCan( 'create', $this->getContext()->getUser(), $title ) &&
+                               $pm->quickUserCan( 'edit', $this->getContext()->getUser(), $title )
                        ) {
                                $message = $this->getContext()->getUser()->isLoggedIn() ? 'noarticletext' : 'noarticletextanon';
                                $text = wfMessage( $message )->plain();
index 2de82bf..dc75541 100644 (file)
@@ -118,6 +118,7 @@ class ImageHistoryList extends ContextSource {
        public function imageHistoryLine( $iscur, $file ) {
                $user = $this->getUser();
                $lang = $this->getLanguage();
+               $pm = MediaWikiServices::getInstance()->getPermissionManager();
                $timestamp = wfTimestamp( TS_MW, $file->getTimestamp() );
                $img = $iscur ? $file->getName() : $file->getArchiveName();
                $userId = $file->getUser( 'id' );
@@ -128,9 +129,7 @@ class ImageHistoryList extends ContextSource {
                $row = $selected = '';
 
                // Deletion link
-               if ( $local && ( MediaWikiServices::getInstance()
-                               ->getPermissionManager()
-                               ->userHasAnyRight( $user, 'delete', 'deletedhistory' ) )
+               if ( $local && ( $pm->userHasAnyRight( $user, 'delete', 'deletedhistory' ) )
                ) {
                        $row .= '<td>';
                        # Link to remove from history
@@ -173,8 +172,8 @@ class ImageHistoryList extends ContextSource {
                $row .= '<td>';
                if ( $iscur ) {
                        $row .= $this->msg( 'filehist-current' )->escaped();
-               } elseif ( $local && $this->title->quickUserCan( 'edit', $user )
-                       && $this->title->quickUserCan( 'upload', $user )
+               } elseif ( $local && $pm->quickUserCan( 'edit', $user, $this->title )
+                       && $pm->quickUserCan( 'upload', $user, $this->title )
                ) {
                        if ( $file->isDeleted( File::DELETED_FILE ) ) {
                                $row .= $this->msg( 'filehist-revert' )->escaped();
index 4f08995..2e43e8c 100644 (file)
@@ -748,7 +748,8 @@ EOT
                        return;
                }
 
-               $canUpload = $this->getTitle()->quickUserCan( 'upload', $this->getContext()->getUser() );
+               $canUpload = MediaWikiServices::getInstance()->getPermissionManager()
+                       ->quickUserCan( 'upload', $this->getContext()->getUser(), $this->getTitle() );
                if ( $canUpload && UploadBase::userCanReUpload(
                                $this->getContext()->getUser(),
                                $this->mPage->getFile() )
index 0fcc97d..2eb5586 100644 (file)
@@ -249,6 +249,10 @@ abstract class Profiler {
         * @since 1.26
         */
        public function logDataPageOutputOnly() {
+               if ( !$this->allowOutput ) {
+                       return;
+               }
+
                $outputs = [];
                foreach ( $this->getOutputs() as $output ) {
                        if ( $output->logsToOutput() ) {
@@ -291,7 +295,7 @@ abstract class Profiler {
         * @param bool $t
         */
        public function setTemplated( $t ) {
-               // wfDeprecated( __METHOD__, '1.34' );
+               wfDeprecated( __METHOD__, '1.34' );
                $this->allowOutput = ( $t === true );
        }
 
@@ -302,7 +306,7 @@ abstract class Profiler {
         * @return bool
         */
        public function getTemplated() {
-               // wfDeprecated( __METHOD__, '1.34' );
+               wfDeprecated( __METHOD__, '1.34' );
                return $this->getAllowOutput();
        }
 
index fe27c04..bc14f4b 100644 (file)
@@ -48,7 +48,7 @@ abstract class ProfilerOutput {
        }
 
        /**
-        * Does log() just send the data to the request/script output?
+        * May the log() try to write to standard output?
         * @return bool
         * @since 1.33
         */
@@ -57,7 +57,10 @@ abstract class ProfilerOutput {
        }
 
        /**
-        * Log MediaWiki-style profiling data
+        * Log MediaWiki-style profiling data.
+        *
+        * For classes that enable logsToOutput(), this must not
+        * be called unless Profiler::setAllowOutput is enabled.
         *
         * @param array $stats Result of Profiler::getFunctionStats()
         */
index 95b5ff9..ee06b59 100644 (file)
  */
 class ProfilerOutputText extends ProfilerOutput {
        /** @var float Min real time display threshold */
-       protected $thresholdMs;
+       private $thresholdMs;
+
+       /** @var bool Whether to use visible text or a comment (for HTML responses) */
+       private $visible;
 
        function __construct( Profiler $collector, array $params ) {
                parent::__construct( $collector, $params );
                $this->thresholdMs = $params['thresholdMs'] ?? 1.0;
+               $this->visible = $params['visible'] ?? false;
        }
 
        public function logsToOutput() {
@@ -41,39 +45,36 @@ class ProfilerOutputText extends ProfilerOutput {
        }
 
        public function log( array $stats ) {
-               if ( $this->collector->getTemplated() ) {
-                       $out = '';
+               $out = '';
 
-                       // Filter out really tiny entries
-                       $min = $this->thresholdMs;
-                       $stats = array_filter( $stats, function ( $a ) use ( $min ) {
-                               return $a['real'] > $min;
-                       } );
-                       // Sort descending by time elapsed
-                       usort( $stats, function ( $a, $b ) {
-                               return $b['real'] <=> $a['real'];
-                       } );
+               // Filter out really tiny entries
+               $min = $this->thresholdMs;
+               $stats = array_filter( $stats, function ( $a ) use ( $min ) {
+                       return $a['real'] > $min;
+               } );
+               // Sort descending by time elapsed
+               usort( $stats, function ( $a, $b ) {
+                       return $b['real'] <=> $a['real'];
+               } );
 
-                       array_walk( $stats,
-                               function ( $item ) use ( &$out ) {
-                                       $out .= sprintf( "%6.2f%% %3.3f %6d - %s\n",
-                                               $item['%real'], $item['real'], $item['calls'], $item['name'] );
-                               }
-                       );
+               array_walk( $stats,
+                       function ( $item ) use ( &$out ) {
+                               $out .= sprintf( "%6.2f%% %3.3f %6d - %s\n",
+                                       $item['%real'], $item['real'], $item['calls'], $item['name'] );
+                       }
+               );
 
-                       $contentType = $this->collector->getContentType();
-                       if ( wfIsCLI() ) {
+               $contentType = $this->collector->getContentType();
+               if ( wfIsCLI() ) {
+                       print "<!--\n{$out}\n-->\n";
+               } elseif ( $contentType === 'text/html' ) {
+                       if ( $this->visible ) {
+                               print "<pre>{$out}</pre>";
+                       } else {
                                print "<!--\n{$out}\n-->\n";
-                       } elseif ( $contentType === 'text/html' ) {
-                               $visible = $this->params['visible'] ?? false;
-                               if ( $visible ) {
-                                       print "<pre>{$out}</pre>";
-                               } else {
-                                       print "<!--\n{$out}\n-->\n";
-                               }
-                       } elseif ( $contentType === 'text/javascript' || $contentType === 'text/css' ) {
-                               print "\n/*\n{$out}*/\n";
                        }
+               } elseif ( $contentType === 'text/javascript' || $contentType === 'text/css' ) {
+                       print "\n/*\n{$out}*/\n";
                }
        }
 }
index eeed05e..b0d0678 100644 (file)
@@ -61,9 +61,11 @@ abstract class Skin extends ContextSource {
 
        /**
         * Fetch the skinname messages for available skins.
+        * @deprecated since 1.34, no longer used.
         * @return string[]
         */
        static function getSkinNameMessages() {
+               wfDeprecated( __METHOD__, '1.34' );
                $messages = [];
                foreach ( self::getSkinNames() as $skinKey => $skinName ) {
                        $messages[] = "skinname-$skinKey";
@@ -459,7 +461,9 @@ abstract class Skin extends ContextSource {
                                $type = 'ns-subject';
                        }
                        // T208315: add HTML class when the user can edit the page
-                       if ( $title->quickUserCan( 'edit', $user ) ) {
+                       if ( MediaWikiServices::getInstance()->getPermissionManager()
+                                       ->quickUserCan( 'edit', $user, $title )
+                       ) {
                                $type .= ' mw-editable';
                        }
                }
@@ -723,14 +727,17 @@ abstract class Skin extends ContextSource {
                $action = $this->getRequest()->getVal( 'action', 'view' );
                $title = $this->getTitle();
                $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
+               $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
 
                if ( ( !$title->exists() || $action == 'history' ) &&
-                       $title->quickUserCan( 'deletedhistory', $this->getUser() )
+                       $permissionManager->quickUserCan( 'deletedhistory', $this->getUser(), $title )
                ) {
                        $n = $title->isDeleted();
 
                        if ( $n ) {
-                               if ( $this->getTitle()->quickUserCan( 'undelete', $this->getUser() ) ) {
+                               if ( $permissionManager->quickUserCan( 'undelete',
+                                               $this->getUser(), $this->getTitle() )
+                               ) {
                                        $msg = 'thisisdeleted';
                                } else {
                                        $msg = 'viewdeleted';
@@ -1311,19 +1318,21 @@ abstract class Skin extends ContextSource {
         * @return array
         */
        public function buildSidebar() {
+               $services = MediaWikiServices::getInstance();
                $callback = function ( $old = null, &$ttl = null ) {
                        $bar = [];
                        $this->addToSidebar( $bar, 'sidebar' );
                        Hooks::run( 'SkinBuildSidebar', [ $this, &$bar ] );
-                       if ( MessageCache::singleton()->isDisabled() ) {
+                       $msgCache = MediaWikiServices::getInstance()->getMessageCache();
+                       if ( $msgCache->isDisabled() ) {
                                $ttl = WANObjectCache::TTL_UNCACHEABLE; // bug T133069
                        }
 
                        return $bar;
                };
 
-               $msgCache = MessageCache::singleton();
-               $wanCache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+               $msgCache = $services->getMessageCache();
+               $wanCache = $services->getMainWANObjectCache();
                $config = $this->getConfig();
 
                $sidebar = $config->get( 'EnableSidebarCache' )
index f348135..3e8972c 100644 (file)
@@ -208,7 +208,7 @@ class SkinTemplate extends Skin {
         * Initialize various variables and generate the template
         */
        function outputPage() {
-               Profiler::instance()->setTemplated( true );
+               Profiler::instance()->setAllowOutput();
                $out = $this->getOutput();
 
                $this->initPage( $out );
@@ -884,6 +884,7 @@ class SkinTemplate extends Skin {
                $out = $this->getOutput();
                $request = $this->getRequest();
                $user = $this->getUser();
+               $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
 
                $content_navigation = [
                        'namespaces' => [],
@@ -895,7 +896,7 @@ class SkinTemplate extends Skin {
                // parameters
                $action = $request->getVal( 'action', 'view' );
 
-               $userCanRead = $title->quickUserCan( 'read', $user );
+               $userCanRead = $permissionManager->quickUserCan( 'read', $user, $title );
 
                // Avoid PHP 7.1 warning of passing $this by reference
                $skinTemplate = $this;
@@ -965,8 +966,9 @@ class SkinTemplate extends Skin {
                                }
 
                                // Checks if user can edit the current page if it exists or create it otherwise
-                               if ( $title->quickUserCan( 'edit', $user )
-                                       && ( $title->exists() || $title->quickUserCan( 'create', $user ) )
+                               if ( $permissionManager->quickUserCan( 'edit', $user, $title ) &&
+                                        ( $title->exists() ||
+                                                $permissionManager->quickUserCan( 'create', $user, $title ) )
                                ) {
                                        // Builds CSS class for talk page links
                                        $isTalkClass = $isTalk ? ' istalk' : '';
@@ -1031,7 +1033,7 @@ class SkinTemplate extends Skin {
                                                'href' => $title->getLocalURL( 'action=history' ),
                                        ];
 
-                                       if ( $title->quickUserCan( 'delete', $user ) ) {
+                                       if ( $permissionManager->quickUserCan( 'delete', $user, $title ) ) {
                                                $content_navigation['actions']['delete'] = [
                                                        'class' => ( $onPage && $action == 'delete' ) ? 'selected' : false,
                                                        'text' => wfMessageFallback( "$skname-action-delete", 'delete' )
@@ -1040,7 +1042,7 @@ class SkinTemplate extends Skin {
                                                ];
                                        }
 
-                                       if ( $title->quickUserCan( 'move', $user ) ) {
+                                       if ( $permissionManager->quickUserCan( 'move', $user, $title ) ) {
                                                $moveTitle = SpecialPage::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
                                                $content_navigation['actions']['move'] = [
                                                        'class' => $this->getTitle()->isSpecial( 'Movepage' ) ? 'selected' : false,
@@ -1051,13 +1053,14 @@ class SkinTemplate extends Skin {
                                        }
                                } else {
                                        // article doesn't exist or is deleted
-                                       if ( $title->quickUserCan( 'deletedhistory', $user ) ) {
+                                       if ( $permissionManager->quickUserCan( 'deletedhistory', $user, $title ) ) {
                                                $n = $title->isDeleted();
                                                if ( $n ) {
                                                        $undelTitle = SpecialPage::getTitleFor( 'Undelete', $title->getPrefixedDBkey() );
                                                        // If the user can't undelete but can view deleted
                                                        // history show them a "View .. deleted" tab instead.
-                                                       $msgKey = $title->quickUserCan( 'undelete', $user ) ? 'undelete' : 'viewdeleted';
+                                                       $msgKey = $permissionManager->quickUserCan( 'undelete',
+                                                               $user, $title ) ? 'undelete' : 'viewdeleted';
                                                        $content_navigation['actions']['undelete'] = [
                                                                'class' => $this->getTitle()->isSpecial( 'Undelete' ) ? 'selected' : false,
                                                                'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
@@ -1068,9 +1071,10 @@ class SkinTemplate extends Skin {
                                        }
                                }
 
-                               if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() &&
-                                       MediaWikiServices::getInstance()->getPermissionManager()
-                                               ->getNamespaceRestrictionLevels( $title->getNamespace(), $user ) !== [ '' ]
+                               if ( $permissionManager->quickUserCan( 'protect', $user, $title ) &&
+                                        $title->getRestrictionTypes() &&
+                                        $permissionManager->getNamespaceRestrictionLevels( $title->getNamespace(),
+                                                $user ) !== [ '' ]
                                ) {
                                        $mode = $title->isProtected() ? 'unprotect' : 'protect';
                                        $content_navigation['actions'][$mode] = [
@@ -1082,9 +1086,8 @@ class SkinTemplate extends Skin {
                                }
 
                                // Checks if the user is logged in
-                               if ( $this->loggedin && MediaWikiServices::getInstance()
-                                               ->getPermissionManager()
-                                               ->userHasAllRights( $user, 'viewmywatchlist', 'editmywatchlist' )
+                               if ( $this->loggedin && $permissionManager->userHasAllRights( $user,
+                                               'viewmywatchlist', 'editmywatchlist' )
                                ) {
                                        /**
                                         * The following actions use messages which, if made particular to
index 83ffe40..72fe57d 100644 (file)
@@ -116,7 +116,7 @@ abstract class WantedQueryPage extends QueryPage {
         * @param object $result Result row
         * @return string
         */
-       private function makeWlhLink( $title, $result ) {
+       protected function makeWlhLink( $title, $result ) {
                $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
                $label = $this->msg( 'nlinks' )->numParams( $result->value )->text();
                return $this->getLinkRenderer()->makeLink( $wlh, $label );
index f1843ea..9d5f430 100644 (file)
@@ -203,8 +203,6 @@ class SpecialContributions extends IncludableSpecialPage {
                        }
                        $pager = new ContribsPager( $this->getContext(), [
                                'target' => $target,
-                               // Temporary, until newbie feature is fully removed from ContribsPager
-                               'contribs' => 'user',
                                'namespace' => $this->opts['namespace'],
                                'tagfilter' => $this->opts['tagfilter'],
                                'start' => $this->opts['start'],
index 40d8962..902bfd7 100644 (file)
@@ -113,17 +113,15 @@ class DeletedContributionsPage extends SpecialPage {
 
                # If there were contributions, and it was a valid user or IP, show
                # the appropriate "footer" message - WHOIS tools, etc.
-               if ( $target != 'newbies' ) {
-                       $message = IP::isIPAddress( $target ) ?
-                               'sp-contributions-footer-anon' :
-                               'sp-contributions-footer';
-
-                       if ( !$this->msg( $message )->isDisabled() ) {
-                               $out->wrapWikiMsg(
-                                       "<div class='mw-contributions-footer'>\n$1\n</div>",
-                                       [ $message, $target ]
-                               );
-                       }
+               $message = IP::isIPAddress( $target ) ?
+                       'sp-contributions-footer-anon' :
+                       'sp-contributions-footer';
+
+               if ( !$this->msg( $message )->isDisabled() ) {
+                       $out->wrapWikiMsg(
+                               "<div class='mw-contributions-footer'>\n$1\n</div>",
+                               [ $message, $target ]
+                       );
                }
        }
 
index da34d81..85f65bb 100644 (file)
@@ -197,7 +197,8 @@ class MovePageForm extends UnlistedSpecialPage {
                }
 
                if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] == 'articleexists'
-                       && $newTitle->quickUserCan( 'delete', $user )
+                       && MediaWikiServices::getInstance()->getPermissionManager()
+                                ->quickUserCan( 'delete', $user, $newTitle )
                ) {
                        $out->wrapWikiMsg(
                                "<div class='warningbox'>\n$1\n</div>\n",
index e0834d5..ecbbfd5 100644 (file)
@@ -131,7 +131,7 @@ class SpecialNewFiles extends IncludableSpecialPage {
                        ],
 
                        'user' => [
-                               'type' => 'text',
+                               'class' => 'HTMLUserTextField',
                                'label-message' => 'newimages-user',
                                'name' => 'user',
                        ],
index ad045e4..2ae4afc 100644 (file)
@@ -518,7 +518,8 @@ class SpecialSearch extends SpecialPage {
                                $messageName = 'searchmenu-exists';
                                $linkClass = 'mw-search-exists';
                        } elseif ( ContentHandler::getForTitle( $title )->supportsDirectEditing()
-                               && $title->quickUserCan( 'create', $this->getUser() )
+                               && MediaWikiServices::getInstance()->getPermissionManager()->quickUserCan( 'create',
+                                       $this->getUser(), $title )
                        ) {
                                $messageName = 'searchmenu-new';
                        }
index 1b0c59a..b80a584 100644 (file)
@@ -41,12 +41,6 @@ class ContribsPager extends RangeChronologicalPager {
         */
        private $target;
 
-       /**
-        * @var string Set to "newbie" to list contributions from the most recent 1% registered users.
-        *  $this->target is ignored then. Defaults to "users".
-        */
-       private $contribs;
-
        /**
         * @var string|int A single namespace number, or an empty string for all namespaces
         */
@@ -104,11 +98,10 @@ class ContribsPager extends RangeChronologicalPager {
        private $templateParser;
 
        public function __construct( IContextSource $context, array $options ) {
-               // Set ->target and ->contribs before calling parent::__construct() so
+               // Set ->target before calling parent::__construct() so
                // parent can call $this->getIndexField() and get the right result. Set
                // the rest too just to keep things simple.
                $this->target = $options['target'] ?? '';
-               $this->contribs = $options['contribs'] ?? 'users';
                $this->namespace = $options['namespace'] ?? '';
                $this->tagFilter = $options['tagfilter'] ?? false;
                $this->nsInvert = $options['nsInvert'] ?? false;
@@ -249,10 +242,6 @@ class ContribsPager extends RangeChronologicalPager {
         * @return string
         */
        private function getTargetTable() {
-               if ( $this->contribs == 'newbie' ) {
-                       return 'revision';
-               }
-
                $user = User::newFromName( $this->target, false );
                $ipRangeConds = $user->isAnon() ? $this->getIpRangeConds( $this->mDb, $this->target ) : null;
                if ( $ipRangeConds ) {
@@ -279,53 +268,25 @@ class ContribsPager extends RangeChronologicalPager {
                ];
 
                // WARNING: Keep this in sync with getTargetTable()!
-
-               if ( $this->contribs == 'newbie' ) {
-                       $max = $this->mDb->selectField( 'user', 'max(user_id)', '', __METHOD__ );
-                       $queryInfo['conds'][] = $revQuery['fields']['rev_user'] . ' >' . (int)( $max - $max / 100 );
-                       # ignore local groups with the bot right
-                       # @todo FIXME: Global groups may have 'bot' rights
-                       $groupsWithBotPermission = MediaWikiServices::getInstance()
-                               ->getPermissionManager()
-                               ->getGroupsWithPermission( 'bot' );
-                       if ( count( $groupsWithBotPermission ) ) {
-                               $queryInfo['tables'][] = 'user_groups';
-                               $queryInfo['conds'][] = 'ug_group IS NULL';
-                               $queryInfo['join_conds']['user_groups'] = [
-                                       'LEFT JOIN', [
-                                               'ug_user = ' . $revQuery['fields']['rev_user'],
-                                               'ug_group' => $groupsWithBotPermission,
-                                               'ug_expiry IS NULL OR ug_expiry >= ' .
-                                                       $this->mDb->addQuotes( $this->mDb->timestamp() )
-                                       ]
-                               ];
-                       }
-                       // (T140537) Disallow looking too far in the past for 'newbies' queries. If the user requested
-                       // a timestamp offset far in the past such that there are no edits by users with user_ids in
-                       // the range, we would end up scanning all revisions from that offset until start of time.
-                       $queryInfo['conds'][] = 'rev_timestamp > ' .
-                               $this->mDb->addQuotes( $this->mDb->timestamp( wfTimestamp() - 30 * 24 * 60 * 60 ) );
+               $user = User::newFromName( $this->target, false );
+               $ipRangeConds = $user->isAnon() ? $this->getIpRangeConds( $this->mDb, $this->target ) : null;
+               if ( $ipRangeConds ) {
+                       $queryInfo['tables'][] = 'ip_changes';
+                       $queryInfo['join_conds']['ip_changes'] = [
+                               'LEFT JOIN', [ 'ipc_rev_id = rev_id' ]
+                       ];
+                       $queryInfo['conds'][] = $ipRangeConds;
                } else {
-                       $user = User::newFromName( $this->target, false );
-                       $ipRangeConds = $user->isAnon() ? $this->getIpRangeConds( $this->mDb, $this->target ) : null;
-                       if ( $ipRangeConds ) {
-                               $queryInfo['tables'][] = 'ip_changes';
-                               $queryInfo['join_conds']['ip_changes'] = [
-                                       'LEFT JOIN', [ 'ipc_rev_id = rev_id' ]
-                               ];
-                               $queryInfo['conds'][] = $ipRangeConds;
+                       // tables and joins are already handled by Revision::getQueryInfo()
+                       $conds = ActorMigration::newMigration()->getWhere( $this->mDb, 'rev_user', $user );
+                       $queryInfo['conds'][] = $conds['conds'];
+                       // Force the appropriate index to avoid bad query plans (T189026)
+                       if ( isset( $conds['orconds']['actor'] ) ) {
+                               // @todo: This will need changing when revision_actor_temp goes away
+                               $queryInfo['options']['USE INDEX']['temp_rev_user'] = 'actor_timestamp';
                        } else {
-                               // tables and joins are already handled by Revision::getQueryInfo()
-                               $conds = ActorMigration::newMigration()->getWhere( $this->mDb, 'rev_user', $user );
-                               $queryInfo['conds'][] = $conds['conds'];
-                               // Force the appropriate index to avoid bad query plans (T189026)
-                               if ( isset( $conds['orconds']['actor'] ) ) {
-                                       // @todo: This will need changing when revision_actor_temp goes away
-                                       $queryInfo['options']['USE INDEX']['temp_rev_user'] = 'actor_timestamp';
-                               } else {
-                                       $queryInfo['options']['USE INDEX']['revision'] =
-                                               isset( $conds['orconds']['userid'] ) ? 'user_timestamp' : 'usertext_timestamp';
-                               }
+                               $queryInfo['options']['USE INDEX']['revision'] =
+                                       isset( $conds['orconds']['userid'] ) ? 'user_timestamp' : 'usertext_timestamp';
                        }
                }
 
@@ -479,10 +440,13 @@ class ContribsPager extends RangeChronologicalPager {
        }
 
        /**
-        * @return string
+        * @deprecated since 1.34, redundant.
+        *
+        * @return string "users"
         */
        public function getContribs() {
-               return $this->contribs;
+               // Brought back for backwards compatibility, see T231540.
+               return 'users';
        }
 
        /**
@@ -544,10 +508,7 @@ class ContribsPager extends RangeChronologicalPager {
                        }
                        if ( isset( $row->rev_id ) ) {
                                $this->mParentLens[$row->rev_id] = $row->rev_len;
-                               if ( $this->contribs === 'newbie' ) { // multiple users
-                                       $batch->add( NS_USER, $row->user_name );
-                                       $batch->add( NS_USER_TALK, $row->user_name );
-                               } elseif ( $isIpRange ) {
+                               if ( $isIpRange ) {
                                        // If this is an IP range, batch the IP's talk page
                                        $batch->add( NS_USER_TALK, $row->rev_user_text );
                                }
@@ -622,6 +583,7 @@ class ContribsPager extends RangeChronologicalPager {
                $attribs = [];
 
                $linkRenderer = $this->getLinkRenderer();
+               $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
 
                $page = null;
                // Create a title for the revision if possible
@@ -647,8 +609,9 @@ class ContribsPager extends RangeChronologicalPager {
                                $topmarktext .= '<span class="mw-uctop">' . $this->messages['uctop'] . '</span>';
                                $classes[] = 'mw-contributions-current';
                                # Add rollback link
-                               if ( !$row->page_is_new && $page->quickUserCan( 'rollback', $user )
-                                       && $page->quickUserCan( 'edit', $user )
+                               if ( !$row->page_is_new &&
+                                       $permissionManager->quickUserCan( 'rollback', $user, $page ) &&
+                                       $permissionManager->quickUserCan( 'edit', $user, $page )
                                ) {
                                        $this->preventClickjacking();
                                        $topmarktext .= ' ' . Linker::generateRollback( $rev, $this->getContext(),
@@ -702,12 +665,9 @@ class ContribsPager extends RangeChronologicalPager {
                        $comment = $lang->getDirMark() . Linker::revComment( $rev, false, true, false );
                        $d = ChangesList::revDateLink( $rev, $user, $lang, $page );
 
-                       # Show user names for /newbies as there may be different users.
-                       # Note that only unprivileged users have rows with hidden user names excluded.
                        # When querying for an IP range, we want to always show user and user talk links.
                        $userlink = '';
-                       if ( ( $this->contribs == 'newbie' && !$rev->isDeleted( RevisionRecord::DELETED_USER ) )
-                               || $this->isQueryableRange( $this->target ) ) {
+                       if ( $this->isQueryableRange( $this->target ) ) {
                                $userlink = ' <span class="mw-changeslist-separator"></span> '
                                        . $lang->getDirMark()
                                        . Linker::userLink( $rev->getUser(), $rev->getUserText() );
index 57db8b3..2cb2b4a 100644 (file)
@@ -72,20 +72,6 @@ class NewFilesPager extends RangeChronologicalPager {
                                ->getWhere( wfGetDB( DB_REPLICA ), 'img_user', User::newFromName( $user, false ) )['conds'];
                }
 
-               if ( $opts->getValue( 'newbies' ) ) {
-                       // newbie = most recent 1% of users
-                       $dbr = wfGetDB( DB_REPLICA );
-                       $max = $dbr->selectField( 'user', 'max(user_id)', '', __METHOD__ );
-                       $conds[] = $imgQuery['fields']['img_user'] . ' >' . (int)( $max - $max / 100 );
-
-                       // there's no point in looking for new user activity in a far past;
-                       // beyond a certain point, we'd just end up scanning the rest of the
-                       // table even though the users we're looking for didn't yet exist...
-                       // see T140537, (for ContribsPages, but similar to this)
-                       $conds[] = 'img_timestamp > ' .
-                               $dbr->addQuotes( $dbr->timestamp( wfTimestamp() - 30 * 24 * 60 * 60 ) );
-               }
-
                if ( !$opts->getValue( 'showbots' ) ) {
                        $groupsWithBotPermission = MediaWikiServices::getInstance()
                                ->getPermissionManager()
index 8c6b2f9..c28890b 100644 (file)
@@ -161,7 +161,7 @@ class UploadFromChunks extends UploadFromFile {
                $ext = FileBackend::extensionFromPath( $this->mVirtualTempPath );
                // Get a 0-byte temp file to perform the concatenation at
                $tmpFile = MediaWikiServices::getInstance()->getTempFSFileFactory()
-                       ->getTempFSFile( 'chunkedupload_', $ext );
+                       ->newTempFSFile( 'chunkedupload_', $ext );
                $tmpPath = false; // fail in concatenate()
                if ( $tmpFile ) {
                        // keep alive with $this
index 0553c92..b0ee5cb 100644 (file)
@@ -4864,8 +4864,7 @@ class User implements IDBAccessObject, UserIdentity {
        /**
         * Get a list of all available permissions.
         *
-        * @deprecated since 1.34, use MediaWikiServices::getInstance()->getPermissionManager()
-        *             ->getAllPermissions() instead
+        * @deprecated since 1.34, use PermissionManager::getAllPermissions() instead
         *
         * @return string[] Array of permission names
         */
index 3220f7a..3cb9c66 100644 (file)
        "nocreate-loggedin": "You do not have permission to create new pages.",
        "sectioneditnotsupported-title": "Section editing not supported",
        "sectioneditnotsupported-text": "Section editing is not supported in this page.",
+       "modeleditnotsupported-title": "Editing not supported",
+       "modeleditnotsupported-text": "Editing is not supported for content model $1.",
        "permissionserrors": "Permission error",
        "permissionserrorstext": "You do not have permission to do that, for the following {{PLURAL:$1|reason|reasons}}:",
        "permissionserrorstext-withaction": "You do not have permission to $2, for the following {{PLURAL:$1|reason|reasons}}:",
        "content-model-json": "JSON",
        "content-json-empty-object": "Empty object",
        "content-json-empty-array": "Empty array",
+       "unsupported-content-model": "<strong>Warning:</strong> Content model $1 is not supported on this wiki.",
+       "unsupported-content-diff": "Diffs are not supported for content model $1.",
+       "unsupported-content-diff2": "Diffs between the content models $1 and $2 are not supported on this wiki.",
        "deprecated-self-close-category": "Pages using invalid self-closed HTML tags",
        "deprecated-self-close-category-desc": "The page contains invalid self-closed HTML tags, such as <code>&lt;b/></code> or <code>&lt;span/></code>.  The behavior of these will change soon to be consistent with the HTML5 specification, so their use in wikitext is deprecated.",
        "duplicate-args-warning": "<strong>Warning:</strong> [[:$1]] is calling [[:$2]] with more than one value for the \"$3\" parameter. Only the last value provided will be used.",
        "wlheader-enotif": "Email notification is enabled.",
        "wlheader-showupdated": "Pages that have been changed since you last visited them are shown in <strong>bold</strong>.",
        "wlnote": "Below {{PLURAL:$1|is the last change|are the last <strong>$1</strong> changes}} in the last {{PLURAL:$2|hour|<strong>$2</strong> hours}}, as of $3, $4.",
-       "wlshowlast": "Show last $1 hours $2 days",
        "watchlist-hide": "Hide",
        "watchlist-submit": "Show",
        "wlshowtime": "Period of time to display:",
        "img-lang-default": "(default language)",
        "img-lang-info": "Render this image in $1. $2",
        "img-lang-go": "Go",
-       "ascending_abbrev": "asc",
-       "descending_abbrev": "desc",
        "table_pager_next": "Next page",
        "table_pager_prev": "Previous page",
        "table_pager_first": "First page",
index 2a55eb3..10dbb80 100644 (file)
        "exif-scenetype-1": "See also:\n* {{msg-mw|Exif-scenetype}}\n* {{msg-mw|Exif-scenetype-1}}",
        "exif-customrendered-0": "{{exif-qqq}}\n\nSee also:\n* {{msg-mw|Exif-customrendered}}\n* {{msg-mw|Exif-customrendered-0}}\n* {{msg-mw|Exif-customrendered-1}}",
        "exif-customrendered-1": "{{exif-qqq}}\n\nSee also:\n* {{msg-mw|Exif-customrendered}}\n* {{msg-mw|Exif-customrendered-0}}\n* {{msg-mw|Exif-customrendered-1}}",
+       "exif-customrendered-2": "{{exif-qqq}}\n\nSee also:\n* {{msg-mw|Exif-customrendered}}",
+       "exif-customrendered-3": "{{exif-qqq}}\n\nSee also:\n* {{msg-mw|Exif-customrendered}}",
+       "exif-customrendered-4": "{{exif-qqq}}\n\nSee also:\n* {{msg-mw|Exif-customrendered}}",
+       "exif-customrendered-6": "{{exif-qqq}}\n\nSee also:\n* {{msg-mw|Exif-customrendered}}",
+       "exif-customrendered-7": "{{exif-qqq}}\n\nSee also:\n* {{msg-mw|Exif-customrendered}}",
+       "exif-customrendered-8": "{{exif-qqq}}\n\nSee also:\n* {{msg-mw|Exif-customrendered}}",
        "exif-exposuremode-0": "{{exif-qqq}}\n{{Related|Exif-exposuremode}}",
        "exif-exposuremode-1": "{{exif-qqq}}\n{{Related|Exif-exposuremode}}",
        "exif-exposuremode-2": "{{exif-qqq}}\n\nA type of exposure mode shown as part of the metadata on image description pages. The Wikipedia article on [[w:Bracketing#Exposure_bracketing|bracketing]] says that 'auto bracket' is a camera exposure setting which automatically takes a series of pictures at slightly different light exposures.\n\n{{Related|Exif-exposuremode}}",
index aa33ee0..03c1da4 100644 (file)
        "nocreate-loggedin": "Used as error message.\n\nSee also:\n* {{msg-mw|Nocreatetext}}",
        "sectioneditnotsupported-title": "Page title of special page, which presumably appears when someone tries to edit a section, and section editing is disabled. Explanation of section editing on [[meta:Help:Section_editing#Section_editing|meta]].",
        "sectioneditnotsupported-text": "I think this is the text of an error message, which presumably appears when someone tries to edit a section, and section editing is disabled. Explanation of section editing on [[meta:Help:Section_editing#Section_editing|meta]].",
+       "modeleditnotsupported-title": "Page title used on the edit page when editing is not supported for the page's content model.",
+       "modeleditnotsupported-text": "Error message show on the edit page when editing is not supported for the page's content model..\n\nParameters:\n* $1 - the name of the content model.",
        "permissionserrors": "Used as title of error message.\n\nSee also:\n* {{msg-mw|loginreqtitle}}\n{{Identical|Permission error}}",
        "permissionserrorstext": "This message is \"without action\" version of {{msg-mw|Permissionserrorstext-withaction}}.\n\nParameters:\n* $1 - the number of reasons that were found why ''the action'' cannot be performed",
        "permissionserrorstext-withaction": "This message is \"with action\" version of {{msg-mw|Permissionserrorstext}}.\n\nParameters:\n* $1 - the number of reasons that were found why the action cannot be performed\n* $2 - one of the action-* messages (for example {{msg-mw|action-edit}}) or other such messages tagged with {{tl|doc-action}} in their documentation\n\nPlease report at [[Support]] if you are unable to properly translate this message. Also see [[phab:T16246]] (now closed) for background.",
        "content-model-json": "{{optional}}\nName for the JSON content model, used when decribing what type of content a page contains.\n\nThis message is substituted in:\n*{{msg-mw|Bad-target-model}}\n*{{msg-mw|Content-not-allowed-here}}\n{{identical|JSON}}",
        "content-json-empty-object": "Used to represent an object with no properties on a JSON content model page.",
        "content-json-empty-array": "Used to represent an array with no values on a JSON content model page.",
+       "unsupported-content-model": "Warning shown when trying to display content with an unknown model.\n\nParameters:\n* $1 - the technical name of the content model.",
+       "unsupported-content-diff": "Warning shown when trying to display a diff between content with a model that does not support diffing (perhaps because it's an unknown model).\n\nParameters:\n* $1 - the technical name of the model of the content",
+       "unsupported-content-diff2": "Warning shown when trying to display a diff between content that uses models that do not support diffing with each other.\n\nParameters:\n* $1 - the technical name of the model of the old content\n* $2 - the technical name of the model of the new content.",
        "deprecated-self-close-category": "This message is used as a category name for a [[mw:Special:MyLanguage/Help:Tracking categories|tracking category]] where pages are placed automatically if they contain invalid self-closed HTML tags, such as <code>&lt;b/></code> or <code>&lt;span/></code>.  The behavior of these will change soon to be consistent with the HTML5 specification, so their use in wikitext is deprecated.",
        "deprecated-self-close-category-desc": "Invalid self-closed HTML tag category description. Shown on [[Special:TrackingCategories]].\n\nSee also:\n* {{msg-mw|deprecated-self-close-category}}",
        "duplicate-args-warning": "If a page calls a template and specifies the same argument more than once, such as <code><nowiki>{{foo|bar=1|bar=2}}</nowiki></code> or <code><nowiki>{{foo|bar|1=baz}}</nowiki></code>, this warning is displayed when previewing.\n\nParameters:\n* $1 - The calling page\n* $2 - The called template\n* $3 - The name of the duplicated argument",
        "wlheader-enotif": "Message at the top of [[Special:Watchlist]], after {{msg-mw|watchlist-details}}. Has to be a full sentence.\n\nSee also:\n* {{msg-mw|Watchlist-options|fieldset}}\n* {{msg-mw|enotif reset|Submit button text}}",
        "wlheader-showupdated": "Message at the top of [[Special:Watchlist]], after {{msg-mw|watchlist-details}}. Has to be a full sentence.",
        "wlnote": "Used on [[Special:Watchlist]] when a maximum number of hours or days is specified.\n\nParameters:\n* $1 - the number of changes shown\n* $2 - the number of hours for which the changes are shown\n* $3 - a date alone\n* $4 - a time alone",
-       "wlshowlast": "Appears on [[Special:Watchlist]]. Parameters:\n* $1 - a choice of different numbers of hours (\"1 | 2 | 6 | 12\")\n* $2 - a choice of different numbers of days (\"1 | 3 | 7\" and the maximum number of days available)\nClicking on your choice changes the list of changes you see (without changing the default in my preferences).",
        "watchlist-hide": "Appears on [[Special:Watchlist]]. It is the first word on a new line with checkboxes to hide/unhide options\n{{Identical|Hide}}",
        "watchlist-submit": "Label on the submit button in [[Special:Watchlist]]\n{{Identical|Show}}",
        "wlshowtime": "Appears on [[Special:Watchlist]]. Label of a drop-down list used to specify the period of time to display in the watchlist. This period can be {{msg-mw|days}} or {{msg-mw|hours}}.",
        "img-lang-default": "An option in the drop down of a translatable file. For example see [[:File:Gerrit patchset 25838 test.svg]].\n\nUsed when it cannot be determined what the default fallback language is.\n\nHowever it should be noted that most of the time, the content displayed for this option would be in English.\n{{Identical|Default language}}",
        "img-lang-info": "Label for drop down box. Appears underneath the image on the image description page. See [[:File:Gerrit patchset 25838 test.svg]] for an example.\n\nParameters:\n* $1 - a drop down box with language options, uses the following messages:\n** {{msg-mw|Img-lang-default}}\n** {{msg-mw|Img-lang-opt}}. e.g. \"English (en)\", \"日本語 (ja)\"\n* $2 - a submit button, which uses the text from {{msg-mw|Img-lang-go}}",
        "img-lang-go": "Go button for the language select for translatable files. See [[:File:Gerrit patchset 25838 test.svg]] for an example.\n\nSee also:\n* {{msg-mw|img-lang-info}}\n{{Identical|Go}}",
-       "ascending_abbrev": "Abbreviation of ascending order.\nSee also:\n* {{msg-mw|Ascending abbrev}}\n* {{msg-mw|Descending abbrev}}",
-       "descending_abbrev": "Abbreviation of descending order.\nSee also:\n* {{msg-mw|Ascending abbrev}}\n* {{msg-mw|Descending abbrev}}",
        "table_pager_next": "Used as image button text of pager. See [[Support|example]] (the bottom of the page).\n{{Identical|Next page}}",
        "table_pager_prev": "Used as image button text of pager. See [[Support|example]] (the bottom of the page).\n{{Identical|Previous page}}",
        "table_pager_first": "Used as image button text of pager. See [[Support|example]] (the bottom of the page).\n{{Identical|First page}}",
index 4d34e5d..6edb7ec 100644 (file)
--- a/load.php
+++ b/load.php
@@ -45,7 +45,7 @@ $context = new ResourceLoaderContext( $resourceLoader, $wgRequest );
 // Respond to ResourceLoader request
 $resourceLoader->respond( $context );
 
-Profiler::instance()->setTemplated( true );
+Profiler::instance()->setAllowOutput();
 
 $mediawiki = new MediaWiki();
 $mediawiki->doPostOutputShutdown( 'fast' );
index c3644ee..130d1fb 100644 (file)
@@ -831,7 +831,7 @@ abstract class Maintenance {
                                        + $wgProfiler
                                        + [ 'threshold' => $wgProfileLimit ]
                        );
-                       $profiler->setTemplated( true );
+                       $profiler->setAllowOutput();
                        Profiler::replaceStubInstance( $profiler );
                }
 
index 1d85dcc..c4f175f 100644 (file)
@@ -46,6 +46,7 @@ SPARQL;
 DELETE {
 ?category ?x ?y
 } WHERE {
+   ?category ?x ?y
    VALUES ?category {
      %s
    }
@@ -62,6 +63,7 @@ DELETE {
 } INSERT {
 %s
 } WHERE {
+  ?category ?x ?y
    VALUES ?category {
      %s
    }
index 1def4bd..0b49359 100644 (file)
       }
     },
     "eslint-utils": {
-      "version": "1.3.1",
-      "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.3.1.tgz",
-      "integrity": "sha512-Z7YjnIldX+2XMcjr7ZkgEsOj/bREONV60qYeB/bjMAqqqZ4zxKyWX+BOUkdmRmA9riiIPVvo5x86m5elviOk0Q==",
-      "dev": true
+      "version": "1.4.2",
+      "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.4.2.tgz",
+      "integrity": "sha512-eAZS2sEUMlIeCjBeubdj45dmBHQwPHWyBcT1VSYB7o9x9WRRqKxyUoiXlRjyAwzN7YEzHJlYg0NmzDRWx6GP4Q==",
+      "dev": true,
+      "requires": {
+        "eslint-visitor-keys": "^1.0.0"
+      }
     },
     "eslint-visitor-keys": {
       "version": "1.0.0",
index d33e3de..8234e89 100644 (file)
@@ -1042,6 +1042,12 @@ return [
        'mediawiki.pager.tablePager' => [
                'styles' => 'resources/src/mediawiki.pager.tablePager/TablePager.less',
        ],
+       'mediawiki.pulsatingdot' => [
+               'styles' => [
+                       'resources/src/mediawiki.pulsatingdot/mediawiki.pulsatingdot.less',
+               ],
+               'targets' => [ 'desktop', 'mobile' ],
+       ],
        'mediawiki.searchSuggest' => [
                'targets' => [ 'desktop', 'mobile' ],
                'scripts' => 'resources/src/mediawiki.searchSuggest/searchSuggest.js',
@@ -1370,7 +1376,7 @@ return [
                        'oojs-ui-core',
                ],
                'messages' => [
-                       // Keep the uses message keys in sync with EditPage#setHeaders
+                       // Keep these message keys in sync with EditPage#setHeaders
                        'creating',
                        'editconflict',
                        'editing',
index 7205620..de08607 100644 (file)
                        );
                },
 
+               // match prefix plus any combining characters to prevent ugly rendering (see T35242)
+               prefixPlusComboHighlight: function ( node, prefix ) {
+
+                       // Equivalent to \p{Mark} (which is not currently available in JavaScript)
+                       var comboMarks = '[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]';
+
+                       $.highlightText.innerHighlight(
+                               node,
+                               new RegExp( '(^)' + mw.RegExp.escape( prefix ) + comboMarks + '*', 'i' )
+                       );
+               },
+
                // scans a node looking for the pattern and wraps a span around each match
                innerHighlight: function ( node, pat ) {
                        var i, match, pos, spannode, middlebit, middleclone;
@@ -81,6 +93,8 @@
         * @param {string} [options.method='splitAndHighlight'] Method of matching to use, one of:
         *   - 'splitAndHighlight': Split `matchString` on spaces, then match each word separately.
         *   - 'prefixHighlight': Match `matchString` at the beginning of text only.
+        *   - 'prefixPlusComboHighlight': Match `matchString` plus any combining characters at
+        *     the beginning of text only.
         * @return {jQuery}
         * @chainable
         */
index f4aea72..31afe3e 100644 (file)
                                                        }
 
                                                        if ( context.config.highlightInput ) {
-                                                               $result.highlightText( context.data.prevText, { method: 'prefixHighlight' } );
+                                                               $result.highlightText( context.data.prevText, { method: 'prefixPlusComboHighlight' } );
                                                        }
 
                                                        // Widen results box if needed (new width is only calculated here, applied later).
diff --git a/resources/src/mediawiki.pulsatingdot/mediawiki.pulsatingdot.less b/resources/src/mediawiki.pulsatingdot/mediawiki.pulsatingdot.less
new file mode 100644 (file)
index 0000000..00a5608
--- /dev/null
@@ -0,0 +1,70 @@
+.mw-pulsating-dot {
+       &:before,
+       &:after {
+               content: '';
+               display: block;
+               position: absolute;
+               border-radius: 50%;
+               background-color: #36c;
+       }
+
+       &:before {
+               width: 36px;
+               height: 36px;
+               top: -18px;
+               left: -18px;
+               opacity: 0;
+               -webkit-animation: mw-pulsating-dot-pulse 3s ease-out;
+               -moz-animation: mw-pulsating-dot-pulse 3s ease-out;
+               animation: mw-pulsating-dot-pulse 3s ease-out;
+               -webkit-animation-iteration-count: infinite;
+               -moz-animation-iteration-count: infinite;
+               animation-iteration-count: infinite;
+       }
+
+       &:after {
+               width: 12px;
+               height: 12px;
+               top: -6px;
+               left: -6px;
+       }
+}
+
+.mw-pulsating-dot-pulse-frames() {
+       0% {
+               transform: scale( 0 );
+               opacity: 0;
+       }
+
+       25% {
+               transform: scale( 0 );
+               opacity: 0.1;
+       }
+
+       50% {
+               transform: scale( 0.1 );
+               opacity: 0.3;
+       }
+
+       75% {
+               transform: scale( 0.5 );
+               opacity: 0.5;
+       }
+
+       100% {
+               transform: scale( 1 );
+               opacity: 0;
+       }
+}
+
+@-webkit-keyframes mw-pulsating-dot-pulse {
+       .mw-pulsating-dot-pulse-frames;
+}
+
+@-moz-keyframes mw-pulsating-dot-pulse {
+       .mw-pulsating-dot-pulse-frames;
+}
+
+@keyframes mw-pulsating-dot-pulse {
+       .mw-pulsating-dot-pulse-frames;
+}
index 5ca39d5..dfc41be 100644 (file)
                        // We have no way to display a translated placeholder for custom formats
                        placeholderDateFormat = '';
                } else {
-                       // Messages: mw-widgets-dateinput-placeholder-day, mw-widgets-dateinput-placeholder-month
+                       // The following messages are used here:
+                       // * mw-widgets-dateinput-placeholder-day
+                       // * mw-widgets-dateinput-placeholder-month
                        placeholderDateFormat = mw.msg( 'mw-widgets-dateinput-placeholder-' + config.precision );
                }
 
index a3249de..a4ee488 100644 (file)
                                        // Whether the store is in use on this page.
                                        enabled: null,
 
-                                       // Modules whose string representation exceeds 100 kB are
-                                       // ineligible for storage. See bug T66721.
-                                       MODULE_SIZE_MAX: 100 * 1000,
+                                       // Modules whose serialised form exceeds 100 kB won't be stored (T66721).
+                                       MODULE_SIZE_MAX: 1e5,
 
                                        // The contents of the store, mapping '[name]@[version]' keys
                                        // to module implementations.
                                         * @return {Object} Module store contents.
                                         */
                                        toJSON: function () {
-                                               return { items: mw.loader.store.items, vary: mw.loader.store.vary };
+                                               return {
+                                                       items: mw.loader.store.items,
+                                                       vary: mw.loader.store.vary,
+                                                       // Store with 1e7 ms accuracy (1e4 seconds, or ~ 2.7 hours),
+                                                       // which is enough for the purpose of expiring after ~ 30 days.
+                                                       asOf: Math.ceil( Date.now() / 1e7 )
+                                               };
                                        },
 
                                        /**
                                                        this.enabled = true;
                                                        // If null, JSON.parse() will cast to string and re-parse, still null.
                                                        data = JSON.parse( raw );
-                                                       if ( data && typeof data.items === 'object' && data.vary === this.vary ) {
+                                                       if ( data &&
+                                                               typeof data.items === 'object' &&
+                                                               data.vary === this.vary &&
+                                                               // Only use if it's been less than 30 days since the data was written
+                                                               // 30 days = 2,592,000 s = 2,592,000,000 ms = Â± 259e7 ms
+                                                               Date.now() < ( data.asOf * 1e7 ) + 259e7
+                                                       ) {
+                                                               // The data is not corrupt, matches our vary context, and has not expired.
                                                                this.items = data.items;
                                                                return;
                                                        }
index 06c6737..e7137d2 100644 (file)
@@ -74,7 +74,7 @@ function isCompatible( ua ) {
                //
                // Please extend the regex instead of adding new ones!
                // And add a test case to startup.test.js
-               !ua.match( /MSIE 10|webOS\/1\.[0-4]|SymbianOS|NetFront|Opera Mini|S40OviBrowser|MeeGo|Android.+Glass|^Mozilla\/5\.0 .+ Gecko\/$|googleweblight|PLAYSTATION|PlayStation/ )
+               !ua.match( /MSIE 10|NetFront|Opera Mini|S40OviBrowser|MeeGo|Android.+Glass|^Mozilla\/5\.0 .+ Gecko\/$|googleweblight|PLAYSTATION|PlayStation/ )
        );
 }
 
index 7c8df1a..6cd7811 100644 (file)
@@ -221,6 +221,12 @@ $wgAutoloadClasses += [
        # tests/phpunit/unit/includes
        'BadFileLookupTest' => "$testDir/phpunit/unit/includes/BadFileLookupTest.php",
 
+       # tests/phpunit/unit/includes/filebackend
+       'FileBackendGroupTestTrait' => "$testDir/phpunit/unit/includes/filebackend/FileBackendGroupTestTrait.php",
+
+       # tests/phpunit/unit/includes/language
+       'LanguageFallbackTestTrait' => "$testDir/phpunit/unit/includes/language/LanguageFallbackTestTrait.php",
+
        # tests/phpunit/unit/includes/libs/filebackend/fsfile
        'TempFSFileTestTrait' => "$testDir/phpunit/unit/includes/libs/filebackend/fsfile/TempFSFileTestTrait.php",
 
index 0fa91d4..d563235 100644 (file)
@@ -3182,7 +3182,7 @@ Parsoid: Pipes in external links in template parameter
 <p><a rel="nofollow" class="external text" href="http://example.com">link</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external text" href="http://example.com" about="#mwt31" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[{{echo|http://example.com}} link]"}},"i":0}}]}'>link</a></p>
+<p><a rel="mw:ExtLink" href="http://example.com" about="#mwt31" typeof="mw:Transclusion" class="external text" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[{{echo|http://example.com}} link]"}},"i":0}}]}'>link</a></p>
 !! end
 
 !! test
@@ -3193,7 +3193,7 @@ Parsoid: pipe in transclusion parameter
 <p><a rel="nofollow" class="external free" href="http://foo.com/a%7Cb">http://foo.com/a%7Cb</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external free" href="http://foo.com/a%7Cb" about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"http://foo.com/a&amp;#124;b"}},"i":0}}]}'>http://foo.com/a%7Cb</a></p>
+<p><a rel="mw:ExtLink" href="http://foo.com/a%7Cb" about="#mwt1" typeof="mw:Transclusion" class="external free" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"http://foo.com/a&amp;#124;b"}},"i":0}}]}'>http://foo.com/a%7Cb</a></p>
 !! end
 
 !! test
@@ -3220,7 +3220,7 @@ Parsoid: Pipe in template with nested template in external link target in templa
 <p><a rel="nofollow" class="external text" href="http://example.org/index.php?title=Parser_test&amp;action=edit">bar</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external text" href="http://example.org/index.php?title=Parser_test&amp;action=edit" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[{{fullurl:{{FULLPAGENAME}}|action=edit}} bar]"}},"i":0}}]}'>bar</a></p>
+<p><a rel="mw:ExtLink" href="http://example.org/index.php?title=Parser_test&amp;action=edit" typeof="mw:Transclusion" class="external text" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[{{fullurl:{{FULLPAGENAME}}|action=edit}} bar]"}},"i":0}}]}'>bar</a></p>
 !! end
 
 !! test
@@ -4049,7 +4049,7 @@ Definition list with news link containing colon
 <dl><dt><a rel="nofollow" class="external free" href="news:alt.wikipedia.rox">news:alt.wikipedia.rox</a></dt>
 <dd>This isn't even a real newsgroup!</dd></dl>
 !! html/parsoid
-<dl><dt><a rel="mw:ExtLink" class="external free" href="news:alt.wikipedia.rox" data-parsoid='{"stx":"url"}'>news:alt.wikipedia.rox</a></dt><dd data-parsoid='{"stx":"row"}'>This isn't even a real newsgroup!</dd></dl>
+<dl><dt><a rel="mw:ExtLink" href="news:alt.wikipedia.rox" class="external free" data-parsoid='{"stx":"url"}'>news:alt.wikipedia.rox</a></dt><dd data-parsoid='{"stx":"row"}'>This isn't even a real newsgroup!</dd></dl>
 !! end
 
 !! test
@@ -4670,7 +4670,7 @@ Definition Lists: Mixed Lists: Test 13
 !! end
 
 # FIXME: Maybe get rid of this test?
-# From whitelist:
+# From old whitelist description:
 # * The test is wrong, there are two colons where there should be :;
 # * The PHP parser is wrong to close the <dl> after the <dt> containing the <ul>.
 !! test
@@ -4828,9 +4828,9 @@ Numbered: <a rel="nofollow" class="external autonumber" href="http://example.net
 Numbered: <a rel="nofollow" class="external autonumber" href="http://example.com">[3]</a>
 </p>
 !! html/parsoid
-<p>Numbered: <a rel="mw:ExtLink" class="external autonumber" href="http://example.com"></a>
-Numbered: <a rel="mw:ExtLink" class="external autonumber" href="http://example.net"></a>
-Numbered: <a rel="mw:ExtLink" class="external autonumber" href="http://example.com"></a></p>
+<p>Numbered: <a rel="mw:ExtLink" href="http://example.com" class="external autonumber"></a>
+Numbered: <a rel="mw:ExtLink" href="http://example.net" class="external autonumber"></a>
+Numbered: <a rel="mw:ExtLink" href="http://example.com" class="external autonumber"></a></p>
 !!end
 
 !! test
@@ -4869,7 +4869,7 @@ External links: dollar sign in URL (autonumber)
 <p><a rel="nofollow" class="external autonumber" href="http://example.com/1$2345">[1]</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external autonumber" href="http://example.com/1$2345"></a></p>
+<p><a rel="mw:ExtLink" href="http://example.com/1$2345" class="external autonumber"></a></p>
 !!end
 
 !! test
@@ -4882,7 +4882,7 @@ http://example.com/1[2345
 <p><a rel="nofollow" class="external free" href="http://example.com/1">http://example.com/1</a>[2345
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external free" href="http://example.com/1">http://example.com/1</a>[2345</p>
+<p><a rel="mw:ExtLink" href="http://example.com/1" class="external free">http://example.com/1</a>[2345</p>
 !! end
 
 !! test
@@ -4895,7 +4895,7 @@ parsoid=wt2html,html2html
 <p><a rel="nofollow" class="external text" href="http://example.com/1">[2345</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external text" href="http://example.com/1">[2345</a></p>
+<p><a rel="mw:ExtLink" href="http://example.com/1" class="external text">[2345</a></p>
 !!end
 
 # parsoid adds a space before the link name
@@ -4956,7 +4956,7 @@ External links: protocol-relative URL in brackets without text
 <p><a rel="nofollow" class="external autonumber" href="//example.com">[1]</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external autonumber" href="//example.com"></a></p>
+<p><a rel="mw:ExtLink" href="//example.com" class="external autonumber"></a></p>
 !! end
 
 !! test
@@ -4994,7 +4994,7 @@ parsoid=wt2html,wt2wt
 </p><p><a href="http://en.wikipedia.org/wiki/Foo" class="extiw" title="wikipedia:Foo"><span>Bar</span></a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external autonumber" href="http://en.wikipedia.org/wiki/Foo"></a></p>
+<p><a rel="mw:ExtLink" href="http://en.wikipedia.org/wiki/Foo" class="external autonumber"></a></p>
 <p><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/Foo" title="wikipedia:Foo">Bar</a></p>
 <p><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/Foo" title="wikipedia:Foo"><span>Bar</span></a></p>
 !! end
@@ -5043,25 +5043,25 @@ http://example.com/url_with_entity&#60;
 <a rel="nofollow" class="external free" href="http://example.com/url_with_entity">http://example.com/url_with_entity</a>&#60;
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external free" href="http://example.com">http://example.com</a>,
-<a rel="mw:ExtLink" class="external free" href="http://example.com">http://example.com</a>;
-<a rel="mw:ExtLink" class="external free" href="http://example.com">http://example.com</a>\
-<a rel="mw:ExtLink" class="external free" href="http://example.com">http://example.com</a>.
-<a rel="mw:ExtLink" class="external free" href="http://example.com">http://example.com</a>:
-<a rel="mw:ExtLink" class="external free" href="http://example.com">http://example.com</a>!
-<a rel="mw:ExtLink" class="external free" href="http://example.com">http://example.com</a>?
-<a rel="mw:ExtLink" class="external free" href="http://example.com">http://example.com</a>)
-<a rel="mw:ExtLink" class="external free" href="http://example.com/url_with_(brackets)">http://example.com/url_with_(brackets)</a>
-(<a rel="mw:ExtLink" class="external free" href="http://example.com/url_without_brackets">http://example.com/url_without_brackets</a>)
-<a rel="mw:ExtLink" class="external free" href="http://example.com/url_with_entity&amp;">http://example.com/url_with_entity&amp;</a>
-<a rel="mw:ExtLink" class="external free" href="http://example.com/url_with_entity&amp;">http://example.com/url_with_entity&amp;</a>
-<a rel="mw:ExtLink" class="external free" href="http://example.com/url_with_entity&amp;">http://example.com/url_with_entity&amp;</a>
-<a rel="mw:ExtLink" class="external free" href="http://example.com/url_with_entity">http://example.com/url_with_entity</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span>
-<a rel="mw:ExtLink" class="external free" href="http://example.com/url_with_entity">http://example.com/url_with_entity</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#xA0;","srcContent":" "}'> </span>
-<a rel="mw:ExtLink" class="external free" href="http://example.com/url_with_entity">http://example.com/url_with_entity</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#160;","srcContent":" "}'> </span>
-<a rel="mw:ExtLink" class="external free" href="http://example.com/url_with_entity">http://example.com/url_with_entity</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;lt;","srcContent":"&lt;"}'>&lt;</span>
-<a rel="mw:ExtLink" class="external free" href="http://example.com/url_with_entity">http://example.com/url_with_entity</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#x3C;","srcContent":"&lt;"}'>&lt;</span>
-<a rel="mw:ExtLink" class="external free" href="http://example.com/url_with_entity">http://example.com/url_with_entity</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#60;","srcContent":"&lt;"}'>&lt;</span></p>
+<p><a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a>,
+<a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a>;
+<a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a>\
+<a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a>.
+<a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a>:
+<a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a>!
+<a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a>?
+<a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a>)
+<a rel="mw:ExtLink" href="http://example.com/url_with_(brackets)" class="external free">http://example.com/url_with_(brackets)</a>
+(<a rel="mw:ExtLink" href="http://example.com/url_without_brackets" class="external free">http://example.com/url_without_brackets</a>)
+<a rel="mw:ExtLink" href="http://example.com/url_with_entity&amp;" class="external free">http://example.com/url_with_entity&amp;</a>
+<a rel="mw:ExtLink" href="http://example.com/url_with_entity&amp;" class="external free">http://example.com/url_with_entity&amp;</a>
+<a rel="mw:ExtLink" href="http://example.com/url_with_entity&amp;" class="external free">http://example.com/url_with_entity&amp;</a>
+<a rel="mw:ExtLink" href="http://example.com/url_with_entity" class="external free">http://example.com/url_with_entity</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span>
+<a rel="mw:ExtLink" href="http://example.com/url_with_entity" class="external free">http://example.com/url_with_entity</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#xA0;","srcContent":" "}'> </span>
+<a rel="mw:ExtLink" href="http://example.com/url_with_entity" class="external free">http://example.com/url_with_entity</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#160;","srcContent":" "}'> </span>
+<a rel="mw:ExtLink" href="http://example.com/url_with_entity" class="external free">http://example.com/url_with_entity</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;lt;","srcContent":"&lt;"}'>&lt;</span>
+<a rel="mw:ExtLink" href="http://example.com/url_with_entity" class="external free">http://example.com/url_with_entity</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#x3C;","srcContent":"&lt;"}'>&lt;</span>
+<a rel="mw:ExtLink" href="http://example.com/url_with_entity" class="external free">http://example.com/url_with_entity</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#60;","srcContent":"&lt;"}'>&lt;</span></p>
 !! end
 
 !! test
@@ -5074,7 +5074,7 @@ http://example.com/url_with_entity&amp;amp;
 <p><a rel="nofollow" class="external free" href="http://example.com/url_with_entity&amp;amp">http://example.com/url_with_entity&amp;amp</a>;
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external free" href="http://example.com/url_with_entity&amp;amp">http://example.com/url_with_entity&amp;amp</a>;</p>
+<p><a rel="mw:ExtLink" href="http://example.com/url_with_entity&amp;amp" class="external free">http://example.com/url_with_entity&amp;amp</a>;</p>
 !! end
 
 !! test
@@ -5089,7 +5089,7 @@ news:'a'b''c''d e
 </p>
 !! html/parsoid
 <p><b>News:</b> Stuff here</p>
-<p><a rel="mw:ExtLink" class="external free" href="news:'a'b">news:'a'b</a><i>c</i>d e</p>
+<p><a rel="mw:ExtLink" href="news:'a'b" class="external free">news:'a'b</a><i>c</i>d e</p>
 !! end
 
 !! test
@@ -5100,7 +5100,7 @@ External links: with entity
 <p><a rel="nofollow" class="external text" href="http://+www.librarieswithoutborders.org">Libraries without borders</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external text" href="http://+www.librarieswithoutborders.org" data-parsoid='{"a":{"href":"http://+www.librarieswithoutborders.org"},"sa":{"href":"http://&amp;#x20;www.librarieswithoutborders.org"}}'>Libraries without borders</a></p>
+<p><a rel="mw:ExtLink" href="http://+www.librarieswithoutborders.org" class="external text" data-parsoid='{"a":{"href":"http://+www.librarieswithoutborders.org"},"sa":{"href":"http://&amp;#x20;www.librarieswithoutborders.org"}}'>Libraries without borders</a></p>
 !! end
 
 !! test
@@ -5233,7 +5233,7 @@ URL in text: [http://example.com http://example.com]
 <p>URL in text: <a rel="nofollow" class="external text" href="http://example.com">http://example.com</a>
 </p>
 !! html/parsoid
-<p>URL in text: <a rel="mw:ExtLink" class="external text" href="http://example.com">http://example.com</a></p>
+<p>URL in text: <a rel="mw:ExtLink" href="http://example.com" class="external text">http://example.com</a></p>
 !! end
 
 !! test
@@ -5244,7 +5244,7 @@ ja-style clickable images: [http://example.com http://meta.wikimedia.org/upload/
 <p>ja-style clickable images: <a rel="nofollow" class="external text" href="http://example.com"><img src="http://meta.wikimedia.org/upload/f/f1/Ncwikicol.png" alt="Ncwikicol.png"/></a>
 </p>
 !! html/parsoid
-<p>ja-style clickable images: <a rel="mw:ExtLink" class="external text" href="http://example.com"><img src="http://meta.wikimedia.org/upload/f/f1/Ncwikicol.png" alt="Ncwikicol.png" data-parsoid='{"type":"extlink"}'/></a></p>
+<p>ja-style clickable images: <a rel="mw:ExtLink" href="http://example.com" class="external text"><img src="http://meta.wikimedia.org/upload/f/f1/Ncwikicol.png" alt="Ncwikicol.png" data-parsoid='{"type":"extlink"}'/></a></p>
 !! end
 
 !! test
@@ -5264,7 +5264,7 @@ Old &amp; use: http://x&amp;y
 <p>Old &amp; use: <a rel="nofollow" class="external free" href="http://x&amp;y">http://x&amp;y</a>
 </p>
 !! html/parsoid
-<p>Old <span typeof="mw:Entity">&amp;</span> use: <a rel="mw:ExtLink" class="external free" href="http://x&amp;y">http://x&amp;y</a></p>
+<p>Old <span typeof="mw:Entity">&amp;</span> use: <a rel="mw:ExtLink" href="http://x&amp;y" class="external free">http://x&amp;y</a></p>
 !! end
 
 !! test
@@ -5275,7 +5275,7 @@ http://example.com/?foo&#61;bar
 <p><a rel="nofollow" class="external free" href="http://example.com/?foo=bar">http://example.com/?foo=bar</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external free" href="http://example.com/?foo=bar">http://example.com/?foo=bar</a></p>
+<p><a rel="mw:ExtLink" href="http://example.com/?foo=bar" class="external free">http://example.com/?foo=bar</a></p>
 !! end
 
 ##
@@ -5292,7 +5292,7 @@ Old &amp; use: [http://x&y]
 <p>Old &amp; use: <a rel="nofollow" class="external autonumber" href="http://x&amp;y">[1]</a>
 </p>
 !! html/parsoid
-<p>Old <span typeof="mw:Entity">&amp;</span> use: <a rel="mw:ExtLink" class="external autonumber" href="http://x&amp;y"></a></p>
+<p>Old <span typeof="mw:Entity">&amp;</span> use: <a rel="mw:ExtLink" href="http://x&amp;y" class="external autonumber"></a></p>
 !! end
 
 # note that parsoid html is identical to [raw ampersand] case; so html2wt
@@ -5307,7 +5307,7 @@ Old &amp; use: [http://x&amp;y]
 <p>Old &amp; use: <a rel="nofollow" class="external autonumber" href="http://x&amp;y">[1]</a>
 </p>
 !! html/parsoid
-<p>Old <span typeof="mw:Entity">&amp;</span> use: <a rel="mw:ExtLink" class="external autonumber" href="http://x&amp;y"></a></p>
+<p>Old <span typeof="mw:Entity">&amp;</span> use: <a rel="mw:ExtLink" href="http://x&amp;y" class="external autonumber"></a></p>
 !! end
 
 !! test
@@ -5318,7 +5318,7 @@ External links: [raw equals]
 <p><a rel="nofollow" class="external autonumber" href="http://example.com/?foo=bar">[1]</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external autonumber" href="http://example.com/?foo=bar"></a></p>
+<p><a rel="mw:ExtLink" href="http://example.com/?foo=bar" class="external autonumber"></a></p>
 !! end
 
 # note that parsoid html is identical to [raw equals] case; so html2wt
@@ -5333,7 +5333,7 @@ parsoid=wt2html,wt2wt,html2html
 <p><a rel="nofollow" class="external autonumber" href="http://example.com/?foo=bar">[1]</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external autonumber" href="http://example.com/?foo=bar"></a></p>
+<p><a rel="mw:ExtLink" href="http://example.com/?foo=bar" class="external autonumber"></a></p>
 !! end
 
 # xxx parsoid strips the IDN character, so the round-trip tests will
@@ -5348,7 +5348,7 @@ parsoid=wt2html,wt2wt,html2html
 <p><a rel="nofollow" class="external autonumber" href="http://example.com/">[1]</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external autonumber" href="http://example.com/"></a></p>
+<p><a rel="mw:ExtLink" href="http://example.com/" class="external autonumber"></a></p>
 !! end
 
 # FIXME: This test (the IDN characters in the text of a link) is an inconsistency.
@@ -5380,7 +5380,7 @@ http://e&zwnj;xample.com/
 <p><a rel="nofollow" class="external free" href="http://example.com/">http://example.com/</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external free" href="http://example.com/">http://example.com/</a></p>
+<p><a rel="mw:ExtLink" href="http://example.com/" class="external free">http://example.com/</a></p>
 !! end
 
 !! test
@@ -5401,7 +5401,7 @@ External links: URL within URL (T2002)
 <p><a rel="nofollow" class="external autonumber" href="http://www.unausa.org/newindex.asp?place=http://www.unausa.org/programs/mun.asp">[1]</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external autonumber" href="http://www.unausa.org/newindex.asp?place=http://www.unausa.org/programs/mun.asp"></a></p>
+<p><a rel="mw:ExtLink" href="http://www.unausa.org/newindex.asp?place=http://www.unausa.org/programs/mun.asp" class="external autonumber"></a></p>
 !! end
 
 !! test
@@ -5439,7 +5439,7 @@ http://www.example.com/<b>html</b>
 <p><a rel="nofollow" class="external free" href="http://www.example.com/">http://www.example.com/</a><b>html</b>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external free" href="http://www.example.com/" data-parsoid='{"stx":"url"}'>http://www.example.com/</a><b data-parsoid='{"stx":"html"}'>html</b></p>
+<p><a rel="mw:ExtLink" href="http://www.example.com/" class="external free" data-parsoid='{"stx":"url"}'>http://www.example.com/</a><b data-parsoid='{"stx":"html"}'>html</b></p>
 !! end
 
 !! test
@@ -5512,8 +5512,8 @@ parsoid=wt2html,html2html
 </p><p><a rel="nofollow" class="external text" href="http://example.com">test </a><a href="/index.php?title=Wikilink&amp;action=edit&amp;redlink=1" class="new" title="Wikilink (page does not exist)">wikilink</a><a rel="nofollow" class="external text" href="http://example.com"> embedded in ext link</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external autonumber" href="http://example.com"></a><a rel="mw:WikiLink" href="./Wikilink" title="Wikilink">wikilink</a><span> embedded in ext link</span></p>
-<p><a rel="mw:ExtLink" class="external text" href="http://example.com">test </a><a rel="mw:WikiLink" href="./Wikilink" title="Wikilink">wikilink</a><span> embedded in ext link</span></p>
+<p><a rel="mw:ExtLink" href="http://example.com" class="external autonumber"></a><a rel="mw:WikiLink" href="./Wikilink" title="Wikilink">wikilink</a><span> embedded in ext link</span></p>
+<p><a rel="mw:ExtLink" href="http://example.com" class="external text">test </a><a rel="mw:WikiLink" href="./Wikilink" title="Wikilink">wikilink</a><span> embedded in ext link</span></p>
 !! end
 
 !! test
@@ -5557,8 +5557,8 @@ parsoid=wt2html
 </p><p>{{echo|[[Foo}}
 </p>
 !! html/parsoid
-<p>[<a rel="mw:ExtLink" class="external free" href="http://example.com">http://example.com</a> x</p>
-<p typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[http://example.com x"}},"i":0}}]}'>[<a rel="mw:ExtLink" class="external free" href="http://example.com">http://example.com</a> x</p>
+<p>[<a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a> x</p>
+<p typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[http://example.com x"}},"i":0}}]}'>[<a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a> x</p>
 <p>[[Foo</p>
 <p>{{echo|[[Foo}}</p>
 !! end
@@ -5595,6 +5595,27 @@ parsoid=wt2html
 <p>[[Foo|<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"]]"}},"i":0}}]}'>]]</span></p>
 !! end
 
+!! article
+Template:pipe page
+!! text
+Main|Page
+!! endarticle
+
+## FIXME: Parsoid doesn't support this and may never.  See T226523
+!! test
+Template returning pipe used in wikilink target
+!! wikitext
+[[{{pipe page}}]]
+!! html/php+tidy
+<p><a href="/index.php?title=Main&amp;action=edit&amp;redlink=1" class="new" title="Main (page does not exist)">Page</a>
+</p>
+!! html/parsoid
+<p>[[<span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"pipe page","href":"./Template:Pipe_page"},"params":{},"i":0}}]}'>Main|Page</span>]]</p>
+!! end
+
+# Italic/link nesting is changed in this test, but the rendered result is the
+# same. Currently the result is actually an improvement over the MediaWiki
+# output.
 !! test
 T4702: Mismatched <i>, <b> and <a> tags are invalid
 !! wikitext
@@ -5603,13 +5624,19 @@ T4702: Mismatched <i>, <b> and <a> tags are invalid
 ''Something [http://example.com in italic'']
 ''Something [http://example.com mixed''''', even bold]'''
 '''''Now [http://example.com both''''']
-!! html
+!! html/php
 <p><a rel="nofollow" class="external text" href="http://example.com"><i>text</i></a>
 <a rel="nofollow" class="external text" href="http://example.com"><b>text</b></a>
 <i>Something </i><a rel="nofollow" class="external text" href="http://example.com"><i>in italic</i></a>
 <i>Something </i><a rel="nofollow" class="external text" href="http://example.com"><i>mixed</i><b>, even bold</b></a>
 <i><b>Now </b></i><a rel="nofollow" class="external text" href="http://example.com"><i><b>both</b></i></a>
 </p>
+!! html/parsoid
+<p><i data-parsoid='{"autoInsertedEnd":true}'><a rel="mw:ExtLink" href="http://example.com" class="external text">text<i data-parsoid='{"autoInsertedEnd":true}'></i></a></i>
+<a rel="mw:ExtLink" href="http://example.com" class="external text"><b data-parsoid='{"autoInsertedEnd":true}'>text</b></a><b data-parsoid='{"autoInsertedEnd":true}'></b>
+<i data-parsoid='{"autoInsertedEnd":true}'>Something <a rel="mw:ExtLink" href="http://example.com" class="external text">in italic<i data-parsoid='{"autoInsertedEnd":true}'></i></a></i>
+<i>Something <a rel="mw:ExtLink" href="http://example.com" class="external text">mixed<b data-parsoid='{"autoInsertedEnd":true}'><i data-parsoid='{"autoInsertedEnd":true}'>, even bold</i></b></a>'</i>
+<b data-parsoid='{"autoInsertedEnd":true}'><i data-parsoid='{"autoInsertedEnd":true}'>Now <a rel="mw:ExtLink" href="http://example.com" class="external text">both<b data-parsoid='{"autoInsertedEnd":true}'><i data-parsoid='{"autoInsertedEnd":true}'></i></b></a></i></b></p>
 !! end
 
 
@@ -5621,7 +5648,7 @@ http://www.example.com/?title=AT%26T
 <p><a rel="nofollow" class="external free" href="http://www.example.com/?title=AT%26T">http://www.example.com/?title=AT%26T</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external free" href="http://www.example.com/?title=AT%26T">http://www.example.com/?title=AT%26T</a></p>
+<p><a rel="mw:ExtLink" href="http://www.example.com/?title=AT%26T" class="external free">http://www.example.com/?title=AT%26T</a></p>
 !! end
 
 # According to https://www.w3.org/TR/2011/WD-html5-20110525/Overview.html#parsing-urls a plain
@@ -5634,7 +5661,7 @@ http://www.example.com/?title=100%25_Bran
 <p><a rel="nofollow" class="external free" href="http://www.example.com/?title=100%25_Bran">http://www.example.com/?title=100%25_Bran</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external free" href="http://www.example.com/?title=100%25_Bran">http://www.example.com/?title=100%25_Bran</a></p>
+<p><a rel="mw:ExtLink" href="http://www.example.com/?title=100%25_Bran" class="external free">http://www.example.com/?title=100%25_Bran</a></p>
 !! end
 
 !! test
@@ -5645,7 +5672,7 @@ http://www.example.com/?title=Ben-Hur_%281959_film%29
 <p><a rel="nofollow" class="external free" href="http://www.example.com/?title=Ben-Hur_%281959_film%29">http://www.example.com/?title=Ben-Hur_%281959_film%29</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external free" href="http://www.example.com/?title=Ben-Hur_%281959_film%29">http://www.example.com/?title=Ben-Hur_%281959_film%29</a></p>
+<p><a rel="mw:ExtLink" href="http://www.example.com/?title=Ben-Hur_%281959_film%29" class="external free">http://www.example.com/?title=Ben-Hur_%281959_film%29</a></p>
 !! end
 
 
@@ -5657,7 +5684,7 @@ T6781: %26 in autonumber URL
 <p><a rel="nofollow" class="external autonumber" href="http://www.example.com/?title=AT%26T">[1]</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external autonumber" href="http://www.example.com/?title=AT%26T"></a></p>
+<p><a rel="mw:ExtLink" href="http://www.example.com/?title=AT%26T" class="external autonumber"></a></p>
 !! end
 
 !! test
@@ -5668,7 +5695,7 @@ T6781, T7267: %26 in autonumber URL
 <p><a rel="nofollow" class="external autonumber" href="http://www.example.com/?title=100%25_Bran">[1]</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external autonumber" href="http://www.example.com/?title=100%25_Bran"></a></p>
+<p><a rel="mw:ExtLink" href="http://www.example.com/?title=100%25_Bran" class="external autonumber"></a></p>
 !! end
 
 !! test
@@ -5679,7 +5706,7 @@ T6781, T7267: %28, %29 in autonumber URL
 <p><a rel="nofollow" class="external autonumber" href="http://www.example.com/?title=Ben-Hur_%281959_film%29">[1]</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external autonumber" href="http://www.example.com/?title=Ben-Hur_%281959_film%29"></a></p>
+<p><a rel="mw:ExtLink" href="http://www.example.com/?title=Ben-Hur_%281959_film%29" class="external autonumber"></a></p>
 !! end
 
 
@@ -5691,7 +5718,7 @@ T6781: %26 in bracketed URL
 <p><a rel="nofollow" class="external text" href="http://www.example.com/?title=AT%26T">link</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external text" href="http://www.example.com/?title=AT%26T">link</a></p>
+<p><a rel="mw:ExtLink" href="http://www.example.com/?title=AT%26T" class="external text">link</a></p>
 !! end
 
 !! test
@@ -5711,7 +5738,7 @@ T6781, T7267: %28, %29 in bracketed URL
 <p><a rel="nofollow" class="external text" href="http://www.example.com/?title=Ben-Hur_%281959_film%29">link</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external text" href="http://www.example.com/?title=Ben-Hur_%281959_film%29">link</a></p>
+<p><a rel="mw:ExtLink" href="http://www.example.com/?title=Ben-Hur_%281959_film%29" class="external text">link</a></p>
 !! end
 
 !! test
@@ -5725,8 +5752,8 @@ External link containing a period in the anchor. (T65947)
 </p><p><a rel="nofollow" class="external text" href="//foo.org/bar.">bang</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external text" href="//foo.org/bar#baz.">bang</a></p>
-<p><a rel="mw:ExtLink" class="external text" href="//foo.org/bar.">bang</a></p>
+<p><a rel="mw:ExtLink" href="//foo.org/bar#baz." class="external text">bang</a></p>
+<p><a rel="mw:ExtLink" href="//foo.org/bar." class="external text">bang</a></p>
 !! end
 
 !! test
@@ -5740,8 +5767,8 @@ External link containing a single quote. (T65947)
 </p><p><a rel="nofollow" class="external text" href="//foo.org/bar&#39;baz">bang</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external autonumber" href="//foo.org/bar'baz"></a></p>
-<p><a rel="mw:ExtLink" class="external text" href="//foo.org/bar'baz">bang</a></p>
+<p><a rel="mw:ExtLink" href="//foo.org/bar'baz" class="external autonumber"></a></p>
+<p><a rel="mw:ExtLink" href="//foo.org/bar'baz" class="external text">bang</a></p>
 !! end
 
 !! test
@@ -5771,7 +5798,7 @@ External link containing double-single-quotes with no space separating the url f
 <p><a rel="nofollow" class="external text" href="http://www.musee-picasso.fr/pages/page_id18528_u1l2.htm"><i>La muerte de Casagemas</i> (1901) en el sitio de </a><a href="/index.php?title=Museo_Picasso_(Par%C3%ADs)&amp;action=edit&amp;redlink=1" class="new" title="Museo Picasso (París) (page does not exist)">Museo Picasso</a>.
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external text" href="http://www.musee-picasso.fr/pages/page_id18528_u1l2.htm"><i>La muerte de Casagemas</i> (1901) en el sitio de </a><a rel="mw:WikiLink" href="./Museo_Picasso_(París)" title="Museo Picasso (París)">Museo Picasso</a><span>.</span></p>
+<p><a rel="mw:ExtLink" href="http://www.musee-picasso.fr/pages/page_id18528_u1l2.htm" class="external text"><i>La muerte de Casagemas</i> (1901) en el sitio de </a><a rel="mw:WikiLink" href="./Museo_Picasso_(París)" title="Museo Picasso (París)">Museo Picasso</a><span>.</span></p>
 !! end
 
 !! test
@@ -5782,7 +5809,7 @@ External link with comments in link text
 <p><a rel="nofollow" class="external text" href="http://www.google.com">Google </a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external text" href="http://www.google.com">Google <!-- comment --></a></p>
+<p><a rel="mw:ExtLink" href="http://www.google.com" class="external text">Google <!-- comment --></a></p>
 !! end
 
 !! test
@@ -5793,7 +5820,7 @@ External link to bare IPv4 address
 <p><a rel="nofollow" class="external text" href="http://192.168.0.1">Link</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external text" href="http://192.168.0.1">Link</a></p>
+<p><a rel="mw:ExtLink" href="http://192.168.0.1" class="external text">Link</a></p>
 !! end
 
 !! test
@@ -5825,9 +5852,9 @@ http://example.com/index.php?foozoid&#x5B;&#x5D;=bar
 </p><p><a rel="nofollow" class="external free" href="http://example.com/index.php?foozoid%5B%5D=bar">http://example.com/index.php?foozoid%5B%5D=bar</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external free" href="http://example.com/index.php?foozoid%5B%5D=bar">http://example.com/index.php?foozoid%5B%5D=bar</a></p>
+<p><a rel="mw:ExtLink" href="http://example.com/index.php?foozoid%5B%5D=bar" class="external free">http://example.com/index.php?foozoid%5B%5D=bar</a></p>
 
-<p><a rel="mw:ExtLink" class="external free" href="http://example.com/index.php?foozoid%5B%5D=bar" data-parsoid='{"stx":"url","a":{"href":"http://example.com/index.php?foozoid%5B%5D=bar"},"sa":{"href":"http://example.com/index.php?foozoid&amp;#x5B;&amp;#x5D;=bar"}}'>http://example.com/index.php?foozoid%5B%5D=bar</a></p>
+<p><a rel="mw:ExtLink" href="http://example.com/index.php?foozoid%5B%5D=bar" class="external free" data-parsoid='{"stx":"url","a":{"href":"http://example.com/index.php?foozoid%5B%5D=bar"},"sa":{"href":"http://example.com/index.php?foozoid&amp;#x5B;&amp;#x5D;=bar"}}'>http://example.com/index.php?foozoid%5B%5D=bar</a></p>
 !! end
 
 !! test
@@ -5873,24 +5900,24 @@ Examples from RFC 2732, section 2:
 <li><a rel="nofollow" class="external free" href="http://[::FFFF:129.144.52.38]:80/index.html">http://[::FFFF:129.144.52.38]:80/index.html</a></li>
 <li><a rel="nofollow" class="external free" href="http://[2010:836B:4179::836B:4179]">http://[2010:836B:4179::836B:4179]</a></li></ul>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external free" href="http://[2404:130:0:1000::187:2]/index.php">http://[2404:130:0:1000::187:2]/index.php</a></p>
+<p><a rel="mw:ExtLink" href="http://[2404:130:0:1000::187:2]/index.php" class="external free">http://[2404:130:0:1000::187:2]/index.php</a></p>
 
 <p>Examples from <a href="https://tools.ietf.org/html/rfc2373" rel="mw:ExtLink" class="external mw-magiclink">RFC 2373</a>, section 2.2:</p>
-<ul><li><a rel="mw:ExtLink" class="external free" href="http://[1080::8:800:200C:417A]/unicast">http://[1080::8:800:200C:417A]/unicast</a></li>
-<li><a rel="mw:ExtLink" class="external free" href="http://[FF01::101]/multicast">http://[FF01::101]/multicast</a></li>
-<li><a rel="mw:ExtLink" class="external free" href="http://[::1]/loopback">http://[::1]/loopback</a></li>
-<li><a rel="mw:ExtLink" class="external free" href="http://[::]/unspecified">http://[::]/unspecified</a></li>
-<li><a rel="mw:ExtLink" class="external free" href="http://[::13.1.68.3]/ipv4compat">http://[::13.1.68.3]/ipv4compat</a></li>
-<li><a rel="mw:ExtLink" class="external free" href="http://[::FFFF:129.144.52.38]/ipv4compat">http://[::FFFF:129.144.52.38]/ipv4compat</a></li></ul>
+<ul><li><a rel="mw:ExtLink" href="http://[1080::8:800:200C:417A]/unicast" class="external free">http://[1080::8:800:200C:417A]/unicast</a></li>
+<li><a rel="mw:ExtLink" href="http://[FF01::101]/multicast" class="external free">http://[FF01::101]/multicast</a></li>
+<li><a rel="mw:ExtLink" href="http://[::1]/loopback" class="external free">http://[::1]/loopback</a></li>
+<li><a rel="mw:ExtLink" href="http://[::]/unspecified" class="external free">http://[::]/unspecified</a></li>
+<li><a rel="mw:ExtLink" href="http://[::13.1.68.3]/ipv4compat" class="external free">http://[::13.1.68.3]/ipv4compat</a></li>
+<li><a rel="mw:ExtLink" href="http://[::FFFF:129.144.52.38]/ipv4compat" class="external free">http://[::FFFF:129.144.52.38]/ipv4compat</a></li></ul>
 
 <p>Examples from <a href="https://tools.ietf.org/html/rfc2732" rel="mw:ExtLink" class="external mw-magiclink">RFC 2732</a>, section 2:</p>
-<ul><li><a rel="mw:ExtLink" class="external free" href="http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html">http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html</a></li>
-<li><a rel="mw:ExtLink" class="external free" href="http://[1080:0:0:0:8:800:200C:417A]/index.html">http://[1080:0:0:0:8:800:200C:417A]/index.html</a></li>
-<li><a rel="mw:ExtLink" class="external free" href="http://[3ffe:2a00:100:7031::1]">http://[3ffe:2a00:100:7031::1]</a></li>
-<li><a rel="mw:ExtLink" class="external free" href="http://[1080::8:800:200C:417A]/foo">http://[1080::8:800:200C:417A]/foo</a></li>
-<li><a rel="mw:ExtLink" class="external free" href="http://[::192.9.5.5]/ipng">http://[::192.9.5.5]/ipng</a></li>
-<li><a rel="mw:ExtLink" class="external free" href="http://[::FFFF:129.144.52.38]:80/index.html">http://[::FFFF:129.144.52.38]:80/index.html</a></li>
-<li><a rel="mw:ExtLink" class="external free" href="http://[2010:836B:4179::836B:4179]">http://[2010:836B:4179::836B:4179]</a></li></ul>
+<ul><li><a rel="mw:ExtLink" href="http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html" class="external free">http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html</a></li>
+<li><a rel="mw:ExtLink" href="http://[1080:0:0:0:8:800:200C:417A]/index.html" class="external free">http://[1080:0:0:0:8:800:200C:417A]/index.html</a></li>
+<li><a rel="mw:ExtLink" href="http://[3ffe:2a00:100:7031::1]" class="external free">http://[3ffe:2a00:100:7031::1]</a></li>
+<li><a rel="mw:ExtLink" href="http://[1080::8:800:200C:417A]/foo" class="external free">http://[1080::8:800:200C:417A]/foo</a></li>
+<li><a rel="mw:ExtLink" href="http://[::192.9.5.5]/ipng" class="external free">http://[::192.9.5.5]/ipng</a></li>
+<li><a rel="mw:ExtLink" href="http://[::FFFF:129.144.52.38]:80/index.html" class="external free">http://[::FFFF:129.144.52.38]:80/index.html</a></li>
+<li><a rel="mw:ExtLink" href="http://[2010:836B:4179::836B:4179]" class="external free">http://[2010:836B:4179::836B:4179]</a></li></ul>
 !! end
 
 !! test
@@ -5936,24 +5963,24 @@ Examples from RFC 2732, section 2:
 <li><a rel="nofollow" class="external text" href="http://[::FFFF:129.144.52.38]:80/index.html">6</a></li>
 <li><a rel="nofollow" class="external text" href="http://[2010:836B:4179::836B:4179]">7</a></li></ul>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external text" href="http://[2404:130:0:1000::187:2]/index.php">test</a></p>
+<p><a rel="mw:ExtLink" href="http://[2404:130:0:1000::187:2]/index.php" class="external text">test</a></p>
 
 <p>Examples from <a href="https://tools.ietf.org/html/rfc2373" rel="mw:ExtLink" class="external mw-magiclink">RFC 2373</a>, section 2.2:</p>
-<ul><li><a rel="mw:ExtLink" class="external text" href="http://[1080::8:800:200C:417A]">unicast</a></li>
-<li><a rel="mw:ExtLink" class="external text" href="http://[FF01::101]">multicast</a></li>
-<li><a rel="mw:ExtLink" class="external text" href="http://[::1]/">loopback</a></li>
-<li><a rel="mw:ExtLink" class="external text" href="http://[::]">unspecified</a></li>
-<li><a rel="mw:ExtLink" class="external text" href="http://[::13.1.68.3]">ipv4compat</a></li>
-<li><a rel="mw:ExtLink" class="external text" href="http://[::FFFF:129.144.52.38]">ipv4compat</a></li></ul>
+<ul><li><a rel="mw:ExtLink" href="http://[1080::8:800:200C:417A]" class="external text">unicast</a></li>
+<li><a rel="mw:ExtLink" href="http://[FF01::101]" class="external text">multicast</a></li>
+<li><a rel="mw:ExtLink" href="http://[::1]/" class="external text">loopback</a></li>
+<li><a rel="mw:ExtLink" href="http://[::]" class="external text">unspecified</a></li>
+<li><a rel="mw:ExtLink" href="http://[::13.1.68.3]" class="external text">ipv4compat</a></li>
+<li><a rel="mw:ExtLink" href="http://[::FFFF:129.144.52.38]" class="external text">ipv4compat</a></li></ul>
 
 <p>Examples from <a href="https://tools.ietf.org/html/rfc2732" rel="mw:ExtLink" class="external mw-magiclink">RFC 2732</a>, section 2:</p>
-<ul><li><a rel="mw:ExtLink" class="external text" href="http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html">1</a></li>
-<li><a rel="mw:ExtLink" class="external text" href="http://[1080:0:0:0:8:800:200C:417A]/index.html">2</a></li>
-<li><a rel="mw:ExtLink" class="external text" href="http://[3ffe:2a00:100:7031::1]">3</a></li>
-<li><a rel="mw:ExtLink" class="external text" href="http://[1080::8:800:200C:417A]/foo">4</a></li>
-<li><a rel="mw:ExtLink" class="external text" href="http://[::192.9.5.5]/ipng">5</a></li>
-<li><a rel="mw:ExtLink" class="external text" href="http://[::FFFF:129.144.52.38]:80/index.html">6</a></li>
-<li><a rel="mw:ExtLink" class="external text" href="http://[2010:836B:4179::836B:4179]">7</a></li></ul>
+<ul><li><a rel="mw:ExtLink" href="http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html" class="external text">1</a></li>
+<li><a rel="mw:ExtLink" href="http://[1080:0:0:0:8:800:200C:417A]/index.html" class="external text">2</a></li>
+<li><a rel="mw:ExtLink" href="http://[3ffe:2a00:100:7031::1]" class="external text">3</a></li>
+<li><a rel="mw:ExtLink" href="http://[1080::8:800:200C:417A]/foo" class="external text">4</a></li>
+<li><a rel="mw:ExtLink" href="http://[::192.9.5.5]/ipng" class="external text">5</a></li>
+<li><a rel="mw:ExtLink" href="http://[::FFFF:129.144.52.38]:80/index.html" class="external text">6</a></li>
+<li><a rel="mw:ExtLink" href="http://[2010:836B:4179::836B:4179]" class="external text">7</a></li></ul>
 !! end
 
 !! test
@@ -5999,7 +6026,7 @@ Non-extlinks in brackets
 [<span about="#mwt22" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span>l's] errand
 [<span about="#mwt23" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span>l's errand]
 [url=<span about="#mwt24" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span>]
-[url=<a rel="mw:ExtLink" class="external free" href="http://example.com">http://example.com</a>]
+[url=<a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a>]
 [http:// bare protocols don't count]</p>
 !! end
 
@@ -6011,7 +6038,7 @@ Percent encoding in external links
 <p><a rel="nofollow" class="external text" href="https://github.com/search?l=&amp;q=ResourceLoader+%40wikimedia">Search</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external text" href="https://github.com/search?l=&amp;q=ResourceLoader+%40wikimedia">Search</a></p>
+<p><a rel="mw:ExtLink" href="https://github.com/search?l=&amp;q=ResourceLoader+%40wikimedia" class="external text">Search</a></p>
 !! end
 
 !! test
@@ -6022,7 +6049,7 @@ http://example.com
 <p><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external free" href="http://example.com">http://example.com</a></p>
+<p><a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a></p>
 !! end
 
 !! test
@@ -6054,14 +6081,14 @@ http://example.com/a)b
 </p><p><a rel="nofollow" class="external text" href="http://example.com)">foo</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external free" href="http://example.com">http://example.com</a>)</p>
-<p><a rel="mw:ExtLink" class="external free" href="http://example.com/test">http://example.com/test</a>)</p>
-<p><a rel="mw:ExtLink" class="external free" href="http://example.com/(test)">http://example.com/(test)</a></p>
-<p><a rel="mw:ExtLink" class="external free" href="http://example.com/((test)">http://example.com/((test)</a></p>
-<p>(<a rel="mw:ExtLink" class="external free" href="http://example.com/(test))">http://example.com/(test))</a></p>
-<p>(<a rel="mw:ExtLink" class="external free" href="http://example.com/(test)))))">http://example.com/(test)))))</a></p>
-<p><a rel="mw:ExtLink" class="external free" href="http://example.com/a)b">http://example.com/a)b</a></p>
-<p><a rel="mw:ExtLink" class="external text" href="http://example.com)">foo</a></p>
+<p><a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a>)</p>
+<p><a rel="mw:ExtLink" href="http://example.com/test" class="external free">http://example.com/test</a>)</p>
+<p><a rel="mw:ExtLink" href="http://example.com/(test)" class="external free">http://example.com/(test)</a></p>
+<p><a rel="mw:ExtLink" href="http://example.com/((test)" class="external free">http://example.com/((test)</a></p>
+<p>(<a rel="mw:ExtLink" href="http://example.com/(test))" class="external free">http://example.com/(test))</a></p>
+<p>(<a rel="mw:ExtLink" href="http://example.com/(test)))))" class="external free">http://example.com/(test)))))</a></p>
+<p><a rel="mw:ExtLink" href="http://example.com/a)b" class="external free">http://example.com/a)b</a></p>
+<p><a rel="mw:ExtLink" href="http://example.com)" class="external text">foo</a></p>
 !! end
 
 !! test
@@ -6075,9 +6102,9 @@ Parenthesis in external links, w/ transclusion or comment
 </p><p>(<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>)
 </p>
 !! html/parsoid
-<p>(<a typeof="mw:ExpandedAttrs" about="#mwt2" rel="mw:ExtLink" class="external free" href="http://example.com/hi" data-parsoid='{"stx":"url","a":{"href":"http://example.com/hi"},"sa":{"href":"http://example.com/{{echo|hi}}"}}' data-mw='{"attribs":[[{"txt":"href"},{"html":"http://example.com/&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[20,31,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"hi\"}},\"i\":0}}]}&#39;>hi&lt;/span>"}]]}'>http://example.com/hi</a>)</p>
+<p>(<a typeof="mw:ExpandedAttrs" about="#mwt2" rel="mw:ExtLink" href="http://example.com/hi" class="external free" data-parsoid='{"stx":"url","a":{"href":"http://example.com/hi"},"sa":{"href":"http://example.com/{{echo|hi}}"}}' data-mw='{"attribs":[[{"txt":"href"},{"html":"http://example.com/&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[20,31,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"hi\"}},\"i\":0}}]}&#39;>hi&lt;/span>"}]]}'>http://example.com/hi</a>)</p>
 
-<p>(<a rel="mw:ExtLink" class="external free" href="http://example.com" data-parsoid='{"stx":"url","a":{"href":"http://example.com"},"sa":{"href":"http://example.com&lt;!-- hi -->"}}'>http://example.com</a>)</p>
+<p>(<a rel="mw:ExtLink" href="http://example.com" class="external free" data-parsoid='{"stx":"url","a":{"href":"http://example.com"},"sa":{"href":"http://example.com&lt;!-- hi -->"}}'>http://example.com</a>)</p>
 !! end
 
 !! test
@@ -6654,6 +6681,8 @@ Allow +/- in 2nd and later cells in a row, in 1st cell when td-attrs are present
 </td></tr></table>
 !!end
 
+# Differences between Parsoid and PHP re: trailing whitespace in a
+# table cell.
 !! test
 Table rowspan
 !! wikitext
@@ -6665,7 +6694,7 @@ Table rowspan
 |Cell 1, row 2
 |Cell 3, row 2
 |}
-!! html
+!! html/php
 <table border="1">
 <tr>
 <td>Cell 1, row 1
@@ -6679,6 +6708,15 @@ Table rowspan
 </td>
 <td>Cell 3, row 2
 </td></tr></table>
+!! html/parsoid
+<table border="1">
+<tbody><tr data-parsoid='{"autoInsertedStart":true}'><td>Cell 1, row 1</td>
+<td rowspan="2">Cell 2, row 1 (and 2)</td>
+<td>Cell 3, row 1</td></tr>
+<tr data-parsoid='{"startTagSrc":"|-"}'>
+<td>Cell 1, row 2</td>
+<td>Cell 3, row 2</td></tr>
+</tbody></table>
 !! end
 
 !! test
@@ -6771,7 +6809,7 @@ parsoid=wt2html,html2html
 !! html/parsoid
 <table><tbody>
 <tr>
-<td data-parsoid='{"startTagSrc":"| ","attrSepSrc":"|","autoInsertedEnd":true}'>[<a rel="mw:ExtLink" class="external free" href="ftp://%7Cx" data-parsoid='{"stx":"url","a":{"href":"ftp://%7Cx"},"sa":{"href":"ftp://|x"}}'>ftp://%7Cx</a></td><td data-parsoid='{"stx":"row","autoInsertedEnd":true}'>]" onmouseover="alert(document.cookie)">test</td></tr></tbody></table>
+<td data-parsoid='{"startTagSrc":"| ","attrSepSrc":"|","autoInsertedEnd":true}'>[<a rel="mw:ExtLink" href="ftp://%7Cx" class="external free" data-parsoid='{"stx":"url","a":{"href":"ftp://%7Cx"},"sa":{"href":"ftp://|x"}}'>ftp://%7Cx</a></td><td data-parsoid='{"stx":"row","autoInsertedEnd":true}'>]" onmouseover="alert(document.cookie)">test</td></tr></tbody></table>
 !! end
 
 !! test
@@ -7695,13 +7733,17 @@ Broken link
 </p>
 !! end
 
+# The PHP parser strips the hash fragment for non-existent pages, but
+# Parsoid does not. (T227693)
 !! test
 Broken link with fragment
 !! wikitext
 [[Zigzagzogzagzig#zug]]
-!! html
+!! html/php
 <p><a href="/index.php?title=Zigzagzogzagzig&amp;action=edit&amp;redlink=1" class="new" title="Zigzagzogzagzig (page does not exist)">Zigzagzogzagzig#zug</a>
 </p>
+!! html/parsoid
+<p><a rel="mw:WikiLink" href="./Zigzagzogzagzig#zug" title="Zigzagzogzagzig" data-parsoid="{&quot;tsr&quot;:[0,23],&quot;src&quot;:&quot;[[Zigzagzogzagzig#zug]]&quot;,&quot;bsp&quot;:[0,23],&quot;stx&quot;:&quot;simple&quot;}">Zigzagzogzagzig#zug</a></p>
 !! end
 
 !! test
@@ -7713,13 +7755,16 @@ Special page link with fragment
 </p>
 !! end
 
+# Parsoid does not strip fragment from red links: T227693
 !! test
 Nonexistent special page link with fragment
 !! wikitext
 [[Special:ThisNameWillHopefullyNeverBeUsed#anchor]]
-!! html
+!! html/php
 <p><a href="/wiki/Special:ThisNameWillHopefullyNeverBeUsed" class="new" title="Special:ThisNameWillHopefullyNeverBeUsed (page does not exist)">Special:ThisNameWillHopefullyNeverBeUsed#anchor</a>
 </p>
+!! html/parsoid
+<p><a rel="mw:WikiLink" href="./Special:ThisNameWillHopefullyNeverBeUsed#anchor" title="Special:ThisNameWillHopefullyNeverBeUsed">Special:ThisNameWillHopefullyNeverBeUsed#anchor</a></p>
 !! end
 
 !! test
@@ -8170,7 +8215,7 @@ Plain link to URL
 <p>[<a rel="nofollow" class="external autonumber" href="http://www.example.com">[1]</a>]
 </p>
 !! html/parsoid
-<p>[<a rel="mw:ExtLink" class="external autonumber" href="http://www.example.com"></a>]</p>
+<p>[<a rel="mw:ExtLink" href="http://www.example.com" class="external autonumber"></a>]</p>
 !! end
 
 !! test
@@ -8199,7 +8244,7 @@ Plain link to protocol-relative URL
 <p>[<a rel="nofollow" class="external autonumber" href="//www.example.com">[1]</a>]
 </p>
 !! html/parsoid
-<p>[<a rel="mw:ExtLink" class="external autonumber" href="//www.example.com"></a>]</p>
+<p>[<a rel="mw:ExtLink" href="//www.example.com" class="external autonumber"></a>]</p>
 !! end
 
 !! test
@@ -8242,7 +8287,7 @@ Piped link to URL: [[http://www.example.com|an example URL]]
 <p>Piped link to URL: [<a rel="nofollow" class="external text" href="http://www.example.com%7Can">example URL</a>]
 </p>
 !! html/parsoid
-<p>Piped link to URL: [<a rel="mw:ExtLink" class="external text" href="http://www.example.com%7Can" data-parsoid='{"a":{"href":"http://www.example.com%7Can"},"sa":{"href":"http://www.example.com|an"}}'>example URL</a>]</p>
+<p>Piped link to URL: [<a rel="mw:ExtLink" href="http://www.example.com%7Can" class="external text" data-parsoid='{"a":{"href":"http://www.example.com%7Can"},"sa":{"href":"http://www.example.com|an"}}'>example URL</a>]</p>
 !! end
 
 !! test
@@ -8264,13 +8309,13 @@ parsoid=wt2html
 </p><p>[<a rel="nofollow" class="external free" href="http://www.example.com">http://www.example.com</a> 
 </p>
 !! html/parsoid
-<p about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[http://www.example.com "},"2":{"wt":"123]"}},"i":0}}]}'>[<a rel="mw:ExtLink" class="external free" href="http://www.example.com">http://www.example.com</a> </p>
+<p about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[http://www.example.com "},"2":{"wt":"123]"}},"i":0}}]}'>[<a rel="mw:ExtLink" href="http://www.example.com" class="external free">http://www.example.com</a> </p>
 
-<p about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[[http://www.example.com |123]]"}},"i":0}}]}'>[<a rel="mw:ExtLink" class="external text" href="http://www.example.com">|123</a>]</p>
+<p about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[[http://www.example.com |123]]"}},"i":0}}]}'>[<a rel="mw:ExtLink" href="http://www.example.com" class="external text">|123</a>]</p>
 
-<p>{{echo|[<a rel="mw:ExtLink" class="external text" href="http://www.example.com" data-parsoid='{"targetOff":114,"contentOffsets":[114,118],"dsr":[90,119,24,1]}'>|123</a>}}</p>
+<p>{{echo|[<a rel="mw:ExtLink" href="http://www.example.com" class="external text" data-parsoid='{"targetOff":114,"contentOffsets":[114,118],"dsr":[90,119,24,1]}'>|123</a>}}</p>
 
-<p about="#mwt3" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[http://www.example.com "},"2":{"wt":"123]]"}},"i":0}}]}'>[<a rel="mw:ExtLink" class="external free" href="http://www.example.com">http://www.example.com</a> </p>
+<p about="#mwt3" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[http://www.example.com "},"2":{"wt":"123]]"}},"i":0}}]}'>[<a rel="mw:ExtLink" href="http://www.example.com" class="external free">http://www.example.com</a> </p>
 !! end
 
 !! test
@@ -8867,8 +8912,8 @@ Interwiki links that cannot be represented in wiki syntax
 <p><a rel="mw:WikiLink/Interwiki" href="http://www.usemod.com/cgi-bin/mb.pl?ok" title="meatball:ok">meatball:ok</a>
 <a rel="mw:WikiLink/Interwiki" href="http://www.usemod.com/cgi-bin/mb.pl?ok#foo" title="meatball:ok">ok with fragment</a>
 <a rel="mw:WikiLink/Interwiki" href="http://www.usemod.com/cgi-bin/mb.pl?ok_as_well%3F" title="meatball:ok as well?">ok ending with ? mark</a>
-<a rel="mw:ExtLink" class="external text" href="http://de.wikipedia.org/wiki/Foo?action=history">has query</a>
-<a rel="mw:ExtLink" class="external text" href="http://de.wikipedia.org/wiki/#foo">is just fragment</a></p>
+<a rel="mw:ExtLink" href="http://de.wikipedia.org/wiki/Foo?action=history" class="external text">has query</a>
+<a rel="mw:ExtLink" href="http://de.wikipedia.org/wiki/#foo" class="external text">is just fragment</a></p>
 !! end
 
 !! test
@@ -11445,7 +11490,7 @@ X[https://tools.ietf.org/html/rfc1234 foo]
 </p>
 !! html/parsoid
 <p>X<a rel="mw:WikiLink" href="./Special:BookSources/0978739256" title="Special:BookSources/0978739256">foo</a></p>
-<p>X<a rel="mw:ExtLink" class="external text" href="https://tools.ietf.org/html/rfc1234">foo</a></p>
+<p>X<a rel="mw:ExtLink" href="https://tools.ietf.org/html/rfc1234" class="external text">foo</a></p>
 !! end
 
 !! test
@@ -11505,14 +11550,44 @@ Template with invalid target containing wikilink
 <p><span typeof="mw:Transclusion" about="#mwt1" data-mw='{"parts":[{"template":{"target":{"wt":"[[Main Page]]"},"params":{},"i":0}}]}'>{{</span><a rel="mw:WikiLink" href="./Main_Page" about="#mwt1">Main Page</a><span about="#mwt1">}}</span></p>
 !! end
 
+# The html2html output of this test is currently failing
+# because the html2wt output is broken; see
+# https://phabricator.wikimedia.org/T220018#5123777 for a discussion.
+# Not (yet) including html2wt as a test mode because there are
+# a couple of different correct ways this could be <nowiki>'ed.
 !! test
 Template with just whitespace in it, T70421
 !! wikitext
 {{echo|{{ }}}}
+!! options
+parsoid=wt2html,html2html
+!! html/php+tidy
+<p>{{ }}
+</p>
 !! html/parsoid
 <p about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"{{ }}"}},"i":0}}]}'>{{ }}</p>
 !! end
 
+# This is currently the wikitext output of html2wt on the above test
+# case; note that it is broken! Adding a <nowiki> around the closing
+# brace changes how the open braces associate, breaking the outer
+# {{echo}} template invocation.  *However* this "broken" wikitext
+# exposed a useful tokenizer bug (T221384) in how the broken_template
+# rule was being backtracked into, so it's a useful test case even
+# if/when the above test case gets its html2wt output fixed.
+!! test
+Template with just whitespace (bad template brace matching)
+!! options
+parsoid=wt2html
+!! wikitext
+{{echo|{{ }<nowiki>}</nowiki>}}
+!! html/php+tidy
+<p>{{echo|{{ }}}}
+</p>
+!! html/parsoid
+<p>{{echo|{{ }<span typeof="mw:Nowiki">}</span>}}</p>
+!! end
+
 !! article
 Template:test
 !! text
@@ -11893,9 +11968,11 @@ Template:loop2
 Template infinite loop
 !! wikitext
 {{loop1}}
-!! html
+!! html/php
 <p><span class="error">Template loop detected: <a href="/wiki/Template:Loop1" title="Template:Loop1">Template:Loop1</a></span>
 </p>
+!! html/parsoid
+<p><span class="error" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"loop1","href":"./Template:Loop1"},"params":{},"i":0}}]}'>Template loop detected: <a rel="mw:WikiLink" href="./Template:Loop1" title="Template:Loop1">Template:Loop1</a></span></p>
 !! end
 
 !! test
@@ -12034,7 +12111,7 @@ Templates with intersecting and overlapping ranges
 <td>hi
 </td></tr></tbody></table>
 !! html/parsoid
-<p about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[{"k":"1"}],[{"k":"1"}],[{"k":"1"}]],"firstWikitextNode":"table"}' data-mw='{"parts":["{|",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"\n&lt;p>ha&lt;/p>"}},"i":0}},"\n","{|",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"\n&lt;p>ho&lt;/p>"}},"i":1}},"\n",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"{{!}}hi"}},"i":2}},"\n|}"]}'>ha</p><table about="#mwt1" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"","html":""},{"html":""}]]}'>
+<p about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[{"k":"1"}],[{"k":"1"}],[{"k":"1"}]],"firstWikitextNode":"TABLE"}' data-mw='{"parts":["{|",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"\n&lt;p>ha&lt;/p>"}},"i":0}},"\n","{|",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"\n&lt;p>ho&lt;/p>"}},"i":1}},"\n",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"{{!}}hi"}},"i":2}},"\n|}"]}'>ha</p><table about="#mwt1" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"","html":""},{"html":""}]]}'>
 
 </table><p about="#mwt1">ho</p><table about="#mwt1" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"","html":""},{"html":""}]]}'>
 
@@ -12115,9 +12192,11 @@ Template:Includes2
 <onlyinclude> being included
 !! wikitext
 {{Includes2}}
-!! html
+!! html/php+tidy
 <p>Foo
 </p>
+!! html/parsoid
+<p><meta typeof="mw:Transclusion mw:Includes/OnlyInclude" about="#mwt1" data-mw='{"parts":[{"template":{"target":{"wt":"Includes2","href":"./Template:Includes2"},"params":{},"i":0}}]}'/><span about="#mwt1">Foo</span><meta typeof="mw:Includes/OnlyInclude/End" about="#mwt1"/></p>
 !! end
 
 
@@ -12131,9 +12210,11 @@ Template:Includes3
 <onlyinclude> and <includeonly> being included
 !! wikitext
 {{Includes3}}
-!! html
+!! html/php+tidy
 <p>Foo
 </p>
+!! html/parsoid
+<p><meta typeof="mw:Transclusion mw:Includes/OnlyInclude" about="#mwt1" data-mw='{"parts":[{"template":{"target":{"wt":"Includes3","href":"./Template:Includes3"},"params":{},"i":0}}]}'/><span about="#mwt1">Foo</span><meta typeof="mw:Includes/OnlyInclude/End" about="#mwt1"/></p>
 !! end
 
 # FIXME: Parsoid's markup for this is quite ugly.
@@ -12152,7 +12233,20 @@ Foo<noinclude>zar</noinclude><includeonly>bar</includeonly>
 Un-closed <noinclude>
 !! wikitext
 <noinclude>
-!! html
+!! html/php+tidy
+!! html/parsoid
+<meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/>
+!! end
+
+!! test
+Empty <noinclude>
+!! wikitext
+Hello<noinclude></noinclude>!
+!! html/php+tidy
+<p>Hello!
+</p>
+!! html/parsoid
+<p>Hello<meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/><meta typeof="mw:Includes/NoInclude/End" data-parsoid='{"src":"&lt;/noinclude>"}'/>!</p>
 !! end
 
 !! test
@@ -12273,6 +12367,7 @@ Un-closed <includeonly>
 ## will normalize the include directives to serialize on their own line.
 ## Selser will take care of preserving formatting in scenarios where they
 ## intermingled with other wikitext.
+## This test also triggered T223411 during Parsoid-PHP porting.
 !! test
 Includes and comments at SOL
 !! options
@@ -12813,9 +12908,9 @@ parsoid=wt2html
 <li>{{echo|<a rel="nofollow" class="external text" href="http://example.com/-{foo">Breaks template, however</a>}}</li></ul>
 !! html/parsoid
 <ul>
-<li><a rel="mw:ExtLink" class="external text" href="http://example.com/-{foo">Example in URL</a></li>
-<li><a rel="mw:ExtLink" class="external text" href="http://example.com">Example in -{link} description</a></li>
-<li>{{echo|<a rel="mw:ExtLink" class="external text" href="http://example.com/-{foo">Breaks template, however</a>}}</li>
+<li><a rel="mw:ExtLink" href="http://example.com/-{foo" class="external text">Example in URL</a></li>
+<li><a rel="mw:ExtLink" href="http://example.com" class="external text">Example in -{link} description</a></li>
+<li>{{echo|<a rel="mw:ExtLink" href="http://example.com/-{foo" class="external text">Breaks template, however</a>}}</li>
 </ul>
 !! end
 
@@ -13877,7 +13972,7 @@ language=zh
 <p><span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"hi&lt;ref>[[ho|{{echo|hi}}]]&lt;/ref>"}},"i":0}}]}'>hi</span><sup about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{},"body":{"id":"mw-reference-text-cite_note-1"}}'><a href="./Main_Page#cite_note-1" style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a></sup>
 <span about="#mwt8" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"hi&lt;ref>[http://test.com?q={{echo|ho}}]&lt;/ref>"}},"i":0}}]}'>hi</span><sup about="#mwt8" class="mw-ref" id="cite_ref-2" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{},"body":{"id":"mw-reference-text-cite_note-2"}}'><a href="./Main_Page#cite_note-2" style="counter-reset: mw-Ref 2;"><span class="mw-reflink-text">[2]</span></a></sup>
 <span about="#mwt13" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"hi&lt;ref>-{ho|{{echo|hi}}}-&lt;/ref>"}},"i":0}}]}'>hi</span><sup about="#mwt13" class="mw-ref" id="cite_ref-3" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{},"body":{"id":"mw-reference-text-cite_note-3"}}'><a href="./Main_Page#cite_note-3" style="counter-reset: mw-Ref 3;"><span class="mw-reflink-text">[3]</span></a></sup></p>
-<ol class="mw-references references" typeof="mw:Extension/references" about="#mwt17" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><a href="./Main_Page#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text"><a rel="mw:WikiLink" href="./Ho" title="Ho">hi</a></span></li><li about="#cite_note-2" id="cite_note-2"><a href="./Main_Page#cite_ref-2" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-2" class="mw-reference-text"><a rel="mw:ExtLink" class="external autonumber" href="http://test.com?q=ho"></a></span></li><li about="#cite_note-3" id="cite_note-3"><a href="./Main_Page#cite_ref-3" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-3" class="mw-reference-text"><span typeof="mw:LanguageVariant" data-mw-variant='{"filter":{"l":["ho"],"t":"hi"}}'></span></span></li></ol>
+<ol class="mw-references references" typeof="mw:Extension/references" about="#mwt17" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><a href="./Main_Page#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text"><a rel="mw:WikiLink" href="./Ho" title="Ho">hi</a></span></li><li about="#cite_note-2" id="cite_note-2"><a href="./Main_Page#cite_ref-2" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-2" class="mw-reference-text"><a rel="mw:ExtLink" href="http://test.com?q=ho" class="external autonumber"></a></span></li><li about="#cite_note-3" id="cite_note-3"><a href="./Main_Page#cite_ref-3" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-3" class="mw-reference-text"><span typeof="mw:LanguageVariant" data-mw-variant='{"filter":{"l":["ho"],"t":"hi"}}'></span></span></li></ol>
 !! end
 
 ###
@@ -15867,7 +15962,7 @@ thumbsize=220
 !! html/php
 <div class="thumb tright"><div class="thumbinner" style="width:222px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" decoding="async" width="220" height="25" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/330px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/440px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a></div></div></div>
 !! html/parsoid
-<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><a rel="mw:ExtLink" class="external free" href="http://example.com">http://example.com</a></figcaption></figure>
+<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a></figcaption></figure>
 !! end
 
 !! test
@@ -15880,7 +15975,7 @@ parsoid=wt2html,wt2wt,html2html
 !! html/php
 <div class="thumb tright"><div class="thumbinner" style="width:222px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Alteration" src="http://example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" decoding="async" width="220" height="25" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/330px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/440px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a></div></div></div>
 !! html/parsoid
-<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img alt="Alteration" resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><a rel="mw:ExtLink" class="external free" href="http://example.com">http://example.com</a></figcaption></figure>
+<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img alt="Alteration" resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a></figcaption></figure>
 !! end
 
 !! test
@@ -15967,7 +16062,7 @@ T3887: A mailto link with a thumbnail
 !! html/php
 <div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" decoding="async" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>Please <a rel="nofollow" class="external free" href="mailto:nobody@example.com">mailto:nobody@example.com</a></div></div></div>
 !! html/parsoid
-<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption>Please <a rel="mw:ExtLink" class="external free" href="mailto:nobody@example.com">mailto:nobody@example.com</a></figcaption></figure>
+<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption>Please <a rel="mw:ExtLink" href="mailto:nobody@example.com" class="external free">mailto:nobody@example.com</a></figcaption></figure>
 !! end
 
 # Pending resolution to T2368
@@ -16150,7 +16245,7 @@ T5090: External links other than http: in image captions
 !! html/php
 <div class="thumb tright"><div class="thumbinner" style="width:202px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg" decoding="async" width="200" height="23" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/300px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/400px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>This caption has <a rel="nofollow" class="external text" href="irc://example.net">irc</a> and <a rel="nofollow" class="external text" href="https://example.com">Secure</a> ext links in it.</div></div></div>
 !! html/parsoid
-<figure typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="23" width="200"/></a><figcaption>This caption has <a rel="mw:ExtLink" class="external text" href="irc://example.net">irc</a> and <a rel="mw:ExtLink" class="external text" href="https://example.com">Secure</a> ext links in it.</figcaption></figure>
+<figure typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="23" width="200"/></a><figcaption>This caption has <a rel="mw:ExtLink" href="irc://example.net" class="external text">irc</a> and <a rel="mw:ExtLink" href="https://example.com" class="external text">Secure</a> ext links in it.</figcaption></figure>
 !! end
 
 !! test
@@ -16650,7 +16745,7 @@ Render invalid page names as plain text (T53090)
 [[.]]
 [[..]]
 [[foo././bar]]
-[[foo<a rel="mw:ExtLink" class="external autonumber" href="http://example.com"></a>xyz]]</p>
+[[foo<a rel="mw:ExtLink" href="http://example.com" class="external autonumber"></a>xyz]]</p>
 
 <p>[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"./../foo"}},"i":0}}]}'>./../foo</span>|bar]]
 [[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo/."}},"i":0}}]}'>foo/.</span>|bar]]
@@ -16748,6 +16843,18 @@ cat=MediaWiki_User's_Guide sort=MediaWiki User's Guide
 <link rel="mw:PageProp/Category" href="./Category:MediaWiki_User's_Guide#MediaWiki%20User's%20Guide" data-parsoid='{"stx":"piped","a":{"href":"./Category:MediaWiki_User&#39;s_Guide"},"sa":{"href":"Category:MediaWiki User&#39;s Guide"}}'/>
 !! end
 
+!! test
+Category with template-generated sort key
+!! options
+cat
+!! wikitext
+[[Category:MediaWiki User's Guide|MediaWiki {{echo|Foo}} Guide]]
+!! html/php
+cat=MediaWiki_User's_Guide sort=MediaWiki Foo Guide
+!! html/parsoid
+<link rel="mw:PageProp/Category" href="./Category:MediaWiki_User's_Guide#MediaWiki%20Foo%20Guide" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"mw:sortKey"},{"html":"MediaWiki &lt;span typeof=\"mw:Transclusion\" data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"Foo\"}},\"i\":0}}]}&apos;>Foo&lt;/span> Guide"}]]}'/>
+!! end
+
 !! test
 Category with empty sort key
 !! options
@@ -17649,7 +17756,7 @@ http://example.com [[File:Foobar.jpg]]
 <p><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a> <a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" width="1941" height="220" /></a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external free" href="http://example.com">http://example.com</a> <figure-inline class="mw-default-size" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></figure-inline></p>
+<p><a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a> <figure-inline class="mw-default-size" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></figure-inline></p>
 !!end
 
 # Parsoid doesn't wt2wt this cleanly because it adds <nowiki>s.
@@ -17952,7 +18059,7 @@ http://example.com[[File:Foobar.jpg]]
 <p><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" width="1941" height="220" /></a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external free" href="http://example.com">http://example.com</a><figure-inline class="mw-default-size" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></figure-inline></p>
+<p><a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a><figure-inline class="mw-default-size" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></figure-inline></p>
 !!end
 
 !! test
@@ -18192,6 +18299,17 @@ I always thought &xacute; was a cute letter.
 </p>
 !! end
 
+!! test
+Text with HTML5 semicolon-less entity (should not decode)
+!! wikitext
+&ampamp;
+!! html/php+tidy
+<p>&amp;ampamp;
+</p>
+!! html/parsoid
+<p>&amp;ampamp;</p>
+!! end
+
 !! test
 HTML5 tags
 !! wikitext
@@ -19765,11 +19883,11 @@ mailto:inline@mail.tld
 </p><p><a rel="nofollow" class="external free" href="mailto:inline@mail.tld">mailto:inline@mail.tld</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external autonumber" href="http://first/"></a> <a rel="mw:ExtLink" class="external autonumber" href="http://second"></a> <a rel="mw:ExtLink" class="external autonumber" href="ftp://ftp"></a></p>
-<p><a rel="mw:ExtLink" class="external free" href="ftp://inlineftp">ftp://inlineftp</a></p>
-<p><a rel="mw:ExtLink" class="external text" href="mailto:enclosed@mail.tld">With target</a></p>
-<p><a rel="mw:ExtLink" class="external autonumber" href="mailto:enclosed@mail.tld"></a></p>
-<p><a rel="mw:ExtLink" class="external free" href="mailto:inline@mail.tld">mailto:inline@mail.tld</a></p>
+<p><a rel="mw:ExtLink" href="http://first/" class="external autonumber"></a> <a rel="mw:ExtLink" href="http://second" class="external autonumber"></a> <a rel="mw:ExtLink" href="ftp://ftp" class="external autonumber"></a></p>
+<p><a rel="mw:ExtLink" href="ftp://inlineftp" class="external free">ftp://inlineftp</a></p>
+<p><a rel="mw:ExtLink" href="mailto:enclosed@mail.tld" class="external text">With target</a></p>
+<p><a rel="mw:ExtLink" href="mailto:enclosed@mail.tld" class="external autonumber"></a></p>
+<p><a rel="mw:ExtLink" href="mailto:inline@mail.tld" class="external free">mailto:inline@mail.tld</a></p>
 !! end
 
 
@@ -19817,7 +19935,7 @@ http://</p><div id="toc" class="toc"><input type="checkbox" role="button" id="to
 </div>
 !! html/parsoid
 <h2 id="onmouseover="><span id="onmouseover.3D" typeof="mw:FallbackId"></span>onmouseover=</h2>
-<p><a rel="mw:ExtLink" class="external free" href="http://__TOC__" data-parsoid='{"stx":"url"}'>http://__TOC__</a></p>
+<p><a rel="mw:ExtLink" href="http://__TOC__" class="external free" data-parsoid='{"stx":"url"}'>http://__TOC__</a></p>
 !! end
 
 !! test
@@ -19884,12 +20002,31 @@ Fuzz testing: Parser22
 http://===r:::https://b
 
 {|
-!! html
+!! html/php
 <p><a rel="nofollow" class="external free" href="http://===r:::https://b">http://===r:::https://b</a>
 </p>
 <table>
 <tr><td></td></tr>
 </table>
+!! html/parsoid
+<p><a rel="mw:ExtLink" href="http://===r:::https://b" class="external free" data-parsoid='{"stx":"url"}'>http://===r:::https://b</a></p>
+
+<table data-parsoid='{"autoInsertedEnd":true}'></table>
+!! end
+
+# The above 'Parser24' fuzz test exposed a tokenizer bug (T221384);
+# this is a minimized version of the above test to catch regressions.
+!! test
+Fuzz testing: Parser24 (minimized)
+!! options
+parsoid=wt2html
+!! wikitext
+{{<u {{{{[[Sx-->}}
+!! html/php+tidy
+<p>{{<u>}}
+</u></p>
+!! html/parsoid
+<p>{{<u data-parsoid='{"stx":"html","a":{"{{{{[[Sx--":null},"sa":{"{{{{[[Sx--":""},"autoInsertedEnd":true}'>}}</u></p>
 !! end
 
 ## Remex doesn't account for fostered content.
@@ -19973,7 +20110,7 @@ http://example.com <nowiki>junk</nowiki>
 <p><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a> junk
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external free" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a> <span typeof="mw:Nowiki">junk</span></p>
+<p><a rel="mw:ExtLink" href="http://example.com" class="external free" data-parsoid='{"stx":"url"}'>http://example.com</a> <span typeof="mw:Nowiki">junk</span></p>
 !! end
 
 !!test
@@ -19984,7 +20121,7 @@ http://example.com<nowiki>junk</nowiki>
 <p><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>junk
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external free" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a><span typeof="mw:Nowiki">junk</span></p>
+<p><a rel="mw:ExtLink" href="http://example.com" class="external free" data-parsoid='{"stx":"url"}'>http://example.com</a><span typeof="mw:Nowiki">junk</span></p>
 !! end
 
 !! test
@@ -19996,7 +20133,7 @@ http://example.com<pre>junk</pre>
 !! html/php+tidy
 <p><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a></p><pre>junk</pre>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external free" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a></p><pre typeof="mw:Extension/pre" about="#mwt2" data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"junk"}}'>junk</pre>
+<p><a rel="mw:ExtLink" href="http://example.com" class="external free" data-parsoid='{"stx":"url"}'>http://example.com</a></p><pre typeof="mw:Extension/pre" about="#mwt2" data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"junk"}}'>junk</pre>
 !! end
 
 !! test
@@ -20020,7 +20157,7 @@ parsoid=wt2html
 <pre dir="&#10;"></pre>
 !! html/parsoid
 <pre dir="
-" typeof="mw:Extension/pre" about="#mwt2"data-mw='{"name":"pre","attrs":{"dir":"\n"},"body":{"extsrc":""}}'></pre>
+" typeof="mw:Extension/pre" about="#mwt2" data-mw='{"name":"pre","attrs":{"dir":""},"body":{"extsrc":""}}'></pre>
 !! end
 
 !! test
@@ -21049,7 +21186,7 @@ Handling of &#x0A; in URLs
 !! html/php
 <ul><li><a rel="nofollow" class="external free" href="irc://%0Aa">irc://%0Aa</a></li></ul>
 !! html/parsoid
-<ul><li><a rel="mw:ExtLink" class="external free" href="irc://%0Aa" data-parsoid='{"stx":"url","a":{"href":"irc://%0Aa"},"sa":{"href":"irc://&amp;#x0A;a"}}'>irc://%0Aa</a></li></ul>
+<ul><li><a rel="mw:ExtLink" href="irc://%0Aa" class="external free" data-parsoid='{"stx":"url","a":{"href":"irc://%0Aa"},"sa":{"href":"irc://&amp;#x0A;a"}}'>irc://%0Aa</a></li></ul>
 !! end
 
 !! test
@@ -21059,7 +21196,7 @@ Handling of %0A in URLs
 !! html/php
 <ul><li><a rel="nofollow" class="external free" href="irc://%0Aa">irc://%0Aa</a></li></ul>
 !! html/parsoid
-<ul><li><a rel="mw:ExtLink" class="external free" href="irc://%0Aa">irc://%0Aa</a></li></ul>
+<ul><li><a rel="mw:ExtLink" href="irc://%0Aa" class="external free">irc://%0Aa</a></li></ul>
 !! end
 
 # The PHP parser strips the empty tags out for giggles; parsoid doesn't.
@@ -21258,7 +21395,7 @@ image4    |300px| centre
 <li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><figure-inline typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"apierror-filedoesnotexist","message":"This image does not exist."}]}'><a href="./Special:FilePath/Image2.gif"><span resource="./File:Image2.gif" data-width="120" data-height="120">File:Image2.gif</span></a></figure-inline></div><div class="gallerytext"></div></li>
 <li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><figure-inline typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"apierror-filedoesnotexist","message":"This image does not exist."}]}'><a href="./Special:FilePath/Image3"><span resource="./File:Image3" data-width="120" data-height="120">File:Image3</span></a></figure-inline></div><div class="gallerytext"></div></li>
 <li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><figure-inline typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"apierror-filedoesnotexist","message":"This image does not exist."}]}'><a href="./Special:FilePath/Image4"><span resource="./File:Image4" data-width="300">File:Image4</span></a></figure-inline></div><div class="gallerytext"></div></li>
-<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><figure-inline typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"apierror-filedoesnotexist","message":"This image does not exist."}]}'><a href="./Special:FilePath/Image5.svg"><span resource="./File:Image5.svg" data-width="120" data-height="120">File:Image5.svg</span></a></figure-inline></div><div class="gallerytext"> <a rel="mw:ExtLink" class="external free" href="http://///////">http://///////</a></div></li>
+<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><figure-inline typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"apierror-filedoesnotexist","message":"This image does not exist."}]}'><a href="./Special:FilePath/Image5.svg"><span resource="./File:Image5.svg" data-width="120" data-height="120">File:Image5.svg</span></a></figure-inline></div><div class="gallerytext"> <a rel="mw:ExtLink" href="http://///////" class="external free">http://///////</a></div></li>
 <li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><figure-inline typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"apierror-filedoesnotexist","message":"This image does not exist."}]}'><a href="./Special:FilePath/*_image6"><span resource="./File:*_image6" data-width="120" data-height="120">File:* image6</span></a></figure-inline></div><div class="gallerytext"></div></li>
 </ul>
 !! end
@@ -21799,6 +21936,30 @@ File:Foobar.jpg
 </ul>
 !! end
 
+!! test
+Gallery in nolines mode
+!! wikitext
+<gallery mode="nolines" showfilenames="yes" caption="No Lines!">
+File:Foobar.jpg|foo
+</gallery>
+!! html/php
+<ul class="gallery mw-gallery-nolines">
+       <li class='gallerycaption'>No Lines!</li>
+               <li class="gallerybox" style="width: 125px"><div style="width: 125px">
+                       <div class="thumb" style="width: 120px;"><div style="margin:0px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" decoding="async" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
+                       <div class="gallerytext">
+<p>foo
+</p>
+                       </div>
+               </div></li>
+</ul>
+!! html/parsoid
+<ul class="gallery mw-gallery-nolines" typeof="mw:Extension/gallery" about="#mwt3" data-mw='{"name":"gallery","attrs":{"mode":"nolines","showfilenames":"yes"},"body":{}}'>
+<li class="gallerycaption">No Lines!</li>
+<li class="gallerybox" style="width: 125px;"><div class="thumb" style="width: 120px;"><figure-inline typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></figure-inline></div><div class="gallerytext">foo</div></li>
+</ul>
+!! end
+
 !! test
 Gallery in slideshow mode
 !! wikitext
@@ -21835,7 +21996,55 @@ File:Foobar.jpg
 </ul>
 !! html/parsoid
 <ul class="gallery mw-gallery-packed" typeof="mw:Extension/gallery" about="#mwt3" data-parsoid='{"dsr":[0,50,23,10]}' data-mw='{"name":"gallery","attrs":{"mode":"packed"},"body":{}}'>
-<li class="gallerybox" style="width: 1061px;"><div class="thumb" style="width: 1059px;"><figure-inline typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/1589px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="120" width="1059"/></a></figure-inline></div><div class="gallerytext"></div></li>
+<li class="gallerybox" style="width: 1061.3333333333333px;"><div class="thumb" style="width: 1059.3333333333333px;"><figure-inline typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/1589px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="120" width="1060"/></a></figure-inline></div><div class="gallerytext"></div></li>
+</ul>
+!! end
+
+!! test
+Gallery in packed-overlay mode
+!! wikitext
+<gallery mode="packed-overlay" showfilenames="yes" caption="Packed Overlay!">
+File:Foobar.jpg|foo
+</gallery>
+!! html/php
+<ul class="gallery mw-gallery-packed-overlay">
+       <li class='gallerycaption'>Packed Overlay!</li>
+               <li class="gallerybox" style="width: 1061.3333333333px"><div style="width: 1061.3333333333px">
+                       <div class="thumb" style="width: 1059.3333333333px;"><div style="margin:0px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/1589px-Foobar.jpg" decoding="async" width="1060" height="120" srcset="http://example.com/images/3/3a/Foobar.jpg 1.5x" /></a></div></div>
+                       <div class="gallerytextwrapper" style="width: 1040px"><div class="gallerytext">
+<p>foo
+</p>
+                       </div></div>
+               </div></li>
+</ul>
+!! html/parsoid
+<ul class="gallery mw-gallery-packed-overlay" typeof="mw:Extension/gallery" about="#mwt3" data-mw='{"name":"gallery","attrs":{"mode":"packed-overlay","showfilenames":"yes"},"body":{}}'>
+<li class="gallerycaption">Packed Overlay!</li>
+<li class="gallerybox" style="width: 1061.3333333333333px;"><div class="thumb" style="width: 1059.3333333333333px;"><figure-inline typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/1589px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="120" width="1060"/></a></figure-inline></div><div class="gallerytextwrapper" style="width: 1040px;"><div class="gallerytext">foo</div></div></li>
+</ul>
+!! end
+
+!! test
+Gallery in packed-hover mode
+!! wikitext
+<gallery mode="packed-hover" showfilenames="yes" caption="Packed Hover!">
+File:Foobar.jpg|foo
+</gallery>
+!! html/php
+<ul class="gallery mw-gallery-packed-hover">
+       <li class='gallerycaption'>Packed Hover!</li>
+               <li class="gallerybox" style="width: 1061.3333333333px"><div style="width: 1061.3333333333px">
+                       <div class="thumb" style="width: 1059.3333333333px;"><div style="margin:0px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/1589px-Foobar.jpg" decoding="async" width="1060" height="120" srcset="http://example.com/images/3/3a/Foobar.jpg 1.5x" /></a></div></div>
+                       <div class="gallerytextwrapper" style="width: 1040px"><div class="gallerytext">
+<p>foo
+</p>
+                       </div></div>
+               </div></li>
+</ul>
+!! html/parsoid
+<ul class="gallery mw-gallery-packed-hover" typeof="mw:Extension/gallery" about="#mwt3" data-mw='{"name":"gallery","attrs":{"mode":"packed-hover","showfilenames":"yes"},"body":{}}'>
+<li class="gallerycaption">Packed Hover!</li>
+<li class="gallerybox" style="width: 1061.3333333333333px;"><div class="thumb" style="width: 1059.3333333333333px;"><figure-inline typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/1589px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="120" width="1060"/></a></figure-inline></div><div class="gallerytextwrapper" style="width: 1040px;"><div class="gallerytext">foo</div></div></li>
 </ul>
 !! end
 
@@ -21895,14 +22104,19 @@ parsoid=wt2html,wt2wt,html2html
 # See: https://www.w3.org/TR/html5/syntax.html#character-references
 # Note that U+000C (form feed) is not a valid XML character, so
 # it is banned even though allowed in HTML5.
+# Note there are also weird legacy numeric entities which are mapped
+# elsewhere; see T113194
 !! test
-Illegal character references (T106578)
+Illegal character references (T106578, T113194)
+!! options
+parsoid={ "modes": ["wt2html","html2html"], "normalizePhp": true }
 !! wikitext
 ; Null: &#00;
 ; FF: &#xC;
 ; CR: &#xD;
 ; Control (low): &#8;
 ; Control (high): &#x7F; &#x9F;
+; Unsupported legacy: &#128; &#130; &#131; &#150; &#159;
 ; Surrogate: &#xD83D;&#xDCA9;
 ; This is an okay astral character: &#x1F4A9;
 !! html+tidy
@@ -21916,6 +22130,8 @@ Illegal character references (T106578)
 <dd>&amp;#8;</dd>
 <dt>Control (high)</dt>
 <dd>&amp;#x7F; &amp;#x9F;</dd>
+<dt>Unsupported legacy</dt>
+<dd>&amp;#128; &amp;#130; &amp;#131; &amp;#150; &amp;#159;</dd>
 <dt>Surrogate</dt>
 <dd>&amp;#xD83D;&amp;#xDCA9;</dd>
 <dt>This is an okay astral character</dt>
@@ -22009,7 +22225,7 @@ T24905: <abbr> followed by ISBN followed by </a>
 <p><abbr>(fr)</abbr> <a href="/wiki/Special:BookSources/2753300917" class="internal mw-magiclink-isbn">ISBN 2753300917</a> <a rel="nofollow" class="external text" href="http://www.example.com">example.com</a>
 </p>
 !! html/parsoid
-<p><abbr data-parsoid='{"stx":"html"}'>(fr)</abbr> <a href="./Special:BookSources/2753300917" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 2753300917</a> <a rel="mw:ExtLink" class="external text" href="http://www.example.com">example.com</a></p>
+<p><abbr data-parsoid='{"stx":"html"}'>(fr)</abbr> <a href="./Special:BookSources/2753300917" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 2753300917</a> <a rel="mw:ExtLink" href="http://www.example.com" class="external text">example.com</a></p>
 !! end
 
 !! test
@@ -22151,7 +22367,7 @@ Images with the "|" character in the comment
 !! html/php
 <div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" decoding="async" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>An <a rel="nofollow" class="external text" href="http://test/?param1=%7Cleft%7C&amp;param2=%7Cx">external</a> URL</div></div></div>
 !! html/parsoid
-<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption>An <a rel="mw:ExtLink" class="external text" href="http://test/?param1=%7Cleft%7C&amp;param2=%7Cx" data-parsoid='{"a":{"href":"http://test/?param1=%7Cleft%7C&amp;param2=%7Cx"},"sa":{"href":"http://test/?param1=|left|&amp;param2=|x"}}'>external</a> URL</figcaption></figure>
+<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption>An <a rel="mw:ExtLink" href="http://test/?param1=%7Cleft%7C&amp;param2=%7Cx" class="external text" data-parsoid='{"a":{"href":"http://test/?param1=%7Cleft%7C&amp;param2=%7Cx"},"sa":{"href":"http://test/?param1=|left|&amp;param2=|x"}}'>external</a> URL</figcaption></figure>
 !! end
 
 !! test
@@ -23381,7 +23597,7 @@ Nested: -{zh-hans:Hi -{zh-cn:China;zh-sg:Singapore;}-;zh-hant:Hello -{zh-tw:Taiw
 <p>Nested: Hello Hong Kong!
 </p>
 !! html/parsoid
-<p>Nested: <span typeof="mw:LanguageVariant" data-parsoid='{"tSp":[7]}' data-mw-variant='{"twoway":[{"l":"zh-hans","t":"Hi &lt;span typeof=\"mw:LanguageVariant\" data-mw-variant=&apos;{\"twoway\":[{\"l\":\"zh-cn\",\"t\":\"China\"},{\"l\":\"zh-sg\",\"t\":\"Singapore\"}]}&apos; data-parsoid=&apos;{\"fl\":[],\"tSp\":[7],\"dsr\":[21,53,null,2]}&apos;>&lt;/span>"},{"l":"zh-hant","t":"Hello &lt;span typeof=\"mw:LanguageVariant\" data-mw-variant=&apos;{\"twoway\":[{\"l\":\"zh-tw\",\"t\":\"Taiwan\"},{\"l\":\"zh-hk\",\"t\":\"H&amp;lt;span typeof=\\\"mw:LanguageVariant\\\" data-mw-variant=&amp;apos;{\\\"disabled\\\":{\\\"t\\\":\\\"ong\\\"}}&amp;apos; data-parsoid=&amp;apos;{\\\"fl\\\":[],\\\"dsr\\\":[90,97,null,2]}&amp;apos;>&amp;lt;/span> K&amp;lt;span typeof=\\\"mw:LanguageVariant\\\" data-mw-variant=&amp;apos;{\\\"disabled\\\":{\\\"t\\\":\\\"\\\"}}&amp;apos; data-parsoid=&amp;apos;{\\\"fl\\\":[],\\\"dsr\\\":[99,103,null,2]}&amp;apos;>&amp;lt;/span>ong\"}]}&apos; data-parsoid=&apos;{\"fl\":[],\"tSp\":[7],\"dsr\":[68,109,null,2]}&apos;>&lt;/span>"}]}'></span>!</p>
+<p>Nested: <span typeof="mw:LanguageVariant" data-parsoid='{"tSp":[7]}' data-mw-variant='{"twoway":[{"l":"zh-hans","t":"Hi &lt;span typeof=\"mw:LanguageVariant\" data-mw-variant=&apos;{\"twoway\":[{\"l\":\"zh-cn\",\"t\":\"China\"},{\"l\":\"zh-sg\",\"t\":\"Singapore\"}]}&apos; data-parsoid=&apos;{\"fl\":[],\"tSp\":[7],\"dsr\":[21,53,2,2]}&apos;>&lt;/span>"},{"l":"zh-hant","t":"Hello &lt;span typeof=\"mw:LanguageVariant\" data-mw-variant=&apos;{\"twoway\":[{\"l\":\"zh-tw\",\"t\":\"Taiwan\"},{\"l\":\"zh-hk\",\"t\":\"H&amp;lt;span typeof=\\\"mw:LanguageVariant\\\" data-mw-variant=&amp;apos;{\\\"disabled\\\":{\\\"t\\\":\\\"ong\\\"}}&amp;apos; data-parsoid=&amp;apos;{\\\"fl\\\":[],\\\"dsr\\\":[90,97,2,2]}&amp;apos;>&amp;lt;/span> K&amp;lt;span typeof=\\\"mw:LanguageVariant\\\" data-mw-variant=&amp;apos;{\\\"disabled\\\":{\\\"t\\\":\\\"\\\"}}&amp;apos; data-parsoid=&amp;apos;{\\\"fl\\\":[],\\\"dsr\\\":[99,103,2,2]}&amp;apos;>&amp;lt;/span>ong\"}]}&apos; data-parsoid=&apos;{\"fl\":[],\"tSp\":[7],\"dsr\":[68,109,2,2]}&apos;>&lt;/span>"}]}'></span>!</p>
 !! end
 
 !! test
@@ -23394,7 +23610,7 @@ language=zh variant=zh-cn
 <p><span title="X">A</span>
 </p>
 !! html/parsoid
-<p><span typeof="mw:LanguageVariant" data-mw-variant='{"filter":{"l":["zh","zh-hans","zh-hant"],"t":"&lt;span title=\"\" about=\"#mwt1\" typeof=\"mw:ExpandedAttrs\" data-parsoid=&#39;{\"stx\":\"html\",\"a\":{\"title\":\"\"},\"sa\":{\"title\":\"-{X}-\"},\"dsr\":[21,49,20,7]}&#39; data-mw=&#39;{\"attribs\":[[{\"txt\":\"title\"},{\"html\":\"&amp;lt;span typeof=\\\"mw:LanguageVariant\\\" data-mw-variant=&amp;apos;{\\\"disabled\\\":{\\\"t\\\":\\\"X\\\"}}&amp;apos; data-parsoid=&amp;apos;{\\\"fl\\\":[],\\\"dsr\\\":[34,39,null,2]}&amp;apos;>&amp;lt;/span>\"}]]}&#39;>A&lt;/span>"}}'></span></p>
+<p><span typeof="mw:LanguageVariant" data-mw-variant='{"filter":{"l":["zh","zh-hans","zh-hant"],"t":"&lt;span title=\"\" about=\"#mwt1\" typeof=\"mw:ExpandedAttrs\" data-parsoid=&#39;{\"stx\":\"html\",\"a\":{\"title\":\"\"},\"sa\":{\"title\":\"-{X}-\"},\"dsr\":[21,49,20,7]}&#39; data-mw=&#39;{\"attribs\":[[{\"txt\":\"title\"},{\"html\":\"&amp;lt;span typeof=\\\"mw:LanguageVariant\\\" data-mw-variant=&amp;apos;{\\\"disabled\\\":{\\\"t\\\":\\\"X\\\"}}&amp;apos; data-parsoid=&amp;apos;{\\\"fl\\\":[],\\\"dsr\\\":[34,39,2,2]}&amp;apos;>&amp;lt;/span>\"}]]}&#39;>A&lt;/span>"}}'></span></p>
 !! end
 
 !! test
@@ -23407,7 +23623,7 @@ language=zh variant=zh-cn
 <p><span title="X">A</span>
 </p>
 !! html/parsoid
-<p><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"&lt;span title=\"\" about=\"#mwt1\" typeof=\"mw:ExpandedAttrs\" data-parsoid=&#39;{\"stx\":\"html\",\"a\":{\"title\":\"\"},\"sa\":{\"title\":\"-{X}-\"},\"dsr\":[2,30,20,7]}&#39; data-mw=&#39;{\"attribs\":[[{\"txt\":\"title\"},{\"html\":\"&amp;lt;span typeof=\\\"mw:LanguageVariant\\\" data-mw-variant=&amp;apos;{\\\"disabled\\\":{\\\"t\\\":\\\"X\\\"}}&amp;apos; data-parsoid=&amp;apos;{\\\"fl\\\":[],\\\"dsr\\\":[15,20,null,2]}&amp;apos;>&amp;lt;/span>\"}]]}&#39;>A&lt;/span>"}}'></span></p>
+<p><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"&lt;span title=\"\" about=\"#mwt1\" typeof=\"mw:ExpandedAttrs\" data-parsoid=&#39;{\"stx\":\"html\",\"a\":{\"title\":\"\"},\"sa\":{\"title\":\"-{X}-\"},\"dsr\":[2,30,20,7]}&#39; data-mw=&#39;{\"attribs\":[[{\"txt\":\"title\"},{\"html\":\"&amp;lt;span typeof=\\\"mw:LanguageVariant\\\" data-mw-variant=&amp;apos;{\\\"disabled\\\":{\\\"t\\\":\\\"X\\\"}}&amp;apos; data-parsoid=&amp;apos;{\\\"fl\\\":[],\\\"dsr\\\":[15,20,2,2]}&amp;apos;>&amp;lt;/span>\"}]]}&#39;>A&lt;/span>"}}'></span></p>
 !! end
 
 # Parsoid and PHP disagree on how to parse this example: Parsoid
@@ -23552,13 +23768,13 @@ gopher://www.google.com
 <a rel="nofollow" class="external text" href="//www.google.com">www.гоогле.цом</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external free" href="http://www.google.com">http://www.google.com</a>
-<a rel="mw:ExtLink" class="external free" href="gopher://www.google.com">gopher://www.google.com</a>
-<a rel="mw:ExtLink" class="external text" href="http://www.google.com">http://www.google.com</a>
-<a rel="mw:ExtLink" class="external text" href="gopher://www.google.com">gopher://www.google.com</a>
-<a rel="mw:ExtLink" class="external text" href="https://www.google.com">irc://www.google.com</a>
-<a rel="mw:ExtLink" class="external text" href="ftp://www.google.com">www.google.com/ftp://dir</a>
-<a rel="mw:ExtLink" class="external text" href="//www.google.com">www.google.com</a></p>
+<p><a rel="mw:ExtLink" href="http://www.google.com" class="external free">http://www.google.com</a>
+<a rel="mw:ExtLink" href="gopher://www.google.com" class="external free">gopher://www.google.com</a>
+<a rel="mw:ExtLink" href="http://www.google.com" class="external text">http://www.google.com</a>
+<a rel="mw:ExtLink" href="gopher://www.google.com" class="external text">gopher://www.google.com</a>
+<a rel="mw:ExtLink" href="https://www.google.com" class="external text">irc://www.google.com</a>
+<a rel="mw:ExtLink" href="ftp://www.google.com" class="external text">www.google.com/ftp://dir</a>
+<a rel="mw:ExtLink" href="//www.google.com" class="external text">www.google.com</a></p>
 !! end
 
 !! test
@@ -24245,7 +24461,7 @@ language=fa
 <p><a rel="nofollow" class="external autonumber" href="http://en.wikipedia.org/">[Û±]</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external autonumber" href="http://en.wikipedia.org/"></a></p>
+<p><a rel="mw:ExtLink" href="http://en.wikipedia.org/" class="external autonumber"></a></p>
 !! end
 
 !! test
@@ -25625,7 +25841,7 @@ T36939 - Case insensitive link parsing ([HttP://])
 <p><a rel="nofollow" class="external autonumber" href="HttP://MediaWiki.Org/">[1]</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external autonumber" href="HttP://MediaWiki.Org/"></a></p>
+<p><a rel="mw:ExtLink" href="HttP://MediaWiki.Org/" class="external autonumber"></a></p>
 !! end
 
 !!test
@@ -25645,7 +25861,7 @@ HttP://MediaWiki.Org/
 <p><a rel="nofollow" class="external free" href="HttP://MediaWiki.Org/">HttP://MediaWiki.Org/</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external free" href="HttP://MediaWiki.Org/">HttP://MediaWiki.Org/</a></p>
+<p><a rel="mw:ExtLink" href="HttP://MediaWiki.Org/" class="external free">HttP://MediaWiki.Org/</a></p>
 !! end
 
 !!test
@@ -25779,6 +25995,17 @@ parsoid=wt2html,wt2wt
 <b><small><figure class="mw-halign-right" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/300px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="34" width="300"/></a><figcaption></figcaption></figure></small></b>
 !! end
 
+## Just a regression test
+!! test
+Wikilink with only closing tag in target
+!! options
+parsoid=wt2html
+!! wikitext
+[[Test|</span>]]
+!! html/parsoid
+<p><a rel="mw:WikiLink" href="./Test" title="Test"></a></p>
+!! end
+
 #### ----------------------------------------------------------------
 #### Parsoid-only testing of Parsoid's impl of LST
 #### Not implemented yet, see
@@ -28417,7 +28644,7 @@ parsoid=html2wt
 !!end
 
 !! test
-Don't block XML namespace declaration
+T72867: Don't block XML namespace declaration
 !! wikitext
 <span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">MediaWiki</span>
 !! html/php
@@ -28591,6 +28818,23 @@ parsoid=html2wt
 [[es:Toxine_bactérienne]]
 !! end
 
+# Regression test for T219023
+!! test
+Emit simple non-piped link where possible
+!! options
+parsoid=html2wt
+!! html/parsoid
+<a rel='mw:WikiLink' href='./VisualEditor'>VisualEditor</a>
+<a rel='mw:WikiLink' href='./VisualEditor'>visualEditor</a>
+<a rel='mw:WikiLink' href='./VisualEditor link'>VisualEditor link</a>
+<a rel='mw:WikiLink' href='./VisualEditor link'>visualEditor link</a>
+!! wikitext
+[[VisualEditor]]
+[[visualEditor]]
+[[VisualEditor link]]
+[[visualEditor link]]
+!! end
+
 !! test
 Image: Modifying size of an image (1)
 !! options
@@ -29604,7 +29848,7 @@ WTS of autolinks with nowikis (round-trip)
 !! wikitext
 x<nowiki/>http://cscott.net<nowiki/>x
 !! html/parsoid
-<p>x<a rel="mw:ExtLink" class="external free" href="http://cscott.net">http://cscott.net</a>x</p>
+<p>x<a rel="mw:ExtLink" href="http://cscott.net" class="external free">http://cscott.net</a>x</p>
 !! end
 
 # this is the "easy" test because it leaves in place all the
@@ -29659,6 +29903,58 @@ parsoid=html2wt
 http://example.com <nowiki>http://example.com</nowiki> is not a link.
 !! end
 
+!! test
+WTS of an autolink surrounded by square brackets (T220018)
+!! options
+parsoid=html2wt
+!! html/parsoid
+<p>[<a rel="mw:ExtLink" href="http://example.com">http://example.com</a>]</p>
+!! wikitext
+<nowiki>[</nowiki>http://example.com]
+!! end
+
+!! test
+WTS of edited autolink surrounded by square brackets (T220018)
+!! options
+parsoid={
+  "modes": ["wt2wt"],
+  "changes": [
+    [ "a", "before", "[" ],
+    [ "a", "after", "]" ]
+  ]
+}
+!! wikitext
+http://example.com
+!! wikitext/edited
+<nowiki>[</nowiki>http://example.com]
+!! end
+
+!! test
+WTS of an external link surrounded by square brackets (T220018)
+!! options
+parsoid=html2wt
+!! html/parsoid
+<p>[<a rel="mw:ExtLink" href="http://example.com">foo</a>]</p>
+!! wikitext
+<nowiki>[</nowiki>[http://example.com foo]]
+!! end
+
+!! test
+WTS of edited external link surrounded by square brackets (T220018)
+!! options
+parsoid={
+  "modes": ["wt2wt"],
+  "changes": [
+    [ "a", "before", "[" ],
+    [ "a", "after", "]" ]
+  ]
+}
+!! wikitext
+[http://example.com foo]
+!! wikitext/edited
+<nowiki>[</nowiki>[http://example.com foo]]
+!! end
+
 !! test
 Magic links inside links (not autolinked)
 !! wikitext
@@ -29687,10 +29983,10 @@ Magic links inside links (not autolinked)
 <a rel="mw:WikiLink" href="./Foo" title="Foo">PMID 1234</a>
 <a rel="mw:WikiLink" href="./Foo" title="Foo">ISBN 123456789x</a></p>
 
-<p><a rel="mw:ExtLink" class="external text" href="http://foo.com">http://example.com</a>
-<a rel="mw:ExtLink" class="external text" href="http://foo.com">RFC 1234</a>
-<a rel="mw:ExtLink" class="external text" href="http://foo.com">PMID 1234</a>
-<a rel="mw:ExtLink" class="external text" href="http://foo.com">ISBN 123456789x</a></p>
+<p><a rel="mw:ExtLink" href="http://foo.com" class="external text">http://example.com</a>
+<a rel="mw:ExtLink" href="http://foo.com" class="external text">RFC 1234</a>
+<a rel="mw:ExtLink" href="http://foo.com" class="external text">PMID 1234</a>
+<a rel="mw:ExtLink" href="http://foo.com" class="external text">ISBN 123456789x</a></p>
 !! end
 
 !! test
@@ -29706,7 +30002,7 @@ Magic links inside image captions (autolinked)
 <div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" decoding="async" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div><a class="external mw-magiclink-pmid" rel="nofollow" href="//www.ncbi.nlm.nih.gov/pubmed/1234?dopt=Abstract">PMID 1234</a></div></div></div>
 <div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" decoding="async" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div><a href="/wiki/Special:BookSources/123456789X" class="internal mw-magiclink-isbn">ISBN 123456789x</a></div></div></div>
 !! html/parsoid
-<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><a rel="mw:ExtLink" class="external free" href="http://example.com">http://example.com</a></figcaption></figure>
+<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a></figcaption></figure>
 <figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><a href="https://tools.ietf.org/html/rfc1234" rel="mw:ExtLink" class="external mw-magiclink">RFC 1234</a></figcaption></figure>
 <figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><a href="//www.ncbi.nlm.nih.gov/pubmed/1234?dopt=Abstract" rel="mw:ExtLink" class="external mw-magiclink">PMID 1234</a></figcaption></figure>
 <figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><a href="./Special:BookSources/123456789X" rel="mw:WikiLink">ISBN 123456789x</a></figcaption></figure>
@@ -30136,7 +30432,7 @@ parsoid=wt2html
 !! wikitext
 {{echo|hi}}[http://example.com [[ho]]]
 !! html/parsoid
-<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"hi"}},"i":0}}]}'>hi</span><a rel="mw:ExtLink" class="external autonumber" href="http://example.com"></a><a rel="mw:WikiLink" href="./Ho" title="Ho" data-parsoid='{"misnested":true}'>ho</a></p>
+<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"hi"}},"i":0}}]}'>hi</span><a rel="mw:ExtLink" href="http://example.com" class="external autonumber"></a><a rel="mw:WikiLink" href="./Ho" title="Ho" data-parsoid='{"misnested":true}'>ho</a></p>
 !! end
 
 !! test
@@ -30152,7 +30448,7 @@ Use data-parsoid.firstWikitextNode to compute newline constraints for template c
 !! options
 parsoid=html2wt
 !! html/parsoid
-<span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"a"}},"i":0}}]}'>a</span><table about="#mwt2" typeof="mw:Transclusion mw:ExpandedAttrs" data-parsoid='{"a":{"{{echo|c\n{{!}}d\n}}":null},"sa":{"{{echo|c\n{{!}}d\n}}":""},"firstWikitextNode":"table","pi":[[{"k":"1"}]]}' data-mw='{"parts":["{|",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"c\n{{!}}d\n"}},"i":0}},"\n|}"]}'>
+<span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"a"}},"i":0}}]}'>a</span><table about="#mwt2" typeof="mw:Transclusion mw:ExpandedAttrs" data-parsoid='{"a":{"{{echo|c\n{{!}}d\n}}":null},"sa":{"{{echo|c\n{{!}}d\n}}":""},"firstWikitextNode":"TABLE","pi":[[{"k":"1"}]]}' data-mw='{"parts":["{|",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"c\n{{!}}d\n"}},"i":0}},"\n|}"]}'>
 <tbody><tr><td>d
 </td></tr>
 </tbody></table>
@@ -30211,9 +30507,9 @@ parsoid={
 </p>
 <a rel="nofollow" class="external text" href="http://www.google.com"></a><div class="thumb tright"><a rel="nofollow" class="external text" href="http://www.google.com"></a><div class="thumbinner" style="width:182px;"><a rel="nofollow" class="external text" href="http://www.google.com"></a><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" decoding="async" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>123</div></div></div>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external text" href="http://www.google.com" data-parsoid='{"targetOff":23,"contentOffsets":[23,46]}'><figure-inline class="mw-default-size" typeof="mw:Image" data-parsoid='{"optList":[{"ck":"caption","ak":"123"}]}' data-mw='{"caption":"123"}'></figure-inline></a><a href="./File:Foobar.jpg" data-parsoid='{"misnested":true}'><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"220","width":"1941"},"sa":{"resource":"File:Foobar.jpg"},"misnested":true}'/></a></p>
+<p><a rel="mw:ExtLink" href="http://www.google.com" class="external text" data-parsoid='{"targetOff":23,"contentOffsets":[23,46]}'><figure-inline class="mw-default-size" typeof="mw:Image" data-parsoid='{"optList":[{"ck":"caption","ak":"123"}]}' data-mw='{"caption":"123"}'></figure-inline></a><a href="./File:Foobar.jpg" data-parsoid='{"misnested":true}'><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"220","width":"1941"},"sa":{"resource":"File:Foobar.jpg"},"misnested":true}'/></a></p>
 
-<a rel="mw:ExtLink" class="external autonumber" href="http://www.google.com" data-parsoid='{"targetOff":72,"contentOffsets":[72,101]}'></a><figure class="mw-default-size" typeof="mw:Image/Thumb" data-parsoid='{"optList":[{"ck":"thumbnail","ak":"thumb"},{"ck":"caption","ak":"123"}]}'><a rel="mw:ExtLink" class="external autonumber" href="http://www.google.com" data-parsoid='{"targetOff":72,"contentOffsets":[72,101]}'></a><a href="./File:Foobar.jpg" data-parsoid='{"misnested":true}'><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"25","width":"220"},"sa":{"resource":"File:Foobar.jpg"},"misnested":true}'/></a><figcaption data-parsoid='{"misnested":true}'>123</figcaption></figure>
+<a rel="mw:ExtLink" href="http://www.google.com" class="external autonumber" data-parsoid='{"targetOff":72,"contentOffsets":[72,101]}'></a><figure class="mw-default-size" typeof="mw:Image/Thumb" data-parsoid='{"optList":[{"ck":"thumbnail","ak":"thumb"},{"ck":"caption","ak":"123"}]}'><a rel="mw:ExtLink" href="http://www.google.com" class="external autonumber" data-parsoid='{"targetOff":72,"contentOffsets":[72,101]}'></a><a href="./File:Foobar.jpg" data-parsoid='{"misnested":true}'><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"25","width":"220"},"sa":{"resource":"File:Foobar.jpg"},"misnested":true}'/></a><figcaption data-parsoid='{"misnested":true}'>123</figcaption></figure>
 !! end
 
 # --------------------------------------------
@@ -31216,6 +31512,20 @@ parsoid=html2wt
 {{echo|foo}}
 !! end
 
+!! test
+Only html p-tag is strong indent pre suppressing
+!! options
+parsoid=html2wt
+!! html/parsoid
+<p>test2<span>
+ test3
+</span></p>
+!! wikitext
+test2<span>
+<nowiki> </nowiki>test3
+</span>
+!! end
+
 # -----------------------------------------------------------------
 # End of section for Parsoid-only html2wt tests for serialization
 # of new content
@@ -31771,8 +32081,8 @@ T51672: Test for brackets in attributes of elements in external link texts
 <a rel="nofollow" class="external text" href="http://example.com/">link <span title="title with &#91;brackets&#93;">span</span></a>
 </p>
 !! html/parsoid
-<p><a rel="mw:ExtLink" class="external text" href="http://example.com/">link <span title="title with [brackets]">span</span></a>
-<a rel="mw:ExtLink" class="external text" href="http://example.com/">link <span title="title with [brackets]" data-parsoid='{"stx":"html","a":{"title":"title with [brackets]"},"sa":{"title":"title with &amp;#91;brackets&amp;#93;"}}'>span</span></a></p>
+<p><a rel="mw:ExtLink" href="http://example.com/" class="external text">link <span title="title with [brackets]">span</span></a>
+<a rel="mw:ExtLink" href="http://example.com/" class="external text">link <span title="title with [brackets]" data-parsoid='{"stx":"html","a":{"title":"title with [brackets]"},"sa":{"title":"title with &amp;#91;brackets&amp;#93;"}}'>span</span></a></p>
 !! end
 
 !! test
@@ -32869,3 +33179,13 @@ header
 *foo
 footer
 !! end
+
+!! test
+Ensure disambiguation links are marked properly
+!! options
+parsoid=wt2html
+!! wikitext
+[[Disambiguation]]
+!! html/parsoid
+<p><a rel="mw:WikiLink" href="./Disambiguation" title="Disambiguation" class="mw-disambig">Disambiguation</a></p>
+!! end
index 33518ef..83f27e8 100644 (file)
@@ -584,24 +584,6 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
                $this->tmpFiles = array_merge( $this->tmpFiles, (array)$files );
        }
 
-       // @todo Make const when we no longer support HHVM (T192166)
-       private static $namespaceAffectingSettings = [
-               'wgAllowImageMoving',
-               'wgCanonicalNamespaceNames',
-               'wgCapitalLinkOverrides',
-               'wgCapitalLinks',
-               'wgContentNamespaces',
-               'wgExtensionMessagesFiles',
-               'wgExtensionNamespaces',
-               'wgExtraNamespaces',
-               'wgExtraSignatureNamespaces',
-               'wgNamespaceContentModels',
-               'wgNamespaceProtection',
-               'wgNamespacesWithSubpages',
-               'wgNonincludableNamespaces',
-               'wgRestrictionLevels',
-       ];
-
        protected function tearDown() {
                global $wgRequest, $wgSQLMode;
 
@@ -648,12 +630,6 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
                foreach ( $this->iniSettings as $name => $value ) {
                        ini_set( $name, $value );
                }
-               if (
-                       array_intersect( self::$namespaceAffectingSettings, array_keys( $this->mwGlobals ) ) ||
-                       array_intersect( self::$namespaceAffectingSettings, $this->mwGlobalsToUnset )
-               ) {
-                       $this->resetNamespaces();
-               }
                $this->mwGlobals = [];
                $this->mwGlobalsToUnset = [];
                $this->restoreLoggers();
@@ -742,7 +718,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
                );
 
                if ( $name === 'ContentLanguage' ) {
-                       $this->doSetMwGlobals( [ 'wgContLang' => $this->localServices->getContentLanguage() ] );
+                       $this->setMwGlobals( [ 'wgContLang' => $this->localServices->getContentLanguage() ] );
                }
        }
 
@@ -753,9 +729,6 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
         * The key is added to the array of globals that will be reset afterwards
         * in the tearDown().
         *
-        * It may be necessary to call resetServices() to allow any changed configuration variables
-        * to take effect on services that get initialized based on these variables.
-        *
         * @par Example
         * @code
         *     protected function setUp() {
@@ -779,8 +752,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
         * @param mixed|null $value Value to set the global to (ignored
         *  if an array is given as first argument).
         *
-        * @note To allow changes to global variables to take effect on global service instances,
-        *       call resetServices().
+        * @note This will call resetServices().
         *
         * @since 1.21
         */
@@ -789,29 +761,13 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
                        $pairs = [ $pairs => $value ];
                }
 
-               if ( isset( $pairs['wgContLang'] ) ) {
-                       throw new MWException(
-                               'No setting $wgContLang, use setContentLang() or setService( \'ContentLanguage\' )'
-                       );
-               }
-
-               $this->doSetMwGlobals( $pairs, $value );
-       }
-
-       /**
-        * An internal method that allows setService() to set globals that tests are not supposed to
-        * touch.
-        */
-       private function doSetMwGlobals( $pairs, $value = null ) {
                $this->doStashMwGlobals( array_keys( $pairs ) );
 
                foreach ( $pairs as $key => $value ) {
                        $GLOBALS[$key] = $value;
                }
 
-               if ( array_intersect( self::$namespaceAffectingSettings, array_keys( $pairs ) ) ) {
-                       $this->resetNamespaces();
-               }
+               $this->resetServices();
        }
 
        /**
@@ -826,23 +782,6 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
                ini_set( $name, $value );
        }
 
-       /**
-        * Must be called whenever namespaces are changed, e.g., $wgExtraNamespaces is altered.
-        * Otherwise old namespace data will lurk and cause bugs.
-        */
-       private function resetNamespaces() {
-               if ( !$this->localServices ) {
-                       throw new Exception( __METHOD__ . ' must be called after MediaWikiTestCase::run()' );
-               }
-
-               if ( $this->localServices !== MediaWikiServices::getInstance() ) {
-                       throw new Exception( __METHOD__ . ' will not work because the global MediaWikiServices '
-                               . 'instance has been replaced by test code.' );
-               }
-
-               Language::clearCaches();
-       }
-
        /**
         * Check if we can back up a value by performing a shallow copy.
         * Values which fail this test are copied recursively.
@@ -939,16 +878,12 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
         * Useful for setting some entries in a configuration array, instead of
         * setting the entire array.
         *
-        * It may be necessary to call resetServices() to allow any changed configuration variables
-        * to take effect on services that get initialized based on these variables.
-        *
         * @param string $name The name of the global, as in wgFooBar
         * @param array $values The array containing the entries to set in that global
         *
         * @throws MWException If the designated global is not an array.
         *
-        * @note To allow changes to global variables to take effect on global service instances,
-        *       call resetServices().
+        * @note This will call resetServices().
         *
         * @since 1.21
         */
@@ -998,6 +933,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
                }
 
                self::resetGlobalParser();
+               Language::clearCaches();
        }
 
        /**
@@ -1182,16 +1118,11 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
         */
        public function setContentLang( $lang ) {
                if ( $lang instanceof Language ) {
-                       $this->setMwGlobals( 'wgLanguageCode', $lang->getCode() );
                        // Set to the exact object requested
                        $this->setService( 'ContentLanguage', $lang );
+                       $this->setMwGlobals( 'wgLanguageCode', $lang->getCode() );
                } else {
                        $this->setMwGlobals( 'wgLanguageCode', $lang );
-                       // Let the service handler make up the object.  Avoid calling setService(), because if
-                       // we do, overrideMwServices() will complain if it's called later on.
-                       $services = MediaWikiServices::getInstance();
-                       $services->resetServiceForTesting( 'ContentLanguage' );
-                       $this->doSetMwGlobals( [ 'wgContLang' => $services->getContentLanguage() ] );
                }
        }
 
@@ -1202,6 +1133,8 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
         * or three values to set a single permission, like
         *   $this->setGroupPermissions( '*', 'read', false );
         *
+        * @note This will call resetServices().
+        *
         * @since 1.31
         * @param array|string $newPerms Either an array of permissions to change,
         *   in which case the next two parameters are ignored; or a single string
@@ -1224,11 +1157,6 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
                }
 
                $this->setMwGlobals( 'wgGroupPermissions', $newPermissions );
-
-               // Reset services so they pick up the new permissions.
-               // Resetting just PermissionManager is not sufficient, since other services may
-               // have the old instance of PermissionManager injected.
-               $this->resetServices();
        }
 
        /**
@@ -2422,6 +2350,9 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
        /**
         * Create a temporary hook handler which will be reset by tearDown.
         * This replaces other handlers for the same hook.
+        *
+        * @note This will call resetServices().
+        *
         * @param string $hookName Hook name
         * @param mixed $handler Value suitable for a hook handler
         * @since 1.28
index 77d7c04..f047d82 100644 (file)
@@ -17,4 +17,16 @@ trait MediaWikiTestCaseTrait {
                        ...array_map( [ $this, 'matches' ], $values )
                ) );
        }
+
+       /**
+        * Return a PHPUnit mock that is expected to never have any methods called on it.
+        *
+        * @param string $type
+        * @return object
+        */
+       protected function createNoOpMock( $type ) {
+               $mock = $this->createMock( $type );
+               $mock->expects( $this->never() )->method( $this->anything() );
+               return $mock;
+       }
 }
index ccf3357..edd8195 100644 (file)
@@ -72,4 +72,34 @@ abstract class MediaWikiUnitTestCase extends TestCase {
                global $wgHooks;
                $wgHooks[$hookName] = [ $handler ];
        }
+
+       protected function getMockMessage( $text, ...$params ) {
+               if ( isset( $params[0] ) && is_array( $params[0] ) ) {
+                       $params = $params[0];
+               }
+
+               $msg = $this->getMockBuilder( Message::class )
+                       ->disableOriginalConstructor()
+                       ->setMethods( [] )
+                       ->getMock();
+
+               $msg->method( 'toString' )->willReturn( $text );
+               $msg->method( '__toString' )->willReturn( $text );
+               $msg->method( 'text' )->willReturn( $text );
+               $msg->method( 'parse' )->willReturn( $text );
+               $msg->method( 'plain' )->willReturn( $text );
+               $msg->method( 'parseAsBlock' )->willReturn( $text );
+               $msg->method( 'escaped' )->willReturn( $text );
+
+               $msg->method( 'title' )->willReturn( $msg );
+               $msg->method( 'inLanguage' )->willReturn( $msg );
+               $msg->method( 'inContentLanguage' )->willReturn( $msg );
+               $msg->method( 'useDatabase' )->willReturn( $msg );
+               $msg->method( 'setContext' )->willReturn( $msg );
+
+               $msg->method( 'exists' )->willReturn( true );
+               $msg->method( 'content' )->willReturn( new MessageContent( $msg ) );
+
+               return $msg;
+       }
 }
index 043d9c3..77fa4a9 100644 (file)
@@ -2,6 +2,7 @@
 DELETE {
 ?category ?x ?y
 } WHERE {
+   ?category ?x ?y
    VALUES ?category {
      <http://acme.test/wiki/Category:Test> <http://acme.test/wiki/Category:Test_2>
    }
index ae2e300..1970d33 100644 (file)
@@ -2,6 +2,7 @@
 DELETE {
 ?category ?x ?y
 } WHERE {
+   ?category ?x ?y
    VALUES ?category {
      <http://acme.test/wiki/Category:Changed_category>
    }
index d22bc47..3ee38df 100644 (file)
@@ -2,6 +2,7 @@
 DELETE {
 ?category ?x ?y
 } WHERE {
+   ?category ?x ?y
    VALUES ?category {
      <http://acme.test/wiki/Category:Test> <http://acme.test/wiki/Category:MovedTo> <http://acme.test/wiki/Category:Test_2> <http://acme.test/wiki/Category:Test_3> <http://acme.test/wiki/Category:Test_4>
    }
index 40c45dc..46c0c42 100644 (file)
@@ -658,7 +658,6 @@ class ActorMigrationTest extends MediaWikiLangTestCase {
                        // for User::getActorId()
                        'wgActorTableSchemaMigrationStage' => $stage
                ] );
-               $this->overrideMwServices();
 
                $user = $this->getMutableTestUser()->getUser();
                $userIdentity = $this->getMock( UserIdentity::class );
index 5d6c067..beddfe8 100644 (file)
@@ -41,7 +41,6 @@ class ContentSecurityPolicyTest extends MediaWikiTestCase {
                // Note, there are some obscure globals which
                // could affect the results which aren't included above.
 
-               $this->overrideMwServices();
                $context = RequestContext::getMain();
                $resp = $context->getRequest()->response();
                $conf = $context->getConfig();
index 660734e..6b650cd 100644 (file)
@@ -120,9 +120,6 @@ class GlobalTest extends MediaWikiTestCase {
                fwrite( $f, 'Message' );
                fclose( $f );
 
-               // Reset the service to avoid cached results
-               $this->overrideMwServices();
-
                $this->assertTrue( wfReadOnly() );
                $this->assertTrue( wfReadOnly() ); # Check cached
        }
@@ -137,7 +134,6 @@ class GlobalTest extends MediaWikiTestCase {
                $this->setMwGlobals( [
                        'wgReadOnly' => 'reason'
                ] );
-               $this->overrideMwServices();
 
                $this->assertSame( 'reason', wfReadOnlyReason() );
        }
@@ -321,33 +317,35 @@ class GlobalTest extends MediaWikiTestCase {
                ] );
                $this->setLogger( 'wfDebug', new LegacyLogger( 'wfDebug' ) );
 
+               unlink( $debugLogFile );
                wfDebug( "This is a normal string" );
                $this->assertEquals( "This is a normal string\n", file_get_contents( $debugLogFile ) );
-               unlink( $debugLogFile );
 
+               unlink( $debugLogFile );
                wfDebug( "This is nöt an ASCII string" );
                $this->assertEquals( "This is nöt an ASCII string\n", file_get_contents( $debugLogFile ) );
-               unlink( $debugLogFile );
 
+               unlink( $debugLogFile );
                wfDebug( "\00305This has böth UTF and control chars\003" );
                $this->assertEquals(
                        " 05This has böth UTF and control chars \n",
                        file_get_contents( $debugLogFile )
                );
-               unlink( $debugLogFile );
 
+               unlink( $debugLogFile );
                wfDebugMem();
                $this->assertGreaterThan(
                        1000,
                        preg_replace( '/\D/', '', file_get_contents( $debugLogFile ) )
                );
-               unlink( $debugLogFile );
 
+               unlink( $debugLogFile );
                wfDebugMem( true );
                $this->assertGreaterThan(
                        1000000,
                        preg_replace( '/\D/', '', file_get_contents( $debugLogFile ) )
                );
+
                unlink( $debugLogFile );
        }
 
index 95571f2..d8d5495 100644 (file)
@@ -18,9 +18,6 @@ class GlobalWithDBTest extends MediaWikiTestCase {
 
                // Don't try to fetch the files from Commons or anything, please
                $this->setMwGlobals( 'wgForeignFileRepos', [] );
-               // We need to reset services immediately so that editPage() doesn't use the old RepoGroup
-               // and hit the network
-               $this->resetServices();
 
                // XXX How do we get file redirects to work?
                $this->editPage( 'File:Redirect to bad.jpg', '#REDIRECT [[Bad.jpg]]' );
index fb32ef7..37d4e0c 100644 (file)
@@ -404,9 +404,6 @@ class MessageTest extends MediaWikiLangTestCase {
         */
        public function testRawHtmlInMsg() {
                $this->setMwGlobals( 'wgRawHtml', true );
-               // We have to reset the core hook registration.
-               // to register the html hook
-               $this->overrideMwServices();
 
                $msg = new RawMessage( '<html><script>alert("xss")</script></html>' );
                $txt = '<span class="error">&lt;html&gt; tags cannot be' .
index 2895fa2..5cf6fbe 100644 (file)
@@ -11,16 +11,6 @@ use Wikimedia\Rdbms\LoadBalancer;
  * @group Database
  */
 class MovePageTest extends MediaWikiTestCase {
-       /**
-        * @param string $class
-        * @return object A mock that throws on any method call
-        */
-       private function getNoOpMock( $class ) {
-               $mock = $this->createMock( $class );
-               $mock->expects( $this->never() )->method( $this->anythingBut( '__destruct' ) );
-               return $mock;
-       }
-
        /**
         * The only files that exist are 'File:Existent.jpg', 'File:Existent2.jpg', and
         * 'File:Existent-file-no-page.jpg'. Calling unexpected methods causes a test failure.
@@ -72,7 +62,7 @@ class MovePageTest extends MediaWikiTestCase {
        private function newMovePage( $old, $new, array $params = [] ) : MovePage {
                $mockLB = $this->createMock( LoadBalancer::class );
                $mockLB->method( 'getConnection' )
-                       ->willReturn( $params['db'] ?? $this->getNoOpMock( IDatabase::class ) );
+                       ->willReturn( $params['db'] ?? $this->createNoOpMock( IDatabase::class ) );
                $mockLB->expects( $this->never() )
                        ->method( $this->anythingBut( 'getConnection', '__destruct' ) );
 
@@ -98,8 +88,8 @@ class MovePageTest extends MediaWikiTestCase {
                        ),
                        $mockLB,
                        $params['nsInfo'] ?? $mockNsInfo,
-                       $params['wiStore'] ?? $this->getNoOpMock( WatchedItemStore::class ),
-                       $params['permMgr'] ?? $this->getNoOpMock( PermissionManager::class ),
+                       $params['wiStore'] ?? $this->createNoOpMock( WatchedItemStore::class ),
+                       $params['permMgr'] ?? $this->createNoOpMock( PermissionManager::class ),
                        $params['repoGroup'] ?? $this->getMockRepoGroup()
                );
        }
@@ -197,7 +187,6 @@ class MovePageTest extends MediaWikiTestCase {
                foreach ( $extraOptions as $key => $val ) {
                        $this->setMwGlobals( "wg$key", $val );
                }
-               $this->overrideMwServices();
                $this->setService( 'RepoGroup', $this->getMockRepoGroup() );
                // This returns true instead of an array if there are no errors
                $this->hideDeprecated( 'Title::isValidMoveOperation' );
index 122f377..0e788e7 100644 (file)
@@ -122,8 +122,6 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
 
                        $this->user = $this->userUser;
                }
-
-               $this->resetServices();
        }
 
        public function tearDown() {
@@ -143,7 +141,6 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
                } else {
                        $this->user = $this->altUser;
                }
-               $this->resetServices();
        }
 
        /**
@@ -421,8 +418,7 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
 
                        global $wgGroupPermissions;
                        $old = $wgGroupPermissions;
-                       $wgGroupPermissions = [];
-                       $this->resetServices();
+                       $this->setMwGlobals( 'wgGroupPermissions', [] );
 
                        $this->assertEquals( $check[$action][1],
                                MediaWikiServices::getInstance()->getPermissionManager()
@@ -433,8 +429,7 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
                        $this->assertEquals( $check[$action][1],
                                MediaWikiServices::getInstance()->getPermissionManager()
                                        ->getPermissionErrors( $action, $this->user, $this->title, 'secure' ) );
-                       $wgGroupPermissions = $old;
-                       $this->resetServices();
+                       $this->setMwGlobals( 'wgGroupPermissions', $old );
 
                        $this->overrideUserPermissions( $this->user, $action );
                        $this->assertEquals( $check[$action][2],
@@ -453,46 +448,39 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
                                        ->userCan( $action, $this->user, $this->title, true ) );
                        $this->assertEquals( $check[$action][3],
                                MediaWikiServices::getInstance()->getPermissionManager()
-                                       ->userCan( $action, $this->user, $this->title,
-                                       PermissionManager::RIGOR_QUICK ) );
+                                       ->quickUserCan( $action, $this->user, $this->title ) );
                        # count( User::getGroupsWithPermissions( $action ) ) < 1
                }
        }
 
        protected function runGroupPermissions( $perm, $action, $result, $result2 = null ) {
-               global $wgGroupPermissions;
-
                if ( $result2 === null ) {
                        $result2 = $result;
                }
 
-               $wgGroupPermissions['autoconfirmed']['move'] = false;
-               $wgGroupPermissions['user']['move'] = false;
-               $this->resetServices();
+               $this->setGroupPermissions( 'autoconfirmed', 'move', false );
+               $this->setGroupPermissions( 'user', 'move', false );
                $this->overrideUserPermissions( $this->user, $perm );
                $res = MediaWikiServices::getInstance()->getPermissionManager()
                        ->getPermissionErrors( $action, $this->user, $this->title );
                $this->assertEquals( $result, $res );
 
-               $wgGroupPermissions['autoconfirmed']['move'] = true;
-               $wgGroupPermissions['user']['move'] = false;
-               $this->resetServices();
+               $this->setGroupPermissions( 'autoconfirmed', 'move', true );
+               $this->setGroupPermissions( 'user', 'move', false );
                $this->overrideUserPermissions( $this->user, $perm );
                $res = MediaWikiServices::getInstance()->getPermissionManager()
                        ->getPermissionErrors( $action, $this->user, $this->title );
                $this->assertEquals( $result2, $res );
 
-               $wgGroupPermissions['autoconfirmed']['move'] = true;
-               $wgGroupPermissions['user']['move'] = true;
-               $this->resetServices();
+               $this->setGroupPermissions( 'autoconfirmed', 'move', true );
+               $this->setGroupPermissions( 'user', 'move', true );
                $this->overrideUserPermissions( $this->user, $perm );
                $res = MediaWikiServices::getInstance()->getPermissionManager()
                        ->getPermissionErrors( $action, $this->user, $this->title );
                $this->assertEquals( $result2, $res );
 
-               $wgGroupPermissions['autoconfirmed']['move'] = false;
-               $wgGroupPermissions['user']['move'] = true;
-               $this->resetServices();
+               $this->setGroupPermissions( 'autoconfirmed', 'move', false );
+               $this->setGroupPermissions( 'user', 'move', true );
                $this->overrideUserPermissions( $this->user, $perm );
                $res = MediaWikiServices::getInstance()->getPermissionManager()
                        ->getPermissionErrors( $action, $this->user, $this->title );
@@ -899,7 +887,7 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
 
                $this->assertEquals( true,
                        MediaWikiServices::getInstance()->getPermissionManager()
-                               ->userCan( 'edit', $this->user, $this->title, PermissionManager::RIGOR_QUICK ) );
+                               ->quickUserCan( 'edit', $this->user, $this->title ) );
 
                $this->title->mRestrictions = [ "edit" => [ 'bogus', "sysop", "protect", "" ],
                        "bogus" => [ 'bogus', "sysop", "protect", "" ] ];
@@ -945,11 +933,11 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
 
                $this->assertEquals( false,
                        MediaWikiServices::getInstance()->getPermissionManager()
-                               ->userCan( 'bogus', $this->user, $this->title, PermissionManager::RIGOR_QUICK ) );
+                               ->quickUserCan( 'bogus', $this->user, $this->title ) );
 
                $this->assertEquals( false,
-                       MediaWikiServices::getInstance()->getPermissionManager()->userCan(
-                               'edit', $this->user, $this->title, PermissionManager::RIGOR_QUICK ) );
+                       MediaWikiServices::getInstance()->getPermissionManager()->quickUserCan(
+                               'edit', $this->user, $this->title ) );
 
                $this->assertEquals( [ [ 'badaccess-group0' ],
                        [ 'protectedpagetext', 'bogus', 'bogus' ],
@@ -965,12 +953,12 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
 
                $this->overrideUserPermissions( $this->user, [ "edit", "editprotected" ] );
                $this->assertEquals( false,
-                       MediaWikiServices::getInstance()->getPermissionManager()->userCan(
-                               'bogus', $this->user, $this->title, PermissionManager::RIGOR_QUICK ) );
+                       MediaWikiServices::getInstance()->getPermissionManager()->quickUserCan(
+                               'bogus', $this->user, $this->title ) );
 
                $this->assertEquals( false,
-                       MediaWikiServices::getInstance()->getPermissionManager()->userCan(
-                               'edit', $this->user, $this->title, PermissionManager::RIGOR_QUICK ) );
+                       MediaWikiServices::getInstance()->getPermissionManager()->quickUserCan(
+                               'edit', $this->user, $this->title ) );
 
                $this->assertEquals( [ [ 'badaccess-group0' ],
                        [ 'protectedpagetext', 'bogus', 'bogus' ],
@@ -1144,7 +1132,6 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
                                ->getPermissionErrors( 'edit', $this->user, $this->title ) );
 
                $this->setMwGlobals( 'wgEmailConfirmToEdit', false );
-               $this->resetServices();
                $this->overrideUserPermissions( $this->user, [
                        'createpage',
                        'edit',
@@ -1188,8 +1175,7 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
                        ->userCan( 'move-target', $this->user, $this->title ) );
                // quickUserCan should ignore user blocks
                $this->assertEquals( true, MediaWikiServices::getInstance()->getPermissionManager()
-                       ->userCan( 'move-target', $this->user, $this->title,
-                               PermissionManager::RIGOR_QUICK ) );
+                       ->quickUserCan( 'move-target', $this->user, $this->title ) );
 
                global $wgLocalTZoffset;
                $wgLocalTZoffset = -60;
@@ -1577,7 +1563,6 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
                        $rights = array_diff( $rights, [ 'writetest' ] );
                } );
 
-               $this->resetServices();
                $rights = MediaWikiServices::getInstance()
                        ->getPermissionManager()
                        ->getUserPermissions( $user );
@@ -1859,10 +1844,47 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
                        'wgRestrictionLevels' => [ '', 'autoconfirmed', 'sysop' ],
                        'wgAutopromote' => []
                ] );
-               $this->resetServices();
                $user = is_null( $userGroups ) ? null : $this->getTestUser( $userGroups )->getUser();
                $this->assertSame( $expected, MediaWikiServices::getInstance()
                        ->getPermissionManager()
                        ->getNamespaceRestrictionLevels( $ns, $user ) );
        }
+
+       /**
+        * @covers \MediaWiki\Permissions\PermissionManager::getAllPermissions
+        */
+       public function testGetAllPermissions() {
+               $this->setMwGlobals( [
+                       'wgAvailableRights' => [ 'test_right' ]
+               ] );
+               $this->resetServices();
+               $this->assertContains(
+                       'test_right',
+                       MediaWikiServices::getInstance()
+                               ->getPermissionManager()
+                               ->getAllPermissions()
+               );
+       }
+
+       /**
+        * @covers \MediaWiki\Permissions\PermissionManager::getRightsCacheKey
+        * @throws \Exception
+        */
+       public function testAnonPermissionsNotClash() {
+               $user1 = User::newFromName( 'User1' );
+               $user2 = User::newFromName( 'User2' );
+               $pm = MediaWikiServices::getInstance()->getPermissionManager();
+               $pm->overrideUserRightsForTesting( $user2, [] );
+               $this->assertNotSame( $pm->getUserPermissions( $user1 ), $pm->getUserPermissions( $user2 ) );
+       }
+
+       /**
+        * @covers \MediaWiki\Permissions\PermissionManager::getRightsCacheKey
+        */
+       public function testAnonPermissionsNotClashOneRegistered() {
+               $user1 = User::newFromName( 'User1' );
+               $user2 = $this->getTestSysop()->getUser();
+               $pm = MediaWikiServices::getInstance()->getPermissionManager();
+               $this->assertNotSame( $pm->getUserPermissions( $user1 ), $pm->getUserPermissions( $user2 ) );
+       }
 }
index 685cb40..4d9f8e1 100644 (file)
@@ -60,8 +60,6 @@ class PrefixSearchTest extends MediaWikiLangTestCase {
 
                $this->originalHandlers = TestingAccessWrapper::newFromClass( Hooks::class )->handlers;
                TestingAccessWrapper::newFromClass( Hooks::class )->handlers = [];
-
-               $this->overrideMwServices();
        }
 
        public function tearDown() {
index 49dcf07..3c6573a 100644 (file)
@@ -25,7 +25,6 @@ class MWBasicRequestAuthorizerTest extends MediaWikiTestCase {
                $user = User::newFromName( 'Test user' );
                // Don't allow the rights to everybody so that user rights kick in.
                $this->mergeMwGlobalArrayValue( 'wgGroupPermissions', [ '*' => $userRights ] );
-               $this->resetServices();
                $this->overrideUserPermissions(
                        $user,
                        array_keys( array_filter( $userRights ), function ( $value ) {
index 57619c5..5cc3646 100644 (file)
@@ -960,7 +960,6 @@ class RevisionQueryInfoTest extends MediaWikiTestCase {
         */
        public function testRevisionSelectFields( $migrationStageSettings, $expected ) {
                $this->setMwGlobals( $migrationStageSettings );
-               $this->overrideMwServices();
 
                $this->hideDeprecated( 'Revision::selectFields' );
                $this->assertArrayEqualsIgnoringIntKeyOrder( $expected, Revision::selectFields() );
@@ -972,7 +971,6 @@ class RevisionQueryInfoTest extends MediaWikiTestCase {
         */
        public function testRevisionSelectArchiveFields( $migrationStageSettings, $expected ) {
                $this->setMwGlobals( $migrationStageSettings );
-               $this->overrideMwServices();
 
                $this->hideDeprecated( 'Revision::selectArchiveFields' );
                $this->assertArrayEqualsIgnoringIntKeyOrder( $expected, Revision::selectArchiveFields() );
@@ -984,7 +982,6 @@ class RevisionQueryInfoTest extends MediaWikiTestCase {
        public function testRevisionUserJoinCond() {
                $this->hideDeprecated( 'Revision::userJoinCond' );
                $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_OLD );
-               $this->overrideMwServices();
                $this->assertEquals(
                        [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
                        Revision::userJoinCond()
@@ -1041,7 +1038,6 @@ class RevisionQueryInfoTest extends MediaWikiTestCase {
         */
        public function testRevisionGetArchiveQueryInfo( $migrationStageSettings, $expected ) {
                $this->setMwGlobals( $migrationStageSettings );
-               $this->overrideMwServices();
 
                $queryInfo = Revision::getArchiveQueryInfo();
                $this->assertQueryInfoEquals( $expected, $queryInfo );
@@ -1053,7 +1049,6 @@ class RevisionQueryInfoTest extends MediaWikiTestCase {
         */
        public function testRevisionGetQueryInfo( $migrationStageSettings, $options, $expected ) {
                $this->setMwGlobals( $migrationStageSettings );
-               $this->overrideMwServices();
 
                $queryInfo = Revision::getQueryInfo( $options );
                $this->assertQueryInfoEquals( $expected, $queryInfo );
@@ -1065,7 +1060,6 @@ class RevisionQueryInfoTest extends MediaWikiTestCase {
         */
        public function testRevisionStoreGetQueryInfo( $migrationStageSettings, $options, $expected ) {
                $this->setMwGlobals( $migrationStageSettings );
-               $this->overrideMwServices();
 
                $store = MediaWikiServices::getInstance()->getRevisionStore();
 
@@ -1083,7 +1077,6 @@ class RevisionQueryInfoTest extends MediaWikiTestCase {
                $expected
        ) {
                $this->setMwGlobals( $migrationStageSettings );
-               $this->overrideMwServices();
 
                $store = MediaWikiServices::getInstance()->getRevisionStore();
 
@@ -1097,7 +1090,6 @@ class RevisionQueryInfoTest extends MediaWikiTestCase {
         */
        public function testRevisionStoreGetArchiveQueryInfo( $migrationStageSettings, $expected ) {
                $this->setMwGlobals( $migrationStageSettings );
-               $this->overrideMwServices();
 
                $store = MediaWikiServices::getInstance()->getRevisionStore();
 
index d4393dd..55bfab7 100644 (file)
@@ -83,8 +83,6 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
                        'wgContentHandlerUseDB' => $this->getContentHandlerUseDB(),
                        'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_NEW,
                ] );
-
-               $this->overrideMwServices();
        }
 
        protected function addCoreDBData() {
@@ -403,7 +401,6 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
                $title = $this->getTestPageTitle();
                $rev = $this->getRevisionRecordFromDetailsArray( $revDetails );
 
-               $this->overrideMwServices();
                $store = MediaWikiServices::getInstance()->getRevisionStore();
                $return = $store->insertRevisionOn( $rev, wfGetDB( DB_MASTER ) );
 
@@ -480,7 +477,6 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
                        'user' => true,
                ];
 
-               $this->overrideMwServices();
                $store = MediaWikiServices::getInstance()->getRevisionStore();
 
                // Insert the first revision
@@ -594,8 +590,6 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
         * @covers \MediaWiki\Revision\RevisionStore::findSlotContentId
         */
        public function testNewNullRevision( Title $title, $revDetails, $comment, $minor = false ) {
-               $this->overrideMwServices();
-
                $user = TestUserRegistry::getMutableTestUser( __METHOD__ )->getUser();
                $page = WikiPage::factory( $title );
 
@@ -1021,7 +1015,6 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
         */
        public function testNewRevisionFromRow_anonEdit_legacyEncoding() {
                $this->setMwGlobals( 'wgLegacyEncoding', 'windows-1252' );
-               $this->overrideMwServices();
                $page = $this->getTestPage();
                $text = __METHOD__ . 'a-ä';
                /** @var Revision $rev */
@@ -1101,7 +1094,6 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
         */
        public function testNewRevisionFromArchiveRow_legacyEncoding() {
                $this->setMwGlobals( 'wgLegacyEncoding', 'windows-1252' );
-               $this->overrideMwServices();
                $store = MediaWikiServices::getInstance()->getRevisionStore();
                $title = Title::newFromText( __METHOD__ );
                $text = __METHOD__ . '-bä';
@@ -1797,7 +1789,6 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
        public function testGetKnownCurrentRevision_userNameChange() {
                global $wgActorTableSchemaMigrationStage;
 
-               $this->overrideMwServices();
                $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
                $this->setService( 'MainWANObjectCache', $cache );
 
@@ -1838,7 +1829,6 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
         * @covers \MediaWiki\Revision\RevisionStore::getKnownCurrentRevision
         */
        public function testGetKnownCurrentRevision_revDelete() {
-               $this->overrideMwServices();
                $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
                $this->setService( 'MainWANObjectCache', $cache );
 
index 83e8d85..7b334ee 100644 (file)
@@ -95,8 +95,6 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
                        'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_NEW,
                ] );
 
-               $this->overrideMwServices();
-
                if ( !$this->testPage ) {
                        /**
                         * We have to create a new page for each subclass as the page creation may result
index d62e4c7..865bd31 100644 (file)
@@ -281,7 +281,6 @@ class RevisionTest extends MediaWikiTestCase {
         * @covers \MediaWiki\Revision\RevisionStore::newMutableRevisionFromArray
         */
        public function testConstructFromRowWithBadPageId() {
-               $this->overrideMwServices();
                Wikimedia\suppressWarnings();
                $rev = new Revision( (object)[
                        'rev_page' => 77777777,
@@ -603,7 +602,6 @@ class RevisionTest extends MediaWikiTestCase {
         */
        public function testLoadFromTitle() {
                $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_NEW );
-               $this->overrideMwServices();
                $title = $this->getMockTitle();
 
                $conditions = [
index ac39b48..1d88122 100644 (file)
@@ -5,6 +5,7 @@ namespace MediaWiki\Tests\Storage;
 use InvalidArgumentException;
 use Language;
 use MediaWiki\MediaWikiServices;
+use MediaWiki\Storage\BlobAccessException;
 use MediaWiki\Storage\SqlBlobStore;
 use MediaWikiTestCase;
 use stdClass;
@@ -218,6 +219,7 @@ class SqlBlobStoreTest extends MediaWikiTestCase {
        }
 
        /**
+        * @param string $blob
         * @dataProvider provideBlobs
         * @covers \MediaWiki\Storage\SqlBlobStore::storeBlob
         * @covers \MediaWiki\Storage\SqlBlobStore::getBlob
@@ -228,6 +230,109 @@ class SqlBlobStoreTest extends MediaWikiTestCase {
                $this->assertSame( $blob, $store->getBlob( $address ) );
        }
 
+       /**
+        * @covers \MediaWiki\Storage\SqlBlobStore::storeBlob
+        * @covers \MediaWiki\Storage\SqlBlobStore::getBlobBatch
+        */
+       public function testSimpleStorageGetBlobBatchSimpleEmpty() {
+               $store = $this->getBlobStore();
+               $this->assertArrayEquals(
+                       [],
+                       $store->getBlobBatch( [] )->getValue()
+               );
+       }
+
+       /**
+        * @param string $blob
+        * @dataProvider provideBlobs
+        * @covers \MediaWiki\Storage\SqlBlobStore::storeBlob
+        * @covers \MediaWiki\Storage\SqlBlobStore::getBlobBatch
+        */
+       public function testSimpleStorageGetBlobBatchSimpleRoundtrip( $blob ) {
+               $store = $this->getBlobStore();
+               $addresses = [
+                       $store->storeBlob( $blob ),
+                       $store->storeBlob( $blob . '1' )
+               ];
+               $this->assertArrayEquals(
+                       array_combine( $addresses, [ $blob, $blob . '1' ] ),
+                       $store->getBlobBatch( $addresses )->getValue()
+               );
+       }
+
+       /**
+        * @covers \MediaWiki\Storage\SqlBlobStore::getBlob
+        */
+       public function testSimpleStorageNonExistentBlob() {
+               $this->setExpectedException( BlobAccessException::class );
+               $store = $this->getBlobStore();
+               $store->getBlob( 'tt:this_will_not_exist' );
+       }
+
+       /**
+        * @covers \MediaWiki\Storage\SqlBlobStore::getBlobBatch
+        */
+       public function testSimpleStorageNonExistentBlobBatch() {
+               $store = $this->getBlobStore();
+               $result = $store->getBlobBatch( [ 'tt:this_will_not_exist', 'tt:1000', 'bla:1001' ] );
+               $this->assertSame(
+                       [
+                               'tt:this_will_not_exist' => null,
+                               'tt:1000' => null,
+                               'bla:1001' => null
+                       ],
+                       $result->getValue()
+               );
+               $this->assertSame( [
+                       [
+                               'type' => 'warning',
+                               'message' => 'internalerror',
+                               'params' => [
+                                       'Bad blob address: tt:this_will_not_exist'
+                               ]
+                       ],
+                       [
+                               'type' => 'warning',
+                               'message' => 'internalerror',
+                               'params' => [
+                                       'Unknown blob address schema: bla'
+                               ]
+                       ],
+                       [
+                               'type' => 'warning',
+                               'message' => 'internalerror',
+                               'params' => [
+                                       'Unable to fetch blob at tt:1000'
+                               ]
+                       ]
+               ], $result->getErrors() );
+       }
+
+       /**
+        * @covers \MediaWiki\Storage\SqlBlobStore::getBlobBatch
+        */
+       public function testSimpleStoragePartialNonExistentBlobBatch() {
+               $store = $this->getBlobStore();
+               $address = $store->storeBlob( 'test_data' );
+               $result = $store->getBlobBatch( [ $address, 'tt:this_will_not_exist_too' ] );
+               $this->assertSame(
+                       [
+                               $address => 'test_data',
+                               'tt:this_will_not_exist_too' => null
+                       ],
+                       $result->getValue()
+               );
+               $this->assertSame( [
+                       [
+                               'type' => 'warning',
+                               'message' => 'internalerror',
+                               'params' => [
+                                       'Bad blob address: tt:this_will_not_exist_too'
+                               ]
+                       ],
+               ], $result->getErrors() );
+       }
+
        /**
         * @dataProvider provideBlobs
         * @covers \MediaWiki\Storage\SqlBlobStore::storeBlob
index 91c4a13..6c17bf5 100644 (file)
@@ -72,7 +72,6 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
 
                        $this->user = $this->userUser;
                }
-               $this->resetServices();
        }
 
        protected function setTitle( $ns, $title = "Main_Page" ) {
@@ -329,9 +328,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
 
                        global $wgGroupPermissions;
                        $old = $wgGroupPermissions;
-                       $wgGroupPermissions = [];
-
-                       $this->resetServices();
+                       $this->setMwGlobals( 'wgGroupPermissions', [] );
 
                        $this->assertEquals( $check[$action][1],
                                $this->title->getUserPermissionsErrors( $action, $this->user, true ) );
@@ -340,8 +337,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                        $this->assertEquals( $check[$action][1],
                                $this->title->getUserPermissionsErrors( $action, $this->user, 'secure' ) );
 
-                       $wgGroupPermissions = $old;
-                       $this->resetServices();
+                       $this->setMwGlobals( 'wgGroupPermissions', $old );
 
                        $this->overrideUserPermissions( $this->user, $action );
                        $this->assertEquals( $check[$action][2],
@@ -361,8 +357,6 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
        }
 
        protected function runGroupPermissions( $action, $result, $result2 = null ) {
-               global $wgGroupPermissions;
-
                if ( $result2 === null ) {
                        $result2 = $result;
                }
@@ -375,30 +369,26 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                $userPermsOverrides = MediaWikiServices::getInstance()->getPermissionManager()
                        ->getUserPermissions( $this->user );
 
-               $wgGroupPermissions['autoconfirmed']['move'] = false;
-               $wgGroupPermissions['user']['move'] = false;
-               $this->resetServices();
+               $this->setGroupPermissions( 'autoconfirmed', 'move', false );
+               $this->setGroupPermissions( 'user', 'move', false );
                $this->overrideUserPermissions( $this->user, $userPermsOverrides );
                $res = $this->title->getUserPermissionsErrors( $action, $this->user );
                $this->assertEquals( $result, $res );
 
-               $wgGroupPermissions['autoconfirmed']['move'] = true;
-               $wgGroupPermissions['user']['move'] = false;
-               $this->resetServices();
+               $this->setGroupPermissions( 'autoconfirmed', 'move', true );
+               $this->setGroupPermissions( 'user', 'move', false );
                $this->overrideUserPermissions( $this->user, $userPermsOverrides );
                $res = $this->title->getUserPermissionsErrors( $action, $this->user );
                $this->assertEquals( $result2, $res );
 
-               $wgGroupPermissions['autoconfirmed']['move'] = true;
-               $wgGroupPermissions['user']['move'] = true;
-               $this->resetServices();
+               $this->setGroupPermissions( 'autoconfirmed', 'move', true );
+               $this->setGroupPermissions( 'user', 'move', true );
                $this->overrideUserPermissions( $this->user, $userPermsOverrides );
                $res = $this->title->getUserPermissionsErrors( $action, $this->user );
                $this->assertEquals( $result2, $res );
 
-               $wgGroupPermissions['autoconfirmed']['move'] = false;
-               $wgGroupPermissions['user']['move'] = true;
-               $this->resetServices();
+               $this->setGroupPermissions( 'autoconfirmed', 'move', false );
+               $this->setGroupPermissions( 'user', 'move', true );
                $this->overrideUserPermissions( $this->user, $userPermsOverrides );
                $res = $this->title->getUserPermissionsErrors( $action, $this->user );
                $this->assertEquals( $result2, $res );
@@ -906,7 +896,6 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                        'wgEmailAuthentication' => true,
                        'wgBlockDisablesLogin' => false,
                ] );
-               $this->resetServices();
 
                $this->overrideUserPermissions(
                        $this->user,
@@ -921,7 +910,6 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                        $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
 
                $this->setMwGlobals( 'wgEmailConfirmToEdit', false );
-               $this->resetServices();
                $this->overrideUserPermissions(
                        $this->user,
                        [ 'createpage', 'edit', 'move', 'rollback', 'patrol', 'upload', 'purge' ]
@@ -1088,7 +1076,6 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                                ],
                        ],
                ] );
-               $this->resetServices();
 
                $now = time();
                $this->user->mBlockedby = $this->user->getName();
index 6cfc377..18faeea 100644 (file)
@@ -150,9 +150,6 @@ class TitleTest extends MediaWikiTestCase {
                                ]
                        ]
                ] );
-
-               // Reset services since we modified $wgLocalInterwikis
-               $this->overrideMwServices();
        }
 
        /**
index c2917b6..2d19d38 100644 (file)
@@ -150,8 +150,6 @@ class ApiBlockTest extends ApiTestCase {
                $this->setMwGlobals( 'wgRevokePermissions',
                        [ 'user' => [ 'applychangetags' => true ] ] );
 
-               $this->resetServices();
-
                $this->doBlock( [ 'tags' => 'custom tag' ] );
        }
 
@@ -162,7 +160,6 @@ class ApiBlockTest extends ApiTestCase {
                $this->mergeMwGlobalArrayValue( 'wgGroupPermissions',
                        [ 'sysop' => $newPermissions ] );
 
-               $this->resetServices();
                $res = $this->doBlock( [ 'hidename' => '' ] );
 
                $dbw = wfGetDB( DB_MASTER );
@@ -212,8 +209,6 @@ class ApiBlockTest extends ApiTestCase {
                $this->setMwGlobals( 'wgRevokePermissions',
                        [ 'sysop' => [ 'blockemail' => true ] ] );
 
-               $this->resetServices();
-
                $this->doBlock( [ 'noemail' => '' ] );
        }
 
index cc5dada..c68954c 100644 (file)
@@ -143,7 +143,6 @@ class ApiDeleteTest extends ApiTestCase {
                ChangeTags::defineTag( 'custom tag' );
                $this->setMwGlobals( 'wgRevokePermissions',
                        [ 'user' => [ 'applychangetags' => true ] ] );
-               $this->resetServices();
 
                $this->editPage( $name, 'Some text' );
 
index 5e5fea3..aafb3a2 100644 (file)
@@ -39,7 +39,6 @@ class ApiEditPageTest extends ApiTestCase {
                        $this->tablesUsed,
                        [ 'change_tag', 'change_tag_def', 'logging' ]
                );
-               $this->resetServices();
        }
 
        public function testEdit() {
@@ -1368,8 +1367,6 @@ class ApiEditPageTest extends ApiTestCase {
                ChangeTags::defineTag( 'custom tag' );
                $this->setMwGlobals( 'wgRevokePermissions',
                        [ 'user' => [ 'applychangetags' => true ] ] );
-               // Supply services with updated globals
-               $this->resetServices();
 
                try {
                        $this->doApiRequestWithToken( [
@@ -1498,8 +1495,6 @@ class ApiEditPageTest extends ApiTestCase {
 
                $this->setMwGlobals( 'wgRevokePermissions',
                        [ 'user' => [ 'upload' => true ] ] );
-               // Supply services with updated globals
-               $this->resetServices();
 
                $this->doApiRequestWithToken( [
                        'action' => 'edit',
@@ -1515,8 +1510,6 @@ class ApiEditPageTest extends ApiTestCase {
                        'The content you supplied exceeds the article size limit of 1 kilobyte.' );
 
                $this->setMwGlobals( 'wgMaxArticleSize', 1 );
-               // Supply services with updated globals
-               $this->resetServices();
 
                $text = str_repeat( '!', 1025 );
 
@@ -1534,8 +1527,6 @@ class ApiEditPageTest extends ApiTestCase {
                        'The action you have requested is limited to users in the group: ' );
 
                $this->setMwGlobals( 'wgRevokePermissions', [ '*' => [ 'edit' => true ] ] );
-               // Supply services with updated globals
-               $this->resetServices();
 
                $this->doApiRequestWithToken( [
                        'action' => 'edit',
@@ -1552,8 +1543,6 @@ class ApiEditPageTest extends ApiTestCase {
 
                $this->setMwGlobals( 'wgRevokePermissions',
                        [ 'user' => [ 'editcontentmodel' => true ] ] );
-               // Supply services with updated globals
-               $this->resetServices();
 
                $this->doApiRequestWithToken( [
                        'action' => 'edit',
index 580efcd..1e2135b 100644 (file)
@@ -141,7 +141,6 @@ class ApiMainTest extends ApiTestCase {
        public function testSetCacheModeUnrecognized() {
                $api = new ApiMain();
                $api->setCacheMode( 'unrecognized' );
-               $this->resetServices();
                $this->assertSame(
                        'private',
                        TestingAccessWrapper::newFromObject( $api )->mCacheMode,
index c98308c..e09e6ad 100644 (file)
@@ -294,7 +294,6 @@ class ApiMoveTest extends ApiTestCase {
                $name = ucfirst( __FUNCTION__ );
 
                $this->mergeMwGlobalArrayValue( 'wgNamespacesWithSubpages', [ NS_MAIN => true ] );
-               $this->resetServices();
 
                $pages = [ $name, "$name/1", "$name/2", "Talk:$name", "Talk:$name/1", "Talk:$name/3" ];
                $ids = [];
index bdce70c..2d0ce26 100644 (file)
@@ -42,6 +42,16 @@ class ApiOptionsTest extends MediaWikiLangTestCase {
                $this->mUserMock->method( 'getOptions' )
                        ->willReturn( [] );
 
+               // DefaultPreferencesFactory calls a ton of user methods, but we still want to list all of
+               // them in case bugs are caused by unexpected things returning null that shouldn't.
+               $this->mUserMock->expects( $this->never() )->method( $this->anythingBut(
+                       'getEffectiveGroups', 'getOptionKinds', 'getInstanceForUpdate', 'getOptions', 'getId',
+                       'isAnon', 'getRequest', 'isLoggedIn', 'getName', 'getGroupMemberships', 'getEditCount',
+                       'getRegistration', 'isAllowed', 'getRealName', 'getOption', 'getStubThreshold',
+                       'getBoolOption', 'getEmail', 'getDatePreference', 'useRCPatrol', 'useNPPatrol',
+                       'setOption', 'saveSettings', 'resetOptions', 'isRegistered'
+               ) );
+
                // Create a new context
                $this->mContext = new DerivativeContext( new RequestContext() );
                $this->mContext->getContext()->setTitle( Title::newFromText( 'Test' ) );
@@ -153,6 +163,8 @@ class ApiOptionsTest extends MediaWikiLangTestCase {
 
        private function executeQuery( $request ) {
                $this->mContext->setRequest( new FauxRequest( $request, true, $this->mSession ) );
+               $this->mUserMock->method( 'getRequest' )->willReturn( $this->mContext->getRequest() );
+
                $this->mTested->execute();
 
                return $this->mTested->getResult()->getResultData( null, [ 'Strip' => 'all' ] );
index a87160a..06b4cf2 100644 (file)
@@ -121,7 +121,6 @@ class ApiParseTest extends ApiTestCase {
 
                $this->setMwGlobals( 'wgExtraInterlanguageLinkPrefixes', [ 'madeuplanguage' ] );
                $this->tablesUsed[] = 'interwiki';
-               $this->resetServices();
        }
 
        /**
index 282188d..0a2558a 100644 (file)
@@ -210,15 +210,16 @@ class ApiQuerySiteinfoTest extends ApiTestCase {
                        $this->setExpectedApiException( 'apierror-siteinfo-includealldenied' );
                }
 
-               $mockLB = $this->getMockBuilder( LoadBalancer::class )
-                       ->disableOriginalConstructor()
-                       ->setMethods( [ 'getMaxLag', 'getLagTimes', 'getServerName', '__destruct' ] )
-                       ->getMock();
+               $mockLB = $this->createMock( LoadBalancer::class );
                $mockLB->method( 'getMaxLag' )->willReturn( [ null, 7, 1 ] );
                $mockLB->method( 'getLagTimes' )->willReturn( [ 5, 7 ] );
                $mockLB->method( 'getServerName' )->will( $this->returnValueMap( [
                        [ 0, 'apple' ], [ 1, 'carrot' ]
                ] ) );
+               $mockLB->method( 'getLocalDomainID' )->willReturn( 'testdomain' );
+               $mockLB->expects( $this->never() )->method( $this->anythingBut(
+                       'getMaxLag', 'getLagTimes', 'getServerName', 'getLocalDomainID', '__destruct'
+               ) );
                $this->setService( 'DBLoadBalancer', $mockLB );
 
                $this->setMwGlobals( 'wgShowHostnames', $showHostnames );
index 0d7ad0c..92804fd 100644 (file)
@@ -37,8 +37,6 @@ class ApiUserrightsTest extends ApiTestCase {
                if ( $remove ) {
                        $this->mergeMwGlobalArrayValue( 'wgRemoveGroups', [ 'bureaucrat' => $remove ] );
                }
-
-               $this->resetServices();
        }
 
        /**
@@ -221,7 +219,6 @@ class ApiUserrightsTest extends ApiTestCase {
                ChangeTags::defineTag( 'custom tag' );
 
                $this->setGroupPermissions( 'user', 'applychangetags', false );
-               $this->resetServices();
 
                $this->doFailedRightsChange(
                        'You do not have permission to apply change tags along with your changes.',
index 92c71bd..301ed10 100644 (file)
@@ -11,13 +11,11 @@ class ApiQueryUserContribsTest extends ApiTestCase {
                global $wgActorTableSchemaMigrationStage;
 
                $reset = new \Wikimedia\ScopedCallback( function ( $v ) {
-                       global $wgActorTableSchemaMigrationStage;
-                       $wgActorTableSchemaMigrationStage = $v;
-                       $this->overrideMwServices();
+                       $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', $v );
                }, [ $wgActorTableSchemaMigrationStage ] );
                // Needs to WRITE_BOTH so READ_OLD tests below work. READ mode here doesn't really matter.
-               $wgActorTableSchemaMigrationStage = SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW;
-               $this->overrideMwServices();
+               $this->setMwGlobals( 'wgActorTableSchemaMigrationStage',
+                       SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW );
 
                $users = [
                        User::newFromName( '192.168.2.2', false ),
@@ -55,7 +53,6 @@ class ApiQueryUserContribsTest extends ApiTestCase {
                $this->markTestSkippedIfDbType( 'sqlite' );
 
                $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', $stage );
-               $this->overrideMwServices();
 
                if ( isset( $params['ucuserids'] ) ) {
                        $params['ucuserids'] = implode( '|', array_map( 'User::idFromName', $params['ucuserids'] ) );
@@ -150,7 +147,6 @@ class ApiQueryUserContribsTest extends ApiTestCase {
         */
        public function testInterwikiUser( $stage ) {
                $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', $stage );
-               $this->overrideMwServices();
 
                $params = [
                        'action' => 'query',
index fc6f688..f8be1d4 100644 (file)
@@ -1473,12 +1473,10 @@ class AuthManagerTest extends \MediaWikiTestCase {
                        ],
                        'wgProxyWhitelist' => [],
                ] );
-               $this->resetServices();
                $status = $this->manager->checkAccountCreatePermissions( new \User );
                $this->assertFalse( $status->isOK() );
                $this->assertTrue( $status->hasMessage( 'sorbs_create_account_reason' ) );
                $this->setMwGlobals( 'wgProxyWhitelist', [ '127.0.0.1' ] );
-               $this->resetServices();
                $status = $this->manager->checkAccountCreatePermissions( new \User );
                $this->assertTrue( $status->isGood() );
        }
@@ -1610,9 +1608,9 @@ class AuthManagerTest extends \MediaWikiTestCase {
                $this->assertSame( AuthenticationResponse::FAIL, $ret->status );
                $this->assertSame( 'noname', $ret->message->getKey() );
 
+               $this->hook( 'LocalUserCreated', $this->never() );
                $readOnlyMode = \MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode();
                $readOnlyMode->setReason( 'Because' );
-               $this->hook( 'LocalUserCreated', $this->never() );
                $userReq->username = self::usernameForCreation();
                $ret = $this->manager->beginAccountCreation( $creator, [ $userReq ], 'http://localhost/' );
                $this->unhook( 'LocalUserCreated' );
@@ -1782,11 +1780,11 @@ class AuthManagerTest extends \MediaWikiTestCase {
                        $session, $this->request->getSession()->getSecret( 'AuthManager::accountCreationState' )
                );
 
+               $this->hook( 'LocalUserCreated', $this->never() );
                $this->request->getSession()->setSecret( 'AuthManager::accountCreationState',
                        [ 'username' => $creator->getName() ] + $session );
                $readOnlyMode = \MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode();
                $readOnlyMode->setReason( 'Because' );
-               $this->hook( 'LocalUserCreated', $this->never() );
                $ret = $this->manager->continueAccountCreation( [] );
                $this->unhook( 'LocalUserCreated' );
                $this->assertSame( AuthenticationResponse::FAIL, $ret->status );
@@ -2366,8 +2364,6 @@ class AuthManagerTest extends \MediaWikiTestCase {
                $this->mergeMwGlobalArrayValue( 'wgObjectCaches',
                        [ __METHOD__ => [ 'class' => 'HashBagOStuff' ] ] );
                $this->setMwGlobals( [ 'wgMainCacheType' => __METHOD__ ] );
-               // Supply services with updated globals
-               $this->resetServices();
 
                // Set up lots of mocks...
                $mocks = [];
@@ -2486,10 +2482,10 @@ class AuthManagerTest extends \MediaWikiTestCase {
 
                // Wiki is read-only
                $session->clear();
+               $this->hook( 'LocalUserCreated', $this->never() );
                $readOnlyMode = \MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode();
                $readOnlyMode->setReason( 'Because' );
                $user = \User::newFromName( $username );
-               $this->hook( 'LocalUserCreated', $this->never() );
                $ret = $this->manager->autoCreateUser( $user, AuthManager::AUTOCREATE_SOURCE_SESSION, true );
                $this->unhook( 'LocalUserCreated' );
                $this->assertEquals( \Status::newFatal( wfMessage( 'readonlytext', 'Because' ) ), $ret );
index e085d88..d4133b7 100644 (file)
@@ -48,7 +48,6 @@ class BlockManagerTest extends MediaWikiTestCase {
        private function getBlockManagerConstructorArgs( $overrideConfig ) {
                $blockManagerConfig = array_merge( $this->blockManagerConfig, $overrideConfig );
                $this->setMwGlobals( $blockManagerConfig );
-               $this->overrideMwServices();
                return [
                        new LoggedServiceOptions(
                                self::$serviceOptionsAccessLog,
index 74ad84a..7abddd4 100644 (file)
@@ -24,7 +24,6 @@ class MessageCacheTest extends MediaWikiLangTestCase {
                // let's choose e.g. German (de)
                $this->setUserLang( 'de' );
                $this->setContentLang( 'de' );
-               $this->resetServices();
        }
 
        function addDBDataOnce() {
@@ -150,7 +149,6 @@ class MessageCacheTest extends MediaWikiLangTestCase {
                                ]
                        ]
                ] );
-               $this->overrideMwServices();
 
                $messageCache = MessageCache::singleton();
                $messageCache->enable();
diff --git a/tests/phpunit/includes/content/UnknownContentHandlerTest.php b/tests/phpunit/includes/content/UnknownContentHandlerTest.php
new file mode 100644 (file)
index 0000000..bc1d3c6
--- /dev/null
@@ -0,0 +1,119 @@
+<?php
+
+use MediaWiki\Revision\SlotRecord;
+use MediaWiki\Revision\SlotRenderingProvider;
+
+/**
+ * @group ContentHandler
+ */
+class UnknownContentHandlerTest extends MediaWikiLangTestCase {
+       /**
+        * @covers UnknownContentHandler::supportsDirectEditing
+        */
+       public function testSupportsDirectEditing() {
+               $handler = new UnknownContentHandler( 'horkyporky' );
+               $this->assertFalse( $handler->supportsDirectEditing(), 'direct editing supported' );
+       }
+
+       /**
+        * @covers UnknownContentHandler::serializeContent
+        */
+       public function testSerializeContent() {
+               $handler = new UnknownContentHandler( 'horkyporky' );
+               $content = new UnknownContent( 'hello world', 'horkyporky' );
+
+               $this->assertEquals( 'hello world', $handler->serializeContent( $content ) );
+               $this->assertEquals(
+                       'hello world',
+                       $handler->serializeContent( $content, 'application/horkyporky' )
+               );
+       }
+
+       /**
+        * @covers UnknownContentHandler::unserializeContent
+        */
+       public function testUnserializeContent() {
+               $handler = new UnknownContentHandler( 'horkyporky' );
+               $content = $handler->unserializeContent( 'hello world' );
+               $this->assertEquals( 'hello world', $content->getData() );
+
+               $content = $handler->unserializeContent( 'hello world', 'application/horkyporky' );
+               $this->assertEquals( 'hello world', $content->getData() );
+       }
+
+       /**
+        * @covers UnknownContentHandler::makeEmptyContent
+        */
+       public function testMakeEmptyContent() {
+               $handler = new UnknownContentHandler( 'horkyporky' );
+               $content = $handler->makeEmptyContent();
+
+               $this->assertTrue( $content->isEmpty() );
+               $this->assertEquals( '', $content->getData() );
+       }
+
+       public static function dataIsSupportedFormat() {
+               return [
+                       [ null, true ],
+                       [ 'application/octet-stream', true ],
+                       [ 'unknown/unknown', true ],
+                       [ 'text/plain', false ],
+                       [ 99887766, false ],
+               ];
+       }
+
+       /**
+        * @dataProvider dataIsSupportedFormat
+        * @covers UnknownContentHandler::isSupportedFormat
+        */
+       public function testIsSupportedFormat( $format, $supported ) {
+               $handler = new UnknownContentHandler( 'horkyporky' );
+               $this->assertEquals( $supported, $handler->isSupportedFormat( $format ) );
+       }
+
+       /**
+        * @covers ContentHandler::getSecondaryDataUpdates
+        */
+       public function testGetSecondaryDataUpdates() {
+               $title = Title::newFromText( 'Somefile.jpg', NS_FILE );
+               $content = new UnknownContent( '', 'horkyporky' );
+
+               /** @var SlotRenderingProvider $srp */
+               $srp = $this->getMock( SlotRenderingProvider::class );
+
+               $handler = new UnknownContentHandler( 'horkyporky' );
+               $updates = $handler->getSecondaryDataUpdates( $title, $content, SlotRecord::MAIN, $srp );
+
+               $this->assertEquals( [], $updates );
+       }
+
+       /**
+        * @covers ContentHandler::getDeletionUpdates
+        */
+       public function testGetDeletionUpdates() {
+               $title = Title::newFromText( 'Somefile.jpg', NS_FILE );
+
+               $handler = new UnknownContentHandler( 'horkyporky' );
+               $updates = $handler->getDeletionUpdates( $title, SlotRecord::MAIN );
+
+               $this->assertEquals( [], $updates );
+       }
+
+       /**
+        * @covers ContentHandler::getDeletionUpdates
+        */
+       public function testGetSlotDiffRenderer() {
+               $context = new RequestContext();
+               $context->setRequest( new FauxRequest() );
+
+               $handler = new UnknownContentHandler( 'horkyporky' );
+               $slotDiffRenderer = $handler->getSlotDiffRenderer( $context );
+
+               $oldContent = $handler->unserializeContent( 'Foo' );
+               $newContent = $handler->unserializeContent( 'Foo bar' );
+
+               $diff = $slotDiffRenderer->getDiff( $oldContent, $newContent );
+               $this->assertNotEmpty( $diff );
+       }
+
+}
diff --git a/tests/phpunit/includes/content/UnknownContentTest.php b/tests/phpunit/includes/content/UnknownContentTest.php
new file mode 100644 (file)
index 0000000..fd8e3ba
--- /dev/null
@@ -0,0 +1,259 @@
+<?php
+
+/**
+ * @group ContentHandler
+ */
+class UnknownContentTest extends MediaWikiLangTestCase {
+
+       /**
+        * @param string $data
+        * @return UnknownContent
+        */
+       public function newContent( $data, $type = 'xyzzy' ) {
+               return new UnknownContent( $data, $type );
+       }
+
+       /**
+        * @covers UnknownContent::getParserOutput
+        */
+       public function testGetParserOutput() {
+               $this->setUserLang( 'en' );
+               $this->setContentLang( 'qqx' );
+
+               $title = Title::newFromText( 'Test' );
+               $content = $this->newContent( 'Horkyporky' );
+
+               $po = $content->getParserOutput( $title );
+               $html = $po->getText();
+               $html = preg_replace( '#<!--.*?-->#sm', '', $html ); // strip comments
+
+               $this->assertNotContains( 'Horkyporky', $html );
+               $this->assertNotContains( '(unsupported-content-model)', $html );
+       }
+
+       /**
+        * @covers UnknownContent::preSaveTransform
+        */
+       public function testPreSaveTransform() {
+               $title = Title::newFromText( 'Test' );
+               $user = $this->getTestUser()->getUser();
+               $content = $this->newContent( 'Horkyporky ~~~' );
+
+               $options = new ParserOptions();
+
+               $this->assertSame( $content, $content->preSaveTransform( $title, $user, $options ) );
+       }
+
+       /**
+        * @covers UnknownContent::preloadTransform
+        */
+       public function testPreloadTransform() {
+               $title = Title::newFromText( 'Test' );
+               $content = $this->newContent( 'Horkyporky ~~~' );
+
+               $options = new ParserOptions();
+
+               $this->assertSame( $content, $content->preloadTransform( $title, $options ) );
+       }
+
+       /**
+        * @covers UnknownContent::getRedirectTarget
+        */
+       public function testGetRedirectTarget() {
+               $content = $this->newContent( '#REDIRECT [[Horkyporky]]' );
+               $this->assertNull( $content->getRedirectTarget() );
+       }
+
+       /**
+        * @covers UnknownContent::isRedirect
+        */
+       public function testIsRedirect() {
+               $content = $this->newContent( '#REDIRECT [[Horkyporky]]' );
+               $this->assertFalse( $content->isRedirect() );
+       }
+
+       /**
+        * @covers UnknownContent::isCountable
+        */
+       public function testIsCountable() {
+               $content = $this->newContent( '[[Horkyporky]]' );
+               $this->assertFalse( $content->isCountable( true ) );
+       }
+
+       /**
+        * @covers UnknownContent::getTextForSummary
+        */
+       public function testGetTextForSummary() {
+               $content = $this->newContent( 'Horkyporky' );
+               $this->assertSame( '', $content->getTextForSummary() );
+       }
+
+       /**
+        * @covers UnknownContent::getTextForSearchIndex
+        */
+       public function testGetTextForSearchIndex() {
+               $content = $this->newContent( 'Horkyporky' );
+               $this->assertSame( '', $content->getTextForSearchIndex() );
+       }
+
+       /**
+        * @covers UnknownContent::copy
+        */
+       public function testCopy() {
+               $content = $this->newContent( 'hello world.' );
+               $copy = $content->copy();
+
+               $this->assertSame( $content, $copy );
+       }
+
+       /**
+        * @covers UnknownContent::getSize
+        */
+       public function testGetSize() {
+               $content = $this->newContent( 'hello world.' );
+
+               $this->assertEquals( 12, $content->getSize() );
+       }
+
+       /**
+        * @covers UnknownContent::getData
+        */
+       public function testGetData() {
+               $content = $this->newContent( 'hello world.' );
+
+               $this->assertEquals( 'hello world.', $content->getData() );
+       }
+
+       /**
+        * @covers UnknownContent::getNativeData
+        */
+       public function testGetNativeData() {
+               $content = $this->newContent( 'hello world.' );
+
+               $this->assertEquals( 'hello world.', $content->getNativeData() );
+       }
+
+       /**
+        * @covers UnknownContent::getWikitextForTransclusion
+        */
+       public function testGetWikitextForTransclusion() {
+               $content = $this->newContent( 'hello world.' );
+
+               $this->assertEquals( '', $content->getWikitextForTransclusion() );
+       }
+
+       /**
+        * @covers UnknownContent::getModel
+        */
+       public function testGetModel() {
+               $content = $this->newContent( "hello world.", 'horkyporky' );
+
+               $this->assertEquals( 'horkyporky', $content->getModel() );
+       }
+
+       /**
+        * @covers UnknownContent::getContentHandler
+        */
+       public function testGetContentHandler() {
+               $this->mergeMwGlobalArrayValue(
+                       'wgContentHandlers',
+                       [ 'horkyporky' => 'UnknownContentHandler' ]
+               );
+
+               $content = $this->newContent( "hello world.", 'horkyporky' );
+
+               $this->assertInstanceOf( UnknownContentHandler::class, $content->getContentHandler() );
+               $this->assertEquals( 'horkyporky', $content->getContentHandler()->getModelID() );
+       }
+
+       public static function dataIsEmpty() {
+               return [
+                       [ '', true ],
+                       [ '  ', false ],
+                       [ '0', false ],
+                       [ 'hallo welt.', false ],
+               ];
+       }
+
+       /**
+        * @dataProvider dataIsEmpty
+        * @covers UnknownContent::isEmpty
+        */
+       public function testIsEmpty( $text, $empty ) {
+               $content = $this->newContent( $text );
+
+               $this->assertEquals( $empty, $content->isEmpty() );
+       }
+
+       public function provideEquals() {
+               return [
+                       [ new UnknownContent( "hallo", 'horky' ), null, false ],
+                       [ new UnknownContent( "hallo", 'horky' ), new UnknownContent( "hallo", 'horky' ), true ],
+                       [ new UnknownContent( "hallo", 'horky' ), new UnknownContent( "hallo", 'xyzzy' ), false ],
+                       [ new UnknownContent( "hallo", 'horky' ), new JavaScriptContent( "hallo" ), false ],
+                       [ new UnknownContent( "hallo", 'horky' ), new WikitextContent( "hallo" ), false ],
+               ];
+       }
+
+       /**
+        * @dataProvider provideEquals
+        * @covers UnknownContent::equals
+        */
+       public function testEquals( Content $a, Content $b = null, $equal = false ) {
+               $this->assertEquals( $equal, $a->equals( $b ) );
+       }
+
+       public static function provideConvert() {
+               return [
+                       [ // #0
+                               'Hallo Welt',
+                               CONTENT_MODEL_WIKITEXT,
+                               'lossless',
+                               'Hallo Welt'
+                       ],
+                       [ // #1
+                               'Hallo Welt',
+                               CONTENT_MODEL_WIKITEXT,
+                               'lossless',
+                               'Hallo Welt'
+                       ],
+                       [ // #1
+                               'Hallo Welt',
+                               CONTENT_MODEL_CSS,
+                               'lossless',
+                               'Hallo Welt'
+                       ],
+                       [ // #1
+                               'Hallo Welt',
+                               CONTENT_MODEL_JAVASCRIPT,
+                               'lossless',
+                               'Hallo Welt'
+                       ],
+               ];
+       }
+
+       /**
+        * @covers UnknownContent::convert
+        */
+       public function testConvert() {
+               $content = $this->newContent( 'More horkyporky?' );
+
+               $this->assertFalse( $content->convert( CONTENT_MODEL_TEXT ) );
+       }
+
+       /**
+        * @covers UnknownContent::__construct
+        * @covers UnknownContentHandler::serializeContent
+        */
+       public function testSerialize() {
+               $this->mergeMwGlobalArrayValue(
+                       'wgContentHandlers',
+                       [ 'horkyporky' => 'UnknownContentHandler' ]
+               );
+
+               $content = $this->newContent( 'Hörkypörky', 'horkyporky' );
+
+               $this->assertSame( 'Hörkypörky', $content->serialize() );
+       }
+
+}
index ba31b4f..c1bb1a0 100644 (file)
@@ -157,8 +157,14 @@ class DifferenceEngineTest extends MediaWikiTestCase {
         * @dataProvider provideGenerateContentDiffBody
         */
        public function testGenerateContentDiffBody(
-               Content $oldContent, Content $newContent, $expectedDiff
+               array $oldContentArgs, array $newContentArgs, $expectedDiff
        ) {
+               $this->mergeMwGlobalArrayValue( 'wgContentHandlers', [
+                       'testing-nontext' => DummyNonTextContentHandler::class,
+               ] );
+               $oldContent = ContentHandler::makeContent( ...$oldContentArgs );
+               $newContent = ContentHandler::makeContent( ...$newContentArgs );
+
                // Set $wgExternalDiffEngine to something bogus to try to force use of
                // the PHP engine rather than wikidiff2.
                $this->setMwGlobals( [
@@ -170,12 +176,9 @@ class DifferenceEngineTest extends MediaWikiTestCase {
                $this->assertSame( $expectedDiff, $this->getPlainDiff( $diff ) );
        }
 
-       public function provideGenerateContentDiffBody() {
-               $this->mergeMwGlobalArrayValue( 'wgContentHandlers', [
-                       'testing-nontext' => DummyNonTextContentHandler::class,
-               ] );
-               $content1 = ContentHandler::makeContent( 'xxx', null, CONTENT_MODEL_TEXT );
-               $content2 = ContentHandler::makeContent( 'yyy', null, CONTENT_MODEL_TEXT );
+       public static function provideGenerateContentDiffBody() {
+               $content1 = [ 'xxx', null, CONTENT_MODEL_TEXT ];
+               $content2 = [ 'yyy', null, CONTENT_MODEL_TEXT ];
 
                return [
                        'self-diff' => [ $content1, $content1, '' ],
index c523561..3eb1201 100644 (file)
@@ -9,14 +9,22 @@ class TextSlotDiffRendererTest extends MediaWikiTestCase {
 
        /**
         * @dataProvider provideGetDiff
-        * @param Content|null $oldContent
-        * @param Content|null $newContent
+        * @param array|null $oldContentArgs To pass to makeContent() (if not null)
+        * @param array|null $newContentArgs
         * @param string|Exception $expectedResult
         * @throws Exception
         */
        public function testGetDiff(
-               Content $oldContent = null, Content $newContent = null, $expectedResult
+               array $oldContentArgs = null, array $newContentArgs = null, $expectedResult
        ) {
+               $this->mergeMwGlobalArrayValue( 'wgContentHandlers', [
+                       'testing' => DummyContentHandlerForTesting::class,
+                       'testing-nontext' => DummyNonTextContentHandler::class,
+               ] );
+
+               $oldContent = $oldContentArgs ? self::makeContent( ...$oldContentArgs ) : null;
+               $newContent = $newContentArgs ? self::makeContent( ...$newContentArgs ) : null;
+
                if ( $expectedResult instanceof Exception ) {
                        $this->setExpectedException( get_class( $expectedResult ), $expectedResult->getMessage() );
                }
@@ -30,31 +38,26 @@ class TextSlotDiffRendererTest extends MediaWikiTestCase {
                $this->assertSame( $expectedResult, $plainDiff );
        }
 
-       public function provideGetDiff() {
-               $this->mergeMwGlobalArrayValue( 'wgContentHandlers', [
-                       'testing' => DummyContentHandlerForTesting::class,
-                       'testing-nontext' => DummyNonTextContentHandler::class,
-               ] );
-
+       public static function provideGetDiff() {
                return [
                        'same text' => [
-                               $this->makeContent( "aaa\nbbb\nccc" ),
-                               $this->makeContent( "aaa\nbbb\nccc" ),
+                               [ "aaa\nbbb\nccc" ],
+                               [ "aaa\nbbb\nccc" ],
                                "",
                        ],
                        'different text' => [
-                               $this->makeContent( "aaa\nbbb\nccc" ),
-                               $this->makeContent( "aaa\nxxx\nccc" ),
+                               [ "aaa\nbbb\nccc" ],
+                               [ "aaa\nxxx\nccc" ],
                                " aaa aaa\n-bbb+xxx\n ccc ccc",
                        ],
                        'no right content' => [
-                               $this->makeContent( "aaa\nbbb\nccc" ),
+                               [ "aaa\nbbb\nccc" ],
                                null,
                                "-aaa+ \n-bbb \n-ccc ",
                        ],
                        'no left content' => [
                                null,
-                               $this->makeContent( "aaa\nbbb\nccc" ),
+                               [ "aaa\nbbb\nccc" ],
                                "- +aaa\n +bbb\n +ccc",
                        ],
                        'no content' => [
@@ -63,13 +66,13 @@ class TextSlotDiffRendererTest extends MediaWikiTestCase {
                                new InvalidArgumentException( '$oldContent and $newContent cannot both be null' ),
                        ],
                        'non-text left content' => [
-                               $this->makeContent( '', 'testing-nontext' ),
-                               $this->makeContent( "aaa\nbbb\nccc" ),
+                               [ '', 'testing-nontext' ],
+                               [ "aaa\nbbb\nccc" ],
                                new ParameterTypeException( '$oldContent', 'TextContent|null' ),
                        ],
                        'non-text right content' => [
-                               $this->makeContent( "aaa\nbbb\nccc" ),
-                               $this->makeContent( '', 'testing-nontext' ),
+                               [ "aaa\nbbb\nccc" ],
+                               [ '', 'testing-nontext' ],
                                new ParameterTypeException( '$newContent', 'TextContent|null' ),
                        ],
                ];
@@ -107,7 +110,7 @@ class TextSlotDiffRendererTest extends MediaWikiTestCase {
         * @param string $model
         * @return null|TextContent
         */
-       private function makeContent( $str, $model = CONTENT_MODEL_TEXT ) {
+       private static function makeContent( $str, $model = CONTENT_MODEL_TEXT ) {
                return ContentHandler::makeContent( $str, null, $model );
        }
 
diff --git a/tests/phpunit/includes/diff/UnsupportedSlotDiffRendererTest.php b/tests/phpunit/includes/diff/UnsupportedSlotDiffRendererTest.php
new file mode 100644 (file)
index 0000000..e8f0bb4
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+
+/**
+ * @covers UnsupportedSlotDiffRenderer
+ */
+class UnsupportedSlotDiffRendererTest extends MediaWikiTestCase {
+
+       public function provideDiff() {
+               $oldContent = new TextContent( 'Kittens' );
+               $newContent = new TextContent( 'Goats' );
+               $badContent = new UnknownContent( 'Dragons', 'xyzzy' );
+
+               yield [ '(unsupported-content-diff)', $oldContent, null ];
+               yield [ '(unsupported-content-diff)', null, $newContent ];
+               yield [ '(unsupported-content-diff)', $oldContent, $newContent ];
+               yield [ '(unsupported-content-diff2)', $badContent, $newContent ];
+               yield [ '(unsupported-content-diff2)', $oldContent, $badContent ];
+               yield [ '(unsupported-content-diff)', null, $badContent ];
+               yield [ '(unsupported-content-diff)', $badContent, null ];
+       }
+
+       /**
+        * @dataProvider provideDiff
+        */
+       public function testDiff( $expected, $oldContent, $newContent ) {
+               $this->mergeMwGlobalArrayValue(
+                       'wgContentHandlers',
+                       [ 'xyzzy' => 'UnknownContentHandler' ]
+               );
+
+               $localizer = $this->getMock( MessageLocalizer::class );
+
+               $localizer->method( 'msg' )
+                       ->willReturnCallback( function ( $key, ...$params ) {
+                               return new RawMessage( "($key)", $params );
+                       } );
+
+               $sdr = new UnsupportedSlotDiffRenderer( $localizer );
+               $this->assertContains( $expected, $sdr->getDiff( $oldContent, $newContent ) );
+       }
+
+}
diff --git a/tests/phpunit/includes/filebackend/FileBackendGroupIntegrationTest.php b/tests/phpunit/includes/filebackend/FileBackendGroupIntegrationTest.php
new file mode 100644 (file)
index 0000000..00fa1bb
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+
+use MediaWiki\MediaWikiServices;
+
+/**
+ * @coversDefaultClass FileBackendGroup
+ * @covers ::singleton
+ * @covers ::destroySingleton
+ */
+class FileBackendGroupIntegrationTest extends MediaWikiIntegrationTestCase {
+       use FileBackendGroupTestTrait;
+
+       private static function getWikiID() {
+               return wfWikiID();
+       }
+
+       private function getLockManagerGroupFactory() {
+               return MediaWikiServices::getInstance()->getLockManagerGroupFactory();
+       }
+
+       private function newObj( array $options = [] ) : FileBackendGroup {
+               $globals = [ 'DirectoryMode', 'FileBackends', 'ForeignFileRepos', 'LocalFileRepo' ];
+               foreach ( $globals as $global ) {
+                       $this->setMwGlobals(
+                               "wg$global", $options[$global] ?? self::getDefaultOptions()[$global] );
+               }
+
+               $serviceMembers = [
+                       'configuredROMode' => 'ConfiguredReadOnlyMode',
+                       'srvCache' => 'LocalServerObjectCache',
+                       'wanCache' => 'MainWANObjectCache',
+                       'mimeAnalyzer' => 'MimeAnalyzer',
+                       'lmgFactory' => 'LockManagerGroupFactory',
+                       'tmpFileFactory' => 'TempFSFileFactory',
+               ];
+
+               foreach ( $serviceMembers as $key => $name ) {
+                       if ( isset( $options[$key] ) ) {
+                               $this->setService( $name, $options[$key] );
+                       }
+               }
+
+               $this->assertEmpty(
+                       array_diff( array_keys( $options ), $globals, array_keys( $serviceMembers ) ) );
+
+               $this->resetServices();
+               FileBackendGroup::destroySingleton();
+
+               $services = MediaWikiServices::getInstance();
+
+               foreach ( $serviceMembers as $key => $name ) {
+                       if ( $key === 'srvCache' ) {
+                               $this->$key = ObjectCache::getLocalServerInstance( 'hash' );
+                       } else {
+                               $this->$key = $services->getService( $name );
+                       }
+               }
+
+               return FileBackendGroup::singleton();
+       }
+}
index 67de698..04452f2 100644 (file)
@@ -7,7 +7,6 @@ class RepoGroupTest extends MediaWikiTestCase {
 
        function testHasForeignRepoNegative() {
                $this->setMwGlobals( 'wgForeignFileRepos', [] );
-               $this->overrideMwServices();
                FileBackendGroup::destroySingleton();
                $this->assertFalse( RepoGroup::singleton()->hasForeignRepos() );
        }
@@ -27,7 +26,6 @@ class RepoGroupTest extends MediaWikiTestCase {
 
        function testForEachForeignRepoNone() {
                $this->setMwGlobals( 'wgForeignFileRepos', [] );
-               $this->overrideMwServices();
                FileBackendGroup::destroySingleton();
                $fakeCallback = $this->createMock( RepoGroupTestHelper::class );
                $fakeCallback->expects( $this->never() )->method( 'callback' );
@@ -48,7 +46,6 @@ class RepoGroupTest extends MediaWikiTestCase {
                        'apiThumbCacheExpiry' => 86400,
                        'directory' => $wgUploadDirectory
                ] ] );
-               $this->overrideMwServices();
                FileBackendGroup::destroySingleton();
        }
 }
index d2c9a32..88ac923 100644 (file)
@@ -51,7 +51,6 @@ class InterwikiTest extends MediaWikiTestCase {
        }
 
        private function setWgInterwikiCache( $interwikiCache ) {
-               $this->overrideMwServices();
                MediaWikiServices::getInstance()->resetServiceForTesting( 'InterwikiLookup' );
                $this->setMwGlobals( 'wgInterwikiCache', $interwikiCache );
        }
index 4318852..7f52ca6 100644 (file)
@@ -82,9 +82,6 @@ class ObjectCacheTest extends MediaWikiTestCase {
 
        /** @covers ObjectCache::newAnything */
        public function testNewAnythingNoAccelNoDb() {
-               $this->overrideMwServices(); // Ensures restore on tear down
-               MediaWiki\MediaWikiServices::disableStorageBackend();
-
                $this->setMwGlobals( [
                        'wgMainCacheType' => CACHE_ACCEL
                ] );
@@ -94,6 +91,8 @@ class ObjectCacheTest extends MediaWikiTestCase {
                        CACHE_ACCEL => [ 'class' => EmptyBagOStuff::class ]
                ] );
 
+               MediaWiki\MediaWikiServices::disableStorageBackend();
+
                $this->assertInstanceOf(
                        EmptyBagOStuff::class,
                        ObjectCache::newAnything( [] ),
@@ -103,7 +102,6 @@ class ObjectCacheTest extends MediaWikiTestCase {
 
        /** @covers ObjectCache::newAnything */
        public function testNewAnythingNothingNoDb() {
-               $this->overrideMwServices();
                MediaWiki\MediaWikiServices::disableStorageBackend();
 
                $this->assertInstanceOf(
index 42edf38..bcbc1ed 100644 (file)
@@ -83,13 +83,11 @@ abstract class PageArchiveTestBase extends MediaWikiTestCase {
 
                $this->tablesUsed += $this->getMcrTablesToReset();
 
-               $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_NEW );
-               $this->setMwGlobals( 'wgContentHandlerUseDB', $this->getContentHandlerUseDB() );
-               $this->setMwGlobals(
-                       'wgMultiContentRevisionSchemaMigrationStage',
-                       $this->getMcrMigrationStage()
-               );
-               $this->overrideMwServices();
+               $this->setMwGlobals( [
+                       'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_NEW,
+                       'wgContentHandlerUseDB' => $this->getContentHandlerUseDB(),
+                       'wgMultiContentRevisionSchemaMigrationStage' => $this->getMcrMigrationStage(),
+               ] );
 
                // First create our dummy page
                $page = Title::newFromText( 'PageArchiveTest_thePage' );
index 30973c8..f071e4b 100644 (file)
@@ -65,8 +65,6 @@ abstract class WikiPageDbTestBase extends MediaWikiLangTestCase {
                        $this->getMcrMigrationStage()
                );
                $this->pagesToDelete = [];
-
-               $this->overrideMwServices();
        }
 
        protected function tearDown() {
index ac4a1ca..428778e 100644 (file)
@@ -18,8 +18,6 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
         * @coversNothing
         */
        public function testServiceWiring() {
-               $this->overrideMwServices();
-
                $ranHook = 0;
                $this->setMwGlobals( 'wgHooks', [
                        'ResourceLoaderRegisterModules' => [
index 372cb33..ed75076 100644 (file)
@@ -68,8 +68,6 @@ class SearchEnginePrefixTest extends MediaWikiLangTestCase {
 
                $this->originalHandlers = TestingAccessWrapper::newFromClass( Hooks::class )->handlers;
                TestingAccessWrapper::newFromClass( Hooks::class )->handlers = [];
-
-               $this->overrideMwServices();
        }
 
        public function tearDown() {
index 9d58cef..68433c6 100644 (file)
@@ -225,7 +225,6 @@ class ChangesListSpecialPageTest extends AbstractChangesListSpecialPageTestCase
 
        public function testRcHidemyselfFilter() {
                $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_NEW );
-               $this->overrideMwServices();
 
                $user = $this->getTestUser()->getUser();
                $user->getActorId( wfGetDB( DB_MASTER ) );
@@ -258,7 +257,6 @@ class ChangesListSpecialPageTest extends AbstractChangesListSpecialPageTestCase
                $this->setMwGlobals(
                        'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
                );
-               $this->overrideMwServices();
 
                $user = $this->getTestUser()->getUser();
                $user->getActorId( wfGetDB( DB_MASTER ) );
@@ -289,7 +287,6 @@ class ChangesListSpecialPageTest extends AbstractChangesListSpecialPageTestCase
 
        public function testRcHidebyothersFilter() {
                $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_NEW );
-               $this->overrideMwServices();
 
                $user = $this->getTestUser()->getUser();
                $user->getActorId( wfGetDB( DB_MASTER ) );
@@ -322,7 +319,6 @@ class ChangesListSpecialPageTest extends AbstractChangesListSpecialPageTestCase
                $this->setMwGlobals(
                        'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
                );
-               $this->overrideMwServices();
 
                $user = $this->getTestUser()->getUser();
                $user->getActorId( wfGetDB( DB_MASTER ) );
@@ -555,7 +551,6 @@ class ChangesListSpecialPageTest extends AbstractChangesListSpecialPageTestCase
 
        public function testFilterUserExpLevelAllExperienceLevels() {
                $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_NEW );
-               $this->overrideMwServices();
 
                $this->assertConditions(
                        [
@@ -573,7 +568,6 @@ class ChangesListSpecialPageTest extends AbstractChangesListSpecialPageTestCase
                $this->setMwGlobals(
                        'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
                );
-               $this->overrideMwServices();
 
                $this->assertConditions(
                        [
@@ -589,7 +583,6 @@ class ChangesListSpecialPageTest extends AbstractChangesListSpecialPageTestCase
 
        public function testFilterUserExpLevelRegistrered() {
                $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_NEW );
-               $this->overrideMwServices();
 
                $this->assertConditions(
                        [
@@ -607,7 +600,6 @@ class ChangesListSpecialPageTest extends AbstractChangesListSpecialPageTestCase
                $this->setMwGlobals(
                        'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
                );
-               $this->overrideMwServices();
 
                $this->assertConditions(
                        [
@@ -623,7 +615,6 @@ class ChangesListSpecialPageTest extends AbstractChangesListSpecialPageTestCase
 
        public function testFilterUserExpLevelUnregistrered() {
                $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_NEW );
-               $this->overrideMwServices();
 
                $this->assertConditions(
                        [
@@ -641,7 +632,6 @@ class ChangesListSpecialPageTest extends AbstractChangesListSpecialPageTestCase
                $this->setMwGlobals(
                        'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
                );
-               $this->overrideMwServices();
 
                $this->assertConditions(
                        [
@@ -657,7 +647,6 @@ class ChangesListSpecialPageTest extends AbstractChangesListSpecialPageTestCase
 
        public function testFilterUserExpLevelRegistreredOrLearner() {
                $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_NEW );
-               $this->overrideMwServices();
 
                $this->assertConditions(
                        [
@@ -675,7 +664,6 @@ class ChangesListSpecialPageTest extends AbstractChangesListSpecialPageTestCase
                $this->setMwGlobals(
                        'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
                );
-               $this->overrideMwServices();
 
                $this->assertConditions(
                        [
@@ -691,7 +679,6 @@ class ChangesListSpecialPageTest extends AbstractChangesListSpecialPageTestCase
 
        public function testFilterUserExpLevelUnregistreredOrExperienced() {
                $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_NEW );
-               $this->overrideMwServices();
 
                $conds = $this->buildQuery( [ 'userExpLevel' => 'unregistered;experienced' ] );
 
@@ -707,7 +694,6 @@ class ChangesListSpecialPageTest extends AbstractChangesListSpecialPageTestCase
                $this->setMwGlobals(
                        'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
                );
-               $this->overrideMwServices();
 
                $conds = $this->buildQuery( [ 'userExpLevel' => 'unregistered;experienced' ] );
 
index 04a89d2..c0376ad 100644 (file)
@@ -33,7 +33,6 @@ class SpecialPageFactoryTest extends MediaWikiTestCase {
                                        $count++;
                                }
                ] ] );
-               $this->overrideMwServices();
                $spf = MediaWikiServices::getInstance()->getSpecialPageFactory();
                $spf->getNames();
                $spf->getNames();
@@ -71,7 +70,6 @@ class SpecialPageFactoryTest extends MediaWikiTestCase {
         */
        public function testGetPage( $spec, $shouldReuseInstance ) {
                $this->mergeMwGlobalArrayValue( 'wgSpecialPages', [ 'testdummy' => $spec ] );
-               $this->overrideMwServices();
 
                $page = SpecialPageFactory::getPage( 'testdummy' );
                $this->assertInstanceOf( SpecialPage::class, $page );
@@ -85,7 +83,6 @@ class SpecialPageFactoryTest extends MediaWikiTestCase {
         */
        public function testGetNames() {
                $this->mergeMwGlobalArrayValue( 'wgSpecialPages', [ 'testdummy' => SpecialAllPages::class ] );
-               $this->overrideMwServices();
 
                $names = SpecialPageFactory::getNames();
                $this->assertInternalType( 'array', $names );
@@ -97,7 +94,6 @@ class SpecialPageFactoryTest extends MediaWikiTestCase {
         */
        public function testResolveAlias() {
                $this->setContentLang( 'de' );
-               $this->overrideMwServices();
 
                list( $name, $param ) = SpecialPageFactory::resolveAlias( 'Spezialseiten/Foo' );
                $this->assertEquals( 'Specialpages', $name );
@@ -109,7 +105,6 @@ class SpecialPageFactoryTest extends MediaWikiTestCase {
         */
        public function testGetLocalNameFor() {
                $this->setContentLang( 'de' );
-               $this->overrideMwServices();
 
                $name = SpecialPageFactory::getLocalNameFor( 'Specialpages', 'Foo' );
                $this->assertEquals( 'Spezialseiten/Foo', $name );
@@ -120,7 +115,6 @@ class SpecialPageFactoryTest extends MediaWikiTestCase {
         */
        public function testGetTitleForAlias() {
                $this->setContentLang( 'de' );
-               $this->overrideMwServices();
 
                $title = SpecialPageFactory::getTitleForAlias( 'Specialpages/Foo' );
                $this->assertEquals( 'Spezialseiten/Foo', $title->getText() );
@@ -138,7 +132,6 @@ class SpecialPageFactoryTest extends MediaWikiTestCase {
                $this->setMwGlobals( 'wgSpecialPages',
                        array_combine( array_keys( $aliasesList ), array_keys( $aliasesList ) )
                );
-               $this->overrideMwServices();
                $this->setContentLang( $lang );
 
                // Catch the warnings we expect to be raised
@@ -267,7 +260,6 @@ class SpecialPageFactoryTest extends MediaWikiTestCase {
                                }
                        ],
                ] );
-               $this->overrideMwServices();
                SpecialPageFactory::getLocalNameFor( 'Specialpages' );
                $this->assertTrue( $called, 'Recursive call succeeded' );
        }
index 7f97a16..03ba960 100644 (file)
@@ -1275,7 +1275,6 @@ class NamespaceInfoTest extends MediaWikiTestCase {
                        'wgRestrictionLevels' => [ '', 'autoconfirmed', 'sysop' ],
                        'wgAutopromote' => []
                ] );
-               $this->resetServices();
                $obj = $this->newObj();
                $user = is_null( $groups ) ? null : $this->getTestUser( $groups )->getUser();
                $this->assertSame( $expected, $obj->getRestrictionLevels( $ns, $user ) );
index 340a4c3..4862747 100644 (file)
@@ -46,8 +46,6 @@ class UserGroupMembershipTest extends MediaWikiTestCase {
                $this->userTester->addGroup( 'unittesters' );
                $this->expiryTime = wfTimestamp( TS_MW, time() + 100500 );
                $this->userTester->addGroup( 'testwriters', $this->expiryTime );
-
-               $this->resetServices();
        }
 
        /**
index f48385d..2d87c78 100644 (file)
@@ -33,7 +33,6 @@ class UserTest extends MediaWikiTestCase {
                        'wgRevokePermissions' => [],
                        'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_NEW,
                ] );
-               $this->overrideMwServices();
 
                $this->setUpPermissionGlobals();
 
@@ -73,7 +72,6 @@ class UserTest extends MediaWikiTestCase {
                RequestContext::getMain()->setRequest( $request );
                TestingAccessWrapper::newFromObject( $user )->mRequest = $request;
                $request->getSession()->setUser( $user );
-               $this->overrideMwServices();
        }
 
        /**
@@ -136,7 +134,6 @@ class UserTest extends MediaWikiTestCase {
                        $rights = array_diff( $rights, [ 'writetest' ] );
                } );
 
-               $this->resetServices();
                $rights = $user->getRights();
                $this->assertContains( 'test', $rights );
                $this->assertContains( 'runtest', $rights );
@@ -929,13 +926,8 @@ class UserTest extends MediaWikiTestCase {
                $this->assertFalse( $user->isPingLimitable() );
 
                $this->setMwGlobals( 'wgRateLimitsExcludedIPs', [] );
-               $noRateLimitUser = $this->getMockBuilder( User::class )->disableOriginalConstructor()
-                       ->setMethods( [ 'getIP', 'getId', 'getGroups' ] )->getMock();
-               $noRateLimitUser->expects( $this->any() )->method( 'getIP' )->willReturn( '1.2.3.4' );
-               $noRateLimitUser->expects( $this->any() )->method( 'getId' )->willReturn( 0 );
-               $noRateLimitUser->expects( $this->any() )->method( 'getGroups' )->willReturn( [] );
-               $this->overrideUserPermissions( $noRateLimitUser, 'noratelimit' );
-               $this->assertFalse( $noRateLimitUser->isPingLimitable() );
+               $this->overrideUserPermissions( $user, 'noratelimit' );
+               $this->assertFalse( $user->isPingLimitable() );
        }
 
        public function provideExperienceLevel() {
@@ -1096,7 +1088,6 @@ class UserTest extends MediaWikiTestCase {
                $this->setMwGlobals( [
                        'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD,
                ] );
-               $this->overrideMwServices();
 
                $domain = MediaWikiServices::getInstance()->getDBLoadBalancer()->getLocalDomainID();
                $this->hideDeprecated( 'User::selectFields' );
index 9616672..fbb893e 100644 (file)
@@ -1837,8 +1837,7 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
                        new WatchedItem( $user, $targets[0], '20151212010101' ),
                        new WatchedItem( $user, $targets[1], null ),
                ];
-               $mockDb = $this->getMockDb();
-               $mockDb->expects( $this->never() )->method( $this->anything() );
+               $mockDb = $this->createNoOpMock( IDatabase::class );
 
                $mockCache = $this->getMockCache();
                $mockCache->expects( $this->at( 1 ) )
@@ -1864,16 +1863,18 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
        }
 
        public function testGetNotificationTimestampsBatch_anonymousUser() {
+               if ( defined( 'HHVM_VERSION' ) ) {
+                       $this->markTestSkipped( 'HHVM Reflection buggy' );
+               }
+
                $targets = [
                        new TitleValue( 0, 'SomeDbKey' ),
                        new TitleValue( 1, 'AnotherDbKey' ),
                ];
 
-               $mockDb = $this->getMockDb();
-               $mockDb->expects( $this->never() )->method( $this->anything() );
+               $mockDb = $this->createNoOpMock( IDatabase::class );
 
-               $mockCache = $this->getMockCache();
-               $mockCache->expects( $this->never() )->method( $this->anything() );
+               $mockCache = $this->createNoOpMock( HashBagOStuff::class );
 
                $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
 
@@ -2086,8 +2087,7 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
 
                $mockQueueGroup = $this->getMockJobQueueGroup();
 
-               $mockRevisionRecord = $this->createMock( RevisionRecord::class );
-               $mockRevisionRecord->expects( $this->never() )->method( $this->anything() );
+               $mockRevisionRecord = $this->createNoOpMock( RevisionRecord::class );
 
                $mockRevisionLookup = $this->getMockRevisionLookup( [
                        'getTimestampFromId' => function () {
@@ -2144,11 +2144,8 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
                $oldid = 22;
                $title = new TitleValue( 0, 'SomeDbKey' );
 
-               $mockRevision = $this->createMock( RevisionRecord::class );
-               $mockRevision->expects( $this->never() )->method( $this->anything() );
-
-               $mockNextRevision = $this->createMock( RevisionRecord::class );
-               $mockNextRevision->expects( $this->never() )->method( $this->anything() );
+               $mockRevision = $this->createNoOpMock( RevisionRecord::class );
+               $mockNextRevision = $this->createNoOpMock( RevisionRecord::class );
 
                $mockDb = $this->getMockDb();
                $mockDb->expects( $this->once() )
@@ -2258,11 +2255,8 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
 
                $mockQueueGroup = $this->getMockJobQueueGroup();
 
-               $mockRevision = $this->createMock( RevisionRecord::class );
-               $mockRevision->expects( $this->never() )->method( $this->anything() );
-
-               $mockNextRevision = $this->createMock( RevisionRecord::class );
-               $mockNextRevision->expects( $this->never() )->method( $this->anything() );
+               $mockRevision = $this->createNoOpMock( RevisionRecord::class );
+               $mockNextRevision = $this->createNoOpMock( RevisionRecord::class );
 
                $mockRevisionLookup = $this->getMockRevisionLookup(
                        [
@@ -2350,11 +2344,8 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
 
                $mockQueueGroup = $this->getMockJobQueueGroup();
 
-               $mockRevision = $this->createMock( RevisionRecord::class );
-               $mockRevision->expects( $this->never() )->method( $this->anything() );
-
-               $mockNextRevision = $this->createMock( RevisionRecord::class );
-               $mockNextRevision->expects( $this->never() )->method( $this->anything() );
+               $mockRevision = $this->createNoOpMock( RevisionRecord::class );
+               $mockNextRevision = $this->createNoOpMock( RevisionRecord::class );
 
                $mockRevisionLookup = $this->getMockRevisionLookup(
                        [
@@ -2442,11 +2433,8 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
 
                $mockQueueGroup = $this->getMockJobQueueGroup();
 
-               $mockRevision = $this->createMock( RevisionRecord::class );
-               $mockRevision->expects( $this->never() )->method( $this->anything() );
-
-               $mockNextRevision = $this->createMock( RevisionRecord::class );
-               $mockNextRevision->expects( $this->never() )->method( $this->anything() );
+               $mockRevision = $this->createNoOpMock( RevisionRecord::class );
+               $mockNextRevision = $this->createNoOpMock( RevisionRecord::class );
 
                $mockRevisionLookup = $this->getMockRevisionLookup(
                        [
diff --git a/tests/phpunit/languages/LanguageFallbackStaticMethodsTest.php b/tests/phpunit/languages/LanguageFallbackStaticMethodsTest.php
new file mode 100644 (file)
index 0000000..a683c9a
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+
+/**
+ * @coversDefaultClass Language
+ */
+class LanguageFallbackStaticMethodsTest extends MediaWikiIntegrationTestCase {
+       use LanguageFallbackTestTrait;
+
+       private function getCallee( array $options = [] ) {
+               if ( isset( $options['siteLangCode'] ) ) {
+                       $this->setMwGlobals( 'wgLanguageCode', $options['siteLangCode'] );
+                       $this->resetServices();
+               }
+               return Language::class;
+       }
+
+       private function getMessagesKey() {
+               return Language::MESSAGES_FALLBACKS;
+       }
+
+       private function getStrictKey() {
+               return Language::STRICT_FALLBACKS;
+       }
+}
index 2a6575a..2037036 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * Try to make sure that extensions register all rights in $wgAvailableRights
  * or via the 'UserGetAllRights' hook.
@@ -19,7 +21,7 @@ class AvailableRightsTest extends PHPUnit\Framework\TestCase {
        private function getAllVisibleRights() {
                global $wgGroupPermissions, $wgRevokePermissions;
 
-               $rights = User::getAllRights();
+               $rights = MediaWikiServices::getInstance()->getPermissionManager()->getAllPermissions();
 
                foreach ( $wgGroupPermissions as $permissions ) {
                        $rights = array_merge( $rights, array_keys( $permissions ) );
@@ -38,7 +40,7 @@ class AvailableRightsTest extends PHPUnit\Framework\TestCase {
        public function testAvailableRights() {
                $missingRights = array_diff(
                        $this->getAllVisibleRights(),
-                       User::getAllRights()
+                       MediaWikiServices::getInstance()->getPermissionManager()->getAllPermissions()
                );
 
                $this->assertEquals(
@@ -76,7 +78,7 @@ class AvailableRightsTest extends PHPUnit\Framework\TestCase {
         */
        private function checkMessagesExist( $prefix ) {
                // Getting all user rights, for core: User::$mCoreRights, for extensions: $wgAvailableRights
-               $allRights = User::getAllRights();
+               $allRights = MediaWikiServices::getInstance()->getPermissionManager()->getAllPermissions();
                $allMessageKeys = Language::getMessageKeysFor( 'en' );
 
                $messagesToCheck = [];
index 37fa030..a46f25d 100644 (file)
@@ -212,7 +212,6 @@ class MediaWikiTestCaseTest extends MediaWikiTestCase {
 
                // the actual test: change config, reset services.
                $this->setMwGlobals( 'wgLanguageCode', 'qqx' );
-               $this->resetServices();
 
                // the overridden service instance should still be there
                $this->assertSame( $myReadOnlyMode, $services->getService( 'ReadOnlyMode' ) );
diff --git a/tests/phpunit/unit/includes/filebackend/FileBackendGroupTestTrait.php b/tests/phpunit/unit/includes/filebackend/FileBackendGroupTestTrait.php
new file mode 100644 (file)
index 0000000..d23f645
--- /dev/null
@@ -0,0 +1,459 @@
+<?php
+
+use MediaWiki\FileBackend\FSFile\TempFSFileFactory;
+use MediaWiki\FileBackend\LockManager\LockManagerGroupFactory;
+use MediaWiki\Logger\LoggerFactory;
+
+/**
+ * Code shared by the FileBackendGroup integration and unit tests. They need merely provide a
+ * suitable newObj() method and everything else works magically.
+ */
+trait FileBackendGroupTestTrait {
+       /**
+        * @param array $options Dictionary to use as a source for ServiceOptions before defaults, plus
+        *   the following options are available to override other arguments:
+        *     * 'configuredROMode'
+        *     * 'lmgFactory'
+        *     * 'mimeAnalyzer'
+        *     * 'tmpFileFactory'
+        */
+       abstract protected function newObj( array $options = [] ) : FileBackendGroup;
+
+       /**
+        * @param string $domain Expected argument that LockManagerGroupFactory::getLockManagerGroup
+        *   will receive
+        */
+       abstract protected function getLockManagerGroupFactory( $domain )
+               : LockManagerGroupFactory;
+
+       /**
+        * @return string As from wfWikiID()
+        */
+       abstract protected static function getWikiID();
+
+       /** @var BagOStuff */
+       private $srvCache;
+
+       /** @var WANObjectCache */
+       private $wanCache;
+
+       /** @var LockManagerGroupFactory */
+       private $lmgFactory;
+
+       /** @var TempFSFileFactory */
+       private $tmpFileFactory;
+
+       private static function getDefaultLocalFileRepo() {
+               return [
+                       'class' => LocalRepo::class,
+                       'name' => 'local',
+                       'directory' => 'upload-dir',
+                       'thumbDir' => 'thumb/',
+                       'transcodedDir' => 'transcoded/',
+                       'fileMode' => 0664,
+                       'scriptDirUrl' => 'script-path/',
+                       'url' => 'upload-path/',
+                       'hashLevels' => 2,
+                       'thumbScriptUrl' => false,
+                       'transformVia404' => false,
+                       'deletedDir' => 'deleted/',
+                       'deletedHashLevels' => 3,
+                       'backend' => 'local-backend',
+               ];
+       }
+
+       private static function getDefaultOptions() {
+               return [
+                       'DirectoryMode' => 0775,
+                       'FileBackends' => [],
+                       'ForeignFileRepos' => [],
+                       'LocalFileRepo' => self::getDefaultLocalFileRepo(),
+                       'wikiId' => self::getWikiID(),
+               ];
+       }
+
+       /**
+        * @covers ::__construct
+        */
+       public function testConstructor_overrideImplicitBackend() {
+               $obj = $this->newObj( [ 'FileBackends' =>
+                       [ [ 'name' => 'local-backend', 'class' => '', 'lockManager' => 'fsLockManager' ] ]
+               ] );
+               $this->assertSame( '', $obj->config( 'local-backend' )['class'] );
+       }
+
+       /**
+        * @covers ::__construct
+        */
+       public function testConstructor_backendObject() {
+               // 'backend' being an object makes that repo from configuration ignored
+               // XXX This is not documented in DefaultSettings.php, does it do anything useful?
+               $obj = $this->newObj( [ 'ForeignFileRepos' => [ [ 'backend' => new stdclass ] ] ] );
+               $this->assertSame( FSFileBackend::class, $obj->config( 'local-backend' )['class'] );
+       }
+
+       /**
+        * @dataProvider provideRegister_domainId
+        * @param string $key Key to check in return value of config()
+        * @param string|callable $expected Expected value of config()[$key], or callable returning it
+        * @param array $extraBackendsOptions To add to the FileBackends entry passed to newObj()
+        * @param array $otherExtraOptions To add to the array passed to newObj() (e.g., services)
+        * @covers ::register
+        */
+       public function testRegister(
+               $key, $expected, array $extraBackendsOptions = [], array $otherExtraOptions = []
+       ) {
+               if ( $expected instanceof Closure ) {
+                       // Lame hack to get around providers being called too early
+                       $expected = $expected();
+               }
+               if ( $key === 'domainId' ) {
+                       // This will change the expected LMG name too
+                       $otherExtraOptions['lmgFactory'] = $this->getLockManagerGroupFactory( $expected );
+               }
+               $obj = $this->newObj( $otherExtraOptions + [
+                       'FileBackends' => [
+                               $extraBackendsOptions + [
+                                       'name' => 'myname', 'class' => '', 'lockManager' => 'fsLockManager'
+                               ]
+                       ],
+               ] );
+               $this->assertSame( $expected, $obj->config( 'myname' )[$key] );
+       }
+
+       public static function provideRegister_domainId() {
+               return [
+                       'domainId with neither wikiId nor domainId set' => [
+                               'domainId',
+                               function () {
+                                       return self::getWikiID();
+                               },
+                       ],
+                       'domainId with wikiId set but no domainId' =>
+                               [ 'domainId', 'id0', [ 'wikiId' => 'id0' ] ],
+                       'domainId with wikiId and domainId set' =>
+                               [ 'domainId', 'dom1', [ 'wikiId' => 'id0', 'domainId' => 'dom1' ] ],
+                       'readOnly without readOnly set' => [ 'readOnly', false ],
+                       'readOnly with readOnly set to string' =>
+                               [ 'readOnly', 'cuz', [ 'readOnly' => 'cuz' ] ],
+                       'readOnly without readOnly set but with string in passed object' => [
+                               'readOnly',
+                               'cuz',
+                               [],
+                               [ 'configuredROMode' => new ConfiguredReadOnlyMode( 'cuz' ) ],
+                  ],
+                  'readOnly with readOnly set to false but string in passed object' => [
+                          'readOnly',
+                          false,
+                          [ 'readOnly' => false ],
+                          [ 'configuredROMode' => new ConfiguredReadOnlyMode( 'cuz' ) ],
+                  ],
+               ];
+       }
+
+       /**
+        * @dataProvider provideRegister_exception
+        * @param array $fileBackends Value of FileBackends to pass to constructor
+        * @param string $class Expected exception class
+        * @param string $msg Expected exception message
+        * @covers ::__construct
+        * @covers ::register
+        */
+       public function testRegister_exception( $fileBackends, $class, $msg ) {
+               $this->setExpectedException( $class, $msg );
+               $this->newObj( [ 'FileBackends' => $fileBackends ] );
+       }
+
+       public static function provideRegister_exception() {
+               return [
+                       'Nameless' => [
+                               [ [] ], InvalidArgumentException::class, "Cannot register a backend with no name."
+                       ],
+                       'Duplicate' => [
+                               [ [ 'name' => 'dupe', 'class' => '' ], [ 'name' => 'dupe' ] ],
+                               LogicException::class,
+                               "Backend with name 'dupe' already registered.",
+                       ],
+                       'Classless' => [
+                               [ [ 'name' => 'classless' ] ],
+                               InvalidArgumentException::class,
+                               "Backend with name 'classless' has no class.",
+                       ],
+               ];
+       }
+
+       /**
+        * @covers ::__construct
+        * @covers ::config
+        * @covers ::get
+        */
+       public function testGet() {
+               $backend = $this->newObj()->get( 'local-backend' );
+               $this->assertTrue( $backend instanceof FSFileBackend );
+       }
+
+       /**
+        * @covers ::get
+        */
+       public function testGetUnrecognized() {
+               $this->setExpectedException( InvalidArgumentException::class,
+                       "No backend defined with the name 'unrecognized'." );
+               $this->newObj()->get( 'unrecognized' );
+       }
+
+       /**
+        * @covers ::__construct
+        * @covers ::config
+        */
+       public function testConfig() {
+               $obj = $this->newObj();
+               $config = $obj->config( 'local-backend' );
+
+               // XXX How to actually test that a profiler is loaded?
+               $this->assertNull( $config['profiler']( 'x' ) );
+               // Equality comparison doesn't work for closures, so just set to null
+               $config['profiler'] = null;
+
+               $this->assertEquals( [
+                       'mimeCallback' => [ $obj, 'guessMimeInternal' ],
+                       'obResetFunc' => 'wfResetOutputBuffers',
+                       'streamMimeFunc' => [ StreamFile::class, 'contentTypeFromPath' ],
+                       'tmpFileFactory' => $this->tmpFileFactory,
+                       'statusWrapper' => [ Status::class, 'wrap' ],
+                       'wanCache' => $this->wanCache,
+                       'srvCache' => $this->srvCache,
+                       'logger' => LoggerFactory::getInstance( 'FileOperation' ),
+                       // This was set to null above in $config, it's not really null
+                       'profiler' => null,
+                       'name' => 'local-backend',
+                       'containerPaths' => [
+                               'local-public' => 'upload-dir',
+                               'local-thumb' => 'thumb/',
+                               'local-transcoded' => 'transcoded/',
+                               'local-deleted' => 'deleted/',
+                               'local-temp' => 'upload-dir/temp',
+                       ],
+                       'fileMode' => 0664,
+                       'directoryMode' => 0775,
+                       'domainId' => self::getWikiID(),
+                       'readOnly' => false,
+                       'class' => FSFileBackend::class,
+                       'lockManager' =>
+                               $this->lmgFactory->getLockManagerGroup( self::getWikiID() )->get( 'fsLockManager' ),
+                       'fileJournal' =>
+                               FileJournal::factory( [ 'class' => NullFileJournal::class ], 'local-backend' ),
+               ], $config );
+
+               // For config values that are objects, check object identity.
+               $this->assertSame( [ $obj, 'guessMimeInternal' ], $config['mimeCallback'] );
+               $this->assertSame( $this->tmpFileFactory, $config['tmpFileFactory'] );
+               $this->assertSame( $this->wanCache, $config['wanCache'] );
+               $this->assertSame( $this->srvCache, $config['srvCache'] );
+       }
+
+       /**
+        * @dataProvider provideConfig_default
+        * @param string $expected Expected default value
+        * @param string $inputName Name to set to null in LocalFileRepo setting
+        * @param string|array $key Key to check in array returned by config(), or array [ 'key1',
+        *   'key2' ] for nested key
+        * @covers ::__construct
+        * @covers ::config
+        */
+       public function testConfig_defaultNull( $expected, $inputName, $key ) {
+               $config = self::getDefaultLocalFileRepo();
+               $config[$inputName] = null;
+
+               $result = $this->newObj( [ 'LocalFileRepo' => $config ] )->config( 'local-backend' );
+
+               $actual = is_string( $key ) ? $result[$key] : $result[$key[0]][$key[1]];
+
+               $this->assertSame( $expected, $actual );
+       }
+
+       /**
+        * @dataProvider provideConfig_default
+        * @param string $expected Expected default value
+        * @param string $inputName Name to unset in LocalFileRepo setting
+        * @param string|array $key Key to check in array returned by config(), or array [ 'key1',
+        *   'key2' ] for nested key
+        * @covers ::__construct
+        * @covers ::config
+        */
+       public function testConfig_defaultUnset( $expected, $inputName, $key ) {
+               $config = self::getDefaultLocalFileRepo();
+               unset( $config[$inputName] );
+
+               $result = $this->newObj( [ 'LocalFileRepo' => $config ] )->config( 'local-backend' );
+
+               $actual = is_string( $key ) ? $result[$key] : $result[$key[0]][$key[1]];
+
+               $this->assertSame( $expected, $actual );
+       }
+
+       public static function provideConfig_default() {
+               return [
+                       'deletedDir' => [ false, 'deletedDir', [ 'containerPaths', 'local-deleted' ] ],
+                       'thumbDir' => [ 'upload-dir/thumb', 'thumbDir', [ 'containerPaths', 'local-thumb' ] ],
+                       'transcodedDir' => [
+                               'upload-dir/transcoded', 'transcodedDir', [ 'containerPaths', 'local-transcoded' ]
+                       ],
+                       'fileMode' => [ 0644, 'fileMode', 'fileMode' ],
+               ];
+       }
+
+       /**
+        * @covers ::config
+        */
+       public function testConfig_fileJournal() {
+               $mockJournal = $this->createMock( FileJournal::class );
+               $mockJournal->expects( $this->never() )->method( $this->anything() );
+
+               $obj = $this->newObj( [ 'FileBackends' => [ [
+                       'name' => 'name',
+                       'class' => '',
+                       'lockManager' => 'fsLockManager',
+                       'fileJournal' => [ 'factory' =>
+                               function () use ( $mockJournal ) {
+                                       return $mockJournal;
+                               }
+                       ],
+               ] ] ] );
+
+               $this->assertSame( $mockJournal, $obj->config( 'name' )['fileJournal'] );
+       }
+
+       /**
+        * @covers ::config
+        */
+       public function testConfigUnrecognized() {
+               $this->setExpectedException( InvalidArgumentException::class,
+                       "No backend defined with the name 'unrecognized'." );
+               $this->newObj()->config( 'unrecognized' );
+       }
+
+       /**
+        * @dataProvider provideBackendFromPath
+        * @covers ::backendFromPath
+        * @param string|null $expected Name of backend that will be returned from 'get', or null
+        * @param string $storagePath
+        */
+       public function testBackendFromPath( $expected = null, $storagePath ) {
+               $obj = $this->newObj( [ 'FileBackends' => [
+                       [ 'name' => '', 'class' => stdclass::class, 'lockManager' => 'fsLockManager' ],
+                       [ 'name' => 'a', 'class' => stdclass::class, 'lockManager' => 'fsLockManager' ],
+                       [ 'name' => 'b', 'class' => stdclass::class, 'lockManager' => 'fsLockManager' ],
+               ] ] );
+               $this->assertSame(
+                       $expected === null ? null : $obj->get( $expected ),
+                       $obj->backendFromPath( $storagePath )
+               );
+       }
+
+       public static function provideBackendFromPath() {
+               return [
+                       'Empty string' => [ null, '' ],
+                       'mwstore://' => [ null, 'mwstore://' ],
+                       'mwstore://a' => [ null, 'mwstore://a' ],
+                       'mwstore:///' => [ null, 'mwstore:///' ],
+                       'mwstore://a/' => [ null, 'mwstore://a/' ],
+                       'mwstore://a//' => [ null, 'mwstore://a//' ],
+                       'mwstore://a/b' => [ 'a', 'mwstore://a/b' ],
+                       'mwstore://a/b/' => [ 'a', 'mwstore://a/b/' ],
+                       'mwstore://a/b////' => [ 'a', 'mwstore://a/b////' ],
+                       'mwstore://a/b/c' => [ 'a', 'mwstore://a/b/c' ],
+                       'mwstore://a/b/c/d' => [ 'a', 'mwstore://a/b/c/d' ],
+                       'mwstore://b/b' => [ 'b', 'mwstore://b/b' ],
+                       'mwstore://c/b' => [ null, 'mwstore://c/b' ],
+               ];
+       }
+
+       /**
+        * @dataProvider provideGuessMimeInternal
+        * @covers ::guessMimeInternal
+        * @param string $storagePath
+        * @param string|null $content
+        * @param string|null $fsPath
+        * @param string|null $expectedExtensionType Expected return of
+        *   MimeAnalyzer::guessTypesForExtension
+        * @param string|null $expectedGuessedMimeType Expected return value of
+        *   MimeAnalyzer::guessMimeType (null if expected not to be called)
+        */
+       public function testGuessMimeInternal(
+               $storagePath,
+               $content,
+               $fsPath,
+               $expectedExtensionType,
+               $expectedGuessedMimeType
+       ) {
+               $mimeAnalyzer = $this->createMock( MimeAnalyzer::class );
+               $mimeAnalyzer->expects( $this->once() )->method( 'guessTypesForExtension' )
+                       ->willReturn( $expectedExtensionType );
+               $tmpFileFactory = $this->createMock( TempFSFileFactory::class );
+
+               if ( !$expectedExtensionType && $fsPath ) {
+                       $tmpFileFactory->expects( $this->never() )->method( 'newTempFSFile' );
+                       $mimeAnalyzer->expects( $this->once() )->method( 'guessMimeType' )
+                               ->with( $fsPath, false )->willReturn( $expectedGuessedMimeType );
+               } elseif ( !$expectedExtensionType && strlen( $content ) ) {
+                       // XXX What should we do about the file creation here? Really we should mock
+                       // file_put_contents() somehow. It's not very nice to ignore the value of
+                       // $wgTmpDirectory.
+                       $tmpFile = ( new TempFSFileFactory() )->newTempFSFile( 'mime_', '' );
+
+                       $tmpFileFactory->expects( $this->once() )->method( 'newTempFSFile' )
+                               ->with( 'mime_', '' )->willReturn( $tmpFile );
+                       $mimeAnalyzer->expects( $this->once() )->method( 'guessMimeType' )
+                               ->with( $tmpFile->getPath(), false )->willReturn( $expectedGuessedMimeType );
+               } else {
+                       $tmpFileFactory->expects( $this->never() )->method( 'newTempFSFile' );
+                       $mimeAnalyzer->expects( $this->never() )->method( 'guessMimeType' );
+               }
+
+               $mimeAnalyzer->expects( $this->never() )
+                       ->method( $this->anythingBut( 'guessTypesForExtension', 'guessMimeType' ) );
+               $tmpFileFactory->expects( $this->never() )
+                       ->method( $this->anythingBut( 'newTempFSFile' ) );
+
+               $obj = $this->newObj( [
+                       'mimeAnalyzer' => $mimeAnalyzer,
+                       'tmpFileFactory' => $tmpFileFactory,
+               ] );
+
+               $this->assertSame( $expectedExtensionType ?? $expectedGuessedMimeType ?? 'unknown/unknown',
+                       $obj->guessMimeInternal( $storagePath, $content, $fsPath ) );
+       }
+
+       public static function provideGuessMimeInternal() {
+               return [
+                       'With extension' =>
+                               [ 'foo.txt', null, null, 'text/plain', null ],
+                       'No extension' =>
+                               [ 'foo', null, null, null, null ],
+                       'Empty content, with extension' =>
+                               [ 'foo.txt', '', null, 'text/plain', null ],
+                       'Empty content, no extension' =>
+                               [ 'foo', '', null, null, null ],
+                       'Non-empty content, with extension' =>
+                               [ 'foo.txt', '<b>foo</b>', null, 'text/plain', null ],
+                       'Non-empty content, no extension' =>
+                               [ 'foo', '<b>foo</b>', null, null, 'text/html' ],
+                       'Empty path, with extension' =>
+                               [ 'foo.txt', null, '', 'text/plain', null ],
+                       'Empty path, no extension' =>
+                               [ 'foo', null, '', null, null ],
+                       'Non-empty path, with extension' =>
+                               [ 'foo.txt', null, '/bogus/path', 'text/plain', null ],
+                       'Non-empty path, no extension' =>
+                               [ 'foo', null, '/bogus/path', null, 'text/html' ],
+                       'Empty path and content, with extension' =>
+                               [ 'foo.txt', '', '', 'text/plain', null ],
+                       'Empty path and content, no extension' =>
+                               [ 'foo', '', '', null, null ],
+                       'Non-empty path and content, with extension' =>
+                               [ 'foo.txt', '<b>foo</b>', '/bogus/path', 'text/plain', null ],
+                       'Non-empty path and content, no extension' =>
+                               [ 'foo', '<b>foo</b>', '/bogus/path', null, 'image/jpeg' ],
+               ];
+       }
+}
index 38fcf29..ca39341 100644 (file)
@@ -10,8 +10,7 @@ use Wikimedia\Rdbms\LBFactory;
  */
 class LockManagerGroupFactoryTest extends MediaWikiUnitTestCase {
        public function testGetLockManagerGroup() {
-               $mockLbFactory = $this->createMock( LBFactory::class );
-               $mockLbFactory->expects( $this->never() )->method( $this->anything() );
+               $mockLbFactory = $this->createNoOpMock( LBFactory::class );
 
                $factory = new LockManagerGroupFactory( 'defaultDomain', [], $mockLbFactory );
                $lbmUnspecified = $factory->getLockManagerGroup();
diff --git a/tests/phpunit/unit/includes/language/LanguageFallbackTestTrait.php b/tests/phpunit/unit/includes/language/LanguageFallbackTestTrait.php
new file mode 100644 (file)
index 0000000..b500b21
--- /dev/null
@@ -0,0 +1,184 @@
+<?php
+
+/**
+ * Code to test the getFallbackFor, getFallbacksFor, and getFallbacksIncludingSiteLanguage methods
+ * that have historically been static methods of the Language class. It can be used to test any
+ * class or object that implements those three methods.
+ */
+trait LanguageFallbackTestTrait {
+       /**
+        * @param array $options Valid keys:
+        *   * expectedGets: How many times we expect to hit the localisation cache. (This can be
+        *   ignored in integration tests -- it's enough to test in unit tests.)
+        *   * siteLangCode
+        * @return string|object Name of class or object with the three methods getFallbackFor,
+        *   getFallbacksFor, and getFallbacksIncludingSiteLanguage.
+        */
+       abstract protected function getCallee( array $options = [] );
+
+       /**
+        * @return int Value that was historically in Language::MESSAGES_FALLBACKS
+        */
+       abstract protected function getMessagesKey();
+
+       /**
+        * @return int Value that was historically in Language::STRICT_FALLBACKS
+        */
+       abstract protected function getStrictKey();
+
+       /**
+        * Convenience/readability wrapper to call a method on a class or object.
+        *
+        * @param string|object As in return value of getCallee()
+        * @param string $method Name of method to call
+        * @param mixed ...$params To pass to method
+        * @return mixed Return value of method
+        */
+       private function callMethod( $callee, $method, ...$params ) {
+               return [ $callee, $method ]( ...$params );
+       }
+
+       /**
+        * @param string $code
+        * @param array $expected
+        * @param array $options
+        * @dataProvider provideGetFallbacksFor
+        * @covers ::getFallbackFor
+        * @covers Language::getFallbackFor
+        */
+       public function testGetFallbackFor( $code, array $expected, array $options = [] ) {
+               $callee = $this->getCallee( $options );
+               // One behavior difference between the old static methods and the new instance methods:
+               // returning null instead of false.
+               $defaultExpected = is_object( $callee ) ? null : false;
+               $this->assertSame( $expected[0] ?? $defaultExpected,
+                       $this->callMethod( $callee, 'getFallbackFor', $code ) );
+       }
+
+       /**
+        * @param string $code
+        * @param array $expected
+        * @param array $options
+        * @dataProvider provideGetFallbacksFor
+        * @covers ::getFallbacksFor
+        * @covers Language::getFallbacksFor
+        */
+       public function testGetFallbacksFor( $code, array $expected, array $options = [] ) {
+               $this->assertSame( $expected,
+                       $this->callMethod( $this->getCallee( $options ), 'getFallbacksFor', $code ) );
+       }
+
+       /**
+        * @param string $code
+        * @param array $expected
+        * @param array $options
+        * @dataProvider provideGetFallbacksFor
+        * @covers ::getFallbacksFor
+        * @covers Language::getFallbacksFor
+        */
+       public function testGetFallbacksFor_messages( $code, array $expected, array $options = [] ) {
+               $this->assertSame( $expected,
+                       $this->callMethod( $this->getCallee( $options ), 'getFallbacksFor',
+                               $code, $this->getMessagesKey() ) );
+       }
+
+       public static function provideGetFallbacksFor() {
+               return [
+                       'en' => [ 'en', [], [ 'expectedGets' => 0 ] ],
+                       'fr' => [ 'fr', [ 'en' ] ],
+                       'sco' => [ 'sco', [ 'en' ] ],
+                       'yi' => [ 'yi', [ 'he', 'en' ] ],
+                       'ruq' => [ 'ruq', [ 'ruq-latn', 'ro', 'en' ] ],
+                       'sh' => [ 'sh', [ 'bs', 'sr-el', 'hr', 'en' ] ],
+               ];
+       }
+
+       /**
+        * @param string $code
+        * @param array $expected
+        * @param array $options
+        * @dataProvider provideGetFallbacksFor_strict
+        * @covers ::getFallbacksFor
+        * @covers Language::getFallbacksFor
+        */
+       public function testGetFallbacksFor_strict( $code, array $expected, array $options = [] ) {
+               $this->assertSame( $expected,
+                       $this->callMethod( $this->getCallee( $options ), 'getFallbacksFor',
+                               $code, $this->getStrictKey() ) );
+       }
+
+       public static function provideGetFallbacksFor_strict() {
+               return [
+                       'en' => [ 'en', [], [ 'expectedGets' => 0 ] ],
+                       'fr' => [ 'fr', [] ],
+                       'sco' => [ 'sco', [ 'en' ] ],
+                       'yi' => [ 'yi', [ 'he' ] ],
+                       'ruq' => [ 'ruq', [ 'ruq-latn', 'ro' ] ],
+                       'sh' => [ 'sh', [ 'bs', 'sr-el', 'hr' ] ],
+               ];
+       }
+
+       /**
+        * @covers ::getFallbacksFor
+        * @covers Language::getFallbacksFor
+        */
+       public function testGetFallbacksFor_exception() {
+               $this->setExpectedException( MWException::class, 'Invalid fallback mode "7"' );
+
+               $callee = $this->getCallee( [ 'expectedGets' => 0 ] );
+
+               // These should not throw, because of short-circuiting. If they do, it will fail the test,
+               // because we pass 5 and 6 instead of 7.
+               $this->callMethod( $callee, 'getFallbacksFor', 'en', 5 );
+               $this->callMethod( $callee, 'getFallbacksFor', '!!!', 6 );
+
+               // This is the one that should throw.
+               $this->callMethod( $callee, 'getFallbacksFor', 'fr', 7 );
+       }
+
+       /**
+        * @param string $code
+        * @param string $siteLangCode
+        * @param array $expected
+        * @param int $expectedGets
+        * @dataProvider provideGetFallbacksIncludingSiteLanguage
+        * @covers ::getFallbacksIncludingSiteLanguage
+        * @covers Language::getFallbacksIncludingSiteLanguage
+        */
+       public function testGetFallbacksIncludingSiteLanguage(
+               $code, $siteLangCode, array $expected, $expectedGets = 1
+       ) {
+               $callee = $this->getCallee(
+                       [ 'siteLangCode' => $siteLangCode, 'expectedGets' => $expectedGets ] );
+               $this->assertSame( $expected,
+                       $this->callMethod( $callee, 'getFallbacksIncludingSiteLanguage', $code ) );
+
+               // Call again to make sure we don't call LocalisationCache again
+               $this->callMethod( $callee, 'getFallbacksIncludingSiteLanguage', $code );
+       }
+
+       public static function provideGetFallbacksIncludingSiteLanguage() {
+               return [
+                       'en on en' => [ 'en', 'en', [ [], [ 'en' ] ], 0 ],
+                       'fr on en' => [ 'fr', 'en', [ [ 'en' ], [] ] ],
+                       'en on fr' => [ 'en', 'fr', [ [], [ 'fr', 'en' ] ] ],
+                       'fr on fr' => [ 'fr', 'fr', [ [ 'en' ], [ 'fr' ] ] ],
+
+                       'sco on en' => [ 'sco', 'en', [ [ 'en' ], [] ] ],
+                       'en on sco' => [ 'en', 'sco', [ [], [ 'sco', 'en' ] ] ],
+                       'sco on sco' => [ 'sco', 'sco', [ [ 'en' ], [ 'sco' ] ] ],
+
+                       'fr on sco' => [ 'fr', 'sco', [ [ 'en' ], [ 'sco' ] ], 2 ],
+                       'sco on fr' => [ 'sco', 'fr', [ [ 'en' ], [ 'fr' ] ], 2 ],
+
+                       'fr on yi' => [ 'fr', 'yi', [ [ 'en' ], [ 'yi', 'he' ] ], 2 ],
+                       'yi on fr' => [ 'yi', 'fr', [ [ 'he', 'en' ], [ 'fr' ] ], 2 ],
+                       'yi on yi' => [ 'yi', 'yi', [ [ 'he', 'en' ], [ 'yi' ] ] ],
+
+                       'sh on ruq' => [ 'sh', 'ruq',
+                               [ [ 'bs', 'sr-el', 'hr', 'en' ], [ 'ruq', 'ruq-latn', 'ro' ] ], 2 ],
+                       'ruq on sh' => [ 'ruq', 'sh',
+                               [ [ 'ruq-latn', 'ro', 'en' ], [ 'sh', 'bs', 'sr-el', 'hr' ] ], 2 ],
+               ];
+       }
+}
index 013fb0d..9230ab7 100644 (file)
                        'Parse an ftp URI correctly with user and password'
                );
 
+               uri = new mw.Uri( 'http://example.com/?foo[1]=b&foo[0]=a&foo[]=c' );
+
+               assert.deepEqual(
+                       uri.query,
+                       {
+                               'foo[1]': 'b',
+                               'foo[0]': 'a',
+                               'foo[]': 'c'
+                       },
+                       'Array query parameters parsed as normal with arrayParams:false'
+               );
+
                assert.throws(
                        function () {
                                return new mw.Uri( 'glaswegian penguins' );
index 894dd19..3258f8e 100644 (file)
@@ -21,6 +21,9 @@
                                window.Set = this.nativeSet;
                                mw.redefineFallbacksForTest();
                        }
+                       if ( this.resetStoreKey ) {
+                               localStorage.removeItem( mw.loader.store.key );
+                       }
                        // Remove any remaining temporary statics
                        // exposed for cross-file mocks.
                        delete mw.loader.testCallback;
                } );
        } );
 
+       QUnit.test( 'mw.loader.store.init - Invalid JSON', function ( assert ) {
+               // Reset
+               this.sandbox.stub( mw.loader.store, 'enabled', null );
+               this.sandbox.stub( mw.loader.store, 'items', {} );
+               this.resetStoreKey = true;
+               localStorage.setItem( mw.loader.store.key, 'invalid' );
+
+               mw.loader.store.init();
+               assert.strictEqual( mw.loader.store.enabled, true, 'Enabled' );
+               assert.strictEqual(
+                       $.isEmptyObject( mw.loader.store.items ),
+                       true,
+                       'Items starts fresh'
+               );
+       } );
+
+       QUnit.test( 'mw.loader.store.init - Wrong JSON', function ( assert ) {
+               // Reset
+               this.sandbox.stub( mw.loader.store, 'enabled', null );
+               this.sandbox.stub( mw.loader.store, 'items', {} );
+               this.resetStoreKey = true;
+               localStorage.setItem( mw.loader.store.key, JSON.stringify( { wrong: true } ) );
+
+               mw.loader.store.init();
+               assert.strictEqual( mw.loader.store.enabled, true, 'Enabled' );
+               assert.strictEqual(
+                       $.isEmptyObject( mw.loader.store.items ),
+                       true,
+                       'Items starts fresh'
+               );
+       } );
+
+       QUnit.test( 'mw.loader.store.init - Expired JSON', function ( assert ) {
+               // Reset
+               this.sandbox.stub( mw.loader.store, 'enabled', null );
+               this.sandbox.stub( mw.loader.store, 'items', {} );
+               this.resetStoreKey = true;
+               localStorage.setItem( mw.loader.store.key, JSON.stringify( {
+                       items: { use: 'not me' },
+                       vary: mw.loader.store.vary,
+                       asOf: 130161 // 2011-04-01 12:00
+               } ) );
+
+               mw.loader.store.init();
+               assert.strictEqual( mw.loader.store.enabled, true, 'Enabled' );
+               assert.strictEqual(
+                       $.isEmptyObject( mw.loader.store.items ),
+                       true,
+                       'Items starts fresh'
+               );
+       } );
+
+       QUnit.test( 'mw.loader.store.init - Good JSON', function ( assert ) {
+               // Reset
+               this.sandbox.stub( mw.loader.store, 'enabled', null );
+               this.sandbox.stub( mw.loader.store, 'items', {} );
+               this.resetStoreKey = true;
+               localStorage.setItem( mw.loader.store.key, JSON.stringify( {
+                       items: { use: 'me' },
+                       vary: mw.loader.store.vary,
+                       asOf: Math.ceil( Date.now() / 1e7 ) - 5 // ~ 13 hours ago
+               } ) );
+
+               mw.loader.store.init();
+               assert.strictEqual( mw.loader.store.enabled, true, 'Enabled' );
+               assert.deepEqual(
+                       mw.loader.store.items,
+                       { use: 'me' },
+                       'Stored items are loaded'
+               );
+       } );
+
        QUnit.test( 'require()', function ( assert ) {
                mw.loader.register( [
                        [ 'test.require1', '0' ],
index e286dd8..6220415 100644 (file)
 
                /* Grade X */
 
+               // Open WebOS < 1.5 (Palm Pre, Palm Pixi)
+               'Mozilla/5.0 (webOS/1.0; U; en-US) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/1.0 Safari/525.27.1 Pre/1.0',
+               'Mozilla/5.0 (webOS/1.4.0; U; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Version/1.0 Safari/532.2 Pixi/1.1 ',
+               // SymbianOS
+               'NokiaN95_8GB-3;Mozilla/5.0 SymbianOS/9.2;U;Series60/3.1 NokiaN95_8GB-3/11.2.011 Profile/MIDP-2.0 Configuration/CLDC-1.1 AppleWebKit/413 (KHTML, like Gecko)',
+               'Nokia7610/2.0 (5.0509.0) SymbianOS/7.0s Series60/2.1 Profile/MIDP-2.0 Configuration/CLDC-1.0 ',
+               'Mozilla/5.0 (SymbianOS/9.1; U; [en]; SymbianOS/91 Series60/3.0) AppleWebKit/413 (KHTML, like Gecko) Safari/413',
+               'Mozilla/5.0 (SymbianOS/9.3; Series60/3.2 NokiaE52-2/091.003; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/533.4 (KHTML, like Gecko) NokiaBrowser/7.3.1.34 Mobile Safari/533.4',
                // Gecko
                'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.7) Gecko/20060928 (Debian|Debian-1.8.0.7-1) Epiphany/2.14',
                'Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.8.1.6) Gecko/20070817 IceWeasel/2.0.0.6-g2',
                'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)',
                // IE Mobile 10
                'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; HTC; Windows Phone 8X by HTC)',
-               // Open WebOS < 1.5 (Palm Pre, Palm Pixi)
-               'Mozilla/5.0 (webOS/1.0; U; en-US) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/1.0 Safari/525.27.1 Pre/1.0',
-               'Mozilla/5.0 (webOS/1.4.0; U; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Version/1.0 Safari/532.2 Pixi/1.1 ',
-               // SymbianOS
-               'NokiaN95_8GB-3;Mozilla/5.0 SymbianOS/9.2;U;Series60/3.1 NokiaN95_8GB-3/11.2.011 Profile/MIDP-2.0 Configuration/CLDC-1.1 AppleWebKit/413 (KHTML, like Gecko)',
-               'Nokia7610/2.0 (5.0509.0) SymbianOS/7.0s Series60/2.1 Profile/MIDP-2.0 Configuration/CLDC-1.0 ',
-               'Mozilla/5.0 (SymbianOS/9.1; U; [en]; SymbianOS/91 Series60/3.0) AppleWebKit/413 (KHTML, like Gecko) Safari/413',
-               'Mozilla/5.0 (SymbianOS/9.3; Series60/3.2 NokiaE52-2/091.003; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/533.4 (KHTML, like Gecko) NokiaBrowser/7.3.1.34 Mobile Safari/533.4',
                // NetFront
                'Mozilla/4.0 (compatible; Linux 2.6.10) NetFront/3.3 Kindle/1.0 (screen 600x800)',
                'Mozilla/4.0 (compatible; Linux 2.6.22) NetFront/3.4 Kindle/2.0 (screen 824x1200; rotate)',