From a5c5257e71544a6a65ee24326d4cd198a3ef6f27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Sat, 16 Mar 2019 12:19:29 +0100 Subject: [PATCH] Directly call action=query&prop=langlinks from JS rather than PHP wrapper When this code was written in 2013 (1a5bdd5bd2c0a0400a611c25f959b99cb3a7f6a3), the langlinks API did not have a way to return the language names (autonyms). This has been added in 2014 (4ba3a9aea96ee21c035c69999be23580e23f4e0a). Change-Id: I70edb846d94b1108b079caf5915532234190da8f --- i18n/ve-mw/api/en.json | 1 - i18n/ve-mw/api/qqq.json | 1 - includes/ApiVisualEditor.php | 52 ------------------- .../ve-mw/ui/pages/ve.ui.MWLanguagesPage.js | 16 +++--- 4 files changed, 10 insertions(+), 60 deletions(-) diff --git a/i18n/ve-mw/api/en.json b/i18n/ve-mw/api/en.json index b060555125..99fc8b67d7 100644 --- a/i18n/ve-mw/api/en.json +++ b/i18n/ve-mw/api/en.json @@ -21,7 +21,6 @@ "Yuki Shira" ] }, - "apierror-visualeditor-api-langlinks-error": "Error querying MediaWiki API", "apierror-visualeditor-badcachekey": "No cached serialization found with that key", "apierror-visualeditor-difffailed": "Diff failed", "apierror-visualeditor-docserver-http-error": "$1", diff --git a/i18n/ve-mw/api/qqq.json b/i18n/ve-mw/api/qqq.json index 8aa4a6cf8f..9cb80aef96 100644 --- a/i18n/ve-mw/api/qqq.json +++ b/i18n/ve-mw/api/qqq.json @@ -30,7 +30,6 @@ "Woytecr" ] }, - "apierror-visualeditor-api-langlinks-error": "{{doc-apierror}}", "apierror-visualeditor-badcachekey": "{{doc-apierror}}", "apierror-visualeditor-difffailed": "{{doc-apierror}}", "apierror-visualeditor-docserver-http-error": "{{Ignored}}\n{{doc-apierror}}\n\nParameters:\n* $1 - Error message, probably in English", diff --git a/includes/ApiVisualEditor.php b/includes/ApiVisualEditor.php index bade61710b..5bab0650e7 100644 --- a/includes/ApiVisualEditor.php +++ b/includes/ApiVisualEditor.php @@ -208,48 +208,6 @@ class ApiVisualEditor extends ApiBase { return $content; } - /** - * Provide the current language links for a given page title - * - * @param Title $title The page title for which to get the current language links - * @return string[]|false The language links - */ - protected function getLangLinks( Title $title ) { - $apiParams = [ - 'action' => 'query', - 'prop' => 'langlinks', - 'lllimit' => 500, - 'titles' => $title->getPrefixedDBkey(), - ]; - $api = new ApiMain( - new DerivativeRequest( - $this->getRequest(), - $apiParams, - /* was posted? */ false - ), - /* enable write? */ true - ); - - $api->execute(); - $result = $api->getResult()->getResultData(); - if ( !isset( $result['query']['pages'][$title->getArticleID()] ) ) { - return false; - } - $page = $result['query']['pages'][$title->getArticleID()]; - if ( !isset( $page['langlinks'] ) ) { - return []; - } - $langlinks = $page['langlinks']; - $langnames = Language::fetchLanguageNames(); - foreach ( $langlinks as $i => $lang ) { - // Check is_array() to filter out API metadata (T218464) - if ( is_array( $lang ) && isset( $langnames[$lang['lang']] ) ) { - $langlinks[$i]['langname'] = $langnames[$lang['lang']]; - } - } - return $langlinks; - } - /** * @inheritDoc */ @@ -660,15 +618,6 @@ class ApiVisualEditor extends ApiBase { ]; } break; - - case 'getlanglinks': - $langlinks = $this->getLangLinks( $title ); - if ( $langlinks === false ) { - $this->dieWithError( 'apierror-visualeditor-api-langlinks-error', 'api-langlinks-error' ); - } else { - $result = [ 'result' => 'success', 'langlinks' => $langlinks ]; - } - break; } $this->getResult()->addValue( null, $this->getModuleName(), $result ); @@ -772,7 +721,6 @@ class ApiVisualEditor extends ApiBase { 'wikitext', 'parsefragment', 'parsedoc', - 'getlanglinks', ], ], 'wikitext' => null, diff --git a/modules/ve-mw/ui/pages/ve.ui.MWLanguagesPage.js b/modules/ve-mw/ui/pages/ve.ui.MWLanguagesPage.js index b7eca03ed2..b5dd6fac7a 100644 --- a/modules/ve-mw/ui/pages/ve.ui.MWLanguagesPage.js +++ b/modules/ve-mw/ui/pages/ve.ui.MWLanguagesPage.js @@ -110,13 +110,13 @@ ve.ui.MWLanguagesPage.prototype.onLoadLanguageData = function ( languages ) { */ ve.ui.MWLanguagesPage.prototype.onAllLanguageItemsSuccess = function ( deferred, response ) { var i, iLen, languages = [], - langlinks = response && response.visualeditor && response.visualeditor.langlinks; + langlinks = OO.getProp( response, 'query', 'pages', 0, 'langlinks' ); if ( langlinks ) { for ( i = 0, iLen = langlinks.length; i < iLen; i++ ) { languages.push( { lang: langlinks[ i ].lang, - langname: langlinks[ i ].langname, - title: langlinks[ i ][ '*' ], + langname: langlinks[ i ].autonym, + title: langlinks[ i ].title, metaItem: null } ); } @@ -168,9 +168,13 @@ ve.ui.MWLanguagesPage.prototype.getAllLanguageItems = function () { var deferred = $.Deferred(); // TODO: Detect paging token if results exceed limit ve.init.target.getContentApi().get( { - action: 'visualeditor', - paction: 'getlanglinks', - page: ve.init.target.getPageName() + format: 'json', + formatversion: 2, + action: 'query', + prop: 'langlinks', + llprop: 'autonym', + lllimit: 500, + titles: ve.init.target.getPageName() } ) .done( this.onAllLanguageItemsSuccess.bind( this, deferred ) ) .fail( this.onAllLanguageItemsError.bind( this, deferred ) );