| 1 | <?php |
| 2 | /** |
| 3 | * Base class for the output of file transformation methods. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | * http://www.gnu.org/copyleft/gpl.html |
| 19 | * |
| 20 | * @file |
| 21 | * @ingroup Media |
| 22 | */ |
| 23 | |
| 24 | use MediaWiki\Message\Message; |
| 25 | |
| 26 | /** |
| 27 | * Basic media transform error class |
| 28 | * |
| 29 | * @newable |
| 30 | * @stable to extend |
| 31 | * @ingroup Media |
| 32 | */ |
| 33 | class MediaTransformError extends MediaTransformOutput { |
| 34 | /** @var Message */ |
| 35 | private $msg; |
| 36 | |
| 37 | /** |
| 38 | * @stable to call |
| 39 | * |
| 40 | * @param string $msg |
| 41 | * @param int $width |
| 42 | * @param int $height |
| 43 | * @param mixed ...$args |
| 44 | */ |
| 45 | public function __construct( $msg, $width, $height, ...$args ) { |
| 46 | $this->msg = wfMessage( $msg )->params( $args ); |
| 47 | $this->width = (int)$width; |
| 48 | $this->height = (int)$height; |
| 49 | $this->url = false; |
| 50 | $this->path = false; |
| 51 | } |
| 52 | |
| 53 | public function toHtml( $options = [] ) { |
| 54 | return "<div class=\"MediaTransformError\" style=\"" . |
| 55 | "width: {$this->width}px; height: {$this->height}px; display:inline-block;\">" . |
| 56 | $this->getHtmlMsg() . |
| 57 | "</div>"; |
| 58 | } |
| 59 | |
| 60 | public function toText() { |
| 61 | return $this->msg->text(); |
| 62 | } |
| 63 | |
| 64 | public function getHtmlMsg() { |
| 65 | return $this->msg->escaped(); |
| 66 | } |
| 67 | |
| 68 | public function getMsg() { |
| 69 | return $this->msg; |
| 70 | } |
| 71 | |
| 72 | public function isError() { |
| 73 | return true; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @stable to override |
| 78 | * |
| 79 | * @return int |
| 80 | */ |
| 81 | public function getHttpStatusCode() { |
| 82 | return 500; |
| 83 | } |
| 84 | } |