3 * Base content handler class for flat text contents.
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.
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.
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
20 * @since 1.36 (As UnknownContentHandler in 1.34)
26 namespace MediaWiki\Content
;
28 use MediaWiki\Content\Renderer\ContentParseParams
;
29 use MediaWiki\Context\IContextSource
;
30 use MediaWiki\Html\Html
;
31 use MediaWiki\Parser\ParserOutput
;
33 use UnsupportedSlotDiffRenderer
;
36 * Content handler implementation for unknown content.
38 * This can be used to handle content for which no ContentHandler exists on the system,
39 * perhaps because the extension that provided it has been removed.
43 class FallbackContentHandler
extends ContentHandler
{
46 * Constructs an FallbackContentHandler. Since FallbackContentHandler can be registered
47 * for multiple model IDs on a system, multiple instances of FallbackContentHandler may
50 * To preserve the serialization format of the original content model, it must be supplied
51 * to the constructor via the $formats parameter. If not given, the default format is
52 * reported as 'application/octet-stream'.
54 * @param string $modelId
55 * @param string[]|null $formats
57 public function __construct( $modelId, $formats = null ) {
61 'application/octet-stream',
62 'application/unknown',
63 'application/x-binary',
71 * Returns the content's data as-is.
73 * @param Content $content
74 * @param string|null $format The serialization format to check
78 public function serializeContent( Content
$content, $format = null ) {
79 /** @var FallbackContent $content */
80 '@phan-var FallbackContent $content';
81 return $content->getData();
85 * Constructs an FallbackContent instance wrapping the given data.
89 * @param string $blob serialized content in an unknown format
90 * @param string|null $format ignored
92 * @return Content The FallbackContent object wrapping $data
94 public function unserializeContent( $blob, $format = null ) {
95 return new FallbackContent( $blob, $this->getModelID() );
99 * Creates an empty FallbackContent object.
103 * @return Content A new FallbackContent object with empty text.
105 public function makeEmptyContent() {
106 return $this->unserializeContent( '' );
112 public function supportsDirectEditing() {
117 * Fills the ParserOutput with an error message.
119 * @param Content $content
120 * @param ContentParseParams $cpoParams
121 * @param ParserOutput &$output The output object to fill (reference).
124 protected function fillParserOutput(
126 ContentParseParams
$cpoParams,
127 ParserOutput
&$output
129 '@phan-var FallbackContent $content';
130 $msg = wfMessage( 'unsupported-content-model', [ $content->getModel() ] );
131 $html = Html
::rawElement( 'div', [ 'class' => 'error' ], $msg->inContentLanguage()->parse() );
132 $output->setRawText( $html );
136 * @param IContextSource $context
138 * @return SlotDiffRenderer
140 protected function getSlotDiffRendererInternal( IContextSource
$context ) {
141 return new UnsupportedSlotDiffRenderer( $context );
144 /** @deprecated class alias since 1.43 */
145 class_alias( FallbackContentHandler
::class, 'FallbackContentHandler' );