Use OutputPage::addWikiTextAsInterface() instead of untidy addWikiText()
authorC. Scott Ananian <cscott@cscott.net>
Tue, 25 Sep 2018 15:02:07 +0000 (11:02 -0400)
committerC. Scott Ananian <cscott@cscott.net>
Wed, 17 Oct 2018 14:35:28 +0000 (10:35 -0400)
This change ensures that the output is tidy, and is necessary to support
future parsers which will not be able to produce untidy output.

Bug: T198214
Change-Id: I743f4185a03403f8d9b9db010ff1ee4e9342e062

20 files changed:
includes/EditPage.php
includes/FileDeleteForm.php
includes/OutputPage.php
includes/ProtectionForm.php
includes/page/Article.php
includes/page/ImagePage.php
includes/specialpage/ChangesListSpecialPage.php
includes/specialpage/LoginSignupSpecialPage.php
includes/specials/SpecialBooksources.php
includes/specials/SpecialConfirmemail.php
includes/specials/SpecialEditTags.php
includes/specials/SpecialImport.php
includes/specials/SpecialMediaStatistics.php
includes/specials/SpecialRevisiondelete.php
includes/specials/SpecialSpecialpages.php
includes/specials/SpecialTags.php
includes/specials/SpecialUndelete.php
includes/specials/SpecialUserrights.php
includes/specials/SpecialVersion.php
tests/phpunit/includes/OutputPageTest.php

index 7143c3f..03b7b45 100644 (file)
@@ -794,7 +794,7 @@ class EditPage {
                $out->addHTML( $this->editFormTextTop );
 
                if ( $errorMessage !== '' ) {
-                       $out->addWikiText( $errorMessage );
+                       $out->addWikiTextAsInterface( $errorMessage );
                        $out->addHTML( "<hr />\n" );
                }
 
@@ -1640,7 +1640,11 @@ class EditPage {
                        case self::AS_CANNOT_USE_CUSTOM_MODEL:
                        case self::AS_PARSE_ERROR:
                        case self::AS_UNICODE_NOT_SUPPORTED:
-                               $out->addWikiText( '<div class="error">' . "\n" . $status->getWikiText() . '</div>' );
+                               $out->addWikiTextAsInterface(
+                                       '<div class="error">' . "\n" .
+                                       $status->getWikiText() .
+                                       '</div>'
+                               );
                                return true;
 
                        case self::AS_SUCCESS_NEW_ARTICLE:
@@ -2991,7 +2995,7 @@ ERROR;
                                        $this->contentFormat,
                                        $ex->getMessage()
                                );
-                               $out->addWikiText( '<div class="error">' . $msg->plain() . '</div>' );
+                               $out->addWikiTextAsInterface( '<div class="error">' . $msg->plain() . '</div>' );
                        }
                }
 
@@ -3109,7 +3113,7 @@ ERROR;
                        }
 
                        if ( $this->hookError !== '' ) {
-                               $out->addWikiText( $this->hookError );
+                               $out->addWikiTextAsInterface( $this->hookError );
                        }
 
                        if ( $this->section != 'new' ) {
@@ -3466,7 +3470,7 @@ ERROR;
                                        $this->contentFormat,
                                        $ex->getMessage()
                                );
-                               $out->addWikiText( '<div class="error">' . $msg->plain() . '</div>' );
+                               $out->addWikiTextAsInterface( '<div class="error">' . $msg->plain() . '</div>' );
                        }
                }
        }
@@ -3707,7 +3711,7 @@ ERROR;
                $out->addHTML( "<div class='editCheckboxes'>" . $checkboxesHTML . "</div>\n" );
 
                // Show copyright warning.
-               $out->addWikiText( $this->getCopywarn() );
+               $out->addWikiTextAsInterface( $this->getCopywarn() );
                $out->addHTML( $this->editFormTextAfterWarn );
 
                $out->addHTML( "<div class='editButtons'>\n" );
index c362ec0..f23d6ec 100644 (file)
@@ -120,7 +120,7 @@ class FileDeleteForm {
 
                        if ( !$status->isGood() ) {
                                $wgOut->addHTML( '<h2>' . $this->prepareMessage( 'filedeleteerror-short' ) . "</h2>\n" );
-                               $wgOut->addWikiText( '<div class="error">' .
+                               $wgOut->addWikiTextAsInterface( '<div class="error">' .
                                        $status->getWikiText( 'filedeleteerror-short', 'filedeleteerror-long' )
                                        . '</div>' );
                        }
index a5f5fab..d3a8d0c 100644 (file)
@@ -2773,7 +2773,7 @@ class OutputPage extends ContextSource {
                        }
                } else {
                        $this->prepareErrorPage( $this->msg( 'permissionserrors' ) );
-                       $this->addWikiText( $this->formatPermissionsErrorMessage( $errors, $action ) );
+                       $this->addWikiTextAsInterface( $this->formatPermissionsErrorMessage( $errors, $action ) );
                }
        }
 
