Merge "Directly call action=query&prop=langlinks from JS rather than PHP wrapper"

This commit is contained in:
jenkins-bot 2019-03-19 14:32:21 +00:00 committed by Gerrit Code Review
commit 2101a0f661
4 changed files with 10 additions and 60 deletions

View file

@ -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",

View file

@ -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",

View file

@ -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,

View file

@ -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 ) );