Merge "Unit tests: Remove duplicated code in ExtensionRegistry"
[lhc/web/wiklou.git] / includes / content / UnknownContentHandler.php
1 <?php
2 /**
3 * Base content handler class for flat text contents.
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 * @since 1.34
21 *
22 * @file
23 * @ingroup Content
24 */
25
26 /**
27 * Content handler implementation for unknown content.
28 *
29 * This can be used to handle content for which no ContentHandler exists on the system,
30 * perhaps because the extension that provided it has been removed.
31 *
32 * @ingroup Content
33 */
34 class UnknownContentHandler extends ContentHandler {
35
36 /**
37 * Constructs an UnknownContentHandler. Since UnknownContentHandler can be registered
38 * for multiple model IDs on a system, multiple instances of UnknownContentHandler may
39 * coexist.
40 *
41 * To preserve the serialization format of the original content model, it must be supplied
42 * to the constructor via the $formats parameter. If not given, the default format is
43 * reported as 'application/octet-stream'.
44 *
45 * @param string $modelId
46 * @param string[]|null $formats
47 */
48 public function __construct( $modelId, $formats = null ) {
49 parent::__construct(
50 $modelId,
51 $formats ?? [
52 'application/octet-stream',
53 'application/unknown',
54 'application/x-binary',
55 'text/unknown',
56 'unknown/unknown',
57 ]
58 );
59 }
60
61 /**
62 * Returns the content's data as-is.
63 *
64 * @param Content $content
65 * @param string|null $format The serialization format to check
66 *
67 * @return mixed
68 */
69 public function serializeContent( Content $content, $format = null ) {
70 /** @var UnknownContent $content */
71 return $content->getData();
72 }
73
74 /**
75 * Constructs an UnknownContent instance wrapping the given data.
76 *
77 * @since 1.21
78 *
79 * @param string $blob serialized content in an unknown format
80 * @param string|null $format ignored
81 *
82 * @return Content The UnknownContent object wrapping $data
83 */
84 public function unserializeContent( $blob, $format = null ) {
85 return new UnknownContent( $blob, $this->getModelID() );
86 }
87
88 /**
89 * Creates an empty UnknownContent object.
90 *
91 * @since 1.21
92 *
93 * @return Content A new UnknownContent object with empty text.
94 */
95 public function makeEmptyContent() {
96 return $this->unserializeContent( '' );
97 }
98
99 /**
100 * @return false
101 */
102 public function supportsDirectEditing() {
103 return false;
104 }
105
106 /**
107 * @param IContextSource $context
108 *
109 * @return SlotDiffRenderer
110 */
111 protected function getSlotDiffRendererInternal( IContextSource $context ) {
112 return new UnsupportedSlotDiffRenderer( $context );
113 }
114 }