Merge "Make DBAccessBase use DBConnRef, rename $wiki, and hide getLoadBalancer()"
[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 '@phan-var UnknownContent $content';
72 return $content->getData();
73 }
74
75 /**
76 * Constructs an UnknownContent instance wrapping the given data.
77 *
78 * @since 1.21
79 *
80 * @param string $blob serialized content in an unknown format
81 * @param string|null $format ignored
82 *
83 * @return Content The UnknownContent object wrapping $data
84 */
85 public function unserializeContent( $blob, $format = null ) {
86 return new UnknownContent( $blob, $this->getModelID() );
87 }
88
89 /**
90 * Creates an empty UnknownContent object.
91 *
92 * @since 1.21
93 *
94 * @return Content A new UnknownContent object with empty text.
95 */
96 public function makeEmptyContent() {
97 return $this->unserializeContent( '' );
98 }
99
100 /**
101 * @return false
102 */
103 public function supportsDirectEditing() {
104 return false;
105 }
106
107 /**
108 * @param IContextSource $context
109 *
110 * @return SlotDiffRenderer
111 */
112 protected function getSlotDiffRendererInternal( IContextSource $context ) {
113 return new UnsupportedSlotDiffRenderer( $context );
114 }
115 }