@@ -4044,7 +4044,7 @@ class OutputPage extends ContextSource {
         *
         * Is equivalent to:
         *
-        *    $wgOut->addWikiText( "<div class='error'>\n"
+        *    $wgOut->addWikiTextAsInterface( "<div class='error'>\n"
         *        . wfMessage( 'some-error' )->plain() . "\n</div>" );
         *
         * The newline after the opening div is needed in some wikitext. See T21226.
@@ -4073,7 +4073,7 @@ class OutputPage extends ContextSource {
                        }
                        $s = str_replace( '$' . ( $n + 1 ), $this->msg( $name, $args )->plain(), $s );
                }
-               $this->addWikiText( $s );
+               $this->addWikiTextAsInterface( $s );
        }
 
        /**
index eacd370..0d0654e 100644 (file)
@@ -216,7 +216,9 @@ class ProtectionForm {
                                'protect-norestrictiontypes-title',
                                $this->mTitle->getPrefixedText()
                        ) );
-                       $out->addWikiText( $this->mContext->msg( 'protect-norestrictiontypes-text' )->plain() );
+                       $out->addWikiTextAsInterface(
+                               $this->mContext->msg( 'protect-norestrictiontypes-text' )->plain()
+                       );
 
                        // Show the log in case protection was possible once
                        $this->showLogExtract( $out );
@@ -246,7 +248,9 @@ class ProtectionForm {
                                $this->mContext->msg( 'protect-title-notallowed',
                                        $this->mTitle->getPrefixedText() )
                        );
-                       $out->addWikiText( $out->formatPermissionsErrorMessage( $this->mPermErrors, 'protect' ) );
+                       $out->addWikiTextAsInterface( $out->formatPermissionsErrorMessage(
+                               $this->mPermErrors, 'protect'
+                       ) );
                } else {
                        $out->setPageTitle( $this->mContext->msg( 'protect-title', $this->mTitle->getPrefixedText() ) );
                        $out->addWikiMsg( 'protect-text',
index 803bf0a..8bc8d1e 100644 (file)
@@ -792,7 +792,7 @@ class Article implements Page {
                                                        $outputPage->setRobotPolicy( 'noindex,nofollow' );
 
                                                        $errortext = $error->getWikiText( false, 'view-pool-error' );
-                                                       $outputPage->addWikiText( Html::errorBox( $errortext ) );
+                                                       $outputPage->addWikiTextAsInterface( Html::errorBox( $errortext ) );
                                                }
                                                # Connection or timeout error
                                                return;
@@ -1461,7 +1461,7 @@ class Article implements Page {
 
                        $dir = $this->getContext()->getLanguage()->getDir();
                        $lang = $this->getContext()->getLanguage()->getHtmlCode();
-                       $outputPage->addWikiText( Xml::openElement( 'div', [
+                       $outputPage->addWikiTextAsInterface( Xml::openElement( 'div', [
                                'class' => "noarticletext mw-content-$dir",
                                'dir' => $dir,
                                'lang' => $lang,
@@ -2087,7 +2087,7 @@ class Article implements Page {
                        );
 
                        if ( $error == '' ) {
-                               $outputPage->addWikiText(
+                               $outputPage->addWikiTextAsInterface(
                                        "<div class=\"error mw-error-cannotdelete\">\n" . $status->getWikiText() . "\n</div>"
                                );
                                $deleteLogPage = new LogPage( 'delete' );
index bf3eaf4..2489386 100644 (file)
@@ -161,7 +161,7 @@ class ImagePage extends Article {
                if ( $this->mExtraDescription ) {
                        $fol = $this->getContext()->msg( 'shareddescriptionfollows' );
                        if ( !$fol->isDisabled() ) {
-                               $out->addWikiText( $fol->plain() );
+                               $out->addWikiTextAsInterface( $fol->plain() );
                        }
                        $out->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . "</div>\n" );
                }
@@ -190,7 +190,7 @@ class ImagePage extends Article {
                                'h2',
                                [ 'id' => 'metadata' ],
                                        $this->getContext()->msg( 'metadata' )->text() ) . "\n" );
-                       $out->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
+                       $out->addWikiTextAsInterface( $this->makeMetadataTable( $formattedMetadata ) );
                        $out->addModules( [ 'mediawiki.action.view.metadata' ] );
                }
 
@@ -542,14 +542,14 @@ class ImagePage extends Article {
                                // to the filename, because it can get copied with it.
                                // See T27277.
                                // phpcs:disable Generic.Files.LineLength
-                               $out->addWikiText( <<<EOT
+                               $out->addWikiTextAsInterface( <<<EOT
 <div class="fullMedia"><span class="dangerousLink">{$medialink}</span> $dirmark<span class="fileInfo">$longDesc</span></div>
 <div class="mediaWarning">$warning</div>
 EOT
                                );
                                // phpcs:enable
                        } else {
-                               $out->addWikiText( <<<EOT
+                               $out->addWikiTextAsInterface( <<<EOT
 <div class="fullMedia">{$medialink} {$dirmark}<span class="fileInfo">$longDesc</span>
 </div>
 EOT
@@ -574,7 +574,7 @@ EOT
                                        'file-no-thumb-animation'
                                )->plain();
 
-                               $out->addWikiText( <<<EOT
+                               $out->addWikiTextAsInterface( <<<EOT
 <div class="mw-noanimatethumb">{$noAnimMesg}</div>
 EOT
                                );
@@ -1005,7 +1005,7 @@ EOT
                $out->setRobotPolicy( 'noindex,nofollow' );
                $out->setArticleRelated( false );
                $out->enableClientCache( false );
-               $out->addWikiText( $description );
+               $out->addWikiTextAsInterface( $description );
        }
 
        /**
index 8ae4649..887b13a 100644 (file)
@@ -1591,7 +1591,8 @@ abstract class ChangesListSpecialPage extends SpecialPage {
        }
 
        /**
-        * Send the text to be displayed before the options. Should use $this->getOutput()->addWikiText()
+        * Send the text to be displayed before the options.
+        * Should use $this->getOutput()->addWikiTextAsInterface()
         * or similar methods to print the text.
         *
         * @param FormOptions $opts
@@ -1601,7 +1602,8 @@ abstract class ChangesListSpecialPage extends SpecialPage {
        }
 
        /**
-        * Send the text to be displayed after the options. Should use $this->getOutput()->addWikiText()
+        * Send the text to be displayed after the options.
+        * Should use $this->getOutput()->addWikiTextAsInterface()
         * or similar methods to print the text.
         *
         * @param FormOptions $opts
index 99a5a9a..eb2259e 100644 (file)
@@ -445,7 +445,7 @@ abstract class LoginSignupSpecialPage extends AuthManagerSpecialPage {
                }
                if ( $extraMessages ) {
                        $extraMessages = Status::wrap( $extraMessages );
-                       $out->addWikiText( $extraMessages->getWikiText() );
+                       $out->addWikiTextAsInterface( $extraMessages->getWikiText() );
                }
 
                $out->addHTML( $injected_html );
index c187156..02c33b5 100644 (file)
@@ -172,7 +172,7 @@ class SpecialBookSources extends SpecialPage {
                                // XXX: in the future, this could be stored as structured data, defining a list of book sources
 
                                $text = $content->getNativeData();
-                               $out->addWikiText( str_replace( 'MAGICNUMBER', $isbn, $text ) );
+                               $out->addWikiTextAsInterface( str_replace( 'MAGICNUMBER', $isbn, $text ) );
 
                                return true;
                        } else {
index f494b9d..b51f92f 100644 (file)
@@ -110,7 +110,7 @@ class EmailConfirmation extends UnlistedSpecialPage {
                                // should never happen, but if so, don't let the user without any message
                                $out->addWikiMsg( 'confirmemail_sent' );
                        } elseif ( $retval instanceof Status && $retval->isGood() ) {
-                               $out->addWikiText( $retval->getValue() );
+                               $out->addWikiTextAsInterface( $retval->getValue() );
                        }
                } else {
                        // date and time are separate parameters to facilitate localisation.
index b657335..c5914ba 100644 (file)
@@ -454,7 +454,7 @@ class SpecialEditTags extends UnlistedSpecialPage {
         */
        protected function failure( $status ) {
                $this->getOutput()->setPageTitle( $this->msg( 'actionfailed' ) );
-               $this->getOutput()->addWikiText(
+               $this->getOutput()->addWikiTextAsInterface(
                        Html::errorBox( $status->getWikiText( 'tags-edit-failure' ) )
                );
                $this->showForm();
index 153b7d1..12b8d50 100644 (file)
@@ -179,7 +179,7 @@ class SpecialImport extends SpecialPage {
 
                $out = $this->getOutput();
                if ( !$source->isGood() ) {
-                       $out->addWikiText( "<div class=\"error\">\n" .
+                       $out->addWikiTextAsInterface( "<div class=\"error\">\n" .
                                $this->msg( 'importfailed', $source->getWikiText() )->parse() . "\n</div>" );
                } else {
                        $importer = new WikiImporter( $source->value, $this->getConfig() );
index 6dbc09b..b6812bc 100644 (file)
@@ -143,7 +143,7 @@ class MediaStatisticsPage extends QueryPage {
                        $this->outputTableEnd();
                        // add total size of all files
                        $this->outputMediaType( 'total' );
-                       $this->getOutput()->addWikiText(
+                       $this->getOutput()->addWikiTextAsInterface(
                                $this->msg( 'mediastatistics-allbytes' )
                                        ->numParams( $this->totalSize )
                                        ->sizeParams( $this->totalSize )
@@ -157,7 +157,7 @@ class MediaStatisticsPage extends QueryPage {
         */
        protected function outputTableEnd() {
                $this->getOutput()->addHTML( Html::closeElement( 'table' ) );
-               $this->getOutput()->addWikiText(
+               $this->getOutput()->addWikiTextAsInterface(
                                $this->msg( 'mediastatistics-bytespertype' )
                                        ->numParams( $this->totalPerType )
                                        ->sizeParams( $this->totalPerType )
index e7db9f5..dba4fb8 100644 (file)
@@ -641,7 +641,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
        protected function failure( $status ) {
                // Messages: revdelete-failure, logdelete-failure
                $this->getOutput()->setPageTitle( $this->msg( 'actionfailed' ) );
-               $this->getOutput()->addWikiText(
+               $this->getOutput()->addWikiTextAsInterface(
                        Html::errorBox(
                                $status->getWikiText( $this->typeLabels['failure'] )
                        )
index 00aa543..6bb0a1c 100644 (file)
@@ -151,7 +151,7 @@ class SpecialSpecialpages extends UnlistedSpecialPage {
                        $out->wrapWikiMsg(
                                "<h2 class=\"mw-specialpages-note-top\">$1</h2>", 'specialpages-note-top'
                        );
-                       $out->addWikiText(
+                       $out->addWikiTextAsInterface(
                                "<div class=\"mw-specialpages-notes\">\n" .
                                implode( "\n", $notes ) .
                                "\n</div>"
index 6b0598c..9a9f4f2 100644 (file)
@@ -321,7 +321,7 @@ class SpecialTags extends SpecialPage {
                        $out->addBacklinkSubtitle( $this->getPageTitle() );
                        return true;
                } else {
-                       $out->addWikiText( "<div class=\"error\">\n" . $status->getWikiText() .
+                       $out->addWikiTextAsInterface( "<div class=\"error\">\n" . $status->getWikiText() .
                                "\n</div>" );
                        return false;
                }
@@ -340,7 +340,7 @@ class SpecialTags extends SpecialPage {
                // is the tag actually able to be deleted?
                $canDeleteResult = ChangeTags::canDeleteTag( $tag, $user );
                if ( !$canDeleteResult->isGood() ) {
-                       $out->addWikiText( "<div class=\"error\">\n" . $canDeleteResult->getWikiText() .
+                       $out->addWikiTextAsInterface( "<div class=\"error\">\n" . $canDeleteResult->getWikiText() .
                                "\n</div>" );
                        if ( !$canDeleteResult->isOK() ) {
                                return;
@@ -402,7 +402,7 @@ class SpecialTags extends SpecialPage {
                $func = $activate ? 'canActivateTag' : 'canDeactivateTag';
                $result = ChangeTags::$func( $tag, $user );
                if ( !$result->isGood() ) {
-                       $out->addWikiText( "<div class=\"error\">\n" . $result->getWikiText() .
+                       $out->addWikiTextAsInterface( "<div class=\"error\">\n" . $result->getWikiText() .
                                "\n</div>" );
                        if ( !$result->isOK() ) {
                                return;
@@ -449,13 +449,13 @@ class SpecialTags extends SpecialPage {
                        return true;
                } elseif ( $status->isOK() && $form->tagAction === 'delete' ) {
                        // deletion succeeded, but hooks raised a warning
-                       $out->addWikiText( $this->msg( 'tags-delete-warnings-after-delete', $tag,
+                       $out->addWikiTextAsInterface( $this->msg( 'tags-delete-warnings-after-delete', $tag,
                                count( $status->getWarningsArray() ) )->text() . "\n" .
                                $status->getWikitext() );
                        $out->addReturnTo( $this->getPageTitle() );
                        return true;
                } else {
-                       $out->addWikiText( "<div class=\"error\">\n" . $status->getWikitext() .
+                       $out->addWikiTextAsInterface( "<div class=\"error\">\n" . $status->getWikitext() .
                                "\n</div>" );
                        return false;
                }
index e4e513e..be3433f 100644 (file)
@@ -1177,7 +1177,7 @@ class SpecialUndelete extends SpecialPage {
                // Show revision undeletion warnings and errors
                $status = $archive->getRevisionStatus();
                if ( $status && !$status->isGood() ) {
-                       $out->addWikiText( '<div class="error" id="mw-error-cannotundelete">' .
+                       $out->addWikiTextAsInterface( '<div class="error" id="mw-error-cannotundelete">' .
                                $status->getWikiText(
                                        'cannotundelete',
                                        'cannotundelete'
@@ -1188,7 +1188,7 @@ class SpecialUndelete extends SpecialPage {
                // Show file undeletion warnings and errors
                $status = $archive->getFileStatus();
                if ( $status && !$status->isGood() ) {
-                       $out->addWikiText( '<div class="error">' .
+                       $out->addWikiTextAsInterface( '<div class="error">' .
                                $status->getWikiText(
                                        'undelete-error-short',
                                        'undelete-error-long'
index 4205188..60f98f1 100644 (file)
@@ -160,7 +160,7 @@ class UserrightsPage extends SpecialPage {
 
                        // save settings
                        if ( !$fetchedStatus->isOK() ) {
-                               $this->getOutput()->addWikiText( $fetchedStatus->getWikiText() );
+                               $this->getOutput()->addWikiTextAsInterface( $fetchedStatus->getWikiText() );
 
                                return;
                        }
@@ -189,7 +189,7 @@ class UserrightsPage extends SpecialPage {
                                        return;
                                } else {
                                        // Print an error message and redisplay the form
-                                       $out->addWikiText( '<div class="error">' . $status->getWikiText() . '</div>' );
+                                       $out->addWikiTextAsInterface( '<div class="error">' . $status->getWikiText() . '</div>' );
                                }
                        }
                }
@@ -468,7 +468,7 @@ class UserrightsPage extends SpecialPage {
        function editUserGroupsForm( $username ) {
                $status = $this->fetchUser( $username, true );
                if ( !$status->isOK() ) {
-                       $this->getOutput()->addWikiText( $status->getWikiText() );
+                       $this->getOutput()->addWikiTextAsInterface( $status->getWikiText() );
 
                        return;
                } else {
index 35c5689..4e9245f 100644 (file)
@@ -106,7 +106,7 @@ class SpecialVersion extends SpecialPage {
                                }
 
                                $out->setPageTitle( $this->msg( 'version-credits-title', $extName ) );
-                               $out->addWikiText( $wikiText );
+                               $out->addWikiTextAsInterface( $wikiText );
                                break;
 
                        case 'license':
@@ -129,12 +129,12 @@ class SpecialVersion extends SpecialPage {
                                }
 
                                $out->setPageTitle( $this->msg( 'version-license-title', $extName ) );
-                               $out->addWikiText( $wikiText );
+                               $out->addWikiTextAsInterface( $wikiText );
                                break;
 
                        default:
                                $out->addModuleStyles( 'mediawiki.special.version' );
-                               $out->addWikiText(
+                               $out->addWikiTextAsInterface(
                                        $this->getMediaWikiCredits() .
                                        $this->softwareInformation() .
                                        $this->getEntryPointInfo()
@@ -146,7 +146,7 @@ class SpecialVersion extends SpecialPage {
                                        $this->getParserTags() .
                                        $this->getParserFunctionHooks()
                                );
-                               $out->addWikiText( $this->getWgHooks() );
+                               $out->addWikiTextAsInterface( $this->getWgHooks() );
                                $out->addHTML( $this->IPInfo() );
 
                                break;
index 211169e..18d2a8a 100644 (file)
@@ -1665,9 +1665,8 @@ class OutputPageTest extends MediaWikiTestCase {
                $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() );
+               // The input is bad unbalanced HTML, but the output is tidied
+               $this->assertSame( "<p>[(<b>a)]\n</b></p>", $op->getHTML() );
        }
 
        /**