| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
namespace MediaWiki\Rest\Handler\Helper; |
| 21 |
|
| 22 |
use MediaWiki\Language\LanguageCode; |
| 23 |
use MediaWiki\Message\Message; |
| 24 |
use MediaWiki\Page\PageIdentity; |
| 25 |
use MediaWiki\Parser\ParserOutput; |
| 26 |
use MediaWiki\Rest\ResponseInterface; |
| 27 |
use MediaWiki\Title\Title; |
| 28 |
use Wikimedia\Parsoid\Utils\ContentUtils; |
| 29 |
use Wikimedia\Parsoid\Utils\DOMUtils; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
class HtmlMessageOutputHelper implements HtmlOutputHelper { |
| 36 |
|
| 37 |
private ?PageIdentity $page; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public function __construct( ?PageIdentity $page = null ) { |
| 43 |
if ( $page === null ) { |
| 44 |
wfDeprecated( __METHOD__ . ' without $page', '1.43' ); |
| 45 |
} |
| 46 |
$this->page = $page; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public function init( PageIdentity $page ): void { |
| 57 |
wfDeprecated( __METHOD__, '1.43' ); |
| 58 |
$this->page = $page; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
private function getDefaultSystemMessage(): ?Message { |
| 65 |
$title = Title::castFromPageIdentity( $this->page ); |
| 66 |
|
| 67 |
return $title ? $title->getDefaultSystemMessage() : null; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
public function getHtml(): ParserOutput { |
| 74 |
$message = $this->getDefaultSystemMessage(); |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
$messageDom = DOMUtils::parseHTML( $message->parse() ); |
| 79 |
DOMUtils::appendToHead( $messageDom, 'meta', [ |
| 80 |
'http-equiv' => 'content-language', |
| 81 |
'content' => LanguageCode::bcp47( $message->getLanguage()->getCode() ), |
| 82 |
] ); |
| 83 |
|
| 84 |
$messageDocHtml = ContentUtils::toXML( $messageDom ); |
| 85 |
|
| 86 |
return new ParserOutput( $messageDocHtml ); |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
public function getETag( string $suffix = '' ): ?string { |
| 93 |
|
| 94 |
|
| 95 |
$output = $this->getHtml(); |
| 96 |
|
| 97 |
return '"message/' . sha1( $output->getRawText() ) . '/' . $suffix . '"'; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
public function getLastModified(): ?string { |
| 108 |
return null; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
public static function getParamSettings(): array { |
| 115 |
return []; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
public function setVariantConversionLanguage( |
| 122 |
$targetLanguage, |
| 123 |
$sourceLanguage = null |
| 124 |
): void { |
| 125 |
|
| 126 |
} |
| 127 |
|
| 128 |
public function putHeaders( |
| 129 |
ResponseInterface $response, |
| 130 |
bool $forHtml = true |
| 131 |
): void { |
| 132 |
|
| 133 |
} |
| 134 |
|
| 135 |
} |