From 225b462a50b545b1f100e0d51a6070b0766ce12a Mon Sep 17 00:00:00 2001 From: "James D. Forrester" Date: Mon, 20 Nov 2017 15:50:22 -0800 Subject: [PATCH] Drop deprecated EnableAPI and EnableWriteAPI settings The siteinfo API response's 'writeapi' value is now hard-set to true, as are the ResourceLoader variables wgEnableAPI and wgEnableWriteAPI, to be deprecated later. Bug: T115414 Change-Id: I54ff9428b247ba203d67aba079149393f323d5a9 --- RELEASE-NOTES-1.32 | 1 + api.php | 21 +++--------- includes/DefaultSettings.php | 21 +----------- includes/OutputPage.php | 34 +++++++++---------- includes/api/ApiQuerySiteinfo.php | 2 +- includes/diff/DifferenceEngine.php | 6 ++-- includes/page/Article.php | 4 +-- .../preferences/DefaultPreferencesFactory.php | 22 ++++++------ .../ResourceLoaderStartUpModule.php | 4 +-- includes/skins/Skin.php | 6 ++-- includes/specials/SpecialApiSandbox.php | 4 --- includes/specials/forms/UploadForm.php | 3 +- opensearch_desc.php | 2 +- tests/phpunit/includes/OutputPageTest.php | 1 - .../includes/api/ApiTestCaseUpload.php | 1 - .../includes/api/ApiUploadTestCase.php | 1 - 16 files changed, 45 insertions(+), 88 deletions(-) diff --git a/RELEASE-NOTES-1.32 b/RELEASE-NOTES-1.32 index 941cf3f1f0..d8eb2e2813 100644 --- a/RELEASE-NOTES-1.32 +++ b/RELEASE-NOTES-1.32 @@ -6,6 +6,7 @@ MediaWiki 1.32 is an alpha-quality branch and is not recommended for use in production. === Configuration changes in 1.32 === +* (T115414) The $wgEnableAPI and $wgEnableWriteAPI settings, deprecated in 1.31, have been removed. * … === New features in 1.32 === diff --git a/api.php b/api.php index d9a69db37e..9c5ac95716 100644 --- a/api.php +++ b/api.php @@ -2,13 +2,10 @@ /** * This file is the entry point for all API queries. * - * It begins by checking whether the API is enabled on this wiki; if not, - * it informs the user that s/he should set $wgEnableAPI to true and exits. - * Otherwise, it constructs a new ApiMain using the parameter passed to it - * as an argument in the URL ('?action=') and with write-enabled set to the - * value of $wgEnableWriteAPI as specified in LocalSettings.php. - * It then invokes "execute()" on the ApiMain object instance, which - * produces output in the format specified in the URL. + * It begins by constructing a new ApiMain using the parameter passed to it + * as an argument in the URL ('?action='). It then invokes "execute()" on the + * ApiMain object instance, which produces output in the format specified in + * the URL. * * Copyright © 2006 Yuri Astrakhan @gmail.com * @@ -55,14 +52,6 @@ if ( isset( $_SERVER['PATH_INFO'] ) && $_SERVER['PATH_INFO'] != '' ) { die( 1 ); } -// Verify that the API has not been disabled -if ( !$wgEnableAPI ) { - header( $_SERVER['SERVER_PROTOCOL'] . ' 500 MediaWiki configuration Error', true, 500 ); - echo 'MediaWiki API is not enabled for this site. Add the following line to your LocalSettings.php' - . '
$wgEnableAPI=true;
'; - die( 1 ); -} - // Set a dummy $wgTitle, because $wgTitle == null breaks various things // In a perfect world this wouldn't be necessary $wgTitle = Title::makeTitle( NS_SPECIAL, 'Badtitle/dummy title for API calls set in api.php' ); @@ -76,7 +65,7 @@ try { * is some form of an ApiMain, possibly even one that produces an error message, * but we don't care here, as that is handled by the constructor. */ - $processor = new ApiMain( RequestContext::getMain(), $wgEnableWriteAPI ); + $processor = new ApiMain( RequestContext::getMain(), true ); // Last chance hook before executing the API Hooks::run( 'ApiBeforeMain', [ &$processor ] ); diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 6d7962c2c1..8ddf3101ed 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -8044,25 +8044,6 @@ $wgExemptFromUserRobotsControl = null; * @{ */ -/** - * Enable the MediaWiki API for convenient access to - * machine-readable data via api.php - * - * See https://www.mediawiki.org/wiki/API - * - * @deprecated since 1.31 - */ -$wgEnableAPI = true; - -/** - * Allow the API to be used to perform write operations - * (page edits, rollback, etc.) when an authorised user - * accesses it - * - * @deprecated since 1.31 - */ -$wgEnableWriteAPI = true; - /** * * WARNING: SECURITY THREAT - debug use only @@ -8217,7 +8198,7 @@ $wgAjaxExportList = []; $wgAjaxUploadDestCheck = true; /** - * Enable previewing licences via AJAX. Also requires $wgEnableAPI to be true. + * Enable previewing licences via AJAX. */ $wgAjaxLicensePreview = true; diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 99dd4a7c0e..dd64413fd4 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -3337,24 +3337,22 @@ class OutputPage extends ContextSource { 'title' => $this->msg( 'opensearch-desc' )->inContentLanguage()->text(), ] ); - if ( $config->get( 'EnableAPI' ) ) { - # Real Simple Discovery link, provides auto-discovery information - # for the MediaWiki API (and potentially additional custom API - # support such as WordPress or Twitter-compatible APIs for a - # blogging extension, etc) - $tags['rsd'] = Html::element( 'link', [ - 'rel' => 'EditURI', - 'type' => 'application/rsd+xml', - // Output a protocol-relative URL here if $wgServer is protocol-relative. - // Whether RSD accepts relative or protocol-relative URLs is completely - // undocumented, though. - 'href' => wfExpandUrl( wfAppendQuery( - wfScript( 'api' ), - [ 'action' => 'rsd' ] ), - PROTO_RELATIVE - ), - ] ); - } + # Real Simple Discovery link, provides auto-discovery information + # for the MediaWiki API (and potentially additional custom API + # support such as WordPress or Twitter-compatible APIs for a + # blogging extension, etc) + $tags['rsd'] = Html::element( 'link', [ + 'rel' => 'EditURI', + 'type' => 'application/rsd+xml', + // Output a protocol-relative URL here if $wgServer is protocol-relative. + // Whether RSD accepts relative or protocol-relative URLs is completely + // undocumented, though. + 'href' => wfExpandUrl( wfAppendQuery( + wfScript( 'api' ), + [ 'action' => 'rsd' ] ), + PROTO_RELATIVE + ), + ] ); # Language variants if ( !$config->get( 'DisableLangConversion' ) ) { diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index 3048273267..3f2d510343 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -223,7 +223,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { if ( $data['readonly'] ) { $data['readonlyreason'] = wfReadOnlyReason(); } - $data['writeapi'] = (bool)$config->get( 'EnableWriteAPI' ); + $data['writeapi'] = true; // Deprecated since MW 1.32 $data['maxarticlesize'] = $config->get( 'MaxArticleSize' ) * 1024; diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php index 8f57c578eb..b1ca435269 100644 --- a/includes/diff/DifferenceEngine.php +++ b/includes/diff/DifferenceEngine.php @@ -524,7 +524,7 @@ class DifferenceEngine extends ContextSource { * or false if no link is needed */ protected function getMarkPatrolledLinkInfo() { - global $wgUseRCPatrol, $wgEnableAPI, $wgEnableWriteAPI; + global $wgUseRCPatrol; $user = $this->getUser(); @@ -564,9 +564,7 @@ class DifferenceEngine extends ContextSource { // Build the link if ( $rcid ) { $this->getOutput()->preventClickjacking(); - if ( $wgEnableAPI && $wgEnableWriteAPI - && $user->isAllowed( 'writeapi' ) - ) { + if ( $user->isAllowed( 'writeapi' ) ) { $this->getOutput()->addModules( 'mediawiki.page.patrol.ajax' ); } diff --git a/includes/page/Article.php b/includes/page/Article.php index 3cbeacffa7..7577972b00 100644 --- a/includes/page/Article.php +++ b/includes/page/Article.php @@ -965,7 +965,7 @@ class Article implements Page { * @return bool */ public function showPatrolFooter() { - global $wgUseNPPatrol, $wgUseRCPatrol, $wgUseFilePatrol, $wgEnableAPI, $wgEnableWriteAPI; + global $wgUseNPPatrol, $wgUseRCPatrol, $wgUseFilePatrol; $outputPage = $this->getContext()->getOutput(); $user = $this->getContext()->getUser(); @@ -1100,7 +1100,7 @@ class Article implements Page { } $outputPage->preventClickjacking(); - if ( $wgEnableAPI && $wgEnableWriteAPI && $user->isAllowed( 'writeapi' ) ) { + if ( $user->isAllowed( 'writeapi' ) ) { $outputPage->addModules( 'mediawiki.page.patrol.ajax' ); } diff --git a/includes/preferences/DefaultPreferencesFactory.php b/includes/preferences/DefaultPreferencesFactory.php index 6eceb84bcf..3bc21f726b 100644 --- a/includes/preferences/DefaultPreferencesFactory.php +++ b/includes/preferences/DefaultPreferencesFactory.php @@ -1188,18 +1188,16 @@ class DefaultPreferencesFactory implements PreferencesFactory { } } - if ( $this->config->get( 'EnableAPI' ) ) { - $defaultPreferences['watchlisttoken'] = [ - 'type' => 'api', - ]; - $defaultPreferences['watchlisttoken-info'] = [ - 'type' => 'info', - 'section' => 'watchlist/tokenwatchlist', - 'label-message' => 'prefs-watchlist-token', - 'default' => $user->getTokenFromOption( 'watchlisttoken' ), - 'help-message' => 'prefs-help-watchlist-token2', - ]; - } + $defaultPreferences['watchlisttoken'] = [ + 'type' => 'api', + ]; + $defaultPreferences['watchlisttoken-info'] = [ + 'type' => 'info', + 'section' => 'watchlist/tokenwatchlist', + 'label-message' => 'prefs-watchlist-token', + 'default' => $user->getTokenFromOption( 'watchlisttoken' ), + 'help-message' => 'prefs-help-watchlist-token2', + ]; } /** diff --git a/includes/resourceloader/ResourceLoaderStartUpModule.php b/includes/resourceloader/ResourceLoaderStartUpModule.php index 681e8dc005..c0dd188423 100644 --- a/includes/resourceloader/ResourceLoaderStartUpModule.php +++ b/includes/resourceloader/ResourceLoaderStartUpModule.php @@ -101,8 +101,8 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { 'wgContentLanguage' => $wgContLang->getCode(), 'wgTranslateNumerals' => $conf->get( 'TranslateNumerals' ), 'wgVersion' => $conf->get( 'Version' ), - 'wgEnableAPI' => $conf->get( 'EnableAPI' ), - 'wgEnableWriteAPI' => $conf->get( 'EnableWriteAPI' ), + 'wgEnableAPI' => true, // Deprecated since MW 1.32 + 'wgEnableWriteAPI' => true, // Deprecated since MW 1.32 'wgMainPageTitle' => $mainPage->getPrefixedText(), 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(), 'wgNamespaceIds' => $namespaceIds, diff --git a/includes/skins/Skin.php b/includes/skins/Skin.php index e2de9ec382..80a1f6eb63 100644 --- a/includes/skins/Skin.php +++ b/includes/skins/Skin.php @@ -171,7 +171,7 @@ abstract class Skin extends ContextSource { * @return array Array of modules with helper keys for easy overriding */ public function getDefaultModules() { - global $wgUseAjax, $wgEnableAPI, $wgEnableWriteAPI; + global $wgUseAjax; $out = $this->getOutput(); $config = $this->getConfig(); @@ -217,8 +217,8 @@ abstract class Skin extends ContextSource { } // Add various resources if required - if ( $wgUseAjax && $wgEnableAPI ) { - if ( $wgEnableWriteAPI && $user->isLoggedIn() + if ( $wgUseAjax ) { + if ( $user->isLoggedIn() && $user->isAllowedAll( 'writeapi', 'viewmywatchlist', 'editmywatchlist' ) && $this->getRelevantTitle()->canExist() ) { diff --git a/includes/specials/SpecialApiSandbox.php b/includes/specials/SpecialApiSandbox.php index 2733e75716..c000d546d1 100644 --- a/includes/specials/SpecialApiSandbox.php +++ b/includes/specials/SpecialApiSandbox.php @@ -35,10 +35,6 @@ class SpecialApiSandbox extends SpecialPage { $out = $this->getOutput(); $this->addHelpLink( 'Help:ApiSandbox' ); - if ( !$this->getConfig()->get( 'EnableAPI' ) ) { - $out->showErrorPage( 'error', 'apisandbox-api-disabled' ); - } - $out->addJsConfigVars( 'apihighlimits', $this->getUser()->isAllowed( 'apihighlimits' ) ); $out->addModuleStyles( [ 'mediawiki.special.apisandbox.styles', diff --git a/includes/specials/forms/UploadForm.php b/includes/specials/forms/UploadForm.php index eacdace18a..a316374f4b 100644 --- a/includes/specials/forms/UploadForm.php +++ b/includes/specials/forms/UploadForm.php @@ -407,8 +407,7 @@ class UploadForm extends HTMLForm { $config = $this->getConfig(); $useAjaxDestCheck = $config->get( 'UseAjax' ) && $config->get( 'AjaxUploadDestCheck' ); - $useAjaxLicensePreview = $config->get( 'UseAjax' ) && - $config->get( 'AjaxLicensePreview' ) && $config->get( 'EnableAPI' ); + $useAjaxLicensePreview = $config->get( 'UseAjax' ) && $config->get( 'AjaxLicensePreview' ); $this->mMaxUploadSize['*'] = UploadBase::getMaxUploadSize(); $scriptVars = [ diff --git a/opensearch_desc.php b/opensearch_desc.php index 92c182d8a7..b9b21611d0 100644 --- a/opensearch_desc.php +++ b/opensearch_desc.php @@ -85,7 +85,7 @@ $urls[] = [ 'template' => $searchPage->getCanonicalURL( 'search={searchTerms}' ) ]; foreach ( $wgOpenSearchTemplates as $type => $template ) { - if ( !$template && $wgEnableAPI ) { + if ( !$template ) { $template = ApiOpenSearch::getOpenSearchTemplate( $type ); } diff --git a/tests/phpunit/includes/OutputPageTest.php b/tests/phpunit/includes/OutputPageTest.php index 88c585fe5c..81bbcd7ea4 100644 --- a/tests/phpunit/includes/OutputPageTest.php +++ b/tests/phpunit/includes/OutputPageTest.php @@ -673,7 +673,6 @@ class OutputPageTest extends MediaWikiTestCase { $context->setConfig( new HashConfig( $config + [ 'AppleTouchIcon' => false, 'DisableLangConversion' => true, - 'EnableAPI' => false, 'EnableCanonicalServerLink' => false, 'Favicon' => false, 'Feed' => false, diff --git a/tests/phpunit/includes/api/ApiTestCaseUpload.php b/tests/phpunit/includes/api/ApiTestCaseUpload.php index 3670fad846..a4ff1f0e90 100644 --- a/tests/phpunit/includes/api/ApiTestCaseUpload.php +++ b/tests/phpunit/includes/api/ApiTestCaseUpload.php @@ -4,5 +4,4 @@ * For backward compatibility since 1.31 */ abstract class ApiTestCaseUpload extends ApiUploadTestCase { - } diff --git a/tests/phpunit/includes/api/ApiUploadTestCase.php b/tests/phpunit/includes/api/ApiUploadTestCase.php index 3c7efd5768..cf56052a55 100644 --- a/tests/phpunit/includes/api/ApiUploadTestCase.php +++ b/tests/phpunit/includes/api/ApiUploadTestCase.php @@ -12,7 +12,6 @@ abstract class ApiUploadTestCase extends ApiTestCase { $this->setMwGlobals( [ 'wgEnableUploads' => true, - 'wgEnableAPI' => true, ] ); $this->clearFakeUploads(); -- 2.20.1