jenkins-bot has submitted this change and it was merged.

Change subject: Create redirects to titles correctly in WikitextContentHandler
......................................................................


Create redirects to titles correctly in WikitextContentHandler

Bug: 50450
Bug: 50451
Change-Id: I6781420f01d8c90d47f4b9f3ad099cadf0f8ced5
---
M includes/content/WikitextContentHandler.php
M tests/phpunit/includes/content/WikitextContentHandlerTest.php
2 files changed, 42 insertions(+), 1 deletion(-)

Approvals:
  Daniel Kinzler: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/content/WikitextContentHandler.php 
b/includes/content/WikitextContentHandler.php
index e1dcc66..8be85bc 100644
--- a/includes/content/WikitextContentHandler.php
+++ b/includes/content/WikitextContentHandler.php
@@ -59,8 +59,19 @@
         * @return Content
         */
        public function makeRedirectContent( Title $destination ) {
+               $optionalColon = '';
+
+               if ( $destination->getNamespace() == NS_CATEGORY ) {
+                       $optionalColon = ':';
+               } else {
+                       $iw = $destination->getInterwiki();
+                       if ( $iw && Language::fetchLanguageName( $iw, null, 
'mw' ) ) {
+                               $optionalColon = ':';
+                       }
+               }
+
                $mwRedir = MagicWord::get( 'redirect' );
-               $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . 
$destination->getPrefixedText() . ']]';
+               $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . 
$optionalColon . $destination->getFullText() . ']]';
 
                return new WikitextContent( $redirectText );
        }
diff --git a/tests/phpunit/includes/content/WikitextContentHandlerTest.php 
b/tests/phpunit/includes/content/WikitextContentHandlerTest.php
index 45d8140..d213251 100644
--- a/tests/phpunit/includes/content/WikitextContentHandlerTest.php
+++ b/tests/phpunit/includes/content/WikitextContentHandlerTest.php
@@ -61,6 +61,36 @@
        }
 
        /**
+        * @dataProvider provideMakeRedirectContent
+        * @param Title|string $title Title object or string for 
Title::newFromText()
+        * @param string $expected Serialized form of the content object built
+        */
+       public function testMakeRedirectContent( $title, $expected ) {
+               global $wgContLang;
+               $wgContLang->resetNamespaces();
+
+               if ( is_string( $title ) ) {
+                       $title = Title::newFromText( $title );
+               }
+               $content = $this->handler->makeRedirectContent( $title );
+               $this->assertEquals( $expected, $content->serialize() );
+       }
+
+       public static function provideMakeRedirectContent() {
+               return array(
+                       array( 'Hello', '#REDIRECT [[Hello]]' ),
+                       array( 'Template:Hello', '#REDIRECT [[Template:Hello]]' 
),
+                       array( 'Hello#section', '#REDIRECT [[Hello#section]]' ),
+                       array( 'user:john_doe#section', '#REDIRECT [[User:John 
doe#section]]' ),
+                       array( 'MEDIAWIKI:FOOBAR', '#REDIRECT 
[[MediaWiki:FOOBAR]]' ),
+                       array( 'Category:Foo', '#REDIRECT [[:Category:Foo]]' ),
+                       array( Title::makeTitle( NS_MAIN, 'en:Foo' ), 
'#REDIRECT [[en:Foo]]' ),
+                       array( Title::makeTitle( NS_MAIN, 'Foo', '', 'en' ), 
'#REDIRECT [[:en:Foo]]' ),
+                       array( Title::makeTitle( NS_MAIN, 'Bar', 'fragment', 
'google' ), '#REDIRECT [[google:Bar#fragment]]' ),
+               );
+       }
+
+       /**
         * @dataProvider dataIsSupportedFormat
         */
        public function testIsSupportedFormat( $format, $supported ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/71272
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6781420f01d8c90d47f4b9f3ad099cadf0f8ced5
Gerrit-PatchSet: 12
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Liangent <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Brian Wolff <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Denny Vrandecic <[email protected]>
Gerrit-Reviewer: Liangent <[email protected]>
Gerrit-Reviewer: Matmarex <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to