Use OutputPage::wrapWikiTextAsInterface() to add safe <div> wrappers
authorC. Scott Ananian <cscott@cscott.net>
Wed, 17 Oct 2018 14:28:05 +0000 (10:28 -0400)
committerC. Scott Ananian <cscott@cscott.net>
Wed, 17 Oct 2018 15:08:16 +0000 (11:08 -0400)
This ensures that broken messages can't break the <div> wrapper and
that the output is tidy.

Bug: T205624
Change-Id: I2511adf593a13528e205a82d9fcdc8a524d0a95f

includes/EditPage.php
includes/FileDeleteForm.php
includes/page/Article.php
includes/page/ImagePage.php
includes/specials/SpecialEditTags.php
includes/specials/SpecialImport.php
includes/specials/SpecialRevisiondelete.php
includes/specials/SpecialSpecialpages.php
includes/specials/SpecialTags.php
includes/specials/SpecialUndelete.php
includes/specials/SpecialUserrights.php

index 03b7b45..90db70f 100644 (file)
@@ -1640,11 +1640,7 @@ class EditPage {
                        case self::AS_CANNOT_USE_CUSTOM_MODEL:
                        case self::AS_PARSE_ERROR:
                        case self::AS_UNICODE_NOT_SUPPORTED:
-                               $out->addWikiTextAsInterface(
-                                       '<div class="error">' . "\n" .
-                                       $status->getWikiText() .
-                                       '</div>'
-                               );
+                               $out->wrapWikiTextAsInterface( 'error', $status->getWikiText() );
                                return true;
 
                        case self::AS_SUCCESS_NEW_ARTICLE:
@@ -2995,7 +2991,7 @@ ERROR;
                                        $this->contentFormat,
                                        $ex->getMessage()
                                );
-                               $out->addWikiTextAsInterface( '<div class="error">' . $msg->plain() . '</div>' );
+                               $out->wrapWikiTextAsInterface( 'error', $msg->plain() );
                        }
                }
 
@@ -3470,7 +3466,7 @@ ERROR;
                                        $this->contentFormat,
                                        $ex->getMessage()
                                );
-                               $out->addWikiTextAsInterface( '<div class="error">' . $msg->plain() . '</div>' );
+                               $out->wrapWikiTextAsInterface( 'error', $msg->plain() );
                        }
                }
        }
