Merge "exception: Avoid preg_replace for literal swap"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 27 Sep 2018 19:45:41 +0000 (19:45 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 27 Sep 2018 19:45:41 +0000 (19:45 +0000)
includes/specials/SpecialImport.php
includes/specials/SpecialNewimages.php
tests/phpunit/includes/OutputPageTest.php

index 3ef64f8..153b7d1 100644 (file)
@@ -179,8 +179,8 @@ class SpecialImport extends SpecialPage {
 
                $out = $this->getOutput();
                if ( !$source->isGood() ) {
-                       $out->addWikiText( "<p class=\"error\">\n" .
-                               $this->msg( 'importfailed', $source->getWikiText() )->parse() . "\n</p>" );
+                       $out->addWikiText( "<div class=\"error\">\n" .
+                               $this->msg( 'importfailed', $source->getWikiText() )->parse() . "\n</div>" );
                } else {
                        $importer = new WikiImporter( $source->value, $this->getConfig() );
                        if ( !is_null( $this->namespace ) ) {
@@ -189,7 +189,7 @@ class SpecialImport extends SpecialPage {
                                $statusRootPage = $importer->setTargetRootPage( $this->rootpage );
                                if ( !$statusRootPage->isGood() ) {
                                        $out->wrapWikiMsg(
-                                               "<p class=\"error\">\n$1\n</p>",
+                                               "<div class=\"error\">\n$1\n</div>",
                                                [
                                                        'import-options-wrong',
                                                        $statusRootPage->getWikiText(),
@@ -224,13 +224,13 @@ class SpecialImport extends SpecialPage {
                        if ( $exception ) {
                                # No source or XML parse error
                                $out->wrapWikiMsg(
-                                       "<p class=\"error\">\n$1\n</p>",
+                                       "<div class=\"error\">\n$1\n</div>",
                                        [ 'importfailed', $exception->getMessage() ]
                                );
                        } elseif ( !$result->isGood() ) {
                                # Zero revisions
                                $out->wrapWikiMsg(
-                                       "<p class=\"error\">\n$1\n</p>",
+                                       "<div class=\"error\">\n$1\n</div>",
                                        [ 'importfailed', $result->getWikiText() ]
                                );
                        } else {
index 513d14c..e88162e 100644 (file)
@@ -219,16 +219,14 @@ class SpecialNewFiles extends IncludableSpecialPage {
                if ( !$message->isDisabled() ) {
                        $contLang = MediaWikiServices::getInstance()->getContentLanguage();
                        $this->getOutput()->addWikiTextTidy(
-                               Html::rawElement( 'p',
+                               Html::rawElement( 'div',
                                        [
 
                                                'lang' => $contLang->getHtmlCode(),
                                                'dir' => $contLang->getDir()
                                        ],
                                        "\n" . $message->plain() . "\n"
-                               ),
-                               /* $lineStart */ false,
-                               /* $interface */ false
+                               )
                        );
                }
        }
index 9d6122d..283e99f 100644 (file)
@@ -1508,6 +1508,36 @@ class OutputPageTest extends MediaWikiTestCase {
                $op->addWikiText( 'a' );
        }
 
+       /**
+        * @covers OutputPage::addWikiMsg
+        */
+       public function testAddWikiMsg() {
+               $msg = wfMessage( 'parentheses' );
+               $this->assertSame( '(a)', $msg->rawParams( 'a' )->plain() );
+
+               $op = $this->newInstance();
+               $this->assertSame( '', $op->getHTML() );
+               $op->addWikiMsg( 'parentheses', "<b>a" );
+               // This is known to be bad unbalanced HTML; this will be fixed
+               // by I743f4185a03403f8d9b9db010ff1ee4e9342e062 (T198214)
+               $this->assertSame( "<p>(<b>a)\n</p>", $op->getHTML() );
+       }
+
+       /**
+        * @covers OutputPage::wrapWikiMsg
+        */
+       public function testWrapWikiMsg() {
+               $msg = wfMessage( 'parentheses' );
+               $this->assertSame( '(a)', $msg->rawParams( 'a' )->plain() );
+
+               $op = $this->newInstance();
+               $this->assertSame( '', $op->getHTML() );
+               $op->wrapWikiMsg( '[$1]', [ 'parentheses', "<b>a" ] );
+               // This is known to be bad unbalanced HTML; this will be fixed
+               // by I743f4185a03403f8d9b9db010ff1ee4e9342e062 (T198214)
+               $this->assertSame( "<p>[(<b>a)]\n</p>", $op->getHTML() );
+       }
+
        /**
         * @covers OutputPage::addParserOutputMetadata
         */