Mholloway has uploaded a new change for review. ( 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, 68 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend refs/changes/55/381155/1 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..bbac27c --- /dev/null +++ b/tests/phpunit/api/ApiMobileViewConvertTitleTest.php @@ -0,0 +1,61 @@ +<?php + +/** +* @group Database +* @group MobileFrontend +* @group medium +*/ +class ApiMobileViewConvertTitleTest extends ApiTestCase { + + private $englishTitle = 'Foo'; + private $pigLatinTitle = 'Oofay'; + + protected function setUp() { + // We'll need to set a new Language object in the context after setting + // $wgUsePigLatinVariant to true so that LanguageEn picks up the en-x-piglatin + // variant. To do that, we'll need to disable Language object caching so that we + // don't end up just re-set a cached LanguageEn that lacks support for the variant. + $this->setMwGlobals( 'wgLangObjCacheSize', 0 ); + $this->setMwGlobals( 'wgUsePigLatinVariant', true ); + parent::setUp(); + + $this->setUserLang( 'en' ); + + $newPage = WikiPage::factory( Title::newFromText( $this->pigLatinTitle ) ); + $newPage->doEditContent( + ContentHandler::makeContent( "Arbay", $newPage->getTitle() ), 'test page' + ); + } + + public function testRequestConverted() { + + $result = $this->doApiRequest( [ + 'action' => 'mobileview', + 'page' => $this->englishTitle, + 'prop' => 'text', + 'sections' => 'all', + 'noheadings' => '', + ] ); + + $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->pigLatinTitle ); + $this->assertEquals( $convertedFrom, $this->englishTitle ); + } + + public function testRequestNotConverted() { + + $result = $this->doApiRequest( [ + 'action' => 'mobileview', + 'page' => $this->pigLatinTitle, + 'prop' => 'text', + 'sections' => 'all', + 'noheadings' => '', + ] ); + + $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: newchange Gerrit-Change-Id: I8a6042e8603a5a8927c90a56b82958d15b499772 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Mholloway <mhollo...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits