From: C. Scott Ananian Date: Tue, 25 Sep 2018 15:02:07 +0000 (-0400) Subject: Use OutputPage::addWikiTextAsInterface() instead of untidy addWikiText() X-Git-Tag: 1.34.0-rc.0~3705^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=c0ed2620535b798f2826fecc4ee998380209be5d Use OutputPage::addWikiTextAsInterface() instead of untidy addWikiText() 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 --- diff --git a/includes/EditPage.php b/includes/EditPage.php index 7143c3f324..03b7b45b88 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -794,7 +794,7 @@ class EditPage { $out->addHTML( $this->editFormTextTop ); if ( $errorMessage !== '' ) { - $out->addWikiText( $errorMessage ); + $out->addWikiTextAsInterface( $errorMessage ); $out->addHTML( "
\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( '
' . "\n" . $status->getWikiText() . '
' ); + $out->addWikiTextAsInterface( + '
' . "\n" . + $status->getWikiText() . + '
' + ); return true; case self::AS_SUCCESS_NEW_ARTICLE: @@ -2991,7 +2995,7 @@ ERROR; $this->contentFormat, $ex->getMessage() ); - $out->addWikiText( '
' . $msg->plain() . '
' ); + $out->addWikiTextAsInterface( '
' . $msg->plain() . '
' ); } } @@ -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( '
' . $msg->plain() . '
' ); + $out->addWikiTextAsInterface( '
' . $msg->plain() . '
' ); } } } @@ -3707,7 +3711,7 @@ ERROR; $out->addHTML( "
" . $checkboxesHTML . "
\n" ); // Show copyright warning. - $out->addWikiText( $this->getCopywarn() ); + $out->addWikiTextAsInterface( $this->getCopywarn() ); $out->addHTML( $this->editFormTextAfterWarn ); $out->addHTML( "
\n" ); diff --git a/includes/FileDeleteForm.php b/includes/FileDeleteForm.php index c362ec0528..f23d6ec0fb 100644 --- a/includes/FileDeleteForm.php +++ b/includes/FileDeleteForm.php @@ -120,7 +120,7 @@ class FileDeleteForm { if ( !$status->isGood() ) { $wgOut->addHTML( '

' . $this->prepareMessage( 'filedeleteerror-short' ) . "

\n" ); - $wgOut->addWikiText( '
' . + $wgOut->addWikiTextAsInterface( '
' . $status->getWikiText( 'filedeleteerror-short', 'filedeleteerror-long' ) . '
' ); } diff --git a/includes/OutputPage.php b/includes/OutputPage.php index a5f5fab08a..d3a8d0c6c2 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -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( "
\n" + * $wgOut->addWikiTextAsInterface( "
\n" * . wfMessage( 'some-error' )->plain() . "\n
" ); * * 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 ); } /** diff --git a/includes/ProtectionForm.php b/includes/ProtectionForm.php index eacd370afd..0d0654e8fa 100644 --- a/includes/ProtectionForm.php +++ b/includes/ProtectionForm.php @@ -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', diff --git a/includes/page/Article.php b/includes/page/Article.php index 803bf0a2b2..8bc8d1e0e7 100644 --- a/includes/page/Article.php +++ b/includes/page/Article.php @@ -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( "
\n" . $status->getWikiText() . "\n
" ); $deleteLogPage = new LogPage( 'delete' ); diff --git a/includes/page/ImagePage.php b/includes/page/ImagePage.php index bf3eaf41d8..248938648a 100644 --- a/includes/page/ImagePage.php +++ b/includes/page/ImagePage.php @@ -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( '
' . $this->mExtraDescription . "
\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( <<addWikiTextAsInterface( <<{$medialink} $dirmark$longDesc
$warning
EOT ); // phpcs:enable } else { - $out->addWikiText( <<addWikiTextAsInterface( <<{$medialink} {$dirmark}$longDesc
EOT @@ -574,7 +574,7 @@ EOT 'file-no-thumb-animation' )->plain(); - $out->addWikiText( <<addWikiTextAsInterface( <<{$noAnimMesg}
EOT ); @@ -1005,7 +1005,7 @@ EOT $out->setRobotPolicy( 'noindex,nofollow' ); $out->setArticleRelated( false ); $out->enableClientCache( false ); - $out->addWikiText( $description ); + $out->addWikiTextAsInterface( $description ); } /** diff --git a/includes/specialpage/ChangesListSpecialPage.php b/includes/specialpage/ChangesListSpecialPage.php index 8ae4649e02..887b13a281 100644 --- a/includes/specialpage/ChangesListSpecialPage.php +++ b/includes/specialpage/ChangesListSpecialPage.php @@ -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 diff --git a/includes/specialpage/LoginSignupSpecialPage.php b/includes/specialpage/LoginSignupSpecialPage.php index 99a5a9a844..eb2259ec42 100644 --- a/includes/specialpage/LoginSignupSpecialPage.php +++ b/includes/specialpage/LoginSignupSpecialPage.php @@ -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 ); diff --git a/includes/specials/SpecialBooksources.php b/includes/specials/SpecialBooksources.php index c187156bee..02c33b543f 100644 --- a/includes/specials/SpecialBooksources.php +++ b/includes/specials/SpecialBooksources.php @@ -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 { diff --git a/includes/specials/SpecialConfirmemail.php b/includes/specials/SpecialConfirmemail.php index f494b9d666..b51f92fa09 100644 --- a/includes/specials/SpecialConfirmemail.php +++ b/includes/specials/SpecialConfirmemail.php @@ -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. diff --git a/includes/specials/SpecialEditTags.php b/includes/specials/SpecialEditTags.php index b657335e31..c5914bae2f 100644 --- a/includes/specials/SpecialEditTags.php +++ b/includes/specials/SpecialEditTags.php @@ -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(); diff --git a/includes/specials/SpecialImport.php b/includes/specials/SpecialImport.php index 153b7d1e2b..12b8d50f70 100644 --- a/includes/specials/SpecialImport.php +++ b/includes/specials/SpecialImport.php @@ -179,7 +179,7 @@ class SpecialImport extends SpecialPage { $out = $this->getOutput(); if ( !$source->isGood() ) { - $out->addWikiText( "
\n" . + $out->addWikiTextAsInterface( "
\n" . $this->msg( 'importfailed', $source->getWikiText() )->parse() . "\n
" ); } else { $importer = new WikiImporter( $source->value, $this->getConfig() ); diff --git a/includes/specials/SpecialMediaStatistics.php b/includes/specials/SpecialMediaStatistics.php index 6dbc09bae0..b6812bca6b 100644 --- a/includes/specials/SpecialMediaStatistics.php +++ b/includes/specials/SpecialMediaStatistics.php @@ -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 ) diff --git a/includes/specials/SpecialRevisiondelete.php b/includes/specials/SpecialRevisiondelete.php index e7db9f5e3c..dba4fb8866 100644 --- a/includes/specials/SpecialRevisiondelete.php +++ b/includes/specials/SpecialRevisiondelete.php @@ -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'] ) ) diff --git a/includes/specials/SpecialSpecialpages.php b/includes/specials/SpecialSpecialpages.php index 00aa543a88..6bb0a1c077 100644 --- a/includes/specials/SpecialSpecialpages.php +++ b/includes/specials/SpecialSpecialpages.php @@ -151,7 +151,7 @@ class SpecialSpecialpages extends UnlistedSpecialPage { $out->wrapWikiMsg( "

$1

", 'specialpages-note-top' ); - $out->addWikiText( + $out->addWikiTextAsInterface( "
\n" . implode( "\n", $notes ) . "\n
" diff --git a/includes/specials/SpecialTags.php b/includes/specials/SpecialTags.php index 6b0598cefc..9a9f4f2fef 100644 --- a/includes/specials/SpecialTags.php +++ b/includes/specials/SpecialTags.php @@ -321,7 +321,7 @@ class SpecialTags extends SpecialPage { $out->addBacklinkSubtitle( $this->getPageTitle() ); return true; } else { - $out->addWikiText( "
\n" . $status->getWikiText() . + $out->addWikiTextAsInterface( "
\n" . $status->getWikiText() . "\n
" ); 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( "
\n" . $canDeleteResult->getWikiText() . + $out->addWikiTextAsInterface( "
\n" . $canDeleteResult->getWikiText() . "\n
" ); 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( "
\n" . $result->getWikiText() . + $out->addWikiTextAsInterface( "
\n" . $result->getWikiText() . "\n
" ); 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( "
\n" . $status->getWikitext() . + $out->addWikiTextAsInterface( "
\n" . $status->getWikitext() . "\n
" ); return false; } diff --git a/includes/specials/SpecialUndelete.php b/includes/specials/SpecialUndelete.php index e4e513e3c3..be3433f23b 100644 --- a/includes/specials/SpecialUndelete.php +++ b/includes/specials/SpecialUndelete.php @@ -1177,7 +1177,7 @@ class SpecialUndelete extends SpecialPage { // Show revision undeletion warnings and errors $status = $archive->getRevisionStatus(); if ( $status && !$status->isGood() ) { - $out->addWikiText( '
' . + $out->addWikiTextAsInterface( '
' . $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( '
' . + $out->addWikiTextAsInterface( '
' . $status->getWikiText( 'undelete-error-short', 'undelete-error-long' diff --git a/includes/specials/SpecialUserrights.php b/includes/specials/SpecialUserrights.php index 42051886f7..60f98f1bda 100644 --- a/includes/specials/SpecialUserrights.php +++ b/includes/specials/SpecialUserrights.php @@ -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( '
' . $status->getWikiText() . '
' ); + $out->addWikiTextAsInterface( '
' . $status->getWikiText() . '
' ); } } } @@ -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 { diff --git a/includes/specials/SpecialVersion.php b/includes/specials/SpecialVersion.php index 35c5689e4f..4e9245f318 100644 --- a/includes/specials/SpecialVersion.php +++ b/includes/specials/SpecialVersion.php @@ -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; diff --git a/tests/phpunit/includes/OutputPageTest.php b/tests/phpunit/includes/OutputPageTest.php index 211169eaef..18d2a8a671 100644 --- a/tests/phpunit/includes/OutputPageTest.php +++ b/tests/phpunit/includes/OutputPageTest.php @@ -1665,9 +1665,8 @@ class OutputPageTest extends MediaWikiTestCase { $op = $this->newInstance(); $this->assertSame( '', $op->getHTML() ); $op->wrapWikiMsg( '[$1]', [ 'parentheses', "a" ] ); - // This is known to be bad unbalanced HTML; this will be fixed - // by I743f4185a03403f8d9b9db010ff1ee4e9342e062 (T198214) - $this->assertSame( "

[(a)]\n

", $op->getHTML() ); + // The input is bad unbalanced HTML, but the output is tidied + $this->assertSame( "

[(a)]\n

", $op->getHTML() ); } /**