jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/381155 )
Change subject: ApiMobileView: Support queries for titles in any language
variant
......................................................................
ApiMobileView: Support queries for titles in any language variant
Adds a call to Language::findVariantLink in makeTitle so that results
will be returned for any title with content available, regardless of the
language variant the title is provided in.
Bug: T176678
Change-Id: I8a6042e8603a5a8927c90a56b82958d15b499772
---
M includes/api/ApiMobileView.php
A tests/phpunit/api/ApiMobileViewConvertTitleTest.php
2 files changed, 54 insertions(+), 0 deletions(-)
Approvals:
jenkins-bot: Verified
Jdlrobson: Looks good to me, approved
diff --git a/includes/api/ApiMobileView.php b/includes/api/ApiMobileView.php
index 0e1c2d4..001733b 100644
--- a/includes/api/ApiMobileView.php
+++ b/includes/api/ApiMobileView.php
@@ -286,10 +286,17 @@
* @return Title
*/
protected function makeTitle( $name ) {
+ global $wgContLang;
$title = Title::newFromText( $name );
if ( !$title ) {
$this->dieWithError( [ 'apierror-invalidtitle',
wfEscapeWikiText( $name ) ] );
}
+ $unconvertedTitle = $title->getPrefixedText();
+ $wgContLang->findVariantLink( $name, $title );
+ if ( $unconvertedTitle !== $title->getPrefixedText() ) {
+ $values = [ 'from' => $unconvertedTitle, 'to' =>
$title->getPrefixedText() ];
+ $this->getResult()->addValue( 'mobileview',
'converted', $values );
+ }
if ( $title->inNamespace( NS_FILE ) ) {
$this->file = $this->findFile( $title );
}
diff --git a/tests/phpunit/api/ApiMobileViewConvertTitleTest.php
b/tests/phpunit/api/ApiMobileViewConvertTitleTest.php
new file mode 100644
index 0000000..6749514
--- /dev/null
+++ b/tests/phpunit/api/ApiMobileViewConvertTitleTest.php
@@ -0,0 +1,47 @@
+<?php
+
+/**
+* @group Database
+* @group MobileFrontend
+* @group medium
+*/
+class ApiMobileViewConvertTitleTest extends ApiTestCase {
+
+ private $simplifiedTitle = '天闻角川';
+ private $traditionalTitle = '天聞角川';
+
+ protected function setUp() {
+ parent::setUp();
+ $this->setUserLang( 'zh' );
+ $this->setContentLang( 'zh' );
+ $this->editPage( $this->simplifiedTitle, 'foo', 'test page' );
+ }
+
+ public function testRequestConverted() {
+ $result = $this->doApiRequest( [
+ 'action' => 'mobileview',
+ 'page' => $this->traditionalTitle,
+ 'prop' => 'text',
+ 'sections' => 'all',
+ ] );
+
+ $this->assertArrayHasKey( 'mobileview', $result[0] );
+ $this->assertArrayHasKey( 'converted', $result[0]['mobileview']
);
+ $convertedFrom = $result[0]['mobileview']['converted']['from'];
+ $convertedTo = $result[0]['mobileview']['converted']['to'];
+ $this->assertEquals( $convertedTo, $this->simplifiedTitle );
+ $this->assertEquals( $convertedFrom, $this->traditionalTitle );
+ }
+
+ public function testRequestNotConverted() {
+ $result = $this->doApiRequest( [
+ 'action' => 'mobileview',
+ 'page' => $this->simplifiedTitle,
+ 'prop' => 'text',
+ 'sections' => 'all',
+ ] );
+
+ $this->assertArrayHasKey( 'mobileview', $result[0] );
+ $this->assertArrayNotHasKey( 'converted',
$result[0]['mobileview'] );
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/381155
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8a6042e8603a5a8927c90a56b82958d15b499772
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Mholloway <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Mholloway <[email protected]>
Gerrit-Reviewer: Pmiazga <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits