Merge "Remove parameter 'options' from hook 'SkinEditSectionLinks'"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 8 May 2019 17:48:39 +0000 (17:48 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 8 May 2019 17:48:39 +0000 (17:48 +0000)
283 files changed:
Gruntfile.js
RELEASE-NOTES-1.34
autoload.php
composer.json
includes/Block.php
includes/DefaultSettings.php
includes/EditPage.php
includes/GlobalFunctions.php
includes/Linker.php
includes/MediaWikiServices.php
includes/MovePage.php
includes/OutputPage.php
includes/Permissions/PermissionManager.php
includes/Pingback.php
includes/ProtectionForm.php
includes/Revision.php
includes/Revision/RevisionLookup.php
includes/Revision/RevisionStore.php
includes/ServiceWiring.php
includes/SiteStatsInit.php
includes/Title.php
includes/TrackingCategories.php
includes/WikiMap.php
includes/actions/HistoryAction.php
includes/actions/InfoAction.php
includes/api/ApiBase.php
includes/api/ApiBlock.php
includes/api/ApiBlockInfoTrait.php [new file with mode: 0644]
includes/api/ApiHelp.php
includes/api/ApiPageSet.php
includes/api/ApiQueryAllDeletedRevisions.php
includes/api/ApiQueryAllPages.php
includes/api/ApiQueryAllRevisions.php
includes/api/ApiQueryInfo.php
includes/api/ApiQuerySearch.php
includes/api/ApiQuerySiteinfo.php
includes/api/ApiQueryUserInfo.php
includes/api/ApiSetNotificationTimestamp.php
includes/api/ApiUnblock.php
includes/api/i18n/ko.json
includes/api/i18n/lb.json
includes/api/i18n/nl.json
includes/api/i18n/pl.json
includes/api/i18n/zh-hant.json
includes/block/AbstractBlock.php [new file with mode: 0644]
includes/block/BlockManager.php
includes/block/SystemBlock.php [new file with mode: 0644]
includes/cache/CacheHelper.php
includes/cache/GenderCache.php
includes/cache/LinkCache.php
includes/cache/MessageCache.php
includes/cache/localisation/LCStoreCDB.php
includes/cache/localisation/LocalisationCache.php
includes/changes/ChangesFeed.php
includes/content/ContentHandler.php
includes/editpage/TextboxBuilder.php
includes/exception/MWExceptionHandler.php
includes/exception/UserBlockedError.php
includes/export/DumpNotalkFilter.php
includes/export/XmlDumpWriter.php
includes/externalstore/ExternalStoreHttp.php
includes/filerepo/FileRepo.php
includes/filerepo/ForeignAPIRepo.php
includes/filerepo/RepoGroup.php
includes/filerepo/file/File.php
includes/filerepo/file/ForeignDBFile.php
includes/gallery/TraditionalImageGallery.php
includes/htmlform/HTMLForm.php
includes/htmlform/OOUIHTMLForm.php
includes/http/CurlHttpRequest.php
includes/http/GuzzleHttpRequest.php
includes/http/Http.php
includes/http/HttpRequestFactory.php
includes/http/MWHttpRequest.php
includes/http/PhpHttpRequest.php
includes/import/ImportStreamSource.php
includes/import/ImportableUploadRevisionImporter.php
includes/import/WikiImporter.php
includes/installer/Installer.php
includes/installer/i18n/ia.json
includes/jobqueue/jobs/ActivityUpdateJob.php
includes/jobqueue/jobs/ClearUserWatchlistJob.php
includes/jobqueue/jobs/UserOptionsUpdateJob.php [new file with mode: 0644]
includes/libs/filebackend/fsfile/TempFSFile.php
includes/linker/LinkRenderer.php
includes/linker/LinkRendererFactory.php
includes/page/Article.php
includes/poolcounter/PoolWorkArticleView.php
includes/preferences/DefaultPreferencesFactory.php
includes/rcfeed/UDPRCFeedEngine.php
includes/resourceloader/ResourceLoaderStartUpModule.php
includes/search/PrefixSearch.php
includes/search/SearchEngine.php
includes/skins/Skin.php
includes/skins/SkinTemplate.php
includes/specialpage/ChangesListSpecialPage.php
includes/specials/SpecialAncientpages.php
includes/specials/SpecialContributions.php
includes/specials/SpecialDeadendpages.php
includes/specials/SpecialDeletedContributions.php
includes/specials/SpecialEditWatchlist.php
includes/specials/SpecialFewestrevisions.php
includes/specials/SpecialListGroupRights.php
includes/specials/SpecialLonelypages.php
includes/specials/SpecialMostcategories.php
includes/specials/SpecialMostinterwikis.php
includes/specials/SpecialMovepage.php
includes/specials/SpecialPasswordPolicies.php
includes/specials/SpecialRandompage.php
includes/specials/SpecialSearch.php
includes/specials/SpecialShortpages.php
includes/specials/SpecialStatistics.php
includes/specials/SpecialUncategorizedpages.php
includes/specials/SpecialWatchlist.php
includes/specials/SpecialWithoutinterwiki.php
includes/specials/forms/UploadForm.php
includes/specials/pagers/ContribsPager.php
includes/title/NaiveImportTitleFactory.php
includes/title/NamespaceImportTitleFactory.php
includes/title/NamespaceInfo.php
includes/title/SubpageImportTitleFactory.php
includes/user/ExternalUserNames.php
includes/user/User.php
includes/user/UserIdentity.php
includes/user/UserIdentityValue.php
includes/watcheditem/NoWriteWatchedItemStore.php
includes/watcheditem/WatchedItem.php
includes/watcheditem/WatchedItemQueryService.php
includes/watcheditem/WatchedItemQueryServiceExtension.php
includes/watcheditem/WatchedItemStore.php
includes/watcheditem/WatchedItemStoreInterface.php
includes/widget/search/SearchFormWidget.php
languages/Language.php
languages/i18n/ang.json
languages/i18n/ar.json
languages/i18n/ban.json
languages/i18n/be-tarask.json
languages/i18n/bjn.json
languages/i18n/bn.json
languages/i18n/ce.json
languages/i18n/da.json
languages/i18n/de.json
languages/i18n/diq.json
languages/i18n/en.json
languages/i18n/eo.json
languages/i18n/hr.json
languages/i18n/hu.json
languages/i18n/hyw.json
languages/i18n/ia.json
languages/i18n/jv.json
languages/i18n/ml.json
languages/i18n/my.json
languages/i18n/nb.json
languages/i18n/nn.json
languages/i18n/nqo.json
languages/i18n/ps.json
languages/i18n/qqq.json
languages/i18n/sah.json
languages/i18n/sr-ec.json
languages/i18n/sw.json
languages/i18n/tr.json
languages/i18n/yue.json
languages/i18n/zh-hant.json
maintenance/benchmarks/bench_HTTP_HTTPS.php
maintenance/cleanupCaps.php
maintenance/cleanupTitles.php
maintenance/cleanupUsersWithNoId.php
maintenance/findHooks.php
maintenance/generateSitemap.php
maintenance/importSiteScripts.php
maintenance/mediawiki.Title/generatePhpCharToUpperMappings.php
maintenance/namespaceDupes.php
maintenance/populateInterwiki.php
maintenance/rebuildFileCache.php
package.json
resources/Resources.php
resources/lib/foreign-resources.yaml
resources/lib/ooui/History.md
resources/lib/ooui/i18n/hy.json
resources/lib/ooui/oojs-ui-apex.js
resources/lib/ooui/oojs-ui-core-apex.css
resources/lib/ooui/oojs-ui-core-wikimediaui.css
resources/lib/ooui/oojs-ui-core.js
resources/lib/ooui/oojs-ui-core.js.map.json
resources/lib/ooui/oojs-ui-toolbars-apex.css
resources/lib/ooui/oojs-ui-toolbars-wikimediaui.css
resources/lib/ooui/oojs-ui-toolbars.js
resources/lib/ooui/oojs-ui-widgets-apex.css
resources/lib/ooui/oojs-ui-widgets-wikimediaui.css
resources/lib/ooui/oojs-ui-widgets.js
resources/lib/ooui/oojs-ui-wikimediaui.js
resources/lib/ooui/oojs-ui-windows-apex.css
resources/lib/ooui/oojs-ui-windows-wikimediaui.css
resources/lib/ooui/oojs-ui-windows.js
resources/lib/ooui/themes/wikimediaui/icons-alerts.json
resources/lib/ooui/themes/wikimediaui/icons-content.json
resources/lib/ooui/themes/wikimediaui/images/icons/alert-error.png [deleted file]
resources/lib/ooui/themes/wikimediaui/images/icons/alert-error.svg [deleted file]
resources/lib/ooui/themes/wikimediaui/images/icons/articleDisambiguation-ltr-invert.png [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/articleDisambiguation-ltr-invert.svg [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/articleDisambiguation-ltr-progressive.png [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/articleDisambiguation-ltr-progressive.svg [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/articleDisambiguation-ltr.png [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/articleDisambiguation-ltr.svg [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/articleDisambiguation-rtl-invert.png [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/articleDisambiguation-rtl-invert.svg [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/articleDisambiguation-rtl-progressive.png [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/articleDisambiguation-rtl-progressive.svg [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/articleDisambiguation-rtl.png [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/articleDisambiguation-rtl.svg [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/articleNotFound-ltr-invert.png [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/articleNotFound-ltr-invert.svg [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/articleNotFound-ltr-progressive.png [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/articleNotFound-ltr-progressive.svg [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/articleNotFound-ltr.png [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/articleNotFound-ltr.svg [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/articleNotFound-rtl-invert.png [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/articleNotFound-rtl-invert.svg [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/articleNotFound-rtl-progressive.png [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/articleNotFound-rtl-progressive.svg [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/articleNotFound-rtl.png [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/articleNotFound-rtl.svg [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/error-error.png [new file with mode: 0644]
resources/lib/ooui/themes/wikimediaui/images/icons/error-error.svg [new file with mode: 0644]
resources/src/mediawiki.action/mediawiki.action.history.styles.less
resources/src/mediawiki.less/mediawiki.ui/mixins.buttons.less [new file with mode: 0644]
resources/src/mediawiki.ui/components/buttons.less
resources/src/mediawiki.widgets/images/page-disambiguation-ltr.svg [deleted file]
resources/src/mediawiki.widgets/images/page-disambiguation-rtl.svg [deleted file]
resources/src/mediawiki.widgets/images/page-not-found-he-yi.svg [deleted file]
resources/src/mediawiki.widgets/images/page-not-found-ltr.svg [deleted file]
resources/src/mediawiki.widgets/images/page-not-found-rtl.svg [deleted file]
resources/src/mediawiki.widgets/mw.widgets.TitleOptionWidget.js
resources/src/mediawiki.widgets/mw.widgets.TitleWidget.less
tests/integration/includes/http/MWHttpRequestTestCase.php
tests/parser/ParserTestPrinter.php
tests/parser/ParserTestRunner.php
tests/phpunit/MediaWikiTestCase.php
tests/phpunit/includes/BlockTest.php
tests/phpunit/includes/ContentSecurityPolicyTest.php
tests/phpunit/includes/GlobalFunctions/GlobalTest.php
tests/phpunit/includes/LinkerTest.php
tests/phpunit/includes/PagePropsTest.php
tests/phpunit/includes/Permissions/PermissionManagerTest.php
tests/phpunit/includes/Revision/RevisionStoreDbTestBase.php
tests/phpunit/includes/RevisionDbTestBase.php
tests/phpunit/includes/SystemBlockTest.php [new file with mode: 0644]
tests/phpunit/includes/TestUserRegistry.php
tests/phpunit/includes/TitlePermissionTest.php
tests/phpunit/includes/TitleTest.php
tests/phpunit/includes/api/ApiBaseTest.php
tests/phpunit/includes/api/ApiBlockInfoTraitTest.php [new file with mode: 0644]
tests/phpunit/includes/api/ApiQueryUserInfoTest.php [deleted file]
tests/phpunit/includes/auth/AuthManagerTest.php
tests/phpunit/includes/config/GlobalVarConfigTest.php
tests/phpunit/includes/db/LBFactoryTest.php
tests/phpunit/includes/editpage/TextboxBuilderTest.php
tests/phpunit/includes/filebackend/FileBackendTest.php
tests/phpunit/includes/filerepo/FileBackendDBRepoWrapperTest.php
tests/phpunit/includes/filerepo/MigrateFileRepoLayoutTest.php
tests/phpunit/includes/filerepo/RepoGroupTest.php
tests/phpunit/includes/http/HttpTest.php
tests/phpunit/includes/jobqueue/JobQueueTest.php
tests/phpunit/includes/libs/CSSMinTest.php
tests/phpunit/includes/libs/objectcache/MultiWriteBagOStuffTest.php
tests/phpunit/includes/libs/objectcache/ReplicatedBagOStuffTest.php
tests/phpunit/includes/linker/LinkRendererFactoryTest.php
tests/phpunit/includes/linker/LinkRendererTest.php
tests/phpunit/includes/preferences/DefaultPreferencesFactoryTest.php
tests/phpunit/includes/title/NamespaceInfoTest.php
tests/phpunit/includes/user/PasswordResetTest.php
tests/phpunit/includes/user/UserTest.php
tests/phpunit/includes/watcheditem/NoWriteWatchedItemStoreUnitTest.php
tests/phpunit/includes/watcheditem/WatchedItemQueryServiceUnitTest.php
tests/phpunit/includes/watcheditem/WatchedItemStoreUnitTest.php
tests/phpunit/mocks/filebackend/MockFileBackend.php
tests/phpunit/mocks/filerepo/MockLocalRepo.php
tests/phpunit/structure/ApiStructureTest.php
tests/phpunit/suites/UploadFromUrlTestSuite.php
tests/selenium/pageobjects/history.page.js
tests/selenium/specs/rollback.js
tests/selenium/wdio-mediawiki/LoginPage.js
tests/selenium/wdio.conf.js

index 765fe55..f3950f6 100644 (file)
@@ -9,7 +9,6 @@ module.exports = function ( grunt ) {
        grunt.loadNpmTasks( 'grunt-banana-checker' );
        grunt.loadNpmTasks( 'grunt-contrib-copy' );
        grunt.loadNpmTasks( 'grunt-eslint' );
-       grunt.loadNpmTasks( 'grunt-jsonlint' );
        grunt.loadNpmTasks( 'grunt-karma' );
        grunt.loadNpmTasks( 'grunt-stylelint' );
        grunt.loadNpmTasks( 'grunt-svgmin' );
@@ -23,10 +22,11 @@ module.exports = function ( grunt ) {
                eslint: {
                        options: {
                                reportUnusedDisableDirectives: true,
+                               extensions: [ '.js', '.json' ],
                                cache: true
                        },
                        all: [
-                               '**/*.js',
+                               '**/*.js{,on}',
                                '!docs/**',
                                '!node_modules/**',
                                '!resources/lib/**',
@@ -36,14 +36,8 @@ module.exports = function ( grunt ) {
                                '!tests/coverage/**',
                                '!vendor/**',
                                // Explicitly say "**/*.js" here in case of symlinks
-                               '!extensions/**/*.js',
-                               '!skins/**/*.js'
-                       ]
-               },
-               jsonlint: {
-                       all: [
-                               '**/*.json',
-                               '!{docs/js,extensions,node_modules,skins,vendor}/**'
+                               '!extensions/**/*.js{,on}',
+                               '!skins/**/*.js{,on}'
                        ]
                },
                banana: {
index 5d46edd..9231380 100644 (file)
@@ -25,6 +25,7 @@ Some specific notes for MediaWiki 1.34 upgrades are below:
 For notes on 1.33.x and older releases, see HISTORY.
 
 === Configuration changes for system administrators in 1.34 ===
+
 ==== New configuration ====
 * …
 
@@ -41,6 +42,7 @@ For notes on 1.33.x and older releases, see HISTORY.
 * …
 
 === External library changes in 1.34 ===
+
 ==== New external libraries ====
 * …
 
@@ -53,7 +55,10 @@ For notes on 1.33.x and older releases, see HISTORY.
 * …
 
 === Bug fixes in 1.34 ===
-* …
+* (T222529) If a log entry or page revision is recorded in the database with an
+  empty username, attempting to display it will log an error and return a "no
+  username available" to the user instead of silently displaying nothing or
+  invalid links.
 
 === Action API changes in 1.34 ===
 * The 'recenteditcount' response property from action=query list=allusers,
@@ -107,6 +112,9 @@ because of Phabricator reports.
 * wfArrayFilter() and wfArrayFilterByKey(), deprecated in 1.32, have been
   removed.
 * wfMakeUrlIndexes() function, deprecated in 1.33, have been removed.
+* Method signatures in WatchedItemQueryServiceExtension have changed from taking
+  User objects to taking UserIdentity objects. Extensions implementing this
+  interface need to be changed accordingly.
 * User::getGroupPage() and ::makeGroupLinkHTML(), deprecated in 1.29, have been
   removed. Use UserGroupMembership::getGroupPage and ::getLink instead.
 * User::makeGroupLinkWiki(), deprecated in 1.29, has been removed. Use
@@ -114,7 +122,7 @@ because of Phabricator reports.
 * …
 
 === Deprecations in 1.34 ===
-* The MWNamespace class is deprecated. Use MediaWikiServices::getNamespaceInfo.
+* The MWNamespace class is deprecated. Use NamespaceInfo.
 * ExtensionRegistry->load() is deprecated, as it breaks dependency checking.
   Instead, use ->queue().
 * User::isBlocked() is deprecated since it does not tell you if the user is
@@ -126,6 +134,25 @@ because of Phabricator reports.
   instead.
 * The Config argument to ChangesListSpecialPage::checkStructuredFilterUiEnabled
   is deprecated. Pass only the User argument.
+* WatchedItem::getUser is deprecated. Use getUserIdentity.
+* Passing a Title as the first parameter to the getTimestampById method of
+  RevisionStore is deprecated. Omit it, passing only the remaining parameters.
+* Title::getPreviousRevisionId and Title::getNextRevisionId are deprecated. Use
+  RevisionLookup::getPreviousRevision and RevisionLookup::getNextRevision.
+* The Title parameter to RevisionLookup::getPreviousRevision and
+  RevisionLookup::getNextRevision is deprecated and should be omitted.
+* MWHttpRequest::factory is deprecated. Use HttpRequestFactory.
+* The Http class is deprecated. For the request, get, and post methods, use
+  HttpRequestFactory. For isValidURI, use MWHttpRequest::isValidURI.  For
+  getProxy, use (string)$wgHTTPProxy. For createMultiClient, construct a
+  MultiHttpClient directly.
+* Http::$httpEngine is deprecated and has no replacement. The default 'guzzle'
+  engine will eventually be made the only engine for HTTP requests.
+* RepoGroup::singleton(), RepoGroup::destroySingleton(),
+  RepoGroup::setSingleton(), wfFindFile(), and wfLocalFile() are all
+  deprecated. Use MediaWikiServices instead.
+* The getSubjectPage, getTalkPage, and getOtherPage of Title are deprecated.
+  Use NamespaceInfo's getSubjectPage, getTalkPage, and getAssociatedPage.
 
 === Other changes in 1.34 ===
 * …
index f8e90b7..5d3e578 100644 (file)
@@ -27,6 +27,7 @@ $wgAutoloadLocalClasses = [
        'ApiAuthManagerHelper' => __DIR__ . '/includes/api/ApiAuthManagerHelper.php',
        'ApiBase' => __DIR__ . '/includes/api/ApiBase.php',
        'ApiBlock' => __DIR__ . '/includes/api/ApiBlock.php',
+       'ApiBlockInfoTrait' => __DIR__ . '/includes/api/ApiBlockInfoTrait.php',
        'ApiCSPReport' => __DIR__ . '/includes/api/ApiCSPReport.php',
        'ApiChangeAuthenticationData' => __DIR__ . '/includes/api/ApiChangeAuthenticationData.php',
        'ApiCheckToken' => __DIR__ . '/includes/api/ApiCheckToken.php',
@@ -1564,6 +1565,7 @@ $wgAutoloadLocalClasses = [
        'UserNamePrefixSearch' => __DIR__ . '/includes/user/UserNamePrefixSearch.php',
        'UserNotLoggedIn' => __DIR__ . '/includes/exception/UserNotLoggedIn.php',
        'UserOptionsMaintenance' => __DIR__ . '/maintenance/userOptions.php',
+       'UserOptionsUpdateJob' => __DIR__ . '/includes/jobqueue/jobs/UserOptionsUpdateJob.php',
        'UserPasswordPolicy' => __DIR__ . '/includes/password/UserPasswordPolicy.php',
        'UserRightsProxy' => __DIR__ . '/includes/user/UserRightsProxy.php',
        'UserrightsPage' => __DIR__ . '/includes/specials/SpecialUserrights.php',
index 3acf73a..a2dcaa1 100644 (file)
@@ -27,7 +27,7 @@
                "ext-xml": "*",
                "guzzlehttp/guzzle": "6.3.3",
                "liuggio/statsd-php-client": "1.0.18",
-               "oojs/oojs-ui": "0.31.5",
+               "oojs/oojs-ui": "0.31.6",
                "pear/mail": "1.4.1",
                "pear/mail_mime": "1.10.2",
                "pear/net_smtp": "1.8.1",
index 0d13f7d..472c36e 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Blocks and bans object
+ * Class for blocks stored in the database.
  *
  * 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
 
 use Wikimedia\Rdbms\Database;
 use Wikimedia\Rdbms\IDatabase;
+use MediaWiki\Block\AbstractBlock;
 use MediaWiki\Block\BlockRestrictionStore;
 use MediaWiki\Block\Restriction\Restriction;
 use MediaWiki\Block\Restriction\NamespaceRestriction;
 use MediaWiki\Block\Restriction\PageRestriction;
 use MediaWiki\MediaWikiServices;
 
-class Block {
-       /** @var string */
-       public $mReason;
-
-       /** @var string */
-       public $mTimestamp;
-
+/**
+ * Blocks (as opposed to system blocks) are stored in the database, may
+ * give rise to autoblocks and may be tracked with cookies. Blocks are
+ * more customizable than system blocks: they may be hardblocks, and
+ * they may be sitewide or partial.
+ */
+class Block extends AbstractBlock {
        /** @var bool */
        public $mAuto;
 
-       /** @var string */
-       public $mExpiry;
-
-       /** @var bool */
-       public $mHideName;
-
        /** @var int */
        public $mParentBlockId;
 
@@ -53,61 +48,23 @@ class Block {
        /** @var bool */
        private $mFromMaster;
 
-       /** @var bool */
-       private $mBlockEmail;
-
-       /** @var bool */
-       private $allowUsertalk;
-
-       /** @var bool */
-       private $blockCreateAccount;
-
-       /** @var User|string */
-       private $target;
-
        /** @var int Hack for foreign blocking (CentralAuth) */
        private $forcedTargetID;
 
-       /**
-        * @var int Block::TYPE_ constant. After the block has been loaded
-        * from the database, this can only be USER, IP or RANGE.
-        */
-       private $type;
-
-       /** @var User */
-       private $blocker;
-
        /** @var bool */
        private $isHardblock;
 
        /** @var bool */
        private $isAutoblocking;
 
-       /** @var string|null */
-       private $systemBlockType;
-
-       /** @var bool */
-       private $isSitewide;
-
        /** @var Restriction[] */
        private $restrictions;
 
-       # TYPE constants
-       const TYPE_USER = 1;
-       const TYPE_IP = 2;
-       const TYPE_RANGE = 3;
-       const TYPE_AUTO = 4;
-       const TYPE_ID = 5;
-
        /**
         * Create a new block with specified option 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
         *     user int             Override target user ID (for foreign users)
-        *     by int               User ID of the blocker
-        *     reason string        Reason of the block
-        *     timestamp string     The time at which the block comes into effect
         *     auto bool            Is this an automatic block?
         *     expiry string        Timestamp of expiration of the block or 'infinity'
         *     anonOnly bool        Only disallow anonymous actions
@@ -116,11 +73,6 @@ class Block {
         *     hideName bool        Hide the target user name
         *     blockEmail bool      Disallow sending emails
         *     allowUsertalk bool   Allow the target to edit its own talk page
-        *     byText string        Username of the blocker (for foreign users)
-        *     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().
         *     sitewide bool        Disallow editing all pages and all contribution
         *                          actions, except those specifically allowed by
         *                          other block flags
@@ -128,12 +80,10 @@ class Block {
         * @since 1.26 $options array
         */
        public function __construct( array $options = [] ) {
+               parent::__construct( $options );
+
                $defaults = [
-                       'address'         => '',
                        'user'            => null,
-                       'by'              => null,
-                       'reason'          => '',
-                       'timestamp'       => '',
                        'auto'            => false,
                        'expiry'          => '',
                        'anonOnly'        => false,
@@ -142,30 +92,16 @@ class Block {
                        'hideName'        => false,
                        'blockEmail'      => false,
                        'allowUsertalk'   => false,
-                       'byText'          => '',
-                       'systemBlock'     => null,
                        'sitewide'        => true,
                ];
 
                $options += $defaults;
 
-               $this->setTarget( $options['address'] );
-
                if ( $this->target instanceof User && $options['user'] ) {
                        # Needed for foreign users
                        $this->forcedTargetID = $options['user'];
                }
 
-               if ( $options['by'] ) {
-                       # Local user
-                       $this->setBlocker( User::newFromId( $options['by'] ) );
-               } else {
-                       # Foreign user
-                       $this->setBlocker( $options['byText'] );
-               }
-
-               $this->setReason( $options['reason'] );
-               $this->setTimestamp( wfTimestamp( TS_MW, $options['timestamp'] ) );
                $this->setExpiry( wfGetDB( DB_REPLICA )->decodeExpiry( $options['expiry'] ) );
 
                # Boolean settings
@@ -179,7 +115,6 @@ class Block {
                $this->isUsertalkEditAllowed( (bool)$options['allowUsertalk'] );
 
                $this->mFromMaster = false;
-               $this->systemBlockType = $options['systemBlock'];
        }
 
        /**
@@ -387,8 +322,9 @@ class Block {
                        if ( $block->getType() == self::TYPE_RANGE ) {
                                # This is the number of bits that are allowed to vary in the block, give
                                # or take some floating point errors
-                               $end = Wikimedia\base_convert( $block->getRangeEnd(), 16, 10 );
-                               $start = Wikimedia\base_convert( $block->getRangeStart(), 16, 10 );
+                               $prefix = 'v6-';
+                               $end = Wikimedia\base_convert( ltrim( $block->getRangeEnd(), $prefix ), 16, 10 );
+                               $start = Wikimedia\base_convert( ltrim( $block->getRangeStart(), $prefix ), 16, 10 );
                                $size = log( $end - $start + 1, 2 );
 
                                # Rank a range block covering a single IP equally with a single-IP block
@@ -543,9 +479,6 @@ class Block {
        public function insert( $dbw = null ) {
                global $wgBlockDisablesLogin;
 
-               if ( $this->getSystemBlockType() !== null ) {
-                       throw new MWException( 'Cannot insert a system block into the database' );
-               }
                if ( !$this->getBlocker() || $this->getBlocker()->getName() === '' ) {
                        throw new MWException( 'Cannot insert a block without a blocker set' );
                }
@@ -859,11 +792,6 @@ class Block {
                        return false;
                }
 
-               # Don't autoblock for system blocks
-               if ( $this->getSystemBlockType() !== null ) {
-                       throw new MWException( 'Cannot autoblock from a system block' );
-               }
-
                # Check for presence on the autoblock whitelist.
                if ( self::isWhitelistedFromAutoblocks( $autoblockIP ) ) {
                        return false;
@@ -1034,26 +962,7 @@ class Block {
        }
 
        /**
-        * Get the user id of the blocking sysop
-        *
-        * @return int (0 for foreign users)
-        */
-       public function getBy() {
-               return $this->getBlocker()->getId();
-       }
-
-       /**
-        * Get the username of the blocking sysop
-        *
-        * @return string
-        */
-       public function getByName() {
-               return $this->getBlocker()->getName();
-       }
-
-       /**
-        * Get the block ID
-        * @return int
+        * @inheritDoc
         */
        public function getId() {
                return $this->mId;
@@ -1077,55 +986,6 @@ class Block {
                return $this;
        }
 
-       /**
-        * Get the reason given for creating the block
-        *
-        * @since 1.33
-        * @return string
-        */
-       public function getReason() {
-               return $this->mReason;
-       }
-
-       /**
-        * Set the reason for creating the block
-        *
-        * @since 1.33
-        * @param string $reason
-        */
-       public function setReason( $reason ) {
-               $this->mReason = $reason;
-       }
-
-       /**
-        * Get whether the block hides the target's username
-        *
-        * @since 1.33
-        * @return bool The block hides the username
-        */
-       public function getHideName() {
-               return $this->mHideName;
-       }
-
-       /**
-        * Set whether ths block hides the target's username
-        *
-        * @since 1.33
-        * @param bool $hideName The block hides the username
-        */
-       public function setHideName( $hideName ) {
-               $this->mHideName = $hideName;
-       }
-
-       /**
-        * Get the system block type, if any
-        * @since 1.29
-        * @return string|null
-        */
-       public function getSystemBlockType() {
-               return $this->systemBlockType;
-       }
-
        /**
         * Get/set a flag determining whether the master is used for reads
         *
@@ -1164,165 +1024,6 @@ class Block {
                        : false;
        }
 
-       /**
-        * Indicates that the block is a sitewide block. This means the user is
-        * prohibited from editing any page on the site (other than their own talk
-        * page).
-        *
-        * @since 1.33
-        * @param null|bool $x
-        * @return bool
-        */
-       public function isSitewide( $x = null ) {
-               return wfSetVar( $this->isSitewide, $x );
-       }
-
-       /**
-        * Get or set the flag indicating whether this block blocks the target from
-        * creating an account. (Note that the flag may be overridden depending on
-        * global configs.)
-        *
-        * @since 1.33
-        * @param null|bool $x Value to set (if null, just get the property value)
-        * @return bool Value of the property
-        */
-       public function isCreateAccountBlocked( $x = null ) {
-               return wfSetVar( $this->blockCreateAccount, $x );
-       }
-
-       /**
-        * Get or set the flag indicating whether this block blocks the target from
-        * sending emails. (Note that the flag may be overridden depending on
-        * global configs.)
-        *
-        * @since 1.33
-        * @param null|bool $x Value to set (if null, just get the property value)
-        * @return bool Value of the property
-        */
-       public function isEmailBlocked( $x = null ) {
-               return wfSetVar( $this->mBlockEmail, $x );
-       }
-
-       /**
-        * Get or set the flag indicating whether this block blocks the target from
-        * editing their own user talk page. (Note that the flag may be overridden
-        * depending on global configs.)
-        *
-        * @since 1.33
-        * @param null|bool $x Value to set (if null, just get the property value)
-        * @return bool Value of the property
-        */
-       public function isUsertalkEditAllowed( $x = null ) {
-               return wfSetVar( $this->allowUsertalk, $x );
-       }
-
-       /**
-        * Determine whether the Block prevents a given right. A right
-        * may be blacklisted or whitelisted, or determined from a
-        * property on the Block object. For certain rights, the property
-        * may be overridden according to global configs.
-        *
-        * @since 1.33
-        * @param string $right Right to check
-        * @return bool|null null if unrecognized right or unset property
-        */
-       public function appliesToRight( $right ) {
-               $config = RequestContext::getMain()->getConfig();
-               $blockDisablesLogin = $config->get( 'BlockDisablesLogin' );
-
-               $res = null;
-               switch ( $right ) {
-                       case 'edit':
-                               // TODO: fix this case to return proper value
-                               $res = true;
-                               break;
-                       case 'createaccount':
-                               $res = $this->isCreateAccountBlocked();
-                               break;
-                       case 'sendemail':
-                               $res = $this->isEmailBlocked();
-                               break;
-                       case 'upload':
-                               // Until T6995 is completed
-                               $res = $this->isSitewide();
-                               break;
-                       case 'read':
-                               $res = false;
-                               break;
-                       case 'purge':
-                               $res = false;
-                               break;
-               }
-               if ( !$res && $blockDisablesLogin ) {
-                       // If a block would disable login, then it should
-                       // prevent any right that all users cannot do
-                       $anon = new User;
-                       $res = $anon->isAllowed( $right ) ? $res : true;
-               }
-
-               return $res;
-       }
-
-       /**
-        * Get/set whether the Block prevents a given action
-        *
-        * @deprecated since 1.33, use appliesToRight to determine block
-        *  behaviour, and specific methods to get/set properties
-        * @param string $action Action to check
-        * @param bool|null $x Value for set, or null to just get value
-        * @return bool|null Null for unrecognized rights.
-        */
-       public function prevents( $action, $x = null ) {
-               $config = RequestContext::getMain()->getConfig();
-               $blockDisablesLogin = $config->get( 'BlockDisablesLogin' );
-               $blockAllowsUTEdit = $config->get( 'BlockAllowsUTEdit' );
-
-               $res = null;
-               switch ( $action ) {
-                       case 'edit':
-                               # For now... <evil laugh>
-                               $res = true;
-                               break;
-                       case 'createaccount':
-                               $res = wfSetVar( $this->blockCreateAccount, $x );
-                               break;
-                       case 'sendemail':
-                               $res = wfSetVar( $this->mBlockEmail, $x );
-                               break;
-                       case 'upload':
-                               // Until T6995 is completed
-                               $res = $this->isSitewide();
-                               break;
-                       case 'editownusertalk':
-                               // NOTE: this check is not reliable on partial blocks
-                               // since partially blocked users are always allowed to edit
-                               // their own talk page unless a restriction exists on the
-                               // page or User_talk: namespace
-                               wfSetVar( $this->allowUsertalk, $x === null ? null : !$x );
-                               $res = !$this->isUsertalkEditAllowed();
-
-                               // edit own user talk can be disabled by config
-                               if ( !$blockAllowsUTEdit ) {
-                                       $res = true;
-                               }
-                               break;
-                       case 'read':
-                               $res = false;
-                               break;
-                       case 'purge':
-                               $res = false;
-                               break;
-               }
-               if ( !$res && $blockDisablesLogin ) {
-                       // If a block would disable login, then it should
-                       // prevent any action that all users cannot do
-                       $anon = new User;
-                       $res = $anon->isAllowed( $action ) ? $res : true;
-               }
-
-               return $res;
-       }
-
        /**
         * Get the block name, but with autoblocked IPs hidden as per standard privacy policy
         * @return string Text is escaped
@@ -1612,170 +1313,15 @@ class Block {
        }
 
        /**
-        * From an existing Block, get the target and the type of target.
-        * Note that, except for null, it is always safe to treat the target
-        * as a string; for User objects this will return User::__toString()
-        * which in turn gives User::getName().
+        * @inheritDoc
         *
-        * @param string|int|User|null $target
-        * @return array [ User|String|null, Block::TYPE_ constant|null ]
-        */
-       public static function parseTarget( $target ) {
-               # We may have been through this before
-               if ( $target instanceof User ) {
-                       if ( IP::isValid( $target->getName() ) ) {
-                               return [ $target, self::TYPE_IP ];
-                       } else {
-                               return [ $target, self::TYPE_USER ];
-                       }
-               } elseif ( $target === null ) {
-                       return [ null, null ];
-               }
-
-               $target = trim( $target );
-
-               if ( IP::isValid( $target ) ) {
-                       # We can still create a User if it's an IP address, but we need to turn
-                       # off validation checking (which would exclude IP addresses)
-                       return [
-                               User::newFromName( IP::sanitizeIP( $target ), false ),
-                               self::TYPE_IP
-                       ];
-
-               } elseif ( IP::isValidRange( $target ) ) {
-                       # Can't create a User from an IP range
-                       return [ IP::sanitizeRange( $target ), self::TYPE_RANGE ];
-               }
-
-               # Consider the possibility that this is not a username at all
-               # but actually an old subpage (T31797)
-               if ( strpos( $target, '/' ) !== false ) {
-                       # An old subpage, drill down to the user behind it
-                       $target = explode( '/', $target )[0];
-               }
-
-               $userObj = User::newFromName( $target );
-               if ( $userObj instanceof User ) {
-                       # Note that since numbers are valid usernames, a $target of "12345" will be
-                       # considered a User.  If you want to pass a block ID, prepend a hash "#12345",
-                       # since hash characters are not valid in usernames or titles generally.
-                       return [ $userObj, self::TYPE_USER ];
-
-               } elseif ( preg_match( '/^#\d+$/', $target ) ) {
-                       # Autoblock reference in the form "#12345"
-                       return [ substr( $target, 1 ), self::TYPE_AUTO ];
-
-               } else {
-                       # WTF?
-                       return [ null, null ];
-               }
-       }
-
-       /**
-        * Get the type of target for this particular block. Autoblocks have whichever type
-        * corresponds to their target, so to detect if a block is an autoblock, we have to
-        * check the mAuto property instead.
-        * @return int Block::TYPE_ constant, will never be TYPE_ID
+        * Autoblocks have whichever type corresponds to their target, so to detect if a block is an
+        * autoblock, we have to check the mAuto property instead.
         */
        public function getType() {
                return $this->mAuto
                        ? self::TYPE_AUTO
-                       : $this->type;
-       }
-
-       /**
-        * Get the target and target type for this particular Block.  Note that for autoblocks,
-        * this returns the unredacted name; frontend functions need to call $block->getRedactedName()
-        * in this situation.
-        * @return array [ User|String, Block::TYPE_ constant ]
-        * @todo FIXME: This should be an integral part of the Block member variables
-        */
-       public function getTargetAndType() {
-               return [ $this->getTarget(), $this->getType() ];
-       }
-
-       /**
-        * Get the target for this particular Block.  Note that for autoblocks,
-        * this returns the unredacted name; frontend functions need to call $block->getRedactedName()
-        * in this situation.
-        * @return User|string
-        */
-       public function getTarget() {
-               return $this->target;
-       }
-
-       /**
-        * Get the block expiry time
-        *
-        * @since 1.19
-        * @return string
-        */
-       public function getExpiry() {
-               return $this->mExpiry;
-       }
-
-       /**
-        * Set the block expiry time
-        *
-        * @since 1.33
-        * @param string $expiry
-        */
-       public function setExpiry( $expiry ) {
-               $this->mExpiry = $expiry;
-       }
-
-       /**
-        * Get the timestamp indicating when the block was created
-        *
-        * @since 1.33
-        * @return string
-        */
-       public function getTimestamp() {
-               return $this->mTimestamp;
-       }
-
-       /**
-        * Set the timestamp indicating when the block was created
-        *
-        * @since 1.33
-        * @param string $timestamp
-        */
-       public function setTimestamp( $timestamp ) {
-               $this->mTimestamp = $timestamp;
-       }
-
-       /**
-        * Set the target for this block, and update $this->type accordingly
-        * @param mixed $target
-        */
-       public function setTarget( $target ) {
-               list( $this->target, $this->type ) = self::parseTarget( $target );
-       }
-
-       /**
-        * Get the user who implemented this block
-        * @return User User object. May name a foreign user.
-        */
-       public function getBlocker() {
-               return $this->blocker;
-       }
-
-       /**
-        * Set the user who implemented (or will implement) this block
-        * @param User|string $user Local User object or username string
-        */
-       public function setBlocker( $user ) {
-               if ( is_string( $user ) ) {
-                       $user = User::newFromName( $user, false );
-               }
-
-               if ( $user->isAnon() && User::isUsableName( $user->getName() ) ) {
-                       throw new InvalidArgumentException(
-                               'Blocker must be a local user or a name that cannot be a local user'
-                       );
-               }
-
-               $this->blocker = $user;
+                       : parent::getType();
        }
 
        /**
@@ -1867,19 +1413,15 @@ class Block {
        }
 
        /**
-        * Get the key and parameters for the corresponding error message.
+        * @inheritDoc
         *
-        * @since 1.22
-        * @param IContextSource $context
-        * @return array
+        * Build different messages for autoblocks and partial blocks.
         */
        public function getPermissionsError( IContextSource $context ) {
                $params = $this->getBlockErrorParams( $context );
 
                $msg = 'blockedtext';
-               if ( $this->getSystemBlockType() !== null ) {
-                       $msg = 'systemblockedtext';
-               } elseif ( $this->mAuto ) {
+               if ( $this->mAuto ) {
                        $msg = 'autoblockedtext';
                } elseif ( !$this->isSitewide() ) {
                        $msg = 'blockedtext-partial';
@@ -1890,45 +1432,6 @@ class Block {
                return $params;
        }
 
-       /**
-        * Get block information used in different block error messages
-        *
-        * @since 1.33
-        * @param IContextSource $context
-        * @return array
-        */
-       public function getBlockErrorParams( IContextSource $context ) {
-               $blocker = $this->getBlocker();
-               if ( $blocker instanceof User ) { // local user
-                       $blockerUserpage = $blocker->getUserPage();
-                       $link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]";
-               } else { // foreign user
-                       $link = $blocker;
-               }
-
-               $reason = $this->getReason();
-               if ( $reason == '' ) {
-                       $reason = $context->msg( 'blockednoreason' )->text();
-               }
-
-               /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
-                * This could be a username, an IP range, or a single IP. */
-               $intended = $this->getTarget();
-               $systemBlockType = $this->getSystemBlockType();
-               $lang = $context->getLanguage();
-
-               return [
-                       $link,
-                       $reason,
-                       $context->getRequest()->getIP(),
-                       $this->getByName(),
-                       $systemBlockType ?? $this->getId(),
-                       $lang->formatExpiry( $this->getExpiry() ),
-                       (string)$intended,
-                       $lang->userTimeAndDate( $this->getTimestamp(), $context->getUser() ),
-               ];
-       }
-
        /**
         * Get Restrictions.
         *
@@ -1967,76 +1470,7 @@ class Block {
        }
 
        /**
-        * Determine whether the block allows the user to edit their own
-        * user talk page. This is done separately from Block::appliesToRight
-        * because there is no right for editing one's own user talk page
-        * and because the user's talk page needs to be passed into the
-        * Block object, which is unaware of the user.
-        *
-        * The ipb_allow_usertalk flag (which corresponds to the property
-        * allowUsertalk) is used on sitewide blocks and partial blocks
-        * that contain a namespace restriction on the user talk namespace,
-        * but do not contain a page restriction on the user's talk page.
-        * For all other (i.e. most) partial blocks, the flag is ignored,
-        * and the user can always edit their user talk page unless there
-        * is a page restriction on their user talk page, in which case
-        * they can never edit it. (Ideally the flag would be stored as
-        * null in these cases, but the database field isn't nullable.)
-        *
-        * This method does not validate that the passed in talk page belongs to the
-        * block target since the target (an IP) might not be the same as the user's
-        * talk page (if they are logged in).
-        *
-        * @since 1.33
-        * @param Title|null $usertalk The user's user talk page. If null,
-        *  and if the target is a User, the target's userpage is used
-        * @return bool The user can edit their talk page
-        */
-       public function appliesToUsertalk( Title $usertalk = null ) {
-               if ( !$usertalk ) {
-                       if ( $this->target instanceof User ) {
-                               $usertalk = $this->target->getTalkPage();
-                       } else {
-                               throw new InvalidArgumentException(
-                                       '$usertalk must be provided if block target is not a user/IP'
-                               );
-                       }
-               }
-
-               if ( $usertalk->getNamespace() !== NS_USER_TALK ) {
-                       throw new InvalidArgumentException(
-                               '$usertalk must be a user talk page'
-                       );
-               }
-
-               if ( !$this->isSitewide() ) {
-                       if ( $this->appliesToPage( $usertalk->getArticleID() ) ) {
-                               return true;
-                       }
-                       if ( !$this->appliesToNamespace( NS_USER_TALK ) ) {
-                               return false;
-                       }
-               }
-
-               // This is a type of block which uses the ipb_allow_usertalk
-               // flag. The flag can still be overridden by global configs.
-               $config = RequestContext::getMain()->getConfig();
-               if ( !$config->get( 'BlockAllowsUTEdit' ) ) {
-                       return true;
-               }
-               return !$this->isUsertalkEditAllowed();
-       }
-
-       /**
-        * Checks if a block applies to a particular title
-        *
-        * This check does not consider whether `$this->isUsertalkEditAllowed`
-        * returns false, as the identity of the user making the hypothetical edit
-        * isn't known here (particularly in the case of IP hardblocks, range
-        * blocks, and auto-blocks).
-        *
-        * @param Title $title
-        * @return bool
+        * @inheritDoc
         */
        public function appliesToTitle( Title $title ) {
                if ( $this->isSitewide() ) {
@@ -2054,12 +1488,7 @@ class Block {
        }
 
        /**
-        * Checks if a block applies to a particular namespace
-        *
-        * @since 1.33
-        *
-        * @param int $ns
-        * @return bool
+        * @inheritDoc
         */
        public function appliesToNamespace( $ns ) {
                if ( $this->isSitewide() ) {
@@ -2077,17 +1506,7 @@ class Block {
        }
 
        /**
-        * Checks if a block applies to a particular page
-        *
-        * This check does not consider whether `$this->isUsertalkEditAllowed`
-        * returns false, as the identity of the user making the hypothetical edit
-        * isn't known here (particularly in the case of IP hardblocks, range
-        * blocks, and auto-blocks).
-        *
-        * @since 1.33
-        *
-        * @param int $pageId
-        * @return bool
+        * @inheritDoc
         */
        public function appliesToPage( $pageId ) {
                if ( $this->isSitewide() ) {
@@ -2127,11 +1546,7 @@ class Block {
        }
 
        /**
-        * Check if the block should be tracked with a cookie.
-        *
-        * @since 1.33
-        * @param bool $isAnon The user is logged out
-        * @return bool The block should be tracked with a cookie
+        * @inheritDoc
         */
        public function shouldTrackWithCookie( $isAnon ) {
                $config = RequestContext::getMain()->getConfig();
@@ -2146,27 +1561,6 @@ class Block {
                }
        }
 
-       /**
-        * Check if the block prevents a user from resetting their password
-        *
-        * @since 1.33
-        * @return bool The block blocks password reset
-        */
-       public function appliesToPasswordReset() {
-               switch ( $this->getSystemBlockType() ) {
-                       case null:
-                       case 'global-block':
-                               return $this->isCreateAccountBlocked();
-                       case 'proxy':
-                               return true;
-                       case 'dnsbl':
-                       case 'wgSoftBlockRanges':
-                               return false;
-                       default:
-                               return true;
-               }
-       }
-
        /**
         * Get a BlockRestrictionStore instance
         *
index b40d33b..33230c8 100644 (file)
@@ -2563,26 +2563,35 @@ $wgUseLocalMessageCache = false;
 $wgAdaptiveMessageCache = false;
 
 /**
- * Localisation cache configuration. Associative array with keys:
- * class:       The class to use. May be overridden by extensions.
+ * Localisation cache configuration.
  *
- * store:       The location to store cache data. May be 'files', 'array', 'db' or
- *              'detect'. If set to "files", data will be in CDB files. If set
- *              to "db", data will be stored to the database. If set to
- *              "detect", files will be used if $wgCacheDirectory is set,
- *              otherwise the database will be used.
- *              "array" is an experimental option that uses PHP files that
- *              store static arrays.
+ * Used by Language::getLocalisationCache() to decide how to construct the
+ * LocalisationCache instance. Associative array with keys:
  *
- * storeClass:  The class name for the underlying storage. If set to a class
- *              name, it overrides the "store" setting.
+ * class:       The class to use for constructing the LocalisationCache object.
+ *              This may be overridden by extensions to a subclass of LocalisationCache.
+ *              Sub classes are expected to still honor the 'storeClass', 'storeDirectory'
+ *              and 'manualRecache' options where applicable.
  *
- * storeDirectory:  If the store class puts its data in files, this is the
- *                  directory it will use. If this is false, $wgCacheDirectory
- *                  will be used.
+ * storeClass:  Which LCStore class implementation to use. This is optional.
+ *              The default LocalisationCache class offers the 'store' option
+ *              as abstraction for this.
  *
- * manualRecache:   Set this to true to disable cache updates on web requests.
- *                  Use maintenance/rebuildLocalisationCache.php instead.
+ * store:       How and where to store localisation cache data.
+ *              This option is ignored if 'storeClass' is explicitly set to a class name.
+ *              Must be one of:
+ *              - 'detect' (default): Automatically select 'files' if 'storeDirectory'
+ *                 or $wgCacheDirectory is set, and fall back to 'db' otherwise.
+ *              - 'files': Store in $wgCacheDirectory as CDB files.
+ *              - 'array': Store in $wgCacheDirectory as PHP static array files.
+ *              - 'db': Store in the l10n_cache database table.
+ *
+ * storeDirectory: If the selected LCStore class puts its data in files, then it
+ *                 will use this directory. If set to false (default), then
+ *                 $wgCacheDirectory is used instead.
+ *
+ * manualRecache: Set this to true to disable cache updates on web requests.
+ *                Use maintenance/rebuildLocalisationCache.php instead.
  */
 $wgLocalisationCacheConf = [
        'class' => LocalisationCache::class,
@@ -6852,7 +6861,7 @@ $wgRCLinkDays = [ 1, 3, 7, 14, 30 ];
  * FormattedRCFeed-specific options:
  * - 'uri' -- [required] The address to which the messages are sent.
  *   The uri scheme of this string will be looked up in $wgRCEngines
- *   to determine which RCFeedEngine class to use.
+ *   to determine which FormattedRCFeed class to use.
  * - 'formatter' -- [required] The class (implementing RCFeedFormatter) which will
  *   produce the text to send. This can also be an object of the class.
  *   Formatters available by default: JSONRCFeedFormatter, XMLRCFeedFormatter,
@@ -7506,6 +7515,7 @@ $wgServiceWiringFiles = [
  * can add to this to provide custom jobs.
  * A job handler should either be a class name to be instantiated,
  * or (since 1.30) a callback to use for creating the job object.
+ * The callback takes (Title, array map of parameters) as arguments.
  */
 $wgJobClasses = [
        'deletePage' => DeletePageJob::class,
@@ -7530,6 +7540,7 @@ $wgJobClasses = [
        'cdnPurge' => CdnPurgeJob::class,
        'userGroupExpiry' => UserGroupExpiryJob::class,
        'clearWatchlistNotifications' => ClearWatchlistNotificationsJob::class,
+       'userOptionsUpdate' => UserOptionsUpdateJob::class,
        'enqueue' => EnqueueJob::class, // local queue for multi-DC setups
        'null' => NullJob::class,
 ];
@@ -8397,7 +8408,7 @@ $wgAsyncHTTPTimeout = 25;
 /**
  * Proxy to use for CURL requests.
  */
-$wgHTTPProxy = false;
+$wgHTTPProxy = '';
 
 /**
  * Local virtual hosts.
index 1d9ff05..2d5b9e2 100644 (file)
@@ -2609,7 +2609,8 @@ ERROR;
                                LogEventsList::showLogExtract(
                                        $out,
                                        'block',
-                                       MWNamespace::getCanonicalName( NS_USER ) . ':' . $block->getTarget(),
+                                       MediaWikiServices::getInstance()->getNamespaceInfo()->
+                                               getCanonicalName( NS_USER ) . ':' . $block->getTarget(),
                                        '',
                                        [
                                                'lim' => 1,
@@ -4451,7 +4452,9 @@ ERROR;
        protected function addPageProtectionWarningHeaders() {
                $out = $this->context->getOutput();
                if ( $this->mTitle->isProtected( 'edit' ) &&
-                       MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace() ) !== [ '' ]
+                       MediaWikiServices::getInstance()->getNamespaceInfo()->getRestrictionLevels(
+                               $this->mTitle->getNamespace()
+                       ) !== [ '' ]
                ) {
                        # Is the title semi-protected?
                        if ( $this->mTitle->isSemiProtected() ) {
index c7a45c7..66a4d9a 100644 (file)
@@ -2633,25 +2633,25 @@ function wfGetLBFactory() {
 
 /**
  * Find a file.
- * Shortcut for RepoGroup::singleton()->findFile()
- *
+ * @deprecated since 1.34, use MediaWikiServices
  * @param string|LinkTarget $title String or LinkTarget object
  * @param array $options Associative array of options (see RepoGroup::findFile)
  * @return File|bool File, or false if the file does not exist
  */
 function wfFindFile( $title, $options = [] ) {
-       return RepoGroup::singleton()->findFile( $title, $options );
+       return MediaWikiServices::getInstance()->getRepoGroup()->findFile( $title, $options );
 }
 
 /**
  * Get an object referring to a locally registered file.
  * Returns a valid placeholder object if the file does not exist.
  *
+ * @deprecated since 1.34, use MediaWikiServices
  * @param Title|string $title
  * @return LocalFile|null A File, or null if passed an invalid Title
  */
 function wfLocalFile( $title ) {
-       return RepoGroup::singleton()->getLocalRepo()->newFile( $title );
+       return MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()->newFile( $title );
 }
 
 /**
index 9cca0be..ff4c786 100644 (file)
@@ -191,7 +191,7 @@ class Linker {
         */
        public static function getInvalidTitleDescription( IContextSource $context, $namespace, $title ) {
                // First we check whether the namespace exists or not.
-               if ( MWNamespace::exists( $namespace ) ) {
+               if ( MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $namespace ) ) {
                        if ( $namespace == NS_MAIN ) {
                                $name = $context->msg( 'blanknamespace' )->text();
                        } else {
@@ -894,6 +894,12 @@ class Linker {
         * @since 1.16.3. $altUserName was added in 1.19.
         */
        public static function userLink( $userId, $userName, $altUserName = false ) {
+               if ( $userName === '' ) {
+                       wfLogWarning( __METHOD__ . ' received an empty username. Are there database errors ' .
+                               'that need to be fixed?' );
+                       return wfMessage( 'empty-username' )->parse();
+               }
+
                $classes = 'mw-userlink';
                $page = null;
                if ( $userId == 0 ) {
@@ -936,6 +942,12 @@ class Linker {
                $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits = null,
                $useParentheses = true
        ) {
+               if ( $userText === '' ) {
+                       wfLogWarning( __METHOD__ . ' received an empty username. Are there database errors ' .
+                               'that need to be fixed?' );
+                       return ' ' . wfMessage( 'empty-username' )->parse();
+               }
+
                global $wgUser, $wgDisableAnonTalk, $wgLang;
                $talkable = !( $wgDisableAnonTalk && $userId == 0 );
                $blockable = !( $flags & self::TOOL_LINKS_NOBLOCK );
@@ -1018,6 +1030,12 @@ class Linker {
         * @return string HTML fragment with user talk link
         */
        public static function userTalkLink( $userId, $userText ) {
+               if ( $userText === '' ) {
+                       wfLogWarning( __METHOD__ . ' received an empty username. Are there database errors ' .
+                               'that need to be fixed?' );
+                       return wfMessage( 'empty-username' )->parse();
+               }
+
                $userTalkPage = new TitleValue( NS_USER_TALK, strtr( $userText, ' ', '_' ) );
                $moreLinkAttribs['class'] = 'mw-usertoollinks-talk';
 
@@ -1034,6 +1052,12 @@ class Linker {
         * @return string HTML fragment with block link
         */
        public static function blockLink( $userId, $userText ) {
+               if ( $userText === '' ) {
+                       wfLogWarning( __METHOD__ . ' received an empty username. Are there database errors ' .
+                               'that need to be fixed?' );
+                       return wfMessage( 'empty-username' )->parse();
+               }
+
                $blockPage = SpecialPage::getTitleFor( 'Block', $userText );
                $moreLinkAttribs['class'] = 'mw-usertoollinks-block';
 
@@ -1049,6 +1073,12 @@ class Linker {
         * @return string HTML fragment with e-mail user link
         */
        public static function emailLink( $userId, $userText ) {
+               if ( $userText === '' ) {
+                       wfLogWarning( __METHOD__ . ' received an empty username. Are there database errors ' .
+                               'that need to be fixed?' );
+                       return wfMessage( 'empty-username' )->parse();
+               }
+
                $emailPage = SpecialPage::getTitleFor( 'Emailuser', $userText );
                $moreLinkAttribs['class'] = 'mw-usertoollinks-mail';
                return self::link( $emailPage,
@@ -1272,7 +1302,12 @@ class Linker {
                                ([^[]*) # 3. link trail (the text up until the next link)
                        /x',
                        function ( $match ) use ( $title, $local, $wikiId ) {
-                               $medians = '(?:' . preg_quote( MWNamespace::getCanonicalName( NS_MEDIA ), '/' ) . '|';
+                               $services = MediaWikiServices::getInstance();
+
+                               $medians = '(?:';
+                               $medians .= preg_quote(
+                                       $services->getNamespaceInfo()->getCanonicalName( NS_MEDIA ), '/' );
+                               $medians .= '|';
                                $medians .= preg_quote(
                                        MediaWikiServices::getInstance()->getContentLanguage()->getNsText( NS_MEDIA ),
                                        '/'
@@ -1380,8 +1415,9 @@ class Linker {
                                        $wikiId,
                                        $linkTarget->getNamespace() === 0
                                                ? $linkTarget->getDBkey()
-                                               : MWNamespace::getCanonicalName( $linkTarget->getNamespace() ) . ':'
-                                                       . $linkTarget->getDBkey(),
+                                               : MediaWikiServices::getInstance()->getNamespaceInfo()->
+                                                       getCanonicalName( $linkTarget->getNamespace() ) .
+                                                       ':' . $linkTarget->getDBkey(),
                                        $linkTarget->getFragment()
                                ),
                                $text,
@@ -1416,7 +1452,10 @@ class Linker {
 
                # Some namespaces don't allow subpages,
                # so only perform processing if subpages are allowed
-               if ( $contextTitle && MWNamespace::hasSubpages( $contextTitle->getNamespace() ) ) {
+               if (
+                       $contextTitle && MediaWikiServices::getInstance()->getNamespaceInfo()->
+                       hasSubpages( $contextTitle->getNamespace() )
+               ) {
                        $hash = strpos( $target, '#' );
                        if ( $hash !== false ) {
                                $suffix = substr( $target, $hash );
index c374a62..d6f50bf 100644 (file)
@@ -48,6 +48,7 @@ use ParserCache;
 use ParserFactory;
 use PasswordFactory;
 use ProxyLookup;
+use RepoGroup;
 use ResourceLoader;
 use SearchEngine;
 use SearchEngineConfig;
@@ -789,6 +790,14 @@ class MediaWikiServices extends ServiceContainer {
                return $this->getService( 'ReadOnlyMode' );
        }
 
+       /**
+        * @since 1.34
+        * @return RepoGroup
+        */
+       public function getRepoGroup() : RepoGroup {
+               return $this->getService( 'RepoGroup' );
+       }
+
        /**
         * @since 1.33
         * @return ResourceLoader
index 24178ac..004ca07 100644 (file)
@@ -233,14 +233,69 @@ class MovePage {
        }
 
        /**
+        * Move a page without taking user permissions into account. Only checks if the move is itself
+        * invalid, e.g., trying to move a special page or trying to move a page onto one that already
+        * exists.
+        *
+        * @param User $user
+        * @param string|null $reason
+        * @param bool|null $createRedirect
+        * @param string[] $changeTags Change tags to apply to the entry in the move log
+        * @return Status
+        */
+       public function move(
+               User $user, $reason = null, $createRedirect = true, array $changeTags = []
+       ) {
+               $status = $this->isValidMove();
+               if ( !$status->isOK() ) {
+                       return $status;
+               }
+
+               return $this->moveUnsafe( $user, $reason, $createRedirect, $changeTags );
+       }
+
+       /**
+        * Same as move(), but with permissions checks.
+        *
+        * @param User $user
+        * @param string|null $reason
+        * @param bool|null $createRedirect Ignored if user doesn't have suppressredirect permission
+        * @param string[] $changeTags Change tags to apply to the entry in the move log
+        * @return Status
+        */
+       public function moveIfAllowed(
+               User $user, $reason = null, $createRedirect = true, array $changeTags = []
+       ) {
+               $status = $this->isValidMove();
+               $status->merge( $this->checkPermissions( $user, $reason ) );
+               if ( $changeTags ) {
+                       $status->merge( ChangeTags::canAddTagsAccompanyingChange( $changeTags, $user ) );
+               }
+
+               if ( !$status->isOK() ) {
+                       // Auto-block user's IP if the account was "hard" blocked
+                       $user->spreadAnyEditBlock();
+                       return $status;
+               }
+
+               // Check suppressredirect permission
+               if ( !$user->isAllowed( 'suppressredirect' ) ) {
+                       $createRedirect = true;
+               }
+
+               return $this->moveUnsafe( $user, $reason, $createRedirect, $changeTags );
+       }
+
+       /**
+        * Moves *without* any sort of safety or sanity checks. Hooks can still fail the move, however.
+        *
         * @param User $user
         * @param string $reason
         * @param bool $createRedirect
-        * @param string[] $changeTags Change tags to apply to the entry in the move log. Caller
-        *  should perform permission checks with ChangeTags::canAddTagsAccompanyingChange
+        * @param string[] $changeTags Change tags to apply to the entry in the move log
         * @return Status
         */
-       public function move( User $user, $reason, $createRedirect, array $changeTags = [] ) {
+       private function moveUnsafe( User $user, $reason, $createRedirect, array $changeTags ) {
                global $wgCategoryCollation;
 
                $status = Status::newGood();
@@ -272,7 +327,8 @@ class MovePage {
                        [ 'cl_from' => $pageid ],
                        __METHOD__
                );
-               $type = MediaWikiServices::getInstance()->getNamespaceInfo()->
+               $services = MediaWikiServices::getInstance();
+               $type = $services->getNamespaceInfo()->
                        getCategoryLinkType( $this->newTitle->getNamespace() );
                foreach ( $prefixes as $prefixRow ) {
                        $prefix = $prefixRow->cl_sortkey_prefix;
@@ -373,11 +429,13 @@ class MovePage {
                # Update watchlists
                $oldtitle = $this->oldTitle->getDBkey();
                $newtitle = $this->newTitle->getDBkey();
-               $oldsnamespace = MWNamespace::getSubject( $this->oldTitle->getNamespace() );
-               $newsnamespace = MWNamespace::getSubject( $this->newTitle->getNamespace() );
+               $oldsnamespace = $services->getNamespaceInfo()->
+                       getSubject( $this->oldTitle->getNamespace() );
+               $newsnamespace = $services->getNamespaceInfo()->
+                       getSubject( $this->newTitle->getNamespace() );
                if ( $oldsnamespace != $newsnamespace || $oldtitle != $newtitle ) {
-                       $store = MediaWikiServices::getInstance()->getWatchedItemStore();
-                       $store->duplicateAllAssociatedEntries( $this->oldTitle, $this->newTitle );
+                       $services->getWatchedItemStore()->duplicateAllAssociatedEntries(
+                               $this->oldTitle, $this->newTitle );
                }
 
                // If it is a file then move it last.
index 3e91fb3..56e2370 100644 (file)
@@ -3430,8 +3430,9 @@ class OutputPage extends ContextSource {
 
                $title = $this->getTitle();
                $ns = $title->getNamespace();
-               $canonicalNamespace = MWNamespace::exists( $ns )
-                       ? MWNamespace::getCanonicalName( $ns )
+               $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
+               $canonicalNamespace = $nsInfo->exists( $ns )
+                       ? $nsInfo->getCanonicalName( $ns )
                        : $title->getNsText();
 
                $sk = $this->getSkin();
index 549b7ba..e443803 100644 (file)
@@ -66,12 +66,16 @@ class PermissionManager {
        /** @var bool If set to true, blocked users will no longer be allowed to log in */
        private $blockDisablesLogin;
 
+       /** @var NamespaceInfo */
+       private $nsInfo;
+
        /**
         * @param SpecialPageFactory $specialPageFactory
         * @param string[] $whitelistRead
         * @param string[] $whitelistReadRegexp
         * @param bool $emailConfirmToEdit
         * @param bool $blockDisablesLogin
+        * @param NamespaceInfo $nsInfo
         */
        public function __construct(
                SpecialPageFactory $specialPageFactory,
index 8d7c3b6..f4e85ad 100644 (file)
@@ -22,6 +22,7 @@
 
 use Psr\Log\LoggerInterface;
 use MediaWiki\Logger\LoggerFactory;
+use MediaWiki\MediaWikiServices;
 
 /**
  * Send information about this MediaWiki instance to MediaWiki.org.
@@ -229,7 +230,7 @@ class Pingback {
                $json = FormatJson::encode( $data );
                $queryString = rawurlencode( str_replace( ' ', '\u0020', $json ) ) . ';';
                $url = 'https://www.mediawiki.org/beacon/event?' . $queryString;
-               return Http::post( $url ) !== false;
+               return MediaWikiServices::getInstance()->getHttpRequestFactory()->post( $url ) !== null;
        }
 
        /**
index 7972a1e..2f10598 100644 (file)
@@ -90,7 +90,7 @@ class ProtectionForm {
         * Loads the current state of protection into the object.
         */
        function loadData() {
-               $levels = MWNamespace::getRestrictionLevels(
+               $levels = MediaWikiServices::getInstance()->getNamespaceInfo()->getRestrictionLevels(
                        $this->mTitle->getNamespace(), $this->mContext->getUser()
                );
                $this->mCascade = $this->mTitle->areRestrictionsCascading();
@@ -179,7 +179,11 @@ class ProtectionForm {
         * Main entry point for action=protect and action=unprotect
         */
        function execute() {
-               if ( MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace() ) === [ '' ] ) {
+               if (
+                       MediaWikiServices::getInstance()->getNamespaceInfo()->getRestrictionLevels(
+                               $this->mTitle->getNamespace()
+                       ) === [ '' ]
+               ) {
                        throw new ErrorPageError( 'protect-badnamespace-title', 'protect-badnamespace-text' );
                }
 
@@ -581,7 +585,8 @@ class ProtectionForm {
        function buildSelector( $action, $selected ) {
                // If the form is disabled, display all relevant levels. Otherwise,
                // just show the ones this user can use.
-               $levels = MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace(),
+               $levels = MediaWikiServices::getInstance()->getNamespaceInfo()->getRestrictionLevels(
+                       $this->mTitle->getNamespace(),
                        $this->disabled ? null : $this->mContext->getUser()
                );
 
index cbaff90..de3c299 100644 (file)
@@ -1008,9 +1008,8 @@ class Revision implements IDBAccessObject {
         * @return Revision|null
         */
        public function getPrevious() {
-               $title = $this->getTitle();
-               $rec = self::getRevisionLookup()->getPreviousRevision( $this->mRecord, $title );
-               return $rec ? new Revision( $rec, self::READ_NORMAL, $title ) : null;
+               $rec = self::getRevisionLookup()->getPreviousRevision( $this->mRecord );
+               return $rec ? new Revision( $rec, self::READ_NORMAL, $this->getTitle() ) : null;
        }
 
        /**
@@ -1019,9 +1018,8 @@ class Revision implements IDBAccessObject {
         * @return Revision|null
         */
        public function getNext() {
-               $title = $this->getTitle();
-               $rec = self::getRevisionLookup()->getNextRevision( $this->mRecord, $title );
-               return $rec ? new Revision( $rec, self::READ_NORMAL, $title ) : null;
+               $rec = self::getRevisionLookup()->getNextRevision( $this->mRecord );
+               return $rec ? new Revision( $rec, self::READ_NORMAL, $this->getTitle() ) : null;
        }
 
        /**
@@ -1256,13 +1254,13 @@ class Revision implements IDBAccessObject {
        /**
         * Get rev_timestamp from rev_id, without loading the rest of the row
         *
-        * @param Title $title
+        * @param Title $title (ignored since 1.34)
         * @param int $id
         * @param int $flags
         * @return string|bool False if not found
         */
        static function getTimestampFromId( $title, $id, $flags = 0 ) {
-               return self::getRevisionStore()->getTimestampFromId( $title, $id, $flags );
+               return self::getRevisionStore()->getTimestampFromId( $id, $flags );
        }
 
        /**
index db6c7c3..17cafc6 100644 (file)
@@ -85,11 +85,12 @@ interface RevisionLookup extends IDBAccessObject {
         * MCR migration note: this replaces Revision::getPrevious
         *
         * @param RevisionRecord $rev
-        * @param Title|null $title if known (optional)
+        * @param int $flags (optional) $flags include:
+        *      IDBAccessObject::READ_LATEST: Select the data from the master
         *
         * @return RevisionRecord|null
         */
-       public function getPreviousRevision( RevisionRecord $rev, Title $title = null );
+       public function getPreviousRevision( RevisionRecord $rev, $flags = 0 );
 
        /**
         * Get next revision for this title
@@ -97,11 +98,24 @@ interface RevisionLookup extends IDBAccessObject {
         * MCR migration note: this replaces Revision::getNext
         *
         * @param RevisionRecord $rev
-        * @param Title|null $title if known (optional)
+        * @param int $flags (optional) $flags include:
+        *      IDBAccessObject::READ_LATEST: Select the data from the master
         *
         * @return RevisionRecord|null
         */
-       public function getNextRevision( RevisionRecord $rev, Title $title = null );
+       public function getNextRevision( RevisionRecord $rev, $flags = 0 );
+
+       /**
+        * Get rev_timestamp from rev_id, without loading the rest of the row.
+        *
+        * MCR migration note: this replaces Revision::getTimestampFromId
+        *
+        * @param int $id
+        * @param int $flags
+        * @return string|bool False if not found
+        * @since 1.34 (present earlier in RevisionStore)
+        */
+       public function getTimestampFromId( $id, $flags = 0 );
 
        /**
         * Load a revision based on a known page ID and current revision ID from the DB
index 0329bd1..ea4cf88 100644 (file)
@@ -278,12 +278,13 @@ class RevisionStore
 
        /**
         * @param int $mode DB_MASTER or DB_REPLICA
+        * @param array $groups
         *
         * @return IDatabase
         */
-       private function getDBConnection( $mode ) {
+       private function getDBConnection( $mode, $groups = [] ) {
                $lb = $this->getDBLoadBalancer();
-               return $lb->getConnection( $mode, [], $this->wikiId );
+               return $lb->getConnection( $mode, $groups, $this->wikiId );
        }
 
        /**
@@ -1739,7 +1740,8 @@ class RevisionStore
                        $user = User::newFromAnyId(
                                $row->ar_user ?? null,
                                $row->ar_user_text ?? null,
-                               $row->ar_actor ?? null
+                               $row->ar_actor ?? null,
+                               $this->wikiId
                        );
                } catch ( InvalidArgumentException $ex ) {
                        wfWarn( __METHOD__ . ': ' . $title->getPrefixedDBkey() . ': ' . $ex->getMessage() );
@@ -1793,7 +1795,8 @@ class RevisionStore
                        $user = User::newFromAnyId(
                                $row->rev_user ?? null,
                                $row->rev_user_text ?? null,
-                               $row->rev_actor ?? null
+                               $row->rev_actor ?? null,
+                               $this->wikiId
                        );
                } catch ( InvalidArgumentException $ex ) {
                        wfWarn( __METHOD__ . ': ' . $title->getPrefixedDBkey() . ': ' . $ex->getMessage() );
@@ -1931,14 +1934,21 @@ class RevisionStore
                /** @var UserIdentity $user */
                $user = null;
 
-               if ( isset( $fields['user'] ) && ( $fields['user'] instanceof UserIdentity ) ) {
+               // If a user is passed in, use it if possible. We cannot use a user from a
+               // remote wiki with unsuppressed ids, due to issues described in T222212.
+               if ( isset( $fields['user'] ) &&
+                       ( $fields['user'] instanceof UserIdentity ) &&
+                       ( $this->wikiId === false ||
+                               ( !$fields['user']->getId() && !$fields['user']->getActorId() ) )
+               ) {
                        $user = $fields['user'];
                } else {
                        try {
                                $user = User::newFromAnyId(
                                        $fields['user'] ?? null,
                                        $fields['user_text'] ?? null,
-                                       $fields['actor'] ?? null
+                                       $fields['actor'] ?? null,
+                                       $this->wikiId
                                );
                        } catch ( InvalidArgumentException $ex ) {
                                $user = null;
@@ -2548,20 +2558,17 @@ class RevisionStore
        }
 
        /**
-        * Get the revision before $rev in the page's history, if any.
-        * Will return null for the first revision but also for deleted or unsaved revisions.
-        *
-        * MCR migration note: this replaces Revision::getPrevious
-        *
-        * @see Title::getPreviousRevisionID
-        * @see PageArchive::getPreviousRevision
+        * Implementation of getPreviousRevision and getNextRevision.
         *
         * @param RevisionRecord $rev
-        * @param Title|null $title if known (optional)
-        *
+        * @param int $flags
+        * @param string $dir 'next' or 'prev'
         * @return RevisionRecord|null
         */
-       public function getPreviousRevision( RevisionRecord $rev, Title $title = null ) {
+       private function getRelativeRevision( RevisionRecord $rev, $flags, $dir ) {
+               $op = $dir === 'next' ? '>' : '<';
+               $sort = $dir === 'next' ? 'ASC' : 'DESC';
+
                if ( !$rev->getId() || !$rev->getPageId() ) {
                        // revision is unsaved or otherwise incomplete
                        return null;
@@ -2572,54 +2579,86 @@ class RevisionStore
                        return null;
                }
 
-               if ( $title === null ) {
-                       // this would fail for deleted revisions
-                       $title = $this->getTitle( $rev->getPageId(), $rev->getId() );
+               list( $dbType, ) = DBAccessObjectUtils::getDBOptions( $flags );
+               $db = $this->getDBConnection( $dbType, [ 'contributions' ] );
+
+               $ts = $this->getTimestampFromId( $rev->getId(), $flags );
+               if ( $ts === false ) {
+                       // XXX Should this be moved into getTimestampFromId?
+                       $ts = $db->selectField( 'archive', 'ar_timestamp',
+                               [ 'ar_rev_id' => $rev->getId() ], __METHOD__ );
+                       if ( $ts === false ) {
+                               // XXX Is this reachable? How can we have a page id but no timestamp?
+                               return null;
+                       }
                }
+               $ts = $db->addQuotes( $db->timestamp( $ts ) );
 
-               $prev = $title->getPreviousRevisionID( $rev->getId() );
-               if ( !$prev ) {
+               $revId = $db->selectField( 'revision', 'rev_id',
+                       [
+                               'rev_page' => $rev->getPageId(),
+                               "rev_timestamp $op $ts OR (rev_timestamp = $ts AND rev_id $op {$rev->getId()})"
+                       ],
+                       __METHOD__,
+                       [
+                               'ORDER BY' => "rev_timestamp $sort, rev_id $sort",
+                               'IGNORE INDEX' => 'rev_timestamp', // Probably needed for T159319
+                       ]
+               );
+
+               if ( $revId === false ) {
                        return null;
                }
 
-               return $this->getRevisionByTitle( $title, $prev );
+               return $this->getRevisionById( intval( $revId ) );
        }
 
        /**
-        * Get the revision after $rev in the page's history, if any.
-        * Will return null for the latest revision but also for deleted or unsaved revisions.
+        * Get the revision before $rev in the page's history, if any.
+        * Will return null for the first revision but also for deleted or unsaved revisions.
         *
-        * MCR migration note: this replaces Revision::getNext
+        * MCR migration note: this replaces Revision::getPrevious
         *
-        * @see Title::getNextRevisionID
+        * @see Title::getPreviousRevisionID
+        * @see PageArchive::getPreviousRevision
         *
         * @param RevisionRecord $rev
-        * @param Title|null $title if known (optional)
+        * @param int $flags (optional) $flags include:
+        *      IDBAccessObject::READ_LATEST: Select the data from the master
         *
         * @return RevisionRecord|null
         */
-       public function getNextRevision( RevisionRecord $rev, Title $title = null ) {
-               if ( !$rev->getId() || !$rev->getPageId() ) {
-                       // revision is unsaved or otherwise incomplete
-                       return null;
-               }
-
-               if ( $rev instanceof RevisionArchiveRecord ) {
-                       // revision is deleted, so it's not part of the page history
-                       return null;
+       public function getPreviousRevision( RevisionRecord $rev, $flags = 0 ) {
+               if ( $flags instanceof Title ) {
+                       // Old calling convention, we don't use Title here anymore
+                       wfDeprecated( __METHOD__ . ' with Title', '1.34' );
+                       $flags = 0;
                }
 
-               if ( $title === null ) {
-                       // this would fail for deleted revisions
-                       $title = $this->getTitle( $rev->getPageId(), $rev->getId() );
-               }
+               return $this->getRelativeRevision( $rev, $flags, 'prev' );
+       }
 
-               $next = $title->getNextRevisionID( $rev->getId() );
-               if ( !$next ) {
-                       return null;
+       /**
+        * Get the revision after $rev in the page's history, if any.
+        * Will return null for the latest revision but also for deleted or unsaved revisions.
+        *
+        * MCR migration note: this replaces Revision::getNext
+        *
+        * @see Title::getNextRevisionID
+        *
+        * @param RevisionRecord $rev
+        * @param int $flags (optional) $flags include:
+        *      IDBAccessObject::READ_LATEST: Select the data from the master
+        * @return RevisionRecord|null
+        */
+       public function getNextRevision( RevisionRecord $rev, $flags = 0 ) {
+               if ( $flags instanceof Title ) {
+                       // Old calling convention, we don't use Title here anymore
+                       wfDeprecated( __METHOD__ . ' with Title', '1.34' );
+                       $flags = 0;
                }
 
-               return $this->getRevisionByTitle( $title, $next );
+               return $this->getRelativeRevision( $rev, $flags, 'next' );
        }
 
        /**
@@ -2658,21 +2697,27 @@ class RevisionStore
        }
 
        /**
-        * Get rev_timestamp from rev_id, without loading the rest of the row
+        * Get rev_timestamp from rev_id, without loading the rest of the row.
+        *
+        * Historically, there was an extra Title parameter that was passed before $id. This is no
+        * longer needed and is deprecated in 1.34.
         *
         * MCR migration note: this replaces Revision::getTimestampFromId
         *
-        * @param Title $title
         * @param int $id
         * @param int $flags
         * @return string|bool False if not found
         */
-       public function getTimestampFromId( $title, $id, $flags = 0 ) {
+       public function getTimestampFromId( $id, $flags = 0 ) {
+               if ( $id instanceof Title ) {
+                       // Old deprecated calling convention supported for backwards compatibility
+                       $id = $flags;
+                       $flags = func_num_args() > 2 ? func_get_arg( 2 ) : 0;
+               }
                $db = $this->getDBConnectionRefForQueryFlags( $flags );
 
-               $conds = [ 'rev_id' => $id ];
-               $conds['rev_page'] = $title->getArticleID();
-               $timestamp = $db->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__ );
+               $timestamp =
+                       $db->selectField( 'revision', 'rev_timestamp', [ 'rev_id' => $id ], __METHOD__ );
 
                return ( $timestamp !== false ) ? wfTimestamp( TS_MW, $timestamp ) : false;
        }
index bf722c3..a30534e 100644 (file)
@@ -208,7 +208,7 @@ return [
        },
 
        'GenderCache' => function ( MediaWikiServices $services ) : GenderCache {
-               return new GenderCache();
+               return new GenderCache( $services->getNamespaceInfo() );
        },
 
        'HttpRequestFactory' =>
@@ -231,7 +231,8 @@ return [
        'LinkCache' => function ( MediaWikiServices $services ) : LinkCache {
                return new LinkCache(
                        $services->getTitleFormatter(),
-                       $services->getMainWANObjectCache()
+                       $services->getMainWANObjectCache(),
+                       $services->getNamespaceInfo()
                );
        },
 
@@ -248,7 +249,8 @@ return [
        'LinkRendererFactory' => function ( MediaWikiServices $services ) : LinkRendererFactory {
                return new LinkRendererFactory(
                        $services->getTitleFormatter(),
-                       $services->getLinkCache()
+                       $services->getLinkCache(),
+                       $services->getNamespaceInfo()
                );
        },
 
@@ -363,7 +365,8 @@ return [
        },
 
        'NamespaceInfo' => function ( MediaWikiServices $services ) : NamespaceInfo {
-               return new NamespaceInfo( $services->getMainConfig() );
+               return new NamespaceInfo( new ServiceOptions( NamespaceInfo::$constructorOptions,
+                       $services->getMainConfig() ) );
        },
 
        'NameTableStoreFactory' => function ( MediaWikiServices $services ) : NameTableStoreFactory {
@@ -460,7 +463,8 @@ return [
                                DefaultPreferencesFactory::$constructorOptions, $services->getMainConfig() ),
                        $services->getContentLanguage(),
                        AuthManager::singleton(),
-                       $services->getLinkRendererFactory()->create()
+                       $services->getLinkRendererFactory()->create(),
+                       $services->getNamespaceInfo()
                );
                $factory->setLogger( LoggerFactory::getInstance( 'preferences' ) );
 
@@ -482,6 +486,15 @@ return [
                );
        },
 
+       'RepoGroup' => function ( MediaWikiServices $services ) : RepoGroup {
+               $config = $services->getMainConfig();
+               return new RepoGroup(
+                       $config->get( 'LocalFileRepo' ),
+                       $config->get( 'ForeignFileRepos' ),
+                       $services->getMainWANObjectCache()
+               );
+       },
+
        'ResourceLoader' => function ( MediaWikiServices $services ) : ResourceLoader {
                // @todo This should not take a Config object, but it's not so easy to remove because it
                // exposes it in a getter, which is actually used.
@@ -696,7 +709,9 @@ return [
                        $services->getMainObjectStash(),
                        new HashBagOStuff( [ 'maxKeys' => 100 ] ),
                        $services->getReadOnlyMode(),
-                       $services->getMainConfig()->get( 'UpdateRowsPerQuery' )
+                       $services->getMainConfig()->get( 'UpdateRowsPerQuery' ),
+                       $services->getNamespaceInfo(),
+                       $services->getRevisionLookup()
                );
                $store->setStatsdDataFactory( $services->getStatsdDataFactory() );
 
index 8adb218..e97db2d 100644 (file)
@@ -68,15 +68,15 @@ class SiteStatsInit {
         * @return int
         */
        public function articles() {
-               $config = MediaWikiServices::getInstance()->getMainConfig();
+               $services = MediaWikiServices::getInstance();
 
                $tables = [ 'page' ];
                $conds = [
-                       'page_namespace' => MWNamespace::getContentNamespaces(),
+                       'page_namespace' => $services->getNamespaceInfo()->getContentNamespaces(),
                        'page_is_redirect' => 0,
                ];
 
-               if ( $config->get( 'ArticleCountMethod' ) == 'link' ) {
+               if ( $services->getMainConfig()->get( 'ArticleCountMethod' ) == 'link' ) {
                        $tables[] = 'pagelinks';
                        $conds[] = 'pl_from=page_id';
                }
index 27baeb2..866f041 100644 (file)
@@ -618,7 +618,7 @@ class Title implements LinkTarget, IDBAccessObject {
                // NOTE: ideally, this would just call makeTitle() and then isValid(),
                // but presently, that means more overhead on a potential performance hotspot.
 
-               if ( !MWNamespace::exists( $ns ) ) {
+               if ( !MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $ns ) ) {
                        return null;
                }
 
@@ -820,7 +820,8 @@ class Title implements LinkTarget, IDBAccessObject {
                $canonicalNamespace = false
        ) {
                if ( $canonicalNamespace ) {
-                       $namespace = MWNamespace::getCanonicalName( $ns );
+                       $namespace = MediaWikiServices::getInstance()->getNamespaceInfo()->
+                               getCanonicalName( $ns );
                } else {
                        $namespace = MediaWikiServices::getInstance()->getContentLanguage()->getNsText( $ns );
                }
@@ -862,13 +863,13 @@ class Title implements LinkTarget, IDBAccessObject {
         * @return bool
         */
        public function isValid() {
-               if ( !MWNamespace::exists( $this->mNamespace ) ) {
+               $services = MediaWikiServices::getInstance();
+               if ( !$services->getNamespaceInfo()->exists( $this->mNamespace ) ) {
                        return false;
                }
 
                try {
-                       $parser = MediaWikiServices::getInstance()->getTitleParser();
-                       $parser->parseTitle( $this->mDbkeyform, $this->mNamespace );
+                       $services->getTitleParser()->parseTitle( $this->mDbkeyform, $this->mNamespace );
                        return true;
                } catch ( MalformedTitleException $ex ) {
                        return false;
@@ -1086,7 +1087,8 @@ class Title implements LinkTarget, IDBAccessObject {
                if ( $this->isExternal() ) {
                        // This probably shouldn't even happen, except for interwiki transclusion.
                        // If possible, use the canonical name for the foreign namespace.
-                       $nsText = MWNamespace::getCanonicalName( $this->mNamespace );
+                       $nsText = MediaWikiServices::getInstance()->getNamespaceInfo()->
+                               getCanonicalName( $this->mNamespace );
                        if ( $nsText !== false ) {
                                return $nsText;
                        }
@@ -1107,8 +1109,9 @@ class Title implements LinkTarget, IDBAccessObject {
         * @return string Namespace text
         */
        public function getSubjectNsText() {
-               return MediaWikiServices::getInstance()->getContentLanguage()->
-                       getNsText( MWNamespace::getSubject( $this->mNamespace ) );
+               $services = MediaWikiServices::getInstance();
+               return $services->getContentLanguage()->
+                       getNsText( $services->getNamespaceInfo()->getSubject( $this->mNamespace ) );
        }
 
        /**
@@ -1117,20 +1120,22 @@ class Title implements LinkTarget, IDBAccessObject {
         * @return string Namespace text
         */
        public function getTalkNsText() {
-               return MediaWikiServices::getInstance()->getContentLanguage()->
-                       getNsText( MWNamespace::getTalk( $this->mNamespace ) );
+               $services = MediaWikiServices::getInstance();
+               return $services->getContentLanguage()->
+                       getNsText( $services->getNamespaceInfo()->getTalk( $this->mNamespace ) );
        }
 
        /**
         * Can this title have a corresponding talk page?
         *
-        * @see MWNamespace::hasTalkNamespace
+        * @see NamespaceInfo::hasTalkNamespace
         * @since 1.30
         *
         * @return bool True if this title either is a talk page or can have a talk page associated.
         */
        public function canHaveTalkPage() {
-               return MWNamespace::hasTalkNamespace( $this->mNamespace );
+               return MediaWikiServices::getInstance()->getNamespaceInfo()->
+                       hasTalkNamespace( $this->mNamespace );
        }
 
        /**
@@ -1148,7 +1153,8 @@ class Title implements LinkTarget, IDBAccessObject {
         * @return bool
         */
        public function isWatchable() {
-               return !$this->isExternal() && MWNamespace::isWatchable( $this->mNamespace );
+               return !$this->isExternal() && MediaWikiServices::getInstance()->getNamespaceInfo()->
+                       isWatchable( $this->mNamespace );
        }
 
        /**
@@ -1209,7 +1215,8 @@ class Title implements LinkTarget, IDBAccessObject {
         * @since 1.19
         */
        public function inNamespace( $ns ) {
-               return MWNamespace::equals( $this->mNamespace, $ns );
+               return MediaWikiServices::getInstance()->getNamespaceInfo()->
+                       equals( $this->mNamespace, $ns );
        }
 
        /**
@@ -1248,7 +1255,8 @@ class Title implements LinkTarget, IDBAccessObject {
         * @return bool
         */
        public function hasSubjectNamespace( $ns ) {
-               return MWNamespace::subjectEquals( $this->mNamespace, $ns );
+               return MediaWikiServices::getInstance()->getNamespaceInfo()->
+                       subjectEquals( $this->mNamespace, $ns );
        }
 
        /**
@@ -1259,7 +1267,8 @@ class Title implements LinkTarget, IDBAccessObject {
         * @return bool
         */
        public function isContentPage() {
-               return MWNamespace::isContent( $this->mNamespace );
+               return MediaWikiServices::getInstance()->getNamespaceInfo()->
+                       isContent( $this->mNamespace );
        }
 
        /**
@@ -1269,7 +1278,10 @@ class Title implements LinkTarget, IDBAccessObject {
         * @return bool
         */
        public function isMovable() {
-               if ( !MWNamespace::isMovable( $this->mNamespace ) || $this->isExternal() ) {
+               if (
+                       !MediaWikiServices::getInstance()->getNamespaceInfo()->
+                               isMovable( $this->mNamespace ) || $this->isExternal()
+               ) {
                        // Interwiki title or immovable namespace. Hooks don't get to override here
                        return false;
                }
@@ -1299,7 +1311,8 @@ class Title implements LinkTarget, IDBAccessObject {
         * @return bool
         */
        public function isSubpage() {
-               return MWNamespace::hasSubpages( $this->mNamespace )
+               return MediaWikiServices::getInstance()->getNamespaceInfo()->
+                       hasSubpages( $this->mNamespace )
                        ? strpos( $this->getText(), '/' ) !== false
                        : false;
        }
@@ -1495,16 +1508,19 @@ class Title implements LinkTarget, IDBAccessObject {
         * @return bool
         */
        public function isTalkPage() {
-               return MWNamespace::isTalk( $this->mNamespace );
+               return MediaWikiServices::getInstance()->getNamespaceInfo()->
+                       isTalk( $this->mNamespace );
        }
 
        /**
         * Get a Title object associated with the talk page of this article
         *
+        * @deprecated since 1.34, use NamespaceInfo::getTalkPage
         * @return Title The object for the talk page
         */
        public function getTalkPage() {
-               return self::makeTitle( MWNamespace::getTalk( $this->mNamespace ), $this->mDbkeyform );
+               return self::castFromLinkTarget(
+                       MediaWikiServices::getInstance()->getNamespaceInfo()->getTalkPage( $this ) );
        }
 
        /**
@@ -1528,37 +1544,26 @@ class Title implements LinkTarget, IDBAccessObject {
         * Get a title object associated with the subject page of this
         * talk page
         *
+        * @deprecated since 1.34, use NamespaceInfo::getSubjectPage
         * @return Title The object for the subject page
         */
        public function getSubjectPage() {
-               // Is this the same title?
-               $subjectNS = MWNamespace::getSubject( $this->mNamespace );
-               if ( $this->mNamespace == $subjectNS ) {
-                       return $this;
-               }
-               return self::makeTitle( $subjectNS, $this->mDbkeyform );
+               return self::castFromLinkTarget(
+                       MediaWikiServices::getInstance()->getNamespaceInfo()->getSubjectPage( $this ) );
        }
 
        /**
         * Get the other title for this page, if this is a subject page
         * get the talk page, if it is a subject page get the talk page
         *
+        * @deprecated since 1.34, use NamespaceInfo::getAssociatedPage
         * @since 1.25
         * @throws MWException If the page doesn't have an other page
         * @return Title
         */
        public function getOtherPage() {
-               if ( $this->isSpecialPage() ) {
-                       throw new MWException( 'Special pages cannot have other pages' );
-               }
-               if ( $this->isTalkPage() ) {
-                       return $this->getSubjectPage();
-               } else {
-                       if ( !$this->canHaveTalkPage() ) {
-                               throw new MWException( "{$this->getPrefixedText()} does not have an other page" );
-                       }
-                       return $this->getTalkPage();
-               }
+               return self::castFromLinkTarget(
+                       MediaWikiServices::getInstance()->getNamespaceInfo()->getAssociatedPage( $this ) );
        }
 
        /**
@@ -1733,7 +1738,10 @@ class Title implements LinkTarget, IDBAccessObject {
         * @since 1.20
         */
        public function getRootText() {
-               if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
+               if (
+                       !MediaWikiServices::getInstance()->getNamespaceInfo()->
+                               hasSubpages( $this->mNamespace )
+               ) {
                        return $this->getText();
                }
 
@@ -1769,7 +1777,10 @@ class Title implements LinkTarget, IDBAccessObject {
         */
        public function getBaseText() {
                $text = $this->getText();
-               if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
+               if (
+                       !MediaWikiServices::getInstance()->getNamespaceInfo()->
+                               hasSubpages( $this->mNamespace )
+               ) {
                        return $text;
                }
 
@@ -1810,7 +1821,10 @@ class Title implements LinkTarget, IDBAccessObject {
         * @return string Subpage name
         */
        public function getSubpageText() {
-               if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
+               if (
+                       !MediaWikiServices::getInstance()->getNamespaceInfo()->
+                               hasSubpages( $this->mNamespace )
+               ) {
                        return $this->mTextform;
                }
                $parts = explode( '/', $this->mTextform );
@@ -2877,7 +2891,10 @@ class Title implements LinkTarget, IDBAccessObject {
         * @return bool
         */
        public function hasSubpages() {
-               if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
+               if (
+                       !MediaWikiServices::getInstance()->getNamespaceInfo()->
+                               hasSubpages( $this->mNamespace )
+               ) {
                        # Duh
                        return false;
                }
@@ -2905,7 +2922,10 @@ class Title implements LinkTarget, IDBAccessObject {
         *  doesn't allow subpages
         */
        public function getSubpages( $limit = -1 ) {
-               if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
+               if (
+                       !MediaWikiServices::getInstance()->getNamespaceInfo()->
+                               hasSubpages( $this->mNamespace )
+               ) {
                        return [];
                }
 
@@ -3139,7 +3159,8 @@ class Title implements LinkTarget, IDBAccessObject {
         * @return string Containing capitalized title
         */
        public static function capitalize( $text, $ns = NS_MAIN ) {
-               if ( MWNamespace::isCapitalized( $ns ) ) {
+               $services = MediaWikiServices::getInstance();
+               if ( $services->getNamespaceInfo()->isCapitalized( $ns ) ) {
                        return MediaWikiServices::getInstance()->getContentLanguage()->ucfirst( $text );
                } else {
                        return $text;
@@ -3445,19 +3466,10 @@ class Title implements LinkTarget, IDBAccessObject {
                array $changeTags = []
        ) {
                global $wgUser;
-               $err = $this->isValidMoveOperation( $nt, $auth, $reason );
-               if ( is_array( $err ) ) {
-                       // Auto-block user's IP if the account was "hard" blocked
-                       $wgUser->spreadAnyEditBlock();
-                       return $err;
-               }
-               // Check suppressredirect permission
-               if ( $auth && !$wgUser->isAllowed( 'suppressredirect' ) ) {
-                       $createRedirect = true;
-               }
 
                $mp = new MovePage( $this, $nt );
-               $status = $mp->move( $wgUser, $reason, $createRedirect, $changeTags );
+               $method = $auth ? 'moveIfAllowed' : 'move';
+               $status = $mp->$method( $wgUser, $reason, $createRedirect, $changeTags );
                if ( $status->isOK() ) {
                        return true;
                } else {
@@ -3490,14 +3502,15 @@ class Title implements LinkTarget, IDBAccessObject {
                        ];
                }
                // Do the source and target namespaces support subpages?
-               if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
+               $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
+               if ( !$nsInfo->hasSubpages( $this->mNamespace ) ) {
                        return [
-                               [ 'namespace-nosubpages', MWNamespace::getCanonicalName( $this->mNamespace ) ],
+                               [ 'namespace-nosubpages', $nsInfo->getCanonicalName( $this->mNamespace ) ],
                        ];
                }
-               if ( !MWNamespace::hasSubpages( $nt->getNamespace() ) ) {
+               if ( !$nsInfo->hasSubpages( $nt->getNamespace() ) ) {
                        return [
-                               [ 'namespace-nosubpages', MWNamespace::getCanonicalName( $nt->getNamespace() ) ],
+                               [ 'namespace-nosubpages', $nsInfo->getCanonicalName( $nt->getNamespace() ) ],
                        ];
                }
 
@@ -3730,57 +3743,25 @@ class Title implements LinkTarget, IDBAccessObject {
         * @return int|bool New revision ID, or false if none exists
         */
        private function getRelativeRevisionID( $revId, $flags, $dir ) {
-               $revId = (int)$revId;
-               if ( $dir === 'next' ) {
-                       $op = '>';
-                       $sort = 'ASC';
-               } elseif ( $dir === 'prev' ) {
-                       $op = '<';
-                       $sort = 'DESC';
-               } else {
-                       throw new InvalidArgumentException( '$dir must be "next" or "prev"' );
-               }
-
-               if ( $flags & self::GAID_FOR_UPDATE ) {
-                       $db = wfGetDB( DB_MASTER );
-               } else {
-                       $db = wfGetDB( DB_REPLICA, 'contributions' );
-               }
-
-               // Intentionally not caring if the specified revision belongs to this
-               // page. We only care about the timestamp.
-               $ts = $db->selectField( 'revision', 'rev_timestamp', [ 'rev_id' => $revId ], __METHOD__ );
-               if ( $ts === false ) {
-                       $ts = $db->selectField( 'archive', 'ar_timestamp', [ 'ar_rev_id' => $revId ], __METHOD__ );
-                       if ( $ts === false ) {
-                               // Or should this throw an InvalidArgumentException or something?
-                               return false;
-                       }
+               $rl = MediaWikiServices::getInstance()->getRevisionLookup();
+               $rlFlags = $flags === self::GAID_FOR_UPDATE ? IDBAccessObject::READ_LATEST : 0;
+               $rev = $rl->getRevisionById( $revId, $rlFlags );
+               if ( !$rev ) {
+                       return false;
                }
-               $ts = $db->addQuotes( $ts );
-
-               $revId = $db->selectField( 'revision', 'rev_id',
-                       [
-                               'rev_page' => $this->getArticleID( $flags ),
-                               "rev_timestamp $op $ts OR (rev_timestamp = $ts AND rev_id $op $revId)"
-                       ],
-                       __METHOD__,
-                       [
-                               'ORDER BY' => "rev_timestamp $sort, rev_id $sort",
-                               'IGNORE INDEX' => 'rev_timestamp', // Probably needed for T159319
-                       ]
-               );
-
-               if ( $revId === false ) {
+               $oldRev = $dir === 'next'
+                       ? $rl->getNextRevision( $rev, $rlFlags )
+                       : $rl->getPreviousRevision( $rev, $rlFlags );
+               if ( !$oldRev ) {
                        return false;
-               } else {
-                       return intval( $revId );
                }
+               return $oldRev->getId();
        }
 
        /**
         * Get the revision ID of the previous revision
         *
+        * @deprecated since 1.34, use RevisionLookup::getPreviousRevision
         * @param int $revId Revision ID. Get the revision that was before this one.
         * @param int $flags Title::GAID_FOR_UPDATE
         * @return int|bool Old revision ID, or false if none exists
@@ -3792,6 +3773,7 @@ class Title implements LinkTarget, IDBAccessObject {
        /**
         * Get the revision ID of the next revision
         *
+        * @deprecated since 1.34, use RevisionLookup::getNextRevision
         * @param int $revId Revision ID. Get the revision that was after this one.
         * @param int $flags Title::GAID_FOR_UPDATE
         * @return int|bool Next revision ID, or false if none exists
@@ -4031,14 +4013,14 @@ class Title implements LinkTarget, IDBAccessObject {
        /**
         * Compare with another title.
         *
-        * @param Title $title
+        * @param LinkTarget $title
         * @return bool
         */
-       public function equals( Title $title ) {
+       public function equals( LinkTarget $title ) {
                // Note: === is necessary for proper matching of number-like titles.
-               return $this->mInterwiki === $title->mInterwiki
-                       && $this->mNamespace == $title->mNamespace
-                       && $this->mDbkeyform === $title->mDbkeyform;
+               return $this->mInterwiki === $title->getInterwiki()
+                       && $this->mNamespace == $title->getNamespace()
+                       && $this->mDbkeyform === $title->getDBkey();
        }
 
        /**
@@ -4342,9 +4324,10 @@ class Title implements LinkTarget, IDBAccessObject {
         */
        public function getNamespaceKey( $prepend = 'nstab-' ) {
                // Gets the subject namespace of this title
-               $subjectNS = MWNamespace::getSubject( $this->mNamespace );
+               $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
+               $subjectNS = $nsInfo->getSubject( $this->mNamespace );
                // Prefer canonical namespace name for HTML IDs
-               $namespaceKey = MWNamespace::getCanonicalName( $subjectNS );
+               $namespaceKey = $nsInfo->getCanonicalName( $subjectNS );
                if ( $namespaceKey === false ) {
                        // Fallback to localised text
                        $namespaceKey = $this->getSubjectNsText();
@@ -4440,7 +4423,8 @@ class Title implements LinkTarget, IDBAccessObject {
        public function canUseNoindex() {
                global $wgExemptFromUserRobotsControl;
 
-               $bannedNamespaces = $wgExemptFromUserRobotsControl ?? MWNamespace::getContentNamespaces();
+               $bannedNamespaces = $wgExemptFromUserRobotsControl ??
+                       MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces();
 
                return !in_array( $this->mNamespace, $bannedNamespaces );
        }
@@ -4607,7 +4591,10 @@ class Title implements LinkTarget, IDBAccessObject {
                        }
                }
 
-               if ( MWNamespace::hasSubpages( $this->mNamespace ) ) {
+               if (
+                       MediaWikiServices::getInstance()->getNamespaceInfo()->
+                               hasSubpages( $this->mNamespace )
+               ) {
                        // Optional notice for page itself and any parent page
                        $editnotice_base = $editnotice_ns;
                        foreach ( explode( '/', $this->mDbkeyform ) as $part ) {
index b3a49c7..ebdbc42 100644 (file)
@@ -19,6 +19,8 @@
  * @ingroup Categories
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * This class performs some operations related to tracking categories, such as creating
  * a list of all such categories.
@@ -80,6 +82,7 @@ class TrackingCategories {
                }
 
                $trackingCategories = [];
+               $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
                foreach ( $categories as $catMsg ) {
                        /*
                         * Check if the tracking category varies by namespace
@@ -96,7 +99,7 @@ class TrackingCategories {
                        // Match things like {{NAMESPACE}} and {{NAMESPACENUMBER}}.
                        // False positives are ok, this is just an efficiency shortcut
                        if ( strpos( $msgObj->plain(), '{{' ) !== false ) {
-                               $ns = MWNamespace::getValidNamespaces();
+                               $ns = $nsInfo->getValidNamespaces();
                                foreach ( $ns as $namesp ) {
                                        $tempTitle = Title::makeTitleSafe( $namesp, $catMsg );
                                        if ( !$tempTitle ) {
index 8b000f2..23b0e3e 100644 (file)
@@ -221,19 +221,29 @@ class WikiMap {
         * @since 1.30
         */
        public static function getWikiFromUrl( $url ) {
+               global $wgCanonicalServer;
+
+               if ( strpos( $url, "$wgCanonicalServer/" ) === 0 ) {
+                       // Optimisation: Handle the the common case.
+                       // (Duplicates self::getCanonicalServerInfoForAllWikis)
+                       return self::getWikiIdFromDbDomain( self::getCurrentWikiDbDomain() );
+               }
+
                $urlPartsCheck = wfParseUrl( $url );
                if ( $urlPartsCheck === false ) {
                        return false;
                }
 
-               $urlPartsCheck = array_intersect_key( $urlPartsCheck, [ 'host' => 1, 'port' => 1 ] );
+               static $relevantKeys = [ 'host' => 1, 'port' => 1 ];
+               $urlPartsCheck = array_intersect_key( $urlPartsCheck, $relevantKeys );
+
                foreach ( self::getCanonicalServerInfoForAllWikis() as $wikiId => $info ) {
                        $urlParts = $info['parts'];
                        if ( $urlParts === false ) {
                                continue; // sanity
                        }
 
-                       $urlParts = array_intersect_key( $urlParts, [ 'host' => 1, 'port' => 1 ] );
+                       $urlParts = array_intersect_key( $urlParts, $relevantKeys );
                        if ( $urlParts == $urlPartsCheck ) {
                                return $wikiId;
                        }
index fc42be4..658ee48 100644 (file)
@@ -267,7 +267,7 @@ class HistoryAction extends FormlessAction {
                $htmlForm
                        ->setMethod( 'get' )
                        ->setAction( wfScript() )
-                       ->setCollapsible( true )
+                       ->setCollapsibleOptions( true )
                        ->setId( 'mw-history-searchform' )
                        ->setSubmitText( $this->msg( 'historyaction-submit' )->text() )
                        ->setWrapperAttributes( [ 'id' => 'mw-history-search' ] )
index 49a6bb5..bfba59a 100644 (file)
@@ -399,7 +399,7 @@ class InfoAction extends FormlessAction {
                }
 
                // Subpages of this page, if subpages are enabled for the current NS
-               if ( MWNamespace::hasSubpages( $title->getNamespace() ) ) {
+               if ( $services->getNamespaceInfo()->hasSubpages( $title->getNamespace() ) ) {
                        $prefixIndex = SpecialPage::getTitleFor(
                                'Prefixindex', $title->getPrefixedText() . '/' );
                        $pageInfo['header-basic'][] = [
@@ -730,12 +730,13 @@ class InfoAction extends FormlessAction {
        protected function pageCounts( Page $page ) {
                $fname = __METHOD__;
                $config = $this->context->getConfig();
-               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+               $services = MediaWikiServices::getInstance();
+               $cache = $services->getMainWANObjectCache();
 
                return $cache->getWithSetCallback(
                        self::getCacheKey( $cache, $page->getTitle(), $page->getLatest() ),
                        WANObjectCache::TTL_WEEK,
-                       function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname ) {
+                       function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname, $services ) {
                                global $wgActorTableSchemaMigrationStage;
 
                                $title = $page->getTitle();
@@ -759,7 +760,7 @@ class InfoAction extends FormlessAction {
                                        $joins = [];
                                }
 
-                               $watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore();
+                               $watchedItemStore = $services->getWatchedItemStore();
 
                                $result = [];
                                $result['watchers'] = $watchedItemStore->countWatchers( $title );
@@ -824,7 +825,7 @@ class InfoAction extends FormlessAction {
                                );
 
                                // Subpages (if enabled)
-                               if ( MWNamespace::hasSubpages( $title->getNamespace() ) ) {
+                               if ( $services->getNamespaceInfo()->hasSubpages( $title->getNamespace() ) ) {
                                        $conds = [ 'page_namespace' => $title->getNamespace() ];
                                        $conds[] = 'page_title ' .
                                                $dbr->buildLike( $title->getDBkey() . '/', $dbr->anyString() );
index 8ab92af..bc62906 100644 (file)
@@ -20,6 +20,8 @@
  * @file
  */
 
+use MediaWiki\Block\AbstractBlock;
+use MediaWiki\MediaWikiServices;
 use Wikimedia\Rdbms\IDatabase;
 
 /**
@@ -36,6 +38,8 @@ use Wikimedia\Rdbms\IDatabase;
  */
 abstract class ApiBase extends ContextSource {
 
+       use ApiBlockInfoTrait;
+
        /**
         * @name Constants for ::getAllowedParams() arrays
         * These constants are keys in the arrays returned by ::getAllowedParams()
@@ -1196,7 +1200,8 @@ abstract class ApiBase extends ContextSource {
                        $provided = $this->getMain()->getCheck( $encParamName );
 
                        if ( isset( $value ) && $type == 'namespace' ) {
-                               $type = MWNamespace::getValidNamespaces();
+                               $type = MediaWikiServices::getInstance()->getNamespaceInfo()->
+                                       getValidNamespaces();
                                if ( isset( $paramSettings[self::PARAM_EXTRA_NAMESPACES] ) &&
                                        is_array( $paramSettings[self::PARAM_EXTRA_NAMESPACES] )
                                ) {
@@ -1811,7 +1816,7 @@ abstract class ApiBase extends ContextSource {
                        if ( is_string( $error[0] ) && isset( self::$blockMsgMap[$error[0]] ) && $user->getBlock() ) {
                                list( $msg, $code ) = self::$blockMsgMap[$error[0]];
                                $status->fatal( ApiMessage::create( $msg, $code,
-                                       [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) ]
+                                       [ 'blockinfo' => $this->getBlockInfo( $user->getBlock() ) ]
                                ) );
                        } else {
                                $status->fatal( ...$error );
@@ -1834,7 +1839,7 @@ abstract class ApiBase extends ContextSource {
                foreach ( self::$blockMsgMap as $msg => list( $apiMsg, $code ) ) {
                        if ( $status->hasMessage( $msg ) && $user->getBlock() ) {
                                $status->replaceMessage( $msg, ApiMessage::create( $apiMsg, $code,
-                                       [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) ]
+                                       [ 'blockinfo' => $this->getBlockInfo( $user->getBlock() ) ]
                                ) );
                        }
                }
@@ -2027,25 +2032,25 @@ abstract class ApiBase extends ContextSource {
         * @param Block $block The block used to generate the ApiUsageException
         * @throws ApiUsageException always
         */
-       public function dieBlocked( Block $block ) {
+       public function dieBlocked( AbstractBlock $block ) {
                // Die using the appropriate message depending on block type
                if ( $block->getType() == Block::TYPE_AUTO ) {
                        $this->dieWithError(
                                'apierror-autoblocked',
                                'autoblocked',
-                               [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $block ) ]
+                               [ 'blockinfo' => $this->getBlockInfo( $block ) ]
                        );
                } elseif ( !$block->isSitewide() ) {
                        $this->dieWithError(
                                'apierror-blocked-partial',
                                'blocked',
-                               [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $block ) ]
+                               [ 'blockinfo' => $this->getBlockInfo( $block ) ]
                        );
                } else {
                        $this->dieWithError(
                                'apierror-blocked',
                                'blocked',
-                               [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $block ) ]
+                               [ 'blockinfo' => $this->getBlockInfo( $block ) ]
                        );
                }
        }
index b5d51aa..336943d 100644 (file)
@@ -28,6 +28,8 @@
  */
 class ApiBlock extends ApiBase {
 
+       use ApiBlockInfoTrait;
+
        /**
         * Blocks the user specified in the parameters for the given expiry, with the
         * given reason, and with all other settings provided in the params. If the block
@@ -50,7 +52,7 @@ class ApiBlock extends ApiBase {
                                $this->dieWithError(
                                        $status,
                                        null,
-                                       [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $block ) ]
+                                       [ 'blockinfo' => $this->getBlockInfo( $block ) ]
                                );
                        }
                }
diff --git a/includes/api/ApiBlockInfoTrait.php b/includes/api/ApiBlockInfoTrait.php
new file mode 100644 (file)
index 0000000..51da835
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+/**
+ * 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
+ */
+
+use MediaWiki\Block\AbstractBlock;
+use MediaWiki\Block\SystemBlock;
+
+/**
+ * @ingroup API
+ */
+trait ApiBlockInfoTrait {
+
+       /**
+        * Get basic info about a given block
+        * @param Block $block
+        * @return array Array containing several keys:
+        *  - blockid - ID of the block
+        *  - blockedby - username of the blocker
+        *  - blockedbyid - user ID of the blocker
+        *  - blockreason - reason provided for the block
+        *  - blockedtimestamp - timestamp for when the block was placed/modified
+        *  - blockexpiry - expiry time of the block
+        *  - systemblocktype - system block type, if any
+        */
+       private function getBlockInfo( AbstractBlock $block ) {
+               $vals = [];
+               $vals['blockid'] = $block->getId();
+               $vals['blockedby'] = $block->getByName();
+               $vals['blockedbyid'] = $block->getBy();
+               $vals['blockreason'] = $block->getReason();
+               $vals['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $block->getTimestamp() );
+               $vals['blockexpiry'] = ApiResult::formatExpiry( $block->getExpiry(), 'infinite' );
+               $vals['blockpartial'] = !$block->isSitewide();
+               if ( $block instanceof SystemBlock ) {
+                       $vals['systemblocktype'] = $block->getSystemBlockType();
+               }
+               return $vals;
+       }
+
+}
index 1656e7c..78efe41 100644 (file)
@@ -583,7 +583,8 @@ class ApiHelp extends ApiBase {
                                                                        break;
 
                                                                case 'namespace':
-                                                                       $namespaces = MWNamespace::getValidNamespaces();
+                                                                       $namespaces = MediaWikiServices::getInstance()->
+                                                                               getNamespaceInfo()->getValidNamespaces();
                                                                        if ( isset( $settings[ApiBase::PARAM_EXTRA_NAMESPACES] ) &&
                                                                                is_array( $settings[ApiBase::PARAM_EXTRA_NAMESPACES] )
                                                                        ) {
index b321c7d..64c6f45 100644 (file)
@@ -866,6 +866,8 @@ class ApiPageSet extends ApiBase {
                        ApiBase::dieDebug( __METHOD__, 'Missing $processTitles parameter when $remaining is provided' );
                }
 
+               $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
+
                $usernames = [];
                if ( $res ) {
                        foreach ( $res as $row ) {
@@ -884,7 +886,7 @@ class ApiPageSet extends ApiBase {
                                $this->processDbRow( $row );
 
                                // Need gender information
-                               if ( MWNamespace::hasGenderDistinction( $row->page_namespace ) ) {
+                               if ( $nsInfo->hasGenderDistinction( $row->page_namespace ) ) {
                                        $usernames[] = $row->page_title;
                                }
                        }
@@ -907,7 +909,7 @@ class ApiPageSet extends ApiBase {
                                                $this->mTitles[] = $title;
 
                                                // need gender information
-                                               if ( MWNamespace::hasGenderDistinction( $ns ) ) {
+                                               if ( $nsInfo->hasGenderDistinction( $ns ) ) {
                                                        $usernames[] = $dbkey;
                                                }
                                        }
@@ -1249,7 +1251,10 @@ class ApiPageSet extends ApiBase {
                        }
 
                        // Need gender information
-                       if ( MWNamespace::hasGenderDistinction( $titleObj->getNamespace() ) ) {
+                       if (
+                               MediaWikiServices::getInstance()->getNamespaceInfo()->
+                                       hasGenderDistinction( $titleObj->getNamespace() )
+                       ) {
                                $usernames[] = $titleObj->getText();
                        }
                }
index bb50185..beaad43 100644 (file)
@@ -49,7 +49,8 @@ class ApiQueryAllDeletedRevisions extends ApiQueryRevisionsBase {
                $user = $this->getUser();
                $db = $this->getDB();
                $params = $this->extractRequestParams( false );
-               $revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
+               $services = MediaWikiServices::getInstance();
+               $revisionStore = $services->getRevisionStore();
 
                $result = $this->getResult();
 
@@ -156,7 +157,8 @@ class ApiQueryAllDeletedRevisions extends ApiQueryRevisionsBase {
                $miser_ns = null;
 
                if ( $mode == 'all' ) {
-                       $namespaces = $params['namespace'] ?? MWNamespace::getValidNamespaces();
+                       $namespaces = $params['namespace'] ??
+                               $services->getNamespaceInfo()->getValidNamespaces();
                        $this->addWhereFld( 'ar_namespace', $namespaces );
 
                        // For from/to/prefix, we have to consider the potential
index 1940600..08f3ea3 100644 (file)
@@ -211,12 +211,13 @@ class ApiQueryAllPages extends ApiQueryGeneratorBase {
                $res = $this->select( __METHOD__ );
 
                // Get gender information
-               if ( MWNamespace::hasGenderDistinction( $params['namespace'] ) ) {
+               $services = MediaWikiServices::getInstance();
+               if ( $services->getNamespaceInfo()->hasGenderDistinction( $params['namespace'] ) ) {
                        $users = [];
                        foreach ( $res as $row ) {
                                $users[] = $row->page_title;
                        }
-                       MediaWikiServices::getInstance()->getGenderCache()->doQuery( $users, __METHOD__ );
+                       $services->getGenderCache()->doQuery( $users, __METHOD__ );
                        $res->rewind(); // reset
                }
 
index 58445a1..050bc0f 100644 (file)
@@ -44,7 +44,8 @@ class ApiQueryAllRevisions extends ApiQueryRevisionsBase {
 
                $db = $this->getDB();
                $params = $this->extractRequestParams( false );
-               $revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
+               $services = MediaWikiServices::getInstance();
+               $revisionStore = $services->getRevisionStore();
 
                $result = $this->getResult();
 
@@ -70,7 +71,7 @@ class ApiQueryAllRevisions extends ApiQueryRevisionsBase {
                if ( $params['namespace'] !== null ) {
                        $params['namespace'] = array_unique( $params['namespace'] );
                        sort( $params['namespace'] );
-                       if ( $params['namespace'] != MWNamespace::getValidNamespaces() ) {
+                       if ( $params['namespace'] != $services->getNamespaceInfo()->getValidNamespaces() ) {
                                $needPageTable = true;
                                if ( $this->getConfig()->get( 'MiserMode' ) ) {
                                        $miser_ns = $params['namespace'];
index a5437ba..276aafb 100644 (file)
@@ -708,10 +708,11 @@ class ApiQueryInfo extends ApiQueryBase {
         */
        private function getTSIDs() {
                $getTitles = $this->talkids = $this->subjectids = [];
+               $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
 
                /** @var Title $t */
                foreach ( $this->everything as $t ) {
-                       if ( MWNamespace::isTalk( $t->getNamespace() ) ) {
+                       if ( $nsInfo->isTalk( $t->getNamespace() ) ) {
                                if ( $this->fld_subjectid ) {
                                        $getTitles[] = $t->getSubjectPage();
                                }
@@ -734,12 +735,12 @@ class ApiQueryInfo extends ApiQueryBase {
                $this->addWhere( $lb->constructSet( 'page', $db ) );
                $res = $this->select( __METHOD__ );
                foreach ( $res as $row ) {
-                       if ( MWNamespace::isTalk( $row->page_namespace ) ) {
-                               $this->talkids[MWNamespace::getSubject( $row->page_namespace )][$row->page_title] =
-                                       (int)$row->page_id;
+                       if ( $nsInfo->isTalk( $row->page_namespace ) ) {
+                               $this->talkids[$nsInfo->getSubject( $row->page_namespace )][$row->page_title] =
+                                       (int)( $row->page_id );
                        } else {
-                               $this->subjectids[MWNamespace::getTalk( $row->page_namespace )][$row->page_title] =
-                                       (int)$row->page_id;
+                               $this->subjectids[$nsInfo->getTalk( $row->page_namespace )][$row->page_title] =
+                                       (int)( $row->page_id );
                        }
                }
        }
index e6403f3..98c6551 100644 (file)
@@ -67,13 +67,6 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                $search->setFeatureData( 'rewrite', (bool)$params['enablerewrites'] );
                $search->setFeatureData( 'interwiki', (bool)$interwiki );
 
-               $nquery = $search->transformSearchTerm( $query );
-               if ( $nquery !== $query ) {
-                       $query = $nquery;
-                       wfDeprecated( 'SearchEngine::transformSearchTerm() (overridden by ' .
-                               get_class( $search ) . ')', '1.32' );
-               }
-
                $nquery = $search->replacePrefixes( $query );
                if ( $nquery !== $query ) {
                        $query = $nquery;
index 68ab725..7e4a891 100644 (file)
@@ -282,27 +282,28 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                $data = [
                        ApiResult::META_TYPE => 'assoc',
                ];
+               $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
                foreach (
                        MediaWikiServices::getInstance()->getContentLanguage()->getFormattedNamespaces()
                        as $ns => $title
                ) {
                        $data[$ns] = [
                                'id' => (int)$ns,
-                               'case' => MWNamespace::isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive',
+                               'case' => $nsInfo->isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive',
                        ];
                        ApiResult::setContentValue( $data[$ns], 'name', $title );
-                       $canonical = MWNamespace::getCanonicalName( $ns );
+                       $canonical = $nsInfo->getCanonicalName( $ns );
 
-                       $data[$ns]['subpages'] = MWNamespace::hasSubpages( $ns );
+                       $data[$ns]['subpages'] = $nsInfo->hasSubpages( $ns );
 
                        if ( $canonical ) {
                                $data[$ns]['canonical'] = strtr( $canonical, '_', ' ' );
                        }
 
-                       $data[$ns]['content'] = MWNamespace::isContent( $ns );
-                       $data[$ns]['nonincludable'] = MWNamespace::isNonincludable( $ns );
+                       $data[$ns]['content'] = $nsInfo->isContent( $ns );
+                       $data[$ns]['nonincludable'] = $nsInfo->isNonincludable( $ns );
 
-                       $contentmodel = MWNamespace::getNamespaceContentModel( $ns );
+                       $contentmodel = $nsInfo->getNamespaceContentModel( $ns );
                        if ( $contentmodel ) {
                                $data[$ns]['defaultcontentmodel'] = $contentmodel;
                        }
index 00d7d84..c495c6d 100644 (file)
@@ -29,6 +29,8 @@ use MediaWiki\MediaWikiServices;
  */
 class ApiQueryUserInfo extends ApiQueryBase {
 
+       use ApiBlockInfoTrait;
+
        const WL_UNREAD_LIMIT = 1000;
 
        private $params = [];
@@ -50,33 +52,6 @@ class ApiQueryUserInfo extends ApiQueryBase {
                $result->addValue( 'query', $this->getModuleName(), $r );
        }
 
-       /**
-        * Get basic info about a given block
-        * @param Block $block
-        * @return array Array containing several keys:
-        *  - blockid - ID of the block
-        *  - blockedby - username of the blocker
-        *  - blockedbyid - user ID of the blocker
-        *  - blockreason - reason provided for the block
-        *  - blockedtimestamp - timestamp for when the block was placed/modified
-        *  - blockexpiry - expiry time of the block
-        *  - systemblocktype - system block type, if any
-        */
-       public static function getBlockInfo( Block $block ) {
-               $vals = [];
-               $vals['blockid'] = $block->getId();
-               $vals['blockedby'] = $block->getByName();
-               $vals['blockedbyid'] = $block->getBy();
-               $vals['blockreason'] = $block->getReason();
-               $vals['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $block->getTimestamp() );
-               $vals['blockexpiry'] = ApiResult::formatExpiry( $block->getExpiry(), 'infinite' );
-               $vals['blockpartial'] = !$block->isSitewide();
-               if ( $block->getSystemBlockType() !== null ) {
-                       $vals['systemblocktype'] = $block->getSystemBlockType();
-               }
-               return $vals;
-       }
-
        /**
         * Get central user info
         * @param Config $config
@@ -129,7 +104,7 @@ class ApiQueryUserInfo extends ApiQueryBase {
                if ( isset( $this->prop['blockinfo'] ) ) {
                        $block = $user->getBlock();
                        if ( $block ) {
-                               $vals = array_merge( $vals, self::getBlockInfo( $block ) );
+                               $vals = array_merge( $vals, $this->getBlockInfo( $block ) );
                        }
                }
 
index ba4c6e8..d2bbe7b 100644 (file)
@@ -77,8 +77,9 @@ class ApiSetNotificationTimestamp extends ApiBase {
                        $titles = $pageSet->getGoodTitles();
                        $title = reset( $titles );
                        if ( $title ) {
+                               // XXX $title isn't actually used, can we just get rid of the previous six lines?
                                $timestamp = MediaWikiServices::getInstance()->getRevisionStore()
-                                       ->getTimestampFromId( $title, $params['torevid'], IDBAccessObject::READ_LATEST );
+                                       ->getTimestampFromId( $params['torevid'], IDBAccessObject::READ_LATEST );
                                if ( $timestamp ) {
                                        $timestamp = $dbw->timestamp( $timestamp );
                                } else {
index 3aad8f4..f038b96 100644 (file)
@@ -28,6 +28,8 @@
  */
 class ApiUnblock extends ApiBase {
 
+       use ApiBlockInfoTrait;
+
        /**
         * Unblocks the specified user or provides the reason the unblock failed.
         */
@@ -48,7 +50,7 @@ class ApiUnblock extends ApiBase {
                                $this->dieWithError(
                                        $status,
                                        null,
-                                       [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $block ) ]
+                                       [ 'blockinfo' => $this->getBlockInfo( $block ) ]
                                );
                        }
                }
index 9497d8d..ea76a45 100644 (file)
        "apihelp-edit-param-text": "문서 내용.",
        "apihelp-edit-param-summary": "편집 요약. 또한 $1section=new 및 $1sectiontitle이 설정되어 있지 않을 때 문단 제목.",
        "apihelp-edit-param-tags": "이 판에 적용할 태그를 변경합니다.",
-       "apihelp-edit-param-minor": "ì\82¬ì\86\8cí\95\9c í\8e¸ì§\91.",
+       "apihelp-edit-param-minor": "ì\9d´ í\8e¸ì§\91ì\9d\84 ì\82¬ì\86\8cí\95\9c í\8e¸ì§\91ì\9c¼ë¡\9c í\91\9cì\8b\9cí\95©ë\8b\88ë\8b¤.",
        "apihelp-edit-param-notminor": "사소하지 않은 편집.",
        "apihelp-edit-param-bot": "이 편집을 봇 편집으로 표시.",
        "apihelp-edit-param-basetimestamp": "기본 판의 타임스탬프이며, 편집 충돌을 발견하기 위해 사용됩니다. [[Special:ApiHelp/query+revisions|action=query&prop=revisions&rvprop=timestamp]]를 통해 가져올 수 있습니다.",
index 615f71e..cfca2ee 100644 (file)
@@ -28,8 +28,8 @@
        "apihelp-edit-summary": "Säiten uleeën an änneren.",
        "apihelp-edit-param-sectiontitle": "Den Titel fir en neien Abschnitt.",
        "apihelp-edit-param-text": "Säiteninhalt.",
-       "apihelp-edit-param-minor": "Kleng Ännerung.",
-       "apihelp-edit-param-notminor": "Keng kleng Ännerung",
+       "apihelp-edit-param-minor": "Dës Ännerung als kleng Ännerung markéieren.",
+       "apihelp-edit-param-notminor": "Dës Ännerung net als keng kleng Ännerung markéieren esouguer wann d'Benotzerastellung \"{{int:tog-minordefault}}\" agestallt ass.",
        "apihelp-edit-param-bot": "Dës Ännerung als eng Bot-Ännerung markéieren.",
        "apihelp-edit-param-createonly": "D'Säit net ännere wann et se scho gëtt.",
        "apihelp-edit-param-watch": "D'Säit op dem aktuelle Benotzer seng Iwwerwaachungslëscht dobäisetzen.",
index 84eef72..15bc802 100644 (file)
@@ -17,7 +17,8 @@
                        "Hex",
                        "Mainframe98",
                        "Southparkfan",
-                       "Elroy"
+                       "Elroy",
+                       "Rots61"
                ]
        },
        "apihelp-main-extended-description": "<div class=\"hlist plainlinks api-main-links\">\n* [[mw:Special:MyLanguage/API:Main_page|Documentatie]]\n* [[mw:Special:MyLanguage/API:FAQ|FAQ]]\n* [https://lists.wikimedia.org/mailman/listinfo/mediawiki-api E-maillijst]\n* [https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce API-aankondigingen]\n* [https://phabricator.wikimedia.org/maniphest/query/GebfyV4uCaLd/#R Bugs & verzoeken]\n</div>\n<strong>Status:</strong> De MediaWiki API is een stabiele interface die actief ondersteund en verbeterd wordt. Hoewel we het proberen te voorkomen, is het mogelijk dat er soms wijzigingen worden aangebracht die bepaalde API-verzoek kunnen verhinderen; abonneer u op de [https://lists.wikimedia.org/pipermail/mediawiki-api-announce/ e-maillijst mediawiki-api-announce] voor meldingen over wijzigingen.\n\n<strong>Foutieve verzoeken:</strong> als de API foutieve verzoeken ontvangt, wordt er geantwoord met een HTTP-header met de sleutel \"MediaWiki-API-Error\" en daarna worden de waarde van de header en de foutcode op dezelfde waarde ingesteld. Zie [[mw:Special:MyLanguage/API:Errors_and_warnings|API: Foutmeldingen en waarschuwingen]] voor meer informatie.\n\n<p class=\"mw-apisandbox-link\"><strong>Testen:</strong> u kunt [[Special:ApiSandbox|eenvoudig API-verzoeken testen]].</p>",
@@ -87,7 +88,7 @@
        "apihelp-edit-param-sectiontitle": "De naam van een nieuwe sectie.",
        "apihelp-edit-param-text": "Pagina-inhoud.",
        "apihelp-edit-param-tags": "De labels voor de revisie wijzigen.",
-       "apihelp-edit-param-minor": "Kleine bewerking.",
+       "apihelp-edit-param-minor": "Mankeer deze bewerking als een kleine bewerking.",
        "apihelp-edit-param-notminor": "Niet-kleine bewerking.",
        "apihelp-edit-param-bot": "Deze bewerking markeren als een botbewerking.",
        "apihelp-edit-param-createonly": "De pagina niet bewerken als die al bestaat.",
index 2d4fc69..d36e4ea 100644 (file)
@@ -16,7 +16,8 @@
                        "Woytecr",
                        "InternerowyGołąb",
                        "CiaPan",
-                       "Vlad5250"
+                       "Vlad5250",
+                       "Railfail536"
                ]
        },
        "apihelp-main-extended-description": "<div class=\"hlist plainlinks api-main-links\">\n* [[mw:Special:MyLanguage/API:Main_page|Dokumentacja]]\n* [[mw:Special:MyLanguage/API:FAQ|FAQ]]\n* [https://lists.wikimedia.org/mailman/listinfo/mediawiki-api Lista dyskusyjna]\n* [https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce Ogłoszenia dotyczące API]\n* [https://phabricator.wikimedia.org/maniphest/query/GebfyV4uCaLd/#R Błędy i propozycje]\n</div>\n<strong>Stan:</strong> Wszystkie funkcje opisane na tej stronie powinny działać, ale API nadal jest aktywnie rozwijane i mogą się zmienić w dowolnym czasie. Subskrybuj [https://lists.wikimedia.org/pipermail/mediawiki-api-announce/ listę dyskusyjną mediawiki-api-announce], aby móc na bieżąco dowiadywać się o aktualizacjach.\n\n<strong>Błędne żądania:</strong> Gdy zostanie wysłane błędne żądanie do API, zostanie wysłany w odpowiedzi nagłówek HTTP z kluczem \"MediaWiki-API-Error\" i zarówno jego wartość jak i wartość kodu błędu wysłanego w odpowiedzi będą miały taką samą wartość. Aby uzyskać więcej informacji, zobacz [[mw:Special:MyLanguage/API:Errors_and_warnings|API: Błędy i ostrzeżenia]].\n\n<strong>Testowanie:</strong> Aby łatwo testować żądania API, zobacz [[Special:ApiSandbox]].",
@@ -81,7 +82,7 @@
        "apihelp-edit-param-text": "Zawartość strony.",
        "apihelp-edit-param-summary": "Opis edycji. Także tytuł sekcji gdy użyto $1section=new, a nie ustawiono $1sectiontitle.",
        "apihelp-edit-param-tags": "Znaczniki zmian do zastosowania w tej edycji.",
-       "apihelp-edit-param-minor": "Drobna zmiana.",
+       "apihelp-edit-param-minor": "Oznacz tą zmianę jako drobną zmianę.",
        "apihelp-edit-param-notminor": "Nie oznaczaj tej zmiany jako drobną.",
        "apihelp-edit-param-bot": "Oznacz tę edycję jako edycję bota.",
        "apihelp-edit-param-basetimestamp": "Czas wersji, która jest edytowana. Służy do wykrywania konfliktów edycji. Można pobrać poprzez [[Special:ApiHelp/query+revisions|action=query&prop=revisions&rvprop=timestamp]].",
index 1026e2d..e565b71 100644 (file)
        "apihelp-edit-param-text": "頁面內容。",
        "apihelp-edit-param-summary": "編輯摘要。 當未設定 $1section=new 與 $1sectiontitle 時也會當做章節標題。",
        "apihelp-edit-param-tags": "更改套用到修訂的標籤。",
-       "apihelp-edit-param-minor": "小編輯。",
-       "apihelp-edit-param-notminor": "非小編輯。",
+       "apihelp-edit-param-minor": "標記此編輯為小編輯。",
+       "apihelp-edit-param-notminor": "不要標記此編輯為小編輯,即使有設定到「{{int:tog-minordefault}}」使用者偏好設定。",
        "apihelp-edit-param-bot": "標記此編輯為機器人編輯。",
        "apihelp-edit-param-basetimestamp": "基於修訂的時間戳記,用來檢測編輯衝突。也许可以取得[[Special:ApiHelp/query+revisions|action=query&prop=revisions&rvprop=timestamp]]認可。",
        "apihelp-edit-param-starttimestamp": "當編輯程序開始的時間戳記,用於偵測編輯衝突。當編輯程序開始時(例如:當載入要編輯的頁面內容),使用 <var>[[Special:ApiHelp/main|curtimestamp]]</var> 可以取得一個適當值。",
diff --git a/includes/block/AbstractBlock.php b/includes/block/AbstractBlock.php
new file mode 100644 (file)
index 0000000..a931d7a
--- /dev/null
@@ -0,0 +1,674 @@
+<?php
+/**
+ * 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
+ */
+
+namespace MediaWiki\Block;
+
+use IContextSource;
+use InvalidArgumentException;
+use IP;
+use RequestContext;
+use Title;
+use User;
+
+/**
+ * @since 1.34 Factored out from Block.
+ */
+abstract class AbstractBlock {
+       /** @var string */
+       public $mReason;
+
+       /** @var string */
+       public $mTimestamp;
+
+       /** @var string */
+       public $mExpiry = '';
+
+       /** @var bool */
+       protected $mBlockEmail = false;
+
+       /** @var bool */
+       protected $allowUsertalk = false;
+
+       /** @var bool */
+       protected $blockCreateAccount = false;
+
+       /** @var bool */
+       public $mHideName = false;
+
+       /** @var User|string */
+       protected $target;
+
+       /**
+        * @var int Block::TYPE_ constant. After the block has been loaded
+        * from the database, this can only be USER, IP or RANGE.
+        */
+       protected $type;
+
+       /** @var User */
+       protected $blocker;
+
+       /** @var bool */
+       protected $isSitewide = true;
+
+       # TYPE constants
+       const TYPE_USER = 1;
+       const TYPE_IP = 2;
+       const TYPE_RANGE = 3;
+       const TYPE_AUTO = 4;
+       const TYPE_ID = 5;
+
+       /**
+        * 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)
+        */
+       function __construct( $options = [] ) {
+               $defaults = [
+                       'address'         => '',
+                       'by'              => null,
+                       'reason'          => '',
+                       'timestamp'       => '',
+                       'byText'          => '',
+               ];
+
+               $options += $defaults;
+
+               $this->setTarget( $options['address'] );
+
+               if ( $options['by'] ) {
+                       # Local user
+                       $this->setBlocker( User::newFromId( $options['by'] ) );
+               } else {
+                       # Foreign user
+                       $this->setBlocker( $options['byText'] );
+               }
+
+               $this->setReason( $options['reason'] );
+               $this->setTimestamp( wfTimestamp( TS_MW, $options['timestamp'] ) );
+       }
+
+       /**
+        * Get the user id of the blocking sysop
+        *
+        * @return int (0 for foreign users)
+        */
+       public function getBy() {
+               return $this->getBlocker()->getId();
+       }
+
+       /**
+        * Get the username of the blocking sysop
+        *
+        * @return string
+        */
+       public function getByName() {
+               return $this->getBlocker()->getName();
+       }
+
+       /**
+        * Get the block ID
+        * @return int|null
+        */
+       public function getId() {
+               return null;
+       }
+
+       /**
+        * Get the reason given for creating the block
+        *
+        * @since 1.33
+        * @return string
+        */
+       public function getReason() {
+               return $this->mReason;
+       }
+
+       /**
+        * Set the reason for creating the block
+        *
+        * @since 1.33
+        * @param string $reason
+        */
+       public function setReason( $reason ) {
+               $this->mReason = $reason;
+       }
+
+       /**
+        * Get whether the block hides the target's username
+        *
+        * @since 1.33
+        * @return bool The block hides the username
+        */
+       public function getHideName() {
+               return $this->mHideName;
+       }
+
+       /**
+        * Set whether ths block hides the target's username
+        *
+        * @since 1.33
+        * @param bool $hideName The block hides the username
+        */
+       public function setHideName( $hideName ) {
+               $this->mHideName = $hideName;
+       }
+
+       /**
+        * Indicates that the block is a sitewide block. This means the user is
+        * prohibited from editing any page on the site (other than their own talk
+        * page).
+        *
+        * @since 1.33
+        * @param null|bool $x
+        * @return bool
+        */
+       public function isSitewide( $x = null ) {
+               return wfSetVar( $this->isSitewide, $x );
+       }
+
+       /**
+        * Get or set the flag indicating whether this block blocks the target from
+        * creating an account. (Note that the flag may be overridden depending on
+        * global configs.)
+        *
+        * @since 1.33
+        * @param null|bool $x Value to set (if null, just get the property value)
+        * @return bool Value of the property
+        */
+       public function isCreateAccountBlocked( $x = null ) {
+               return wfSetVar( $this->blockCreateAccount, $x );
+       }
+
+       /**
+        * Get or set the flag indicating whether this block blocks the target from
+        * sending emails. (Note that the flag may be overridden depending on
+        * global configs.)
+        *
+        * @since 1.33
+        * @param null|bool $x Value to set (if null, just get the property value)
+        * @return bool Value of the property
+        */
+       public function isEmailBlocked( $x = null ) {
+               return wfSetVar( $this->mBlockEmail, $x );
+       }
+
+       /**
+        * Get or set the flag indicating whether this block blocks the target from
+        * editing their own user talk page. (Note that the flag may be overridden
+        * depending on global configs.)
+        *
+        * @since 1.33
+        * @param null|bool $x Value to set (if null, just get the property value)
+        * @return bool Value of the property
+        */
+       public function isUsertalkEditAllowed( $x = null ) {
+               return wfSetVar( $this->allowUsertalk, $x );
+       }
+
+       /**
+        * Determine whether the Block prevents a given right. A right
+        * may be blacklisted or whitelisted, or determined from a
+        * property on the Block object. For certain rights, the property
+        * may be overridden according to global configs.
+        *
+        * @since 1.33
+        * @param string $right Right to check
+        * @return bool|null null if unrecognized right or unset property
+        */
+       public function appliesToRight( $right ) {
+               $config = RequestContext::getMain()->getConfig();
+               $blockDisablesLogin = $config->get( 'BlockDisablesLogin' );
+
+               $res = null;
+               switch ( $right ) {
+                       case 'edit':
+                               // TODO: fix this case to return proper value
+                               $res = true;
+                               break;
+                       case 'createaccount':
+                               $res = $this->isCreateAccountBlocked();
+                               break;
+                       case 'sendemail':
+                               $res = $this->isEmailBlocked();
+                               break;
+                       case 'upload':
+                               // Until T6995 is completed
+                               $res = $this->isSitewide();
+                               break;
+                       case 'read':
+                               $res = false;
+                               break;
+                       case 'purge':
+                               $res = false;
+                               break;
+               }
+               if ( !$res && $blockDisablesLogin ) {
+                       // If a block would disable login, then it should
+                       // prevent any right that all users cannot do
+                       $anon = new User;
+                       $res = $anon->isAllowed( $right ) ? $res : true;
+               }
+
+               return $res;
+       }
+
+       /**
+        * Get/set whether the Block prevents a given action
+        *
+        * @deprecated since 1.33, use appliesToRight to determine block
+        *  behaviour, and specific methods to get/set properties
+        * @param string $action Action to check
+        * @param bool|null $x Value for set, or null to just get value
+        * @return bool|null Null for unrecognized rights.
+        */
+       public function prevents( $action, $x = null ) {
+               $config = RequestContext::getMain()->getConfig();
+               $blockDisablesLogin = $config->get( 'BlockDisablesLogin' );
+               $blockAllowsUTEdit = $config->get( 'BlockAllowsUTEdit' );
+
+               $res = null;
+               switch ( $action ) {
+                       case 'edit':
+                               # For now... <evil laugh>
+                               $res = true;
+                               break;
+                       case 'createaccount':
+                               $res = wfSetVar( $this->blockCreateAccount, $x );
+                               break;
+                       case 'sendemail':
+                               $res = wfSetVar( $this->mBlockEmail, $x );
+                               break;
+                       case 'upload':
+                               // Until T6995 is completed
+                               $res = $this->isSitewide();
+                               break;
+                       case 'editownusertalk':
+                               // NOTE: this check is not reliable on partial blocks
+                               // since partially blocked users are always allowed to edit
+                               // their own talk page unless a restriction exists on the
+                               // page or User_talk: namespace
+                               wfSetVar( $this->allowUsertalk, $x === null ? null : !$x );
+                               $res = !$this->isUsertalkEditAllowed();
+
+                               // edit own user talk can be disabled by config
+                               if ( !$blockAllowsUTEdit ) {
+                                       $res = true;
+                               }
+                               break;
+                       case 'read':
+                               $res = false;
+                               break;
+                       case 'purge':
+                               $res = false;
+                               break;
+               }
+               if ( !$res && $blockDisablesLogin ) {
+                       // If a block would disable login, then it should
+                       // prevent any action that all users cannot do
+                       $anon = new User;
+                       $res = $anon->isAllowed( $action ) ? $res : true;
+               }
+
+               return $res;
+       }
+
+       /**
+        * From an existing Block, get the target and the type of target.
+        * Note that, except for null, it is always safe to treat the target
+        * as a string; for User objects this will return User::__toString()
+        * which in turn gives User::getName().
+        *
+        * @param string|int|User|null $target
+        * @return array [ User|String|null, Block::TYPE_ constant|null ]
+        */
+       public static function parseTarget( $target ) {
+               # We may have been through this before
+               if ( $target instanceof User ) {
+                       if ( IP::isValid( $target->getName() ) ) {
+                               return [ $target, self::TYPE_IP ];
+                       } else {
+                               return [ $target, self::TYPE_USER ];
+                       }
+               } elseif ( $target === null ) {
+                       return [ null, null ];
+               }
+
+               $target = trim( $target );
+
+               if ( IP::isValid( $target ) ) {
+                       # We can still create a User if it's an IP address, but we need to turn
+                       # off validation checking (which would exclude IP addresses)
+                       return [
+                               User::newFromName( IP::sanitizeIP( $target ), false ),
+                               self::TYPE_IP
+                       ];
+
+               } elseif ( IP::isValidRange( $target ) ) {
+                       # Can't create a User from an IP range
+                       return [ IP::sanitizeRange( $target ), self::TYPE_RANGE ];
+               }
+
+               # Consider the possibility that this is not a username at all
+               # but actually an old subpage (T31797)
+               if ( strpos( $target, '/' ) !== false ) {
+                       # An old subpage, drill down to the user behind it
+                       $target = explode( '/', $target )[0];
+               }
+
+               $userObj = User::newFromName( $target );
+               if ( $userObj instanceof User ) {
+                       # Note that since numbers are valid usernames, a $target of "12345" will be
+                       # considered a User.  If you want to pass a block ID, prepend a hash "#12345",
+                       # since hash characters are not valid in usernames or titles generally.
+                       return [ $userObj, self::TYPE_USER ];
+
+               } elseif ( preg_match( '/^#\d+$/', $target ) ) {
+                       # Autoblock reference in the form "#12345"
+                       return [ substr( $target, 1 ), self::TYPE_AUTO ];
+
+               } else {
+                       return [ null, null ];
+               }
+       }
+
+       /**
+        * Get the type of target for this particular block.
+        * @return int Block::TYPE_ constant, will never be TYPE_ID
+        */
+       public function getType() {
+               return $this->type;
+       }
+
+       /**
+        * Get the target and target type for this particular Block.  Note that for autoblocks,
+        * this returns the unredacted name; frontend functions need to call $block->getRedactedName()
+        * in this situation.
+        * @return array [ User|String, Block::TYPE_ constant ]
+        * @todo FIXME: This should be an integral part of the Block member variables
+        */
+       public function getTargetAndType() {
+               return [ $this->getTarget(), $this->getType() ];
+       }
+
+       /**
+        * Get the target for this particular Block.  Note that for autoblocks,
+        * this returns the unredacted name; frontend functions need to call $block->getRedactedName()
+        * in this situation.
+        * @return User|string
+        */
+       public function getTarget() {
+               return $this->target;
+       }
+
+       /**
+        * Get the block expiry time
+        *
+        * @since 1.19
+        * @return string
+        */
+       public function getExpiry() {
+               return $this->mExpiry;
+       }
+
+       /**
+        * Set the block expiry time
+        *
+        * @since 1.33
+        * @param string $expiry
+        */
+       public function setExpiry( $expiry ) {
+               $this->mExpiry = $expiry;
+       }
+
+       /**
+        * Get the timestamp indicating when the block was created
+        *
+        * @since 1.33
+        * @return string
+        */
+       public function getTimestamp() {
+               return $this->mTimestamp;
+       }
+
+       /**
+        * Set the timestamp indicating when the block was created
+        *
+        * @since 1.33
+        * @param string $timestamp
+        */
+       public function setTimestamp( $timestamp ) {
+               $this->mTimestamp = $timestamp;
+       }
+
+       /**
+        * Set the target for this block, and update $this->type accordingly
+        * @param mixed $target
+        */
+       public function setTarget( $target ) {
+               list( $this->target, $this->type ) = static::parseTarget( $target );
+       }
+
+       /**
+        * Get the user who implemented this block
+        * @return User User object. May name a foreign user.
+        */
+       public function getBlocker() {
+               return $this->blocker;
+       }
+
+       /**
+        * Set the user who implemented (or will implement) this block
+        * @param User|string $user Local User object or username string
+        */
+       public function setBlocker( $user ) {
+               if ( is_string( $user ) ) {
+                       $user = User::newFromName( $user, false );
+               }
+
+               if ( $user->isAnon() && User::isUsableName( $user->getName() ) ) {
+                       throw new InvalidArgumentException(
+                               'Blocker must be a local user or a name that cannot be a local user'
+                       );
+               }
+
+               $this->blocker = $user;
+       }
+
+       /**
+        * Get the key and parameters for the corresponding error message.
+        *
+        * @since 1.22
+        * @param IContextSource $context
+        * @return array
+        */
+       abstract public function getPermissionsError( IContextSource $context );
+
+       /**
+        * Get block information used in different block error messages
+        *
+        * @since 1.33
+        * @param IContextSource $context
+        * @return array
+        */
+       public function getBlockErrorParams( IContextSource $context ) {
+               $blocker = $this->getBlocker();
+               if ( $blocker instanceof User ) { // local user
+                       $blockerUserpage = $blocker->getUserPage();
+                       $link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]";
+               } else { // foreign user
+                       $link = $blocker;
+               }
+
+               $reason = $this->getReason();
+               if ( $reason == '' ) {
+                       $reason = $context->msg( 'blockednoreason' )->text();
+               }
+
+               /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
+                * This could be a username, an IP range, or a single IP. */
+               $intended = $this->getTarget();
+               $lang = $context->getLanguage();
+
+               return [
+                       $link,
+                       $reason,
+                       $context->getRequest()->getIP(),
+                       $this->getByName(),
+                       // TODO: SystemBlock replaces this with the system block type. Clean up
+                       // error params so that this is not necessary.
+                       $this->getId(),
+                       $lang->formatExpiry( $this->getExpiry() ),
+                       (string)$intended,
+                       $lang->userTimeAndDate( $this->getTimestamp(), $context->getUser() ),
+               ];
+       }
+
+       /**
+        * Determine whether the block allows the user to edit their own
+        * user talk page. This is done separately from Block::appliesToRight
+        * because there is no right for editing one's own user talk page
+        * and because the user's talk page needs to be passed into the
+        * Block object, which is unaware of the user.
+        *
+        * The ipb_allow_usertalk flag (which corresponds to the property
+        * allowUsertalk) is used on sitewide blocks and partial blocks
+        * that contain a namespace restriction on the user talk namespace,
+        * but do not contain a page restriction on the user's talk page.
+        * For all other (i.e. most) partial blocks, the flag is ignored,
+        * and the user can always edit their user talk page unless there
+        * is a page restriction on their user talk page, in which case
+        * they can never edit it. (Ideally the flag would be stored as
+        * null in these cases, but the database field isn't nullable.)
+        *
+        * This method does not validate that the passed in talk page belongs to the
+        * block target since the target (an IP) might not be the same as the user's
+        * talk page (if they are logged in).
+        *
+        * @since 1.33
+        * @param Title|null $usertalk The user's user talk page. If null,
+        *  and if the target is a User, the target's userpage is used
+        * @return bool The user can edit their talk page
+        */
+       public function appliesToUsertalk( Title $usertalk = null ) {
+               if ( !$usertalk ) {
+                       if ( $this->target instanceof User ) {
+                               $usertalk = $this->target->getTalkPage();
+                       } else {
+                               throw new InvalidArgumentException(
+                                       '$usertalk must be provided if block target is not a user/IP'
+                               );
+                       }
+               }
+
+               if ( $usertalk->getNamespace() !== NS_USER_TALK ) {
+                       throw new InvalidArgumentException(
+                               '$usertalk must be a user talk page'
+                       );
+               }
+
+               if ( !$this->isSitewide() ) {
+                       if ( $this->appliesToPage( $usertalk->getArticleID() ) ) {
+                               return true;
+                       }
+                       if ( !$this->appliesToNamespace( NS_USER_TALK ) ) {
+                               return false;
+                       }
+               }
+
+               // This is a type of block which uses the ipb_allow_usertalk
+               // flag. The flag can still be overridden by global configs.
+               $config = RequestContext::getMain()->getConfig();
+               if ( !$config->get( 'BlockAllowsUTEdit' ) ) {
+                       return true;
+               }
+               return !$this->isUsertalkEditAllowed();
+       }
+
+       /**
+        * Checks if a block applies to a particular title
+        *
+        * This check does not consider whether `$this->isUsertalkEditAllowed`
+        * returns false, as the identity of the user making the hypothetical edit
+        * isn't known here (particularly in the case of IP hardblocks, range
+        * blocks, and auto-blocks).
+        *
+        * @param Title $title
+        * @return bool
+        */
+       public function appliesToTitle( Title $title ) {
+               return $this->isSitewide();
+       }
+
+       /**
+        * Checks if a block applies to a particular namespace
+        *
+        * @since 1.33
+        *
+        * @param int $ns
+        * @return bool
+        */
+       public function appliesToNamespace( $ns ) {
+               return $this->isSitewide();
+       }
+
+       /**
+        * Checks if a block applies to a particular page
+        *
+        * This check does not consider whether `$this->isUsertalkEditAllowed`
+        * returns false, as the identity of the user making the hypothetical edit
+        * isn't known here (particularly in the case of IP hardblocks, range
+        * blocks, and auto-blocks).
+        *
+        * @since 1.33
+        *
+        * @param int $pageId
+        * @return bool
+        */
+       public function appliesToPage( $pageId ) {
+               return $this->isSitewide();
+       }
+
+       /**
+        * Check if the block should be tracked with a cookie.
+        *
+        * @since 1.33
+        * @param bool $isAnon The user is logged out
+        * @return bool The block should be tracked with a cookie
+        */
+       public function shouldTrackWithCookie( $isAnon ) {
+               return false;
+       }
+
+       /**
+        * Check if the block prevents a user from resetting their password
+        *
+        * @since 1.33
+        * @return bool The block blocks password reset
+        */
+       public function appliesToPasswordReset() {
+               return $this->isCreateAccountBlocked();
+       }
+
+}
index 3ef35d7..ba4c569 100644 (file)
@@ -22,10 +22,10 @@ namespace MediaWiki\Block;
 
 use Block;
 use IP;
+use MediaWiki\User\UserIdentity;
 use User;
 use WebRequest;
 use Wikimedia\IPSet;
-use MediaWiki\User\UserIdentity;
 
 /**
  * A service class for checking blocks.
@@ -139,22 +139,25 @@ class BlockManager {
                $block = Block::newFromTarget( $user, $ip, !$fromReplica );
 
                // Cookie blocking
-               if ( !$block instanceof Block ) {
+               if ( !$block instanceof AbstractBlock ) {
                        $block = $this->getBlockFromCookieValue( $user, $request );
                }
 
                // Proxy blocking
-               if ( !$block instanceof Block && $ip !== null && !in_array( $ip, $this->proxyWhitelist ) ) {
+               if ( !$block instanceof AbstractBlock
+                       && $ip !== null
+                       && !in_array( $ip, $this->proxyWhitelist )
+               ) {
                        // Local list
                        if ( $this->isLocallyBlockedProxy( $ip ) ) {
-                               $block = new Block( [
+                               $block = new SystemBlock( [
                                        'byText' => wfMessage( 'proxyblocker' )->text(),
                                        'reason' => wfMessage( 'proxyblockreason' )->plain(),
                                        'address' => $ip,
                                        'systemBlock' => 'proxy',
                                ] );
                        } elseif ( $isAnon && $this->isDnsBlacklisted( $ip ) ) {
-                               $block = new Block( [
+                               $block = new SystemBlock( [
                                        'byText' => wfMessage( 'sorbs' )->text(),
                                        'reason' => wfMessage( 'sorbsreason' )->plain(),
                                        'address' => $ip,
@@ -164,7 +167,7 @@ class BlockManager {
                }
 
                // (T25343) Apply IP blocks to the contents of XFF headers, if enabled
-               if ( !$block instanceof Block
+               if ( !$block instanceof AbstractBlock
                        && $this->applyIpBlocksToXff
                        && $ip !== null
                        && !in_array( $ip, $this->proxyWhitelist )
@@ -176,19 +179,19 @@ class BlockManager {
                        $xffblocks = Block::getBlocksForIPList( $xff, $isAnon, !$fromReplica );
                        // TODO: remove dependency on Block
                        $block = Block::chooseBlock( $xffblocks, $xff );
-                       if ( $block instanceof Block ) {
+                       if ( $block instanceof AbstractBlock ) {
                                # Mangle the reason to alert the user that the block
                                # originated from matching the X-Forwarded-For header.
                                $block->setReason( wfMessage( 'xffblockreason', $block->getReason() )->plain() );
                        }
                }
 
-               if ( !$block instanceof Block
+               if ( !$block instanceof AbstractBlock
                        && $ip !== null
                        && $isAnon
                        && IP::isInRanges( $ip, $this->softBlockRanges )
                ) {
-                       $block = new Block( [
+                       $block = new SystemBlock( [
                                'address' => $ip,
                                'byText' => 'MediaWiki default',
                                'reason' => wfMessage( 'softblockrangesreason', $ip )->plain(),
diff --git a/includes/block/SystemBlock.php b/includes/block/SystemBlock.php
new file mode 100644 (file)
index 0000000..2a8c663
--- /dev/null
@@ -0,0 +1,107 @@
+<?php
+/**
+ * Class for temporary blocks created on enforcement.
+ *
+ * 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
+ */
+
+namespace MediaWiki\Block;
+
+use IContextSource;
+
+/**
+ * System blocks are temporary blocks that are created on enforcement (e.g.
+ * from IP blacklists) and are not saved to the database. The target of a
+ * system block is an IP address. System blocks do not give rise to
+ * autoblocks and are not tracked with cookies.
+ *
+ * @since 1.34
+ */
+class SystemBlock extends AbstractBlock {
+       /** @var string|null */
+       private $systemBlockType;
+
+       /**
+        * 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().
+        */
+       function __construct( $options = [] ) {
+               parent::__construct( $options );
+
+               $defaults = [
+                       'systemBlock' => null,
+               ];
+
+               $options += $defaults;
+
+               $this->systemBlockType = $options['systemBlock'];
+       }
+
+       /**
+        * Get the system block type, if any. A SystemBlock can have the following types:
+        * - 'proxy': the IP is blacklisted in $wgProxyList
+        * - 'dnsbl': the IP is associated with a blacklisted domain in $wgDnsBlacklistUrls
+        * - 'wgSoftBlockRanges': the IP is covered by $wgSoftBlockRanges
+        * - 'global-block': for backwards compatability with the UserIsBlockedGlobally hook
+        *
+        * @since 1.29
+        * @return string|null
+        */
+       public function getSystemBlockType() {
+               return $this->systemBlockType;
+       }
+
+       /**
+        * @inheritDoc
+        */
+       public function getPermissionsError( IContextSource $context ) {
+               $params = $this->getBlockErrorParams( $context );
+               // TODO: Clean up error messages params so we don't have to do this
+               $params[ 4 ] = $this->getSystemBlockType();
+
+               $msg = 'systemblockedtext';
+
+               array_unshift( $params, $msg );
+
+               return $params;
+       }
+
+       /**
+        * @inheritDoc
+        */
+       public function appliesToPasswordReset() {
+               switch ( $this->getSystemBlockType() ) {
+                       case null:
+                       case 'global-block':
+                               return $this->isCreateAccountBlocked();
+                       case 'proxy':
+                               return true;
+                       case 'dnsbl':
+                       case 'wgSoftBlockRanges':
+                               return false;
+                       default:
+                               return true;
+               }
+       }
+
+}
index ec6ce04..d798ddb 100644 (file)
@@ -288,7 +288,9 @@ class CacheHelper implements ICacheHelper {
                        throw new MWException( 'No cache key set, so cannot obtain or save the CacheHelper values.' );
                }
 
-               return wfMemcKey( ...array_values( $this->cacheKey ) );
+               return ObjectCache::getLocalClusterInstance()->makeKey(
+                       ...array_values( $this->cacheKey )
+               );
        }
 
        /**
index 7228814..eedc3c6 100644 (file)
@@ -34,6 +34,13 @@ class GenderCache {
        protected $misses = 0;
        protected $missLimit = 1000;
 
+       /** @var NamespaceInfo */
+       private $nsInfo;
+
+       public function __construct( NamespaceInfo $nsInfo = null ) {
+               $this->nsInfo = $nsInfo ?? MediaWikiServices::getInstance()->getNamespaceInfo();
+       }
+
        /**
         * @deprecated in 1.28 see MediaWikiServices::getInstance()->getGenderCache()
         * @return GenderCache
@@ -97,7 +104,7 @@ class GenderCache {
        public function doLinkBatch( $data, $caller = '' ) {
                $users = [];
                foreach ( $data as $ns => $pagenames ) {
-                       if ( !MWNamespace::hasGenderDistinction( $ns ) ) {
+                       if ( !$this->nsInfo->hasGenderDistinction( $ns ) ) {
                                continue;
                        }
                        foreach ( array_keys( $pagenames ) as $username ) {
@@ -122,7 +129,7 @@ class GenderCache {
                        if ( !$titleObj ) {
                                continue;
                        }
-                       if ( !MWNamespace::hasGenderDistinction( $titleObj->getNamespace() ) ) {
+                       if ( !$this->nsInfo->hasGenderDistinction( $titleObj->getNamespace() ) ) {
                                continue;
                        }
                        $users[] = $titleObj->getText();
index c13f95e..1bcf948 100644 (file)
@@ -45,17 +45,29 @@ class LinkCache {
        /** @var TitleFormatter */
        private $titleFormatter;
 
+       /** @var NamespaceInfo */
+       private $nsInfo;
+
        /**
         * How many Titles to store. There are two caches, so the amount actually
         * stored in memory can be up to twice this.
         */
        const MAX_SIZE = 10000;
 
-       public function __construct( TitleFormatter $titleFormatter, WANObjectCache $cache ) {
+       public function __construct(
+               TitleFormatter $titleFormatter,
+               WANObjectCache $cache,
+               NamespaceInfo $nsInfo = null
+       ) {
+               if ( !$nsInfo ) {
+                       wfDeprecated( __METHOD__ . ' with no NamespaceInfo argument', '1.34' );
+                       $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
+               }
                $this->goodLinks = new MapCacheLRU( self::MAX_SIZE );
                $this->badLinks = new MapCacheLRU( self::MAX_SIZE );
                $this->wanCache = $cache;
                $this->titleFormatter = $titleFormatter;
+               $this->nsInfo = $nsInfo;
        }
 
        /**
@@ -231,9 +243,7 @@ class LinkCache {
         */
        public function addLinkObj( LinkTarget $nt ) {
                $key = $this->titleFormatter->getPrefixedDBkey( $nt );
-               if ( $this->isBadLink( $key ) || $nt->isExternal()
-                       || $nt->inNamespace( NS_SPECIAL )
-               ) {
+               if ( $this->isBadLink( $key ) || $nt->isExternal() || $nt->getNamespace() < 0 ) {
                        return 0;
                }
                $id = $this->getGoodLinkID( $key );
@@ -300,11 +310,11 @@ class LinkCache {
                        return true;
                }
                // Focus on transcluded pages more than the main content
-               if ( MWNamespace::isContent( $ns ) ) {
+               if ( $this->nsInfo->isContent( $ns ) ) {
                        return false;
                }
                // Non-talk extension namespaces (e.g. NS_MODULE)
-               return ( $ns >= 100 && MWNamespace::isSubject( $ns ) );
+               return ( $ns >= 100 && $this->nsInfo->isSubject( $ns ) );
        }
 
        private function fetchPageRow( IDatabase $db, LinkTarget $nt ) {
index fb4c7b6..328cc2f 100644 (file)
@@ -718,8 +718,7 @@ class MessageCache {
                $this->wanCache->touchCheckKey( $this->getCheckKey( $code ) );
 
                // Purge the messages in the message blob store and fire any hook handlers
-               $resourceloader = RequestContext::getMain()->getOutput()->getResourceLoader();
-               $blobStore = $resourceloader->getMessageBlobStore();
+               $blobStore = MediaWikiServices::getInstance()->getResourceLoader()->getMessageBlobStore();
                foreach ( $replacements as list( $title, $msg ) ) {
                        $blobStore->updateMessage( $this->contLang->lcfirst( $msg ) );
                        Hooks::run( 'MessageCacheReplace', [ $title, $newTextByTitle[$title] ] );
index 8814cff..3455470 100644 (file)
@@ -22,9 +22,7 @@ use Cdb\Reader;
 use Cdb\Writer;
 
 /**
- * LCStore implementation which stores data as a collection of CDB files in the
- * directory given by $wgCacheDirectory. If $wgCacheDirectory is not set, this
- * will throw an exception.
+ * LCStore implementation which stores data as a collection of CDB files.
  *
  * Profiling indicates that on Linux, this implementation outperforms MySQL if
  * the directory is on a local filesystem and there is ample kernel cache
index 8df8013..8a3a818 100644 (file)
@@ -192,7 +192,7 @@ class LocalisationCache {
                global $wgCacheDirectory;
 
                $this->conf = $conf;
-               $storeConf = [];
+               $storeArg = [];
                if ( !empty( $conf['storeClass'] ) ) {
                        $storeClass = $conf['storeClass'];
                } else {
@@ -203,7 +203,7 @@ class LocalisationCache {
                                        break;
                                case 'db':
                                        $storeClass = LCStoreDB::class;
-                                       $storeConf['server'] = $conf['storeServer'] ?? [];
+                                       $storeArg['server'] = $conf['storeServer'] ?? [];
                                        break;
                                case 'array':
                                        $storeClass = LCStoreStaticArray::class;
@@ -212,11 +212,11 @@ class LocalisationCache {
                                        if ( !empty( $conf['storeDirectory'] ) ) {
                                                $storeClass = LCStoreCDB::class;
                                        } elseif ( $wgCacheDirectory ) {
-                                               $storeConf['directory'] = $wgCacheDirectory;
+                                               $storeArg['directory'] = $wgCacheDirectory;
                                                $storeClass = LCStoreCDB::class;
                                        } else {
                                                $storeClass = LCStoreDB::class;
-                                               $storeConf['server'] = $conf['storeServer'] ?? [];
+                                               $storeArg['server'] = $conf['storeServer'] ?? [];
                                        }
                                        break;
                                default:
@@ -228,10 +228,10 @@ class LocalisationCache {
 
                wfDebugLog( 'caches', static::class . ": using store $storeClass" );
                if ( !empty( $conf['storeDirectory'] ) ) {
-                       $storeConf['directory'] = $conf['storeDirectory'];
+                       $storeArg['directory'] = $conf['storeDirectory'];
                }
 
-               $this->store = new $storeClass( $storeConf );
+               $this->store = new $storeClass( $storeArg );
                foreach ( [ 'manualRecache', 'forceRecache' ] as $var ) {
                        if ( isset( $conf[$var] ) ) {
                                $this->$var = $conf[$var];
@@ -1033,9 +1033,7 @@ class LocalisationCache {
                # HACK: If using a null (i.e. disabled) storage backend, we
                # can't write to the MessageBlobStore either
                if ( $purgeBlobs && !$this->store instanceof LCStoreNull ) {
-                       $blobStore = new MessageBlobStore(
-                               MediaWikiServices::getInstance()->getResourceLoader()
-                       );
+                       $blobStore = MediaWikiServices::getInstance()->getResourceLoader()->getMessageBlobStore();
                        $blobStore->clear();
                }
        }
index 4d00fbc..bb9114a 100644 (file)
@@ -20,6 +20,8 @@
  * @file
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * Feed to Special:RecentChanges and Special:RecentChangesLinked.
  *
@@ -88,9 +90,10 @@ class ChangesFeed {
                        }
                }
 
+               $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
                foreach ( $sorted as $obj ) {
                        $title = Title::makeTitle( $obj->rc_namespace, $obj->rc_title );
-                       $talkpage = MWNamespace::hasTalkNamespace( $obj->rc_namespace )
+                       $talkpage = $nsInfo->hasTalkNamespace( $obj->rc_namespace )
                                ? $title->getTalkPage()->getFullURL()
                                : '';
 
index decbb0c..cc73dd2 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 /**
  * Base class for content handling.
  *
index 354cc61..103b3e5 100644 (file)
@@ -24,7 +24,7 @@
 
 namespace MediaWiki\EditPage;
 
-use MWNamespace;
+use MediaWiki\MediaWikiServices;
 use Sanitizer;
 use Title;
 use User;
@@ -75,7 +75,8 @@ class TextboxBuilder {
        public function getTextboxProtectionCSSClasses( Title $title ) {
                $classes = []; // Textarea CSS
                if ( $title->isProtected( 'edit' ) &&
-                       MWNamespace::getRestrictionLevels( $title->getNamespace() ) !== [ '' ]
+                       MediaWikiServices::getInstance()->getNamespaceInfo()->
+                       getRestrictionLevels( $title->getNamespace() ) !== [ '' ]
                ) {
                        # Is the title semi-protected?
                        if ( $title->isSemiProtected() ) {
index 6e3fa79..b4e483b 100644 (file)
@@ -74,9 +74,32 @@ class MWExceptionHandler {
         * Install handlers with PHP.
         */
        public static function installHandler() {
+               // This catches:
+               // * Exception objects that were explicitly thrown but not
+               //   caught anywhere in the application. This is rare given those
+               //   would normally be caught at a high-level like MediaWiki::run (index.php),
+               //   api.php, or ResourceLoader::respond (load.php). These high-level
+               //   catch clauses would then call MWExceptionHandler::logException
+               //   or MWExceptionHandler::handleException.
+               //   If they are not caught, then they are handled here.
+               // * Error objects (on PHP 7+), for issues that would historically
+               //   cause fatal errors but may now be caught as Throwable (not Exception).
+               //   Same as previous case, but more common to bubble to here instead of
+               //   caught locally because they tend to not be safe to recover from.
+               //   (e.g. argument TypeErorr, devision by zero, etc.)
                set_exception_handler( 'MWExceptionHandler::handleUncaughtException' );
+
+               // This catches:
+               // * Non-fatal errors (e.g. PHP Notice, PHP Warning, PHP Error) that do not
+               //   interrupt execution in any way. We log these in the background and then
+               //   continue execution.
+               // * Fatal errors (on HHVM in PHP5 mode) where PHP 7 would throw Throwable.
                set_error_handler( 'MWExceptionHandler::handleError' );
 
+               // This catches:
+               // * Fatal error for which no Throwable is thrown (PHP 7), and no Error emitted (HHVM).
+               //   This includes Out-Of-Memory and Timeout fatals.
+               //
                // Reserve 16k of memory so we can report OOM fatals
                self::$reservedMemory = str_repeat( ' ', 16384 );
                register_shutdown_function( 'MWExceptionHandler::handleFatalError' );
index 9d19f8b..9746c2b 100644 (file)
@@ -18,6 +18,8 @@
  * @file
  */
 
+use MediaWiki\Block\AbstractBlock;
+
 /**
  * Show an error when the user tries to do something whilst blocked.
  *
@@ -25,7 +27,7 @@
  * @ingroup Exception
  */
 class UserBlockedError extends ErrorPageError {
-       public function __construct( Block $block ) {
+       public function __construct( AbstractBlock $block ) {
                // @todo FIXME: Implement a more proper way to get context here.
                $params = $block->getPermissionsError( RequestContext::getMain() );
                parent::__construct( 'blockedtitle', array_shift( $params ), $params );
index c201c76..6b2a22a 100644 (file)
@@ -23,6 +23,8 @@
  * @file
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * @ingroup Dump
  */
@@ -32,6 +34,7 @@ class DumpNotalkFilter extends DumpFilter {
         * @return bool
         */
        protected function pass( $page ) {
-               return !MWNamespace::isTalk( $page->page_namespace );
+               return !MediaWikiServices::getInstance()->getNamespaceInfo()->
+                       isTalk( $page->page_namespace );
        }
 }
index 54249a8..39153cf 100644 (file)
@@ -141,6 +141,7 @@ class XmlDumpWriter {
         */
        function namespaces() {
                $spaces = "<namespaces>\n";
+               $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
                foreach (
                        MediaWikiServices::getInstance()->getContentLanguage()->getFormattedNamespaces()
                        as $ns => $title
@@ -149,7 +150,8 @@ class XmlDumpWriter {
                                Xml::element( 'namespace',
                                        [
                                                'key' => $ns,
-                                               'case' => MWNamespace::isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive',
+                                               'case' => $nsInfo->isCapitalized( $ns )
+                                                       ? 'first-letter' : 'case-sensitive',
                                        ], $title ) . "\n";
                }
                $spaces .= "    </namespaces>";
index 879686f..a723557 100644 (file)
@@ -20,6 +20,8 @@
  * @file
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * Example class for HTTP accessible external objects.
  * Only supports reading, not storing.
@@ -28,7 +30,8 @@
  */
 class ExternalStoreHttp extends ExternalStoreMedium {
        public function fetchFromURL( $url ) {
-               return Http::get( $url, [], __METHOD__ );
+               return MediaWikiServices::getInstance()->getHttpRequestFactory()->
+                       get( $url, [], __METHOD__ );
        }
 
        public function store( $location, $data ) {
index 3a366c8..3e11a48 100644 (file)
@@ -176,7 +176,8 @@ class FileRepo {
                }
 
                // Optional settings that have a default
-               $this->initialCapital = $info['initialCapital'] ?? MWNamespace::isCapitalized( NS_FILE );
+               $this->initialCapital = $info['initialCapital'] ??
+                       MediaWikiServices::getInstance()->getNamespaceInfo()->isCapitalized( NS_FILE );
                $this->url = $info['url'] ?? false; // a subclass may set the URL (e.g. ForeignAPIRepo)
                if ( isset( $info['thumbUrl'] ) ) {
                        $this->thumbUrl = $info['thumbUrl'];
@@ -645,7 +646,10 @@ class FileRepo {
         * @return string
         */
        public function getNameFromTitle( Title $title ) {
-               if ( $this->initialCapital != MWNamespace::isCapitalized( NS_FILE ) ) {
+               if (
+                       $this->initialCapital !=
+                       MediaWikiServices::getInstance()->getNamespaceInfo()->isCapitalized( NS_FILE )
+               ) {
                        $name = $title->getUserCaseDBKey();
                        if ( $this->initialCapital ) {
                                $name = MediaWikiServices::getInstance()->getContentLanguage()->ucfirst( $name );
index 346ec8e..2c6f296 100644 (file)
@@ -502,8 +502,9 @@ class ForeignAPIRepo extends FileRepo {
        }
 
        /**
-        * Like a Http:get request, but with custom User-Agent.
-        * @see Http::get
+        * Like a HttpRequestFactory::get request, but with custom User-Agent.
+        * @see HttpRequestFactory::get
+        * @todo Can this use HttpRequestFactory::get() but just pass the 'userAgent' option?
         * @param string $url
         * @param string $timeout
         * @param array $options
index b6c70ab..8047835 100644 (file)
@@ -35,6 +35,9 @@ class RepoGroup {
        /** @var FileRepo[] */
        protected $foreignRepos;
 
+       /** @var WANObjectCache */
+       protected $wanCache;
+
        /** @var bool */
        protected $reposInitialised = false;
 
@@ -47,66 +50,60 @@ class RepoGroup {
        /** @var ProcessCacheLRU */
        protected $cache;
 
-       /** @var RepoGroup */
-       protected static $instance;
-
        /** Maximum number of cache items */
        const MAX_CACHE_SIZE = 500;
 
        /**
-        * Get a RepoGroup instance. At present only one instance of RepoGroup is
-        * needed in a MediaWiki invocation, this may change in the future.
+        * @deprecated since 1.34, use MediaWikiServices::getRepoGroup
         * @return RepoGroup
         */
        static function singleton() {
-               if ( self::$instance ) {
-                       return self::$instance;
-               }
-               global $wgLocalFileRepo, $wgForeignFileRepos;
-               /** @var array $wgLocalFileRepo */
-               self::$instance = new RepoGroup( $wgLocalFileRepo, $wgForeignFileRepos );
-
-               return self::$instance;
+               return MediaWikiServices::getInstance()->getRepoGroup();
        }
 
        /**
-        * Destroy the singleton instance, so that a new one will be created next
-        * time singleton() is called.
+        * @deprecated since 1.34, use MediaWikiTestCase::overrideMwServices() or similar. This will
+        * cause bugs if you don't reset all other services that depend on this one at the same time.
         */
        static function destroySingleton() {
-               self::$instance = null;
+               MediaWikiServices::getInstance()->resetServiceForTesting( 'RepoGroup' );
        }