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