Debian Codegraph @

includes/content/FallbackContent.php

raw symbols SCIP
1 <?php
2 /**
3 * Content object implementation for representing unknown content.
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.36 (As UnknownContent in 1.34)
21 *
22 * @file
23 * @ingroup Content
24 *
25 * @author Daniel Kinzler
26 */
27
28 namespace MediaWiki\Content;
29
30 /**
31 * Content object implementation representing unknown content.
32 *
33 * This can be used to handle content for which no ContentHandler exists on the system,
34 * perhaps because the extension that provided it has been removed.
35 *
36 * FallbackContent instances are immutable.
37 *
38 * @ingroup Content
39 */
40 class FallbackContent extends AbstractContent {
41
42 /** @var string */
43 private $data;
44
45 /**
46 * @param string $data
47 * @param string $model_id The model ID to handle
48 */
49 public function __construct( $data, $model_id ) {
50 parent::__construct( $model_id );
51
52 $this->data = $data;
53 }
54
55 /**
56 * @return Content $this
57 */
58 public function copy() {
59 // FallbackContent is immutable, so no need to copy.
60 return $this;
61 }
62
63 /**
64 * Returns an empty string.
65 *
66 * @param int $maxlength
67 *
68 * @return string
69 */
70 public function getTextForSummary( $maxlength = 250 ) {
71 return '';
72 }
73
74 /**
75 * Returns the data size in bytes.
76 *
77 * @return int
78 */
79 public function getSize() {
80 return strlen( $this->data );
81 }
82
83 /**
84 * Returns false.
85 *
86 * @param bool|null $hasLinks If it is known whether this content contains links,
87 * provide this information here, to avoid redundant parsing to find out.
88 *
89 * @return bool
90 */
91 public function isCountable( $hasLinks = null ) {
92 return false;
93 }
94
95 /**
96 * @return string data of unknown format and meaning
97 */
98 public function getNativeData() {
99 return $this->getData();
100 }
101
102 /**
103 * @return string data of unknown format and meaning
104 */
105 public function getData() {
106 return $this->data;
107 }
108
109 /**
110 * @param string|null $format
111 *
112 * @return string data of unknown format and meaning
113 */
114 public function serialize( $format = null ) {
115 return $this->getData();
116 }
117
118 /**
119 * Returns an empty string.
120 *
121 * @return string The raw text.
122 */
123 public function getTextForSearchIndex() {
124 return '';
125 }
126
127 /**
128 * @return false
129 */
130 public function getWikitextForTransclusion() {
131 return false;
132 }
133
134 /**
135 * @param string $toModel
136 * @param string $lossy
137 * @return false
138 */
139 public function convert( $toModel, $lossy = '' ) {
140 return false;
141 }
142
143 protected function equalsInternal( Content $that ) {
144 if ( !$that instanceof FallbackContent ) {
145 return false;
146 }
147
148 return $this->getData() == $that->getData();
149 }
150
151 }
152 /** @deprecated class alias since 1.43 */
153 class_alias( FallbackContent::class, 'FallbackContent' );