From 414fca2323456c0f59d0a155784f9dcac393a227 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Thu, 25 Jan 2007 03:07:39 +0000 Subject: [PATCH] (bug 8652) Catch exceptions generated by malformed XML in multipage media. Note: not tested, since I don't have all that fancy image-using stuff set up (:P), but it's just a try/catch block, so at worst it just won't work. Better than having the entire page crash due to an unhandled exception . . . Incidentally, should we maybe use set_exception_handler()? --- RELEASE-NOTES | 1 + includes/ImagePage.php | 76 ++++++++++++++++++------------- languages/messages/MessagesEn.php | 1 + 3 files changed, 47 insertions(+), 31 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 1024128f9e..075873f6c6 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -146,6 +146,7 @@ lighter making things easier to read. alias to that which should be used to make it more self documentating. * (bug 8749) Bring MySQL 5 table defs back into sync * (bug 8751) Set session cookies to HTTPS-only to match other cookies +* (bug 8652) Catch exceptions generated by malformed XML in multipage media == Languages updated == diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 2e6e94e4d3..f57e9d754a 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -248,39 +248,53 @@ class ImagePage extends Article { htmlspecialchars( $this->img->getTitle()->getPrefixedText() ).'" />' . $anchorclose . '' ); if ( $this->img->isMultipage() ) { - $count = $this->img->pageCount(); + try { + // Apparently SimpleXmlElement->__construct() can throw + // exceptions for malformed XML, although this isn't documented . . . + // http://us2.php.net/manual/en/function.simplexml-element-construct.php - if ( $page > 1 ) { - $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false ); - $link = $sk->makeLinkObj( $this->mTitle, $label, 'page='. ($page-1) ); - $this->img->selectPage( $page - 1 ); - $thumb1 = $sk->makeThumbLinkObj( $this->img, $link, $label, 'none' ); - } else { - $thumb1 = ''; - } - - if ( $page < $count ) { - $label = wfMsg( 'imgmultipagenext' ); - $this->img->selectPage( $page + 1 ); - $link = $sk->makeLinkObj( $this->mTitle, $label, 'page='. ($page+1) ); - $thumb2 = $sk->makeThumbLinkObj( $this->img, $link, $label, 'none' ); - } else { - $thumb2 = ''; - } - - $select = '
' ; - $select .= $wgOut->parse( wfMsg( 'imgmultigotopre' ), false ) . - ' '; + for ( $i=1; $i <= $count; $i++ ) { + $select .= Xml::option( $wgLang->formatNum( $i ), $i, + $i == $page ); + } + $select .= '' . $wgOut->parse( wfMsg( 'imgmultigotopost' ), false ) . + '
'; + + $wgOut->addHTML( '
' . + "$select
$thumb1\n$thumb2
" ); + } catch( Exception $e ) { + if ( $e->getText() == "String could not be parsed as XML" ) { + // Hacky and fragile string test, yay + $errorMsg = wfMsg( 'imgmultiparseerror' ); + $wgOut->addHtml( "$errorMsg" ); + } else { + throw $e; + } } - $select .= '' . $wgOut->parse( wfMsg( 'imgmultigotopost' ), false ) . - ''; - - $wgOut->addHTML( '
' . - "$select
$thumb1\n$thumb2
" ); } } else { #if direct link is allowed but it's not a renderable image, show an icon. diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 96dead006e..45e759f03d 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -2722,6 +2722,7 @@ Please confirm that really want to recreate this page.', 'imgmultigo' => 'Go!', 'imgmultigotopre' => 'Go to page', 'imgmultigotopost' => '', +'imgmultiparseerror' => 'The image file appears to be corrupted or incorrect, so {{SITENAME}} cannot retrieve a list of pages.', # Table pager 'ascending_abbrev' => 'asc', -- 2.20.1