index f23d6ec..3e0595e 100644 (file)
@@ -120,9 +120,10 @@ class FileDeleteForm {
 
                        if ( !$status->isGood() ) {
                                $wgOut->addHTML( '<h2>' . $this->prepareMessage( 'filedeleteerror-short' ) . "</h2>\n" );
-                               $wgOut->addWikiTextAsInterface( '<div class="error">' .
+                               $wgOut->wrapWikiTextAsInterface(
+                                       'error',
                                        $status->getWikiText( 'filedeleteerror-short', 'filedeleteerror-long' )
-                                       . '</div>' );
+                               );
                        }
                        if ( $status->isOK() ) {
                                $wgOut->setPageTitle( wfMessage( 'actioncomplete' ) );
index 8bc8d1e..e18f524 100644 (file)
@@ -792,7 +792,7 @@ class Article implements Page {
                                                        $outputPage->setRobotPolicy( 'noindex,nofollow' );
 
                                                        $errortext = $error->getWikiText( false, 'view-pool-error' );
-                                                       $outputPage->addWikiTextAsInterface( Html::errorBox( $errortext ) );
+                                                       $outputPage->wrapWikiTextAsInterface( 'errorbox', $errortext );
                                                }
                                                # Connection or timeout error
                                                return;
@@ -2087,8 +2087,9 @@ class Article implements Page {
                        );
 
                        if ( $error == '' ) {
-                               $outputPage->addWikiTextAsInterface(
-                                       "<div class=\"error mw-error-cannotdelete\">\n" . $status->getWikiText() . "\n</div>"
+                               $outputPage->wrapWikiTextAsInterface(
+                                       'error mw-error-cannotdelete',
+                                       $status->getWikiText()
                                );
                                $deleteLogPage = new LogPage( 'delete' );
                                $outputPage->addHTML( Xml::element( 'h2', null, $deleteLogPage->getName()->text() ) );
index 2489386..5382c55 100644 (file)
@@ -542,16 +542,15 @@ class ImagePage extends Article {
                                // to the filename, because it can get copied with it.
                                // See T27277.
                                // phpcs:disable Generic.Files.LineLength
-                               $out->addWikiTextAsInterface( <<<EOT
-<div class="fullMedia"><span class="dangerousLink">{$medialink}</span> $dirmark<span class="fileInfo">$longDesc</span></div>
-<div class="mediaWarning">$warning</div>
+                               $out->wrapWikiTextAsInterface( 'fullMedia', <<<EOT
+<span class="dangerousLink">{$medialink}</span> $dirmark<span class="fileInfo">$longDesc</span>
 EOT
                                );
                                // phpcs:enable
+                               $out->wrapWikiTextAsInterface( 'mediaWarning', $warning );
                        } else {
-                               $out->addWikiTextAsInterface( <<<EOT
-<div class="fullMedia">{$medialink} {$dirmark}<span class="fileInfo">$longDesc</span>
-</div>
+                               $out->wrapWikiTextAsInterface( 'fullMedia', <<<EOT
+{$medialink} {$dirmark}<span class="fileInfo">$longDesc</span>
 EOT
                                );
                        }
@@ -574,10 +573,7 @@ EOT
                                        'file-no-thumb-animation'
                                )->plain();
 
-                               $out->addWikiTextAsInterface( <<<EOT
-<div class="mw-noanimatethumb">{$noAnimMesg}</div>
-EOT
-                               );
+                               $out->wrapWikiTextAsInterface( 'mw-noanimatethumb', $noAnimMesg );
                        }
 
                        if ( !$this->displayImg->isLocal() ) {
index c5914ba..6198a84 100644 (file)
@@ -454,8 +454,8 @@ class SpecialEditTags extends UnlistedSpecialPage {
         */
        protected function failure( $status ) {
                $this->getOutput()->setPageTitle( $this->msg( 'actionfailed' ) );
-               $this->getOutput()->addWikiTextAsInterface(
-                       Html::errorBox( $status->getWikiText( 'tags-edit-failure' ) )
+               $this->getOutput()->wrapWikiTextAsInterface(
+                       'errorbox', $status->getWikiText( 'tags-edit-failure' )
                );
                $this->showForm();
        }
index 12b8d50..839a9bc 100644 (file)
@@ -179,8 +179,9 @@ class SpecialImport extends SpecialPage {
 
                $out = $this->getOutput();
                if ( !$source->isGood() ) {
-                       $out->addWikiTextAsInterface( "<div class=\"error\">\n" .
-                               $this->msg( 'importfailed', $source->getWikiText() )->parse() . "\n</div>" );
+                       $out->wrapWikiTextAsInterface( 'error',
+                               $this->msg( 'importfailed', $source->getWikiText() )->plain()
+                       );
                } else {
                        $importer = new WikiImporter( $source->value, $this->getConfig() );
                        if ( !is_null( $this->namespace ) ) {
index dba4fb8..7661f28 100644 (file)
@@ -641,10 +641,9 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
        protected function failure( $status ) {
                // Messages: revdelete-failure, logdelete-failure
                $this->getOutput()->setPageTitle( $this->msg( 'actionfailed' ) );
-               $this->getOutput()->addWikiTextAsInterface(
-                       Html::errorBox(
-                               $status->getWikiText( $this->typeLabels['failure'] )
-                       )
+               $this->getOutput()->wrapWikiTextAsInterface(
+                       'errorbox',
+                       $status->getWikiText( $this->typeLabels['failure'] )
                );
                $this->showForm();
        }
index 6bb0a1c..585a7cd 100644 (file)
@@ -151,10 +151,9 @@ class SpecialSpecialpages extends UnlistedSpecialPage {
                        $out->wrapWikiMsg(
                                "<h2 class=\"mw-specialpages-note-top\">$1</h2>", 'specialpages-note-top'
                        );
-                       $out->addWikiTextAsInterface(
-                               "<div class=\"mw-specialpages-notes\">\n" .
-                               implode( "\n", $notes ) .
-                               "\n</div>"
+                       $out->wrapWikiTextAsInterface(
+                               'mw-specialpages-notes',
+                               implode( "\n", $notes )
                        );
                }
        }
index 9a9f4f2..ca8ce89 100644 (file)
@@ -321,8 +321,7 @@ class SpecialTags extends SpecialPage {
                        $out->addBacklinkSubtitle( $this->getPageTitle() );
                        return true;
                } else {
-                       $out->addWikiTextAsInterface( "<div class=\"error\">\n" . $status->getWikiText() .
-                               "\n</div>" );
+                       $out->wrapWikiTextAsInterface( 'error', $status->getWikiText() );
                        return false;
                }
        }
@@ -340,8 +339,7 @@ class SpecialTags extends SpecialPage {
                // is the tag actually able to be deleted?
                $canDeleteResult = ChangeTags::canDeleteTag( $tag, $user );
                if ( !$canDeleteResult->isGood() ) {
-                       $out->addWikiTextAsInterface( "<div class=\"error\">\n" . $canDeleteResult->getWikiText() .
-                               "\n</div>" );
+                       $out->wrapWikiTextAsInterface( 'error', $canDeleteResult->getWikiText() );
                        if ( !$canDeleteResult->isOK() ) {
                                return;
                        }
@@ -402,8 +400,7 @@ class SpecialTags extends SpecialPage {
                $func = $activate ? 'canActivateTag' : 'canDeactivateTag';
                $result = ChangeTags::$func( $tag, $user );
                if ( !$result->isGood() ) {
-                       $out->addWikiTextAsInterface( "<div class=\"error\">\n" . $result->getWikiText() .
-                               "\n</div>" );
+                       $out->wrapWikiTextAsInterface( 'error', $result->getWikiText() );
                        if ( !$result->isOK() ) {
                                return;
                        }
@@ -455,8 +452,7 @@ class SpecialTags extends SpecialPage {
                        $out->addReturnTo( $this->getPageTitle() );
                        return true;
                } else {
-                       $out->addWikiTextAsInterface( "<div class=\"error\">\n" . $status->getWikitext() .
-                               "\n</div>" );
+                       $out->wrapWikiTextAsInterface( 'error', $status->getWikitext() );
                        return false;
                }
        }
index be3433f..a93dec0 100644 (file)
@@ -1177,7 +1177,9 @@ class SpecialUndelete extends SpecialPage {
                // Show revision undeletion warnings and errors
                $status = $archive->getRevisionStatus();
                if ( $status && !$status->isGood() ) {
-                       $out->addWikiTextAsInterface( '<div class="error" id="mw-error-cannotundelete">' .
+                       $out->wrapWikiTextAsInterface(
+                               'error',
+                               '<div id="mw-error-cannotundelete">' .
                                $status->getWikiText(
                                        'cannotundelete',
                                        'cannotundelete'
@@ -1188,11 +1190,12 @@ class SpecialUndelete extends SpecialPage {
                // Show file undeletion warnings and errors
                $status = $archive->getFileStatus();
                if ( $status && !$status->isGood() ) {
-                       $out->addWikiTextAsInterface( '<div class="error">' .
+                       $out->wrapWikiTextAsInterface(
+                               'error',
                                $status->getWikiText(
                                        'undelete-error-short',
                                        'undelete-error-long'
-                               ) . '</div>'
+                               )
                        );
                }
        }
index 60f98f1..f63c884 100644 (file)
@@ -189,7 +189,7 @@ class UserrightsPage extends SpecialPage {
                                        return;
                                } else {
                                        // Print an error message and redisplay the form
-                                       $out->addWikiTextAsInterface( '<div class="error">' . $status->getWikiText() . '</div>' );
+                                       $out->wrapWikiTextAsInterface( 'error', $status->getWikiText() );
                                }
                        }
                }