Index: branches/Wikidata/phase3/includes/Content.php |
— | — | @@ -2,47 +2,33 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * A content object represents page content, e.g. the text to show on a page. |
| 6 | + * Content objects have no knowledge about how they relate to Wiki pages. |
| 7 | + * Content objects are imutable. |
6 | 8 | * |
7 | 9 | */ |
8 | 10 | abstract class Content { |
9 | 11 | |
10 | | - public function __construct( Title $title = null, $revId = null, $modelName = null ) { #FIXME: really need revId? annoying! #FIXME: really $title? or just when parsing, every time? |
| 12 | + public function __construct( $modelName = null ) { #FIXME: really need revId? annoying! #FIXME: really $title? or just when parsing, every time? |
11 | 13 | $this->mModelName = $modelName; |
12 | | - $this->mTitle = $title; |
13 | | - $this->mRevId = $revId; |
14 | 14 | } |
15 | 15 | |
16 | 16 | public function getModelName() { |
17 | 17 | return $this->mModelName; |
18 | 18 | } |
19 | 19 | |
20 | | - public function getTitle() { |
21 | | - return $this->mTitle; |
22 | | - } |
| 20 | + public abstract function getSearchText( ); |
23 | 21 | |
24 | | - public function getRevId() { |
25 | | - return $this->mRevId; |
26 | | - } |
| 22 | + public abstract function getWikitextForTransclusion( ); |
27 | 23 | |
28 | | - public abstract function getSearchText( $obj ); |
29 | | - |
30 | | - public abstract function getWikitextForTransclusion( $obj ); |
31 | | - |
32 | | - public abstract function getParserOutput( ParserOptions $options = NULL ); |
33 | | - |
| 24 | + /** |
| 25 | + * Returns native represenation of the data. Interpretation depends on the data model used, |
| 26 | + * as given by getDataModel(). |
| 27 | + * |
| 28 | + */ |
34 | 29 | public abstract function getRawData( ); |
35 | 30 | |
36 | | - public function getHtml( ParserOptions $options ) { |
37 | | - $po = $this->getParserOutput( $options ); |
38 | | - return $po->getText(); |
39 | | - } |
| 31 | + public abstract function getParserOutput( Title $title = null, $revId = null, ParserOptions $options = NULL ); |
40 | 32 | |
41 | | - public function getIndexUpdateJobs( ParserOptions $options , $recursive = true ) { |
42 | | - $po = $this->getParserOutput( $options ); |
43 | | - $update = new LinksUpdate( $this->mTitle, $po, $recursive ); |
44 | | - return $update; |
45 | | - } |
46 | | - |
47 | 33 | public function getRedirectChain() { |
48 | 34 | return null; |
49 | 35 | } |
— | — | @@ -60,20 +46,20 @@ |
61 | 47 | } |
62 | 48 | |
63 | 49 | /** |
64 | | - * Replaces the section with the given id. |
| 50 | + * Replaces a section of the content. |
65 | 51 | * |
66 | | - * The default implementation returns $this. |
67 | | - * |
68 | | - * @param String $sectionId the section's id |
69 | | - * @param Content $with the section's new content |
70 | | - * @return Content a new content object with the section replaced, or this content object if the section couldn't be replaced. |
| 52 | + * @param $section empty/null/false or a section number (0, 1, 2, T1, T2...), or "new" |
| 53 | + * @param $with Content: new content of the section |
| 54 | + * @param $sectionTitle String: new section's subject, only if $section is 'new' |
| 55 | + * @return string Complete article text, or null if error |
71 | 56 | */ |
72 | | - public function replaceSection( $sectionId ) { |
| 57 | + public function replaceSection( $section, Content $with, $sectionTitle = '' ) { |
| 58 | + return $this; |
73 | 59 | } |
74 | 60 | |
75 | | - #XXX: is the native model for wikitext a string or the parser output? parse early or parse late? |
| 61 | + #TODO: implement specialized ParserOutput for Wikidata model |
| 62 | + #TODO: provide addToParserOutput fule Multipart... somehow. |
76 | 63 | |
77 | | - |
78 | 64 | # TODO: EditPage::mergeChanges( Content $a, Content $b ) |
79 | 65 | # TODO: Wikipage::isCountable(Content $a) |
80 | 66 | # TODO: Title::newFromRedirectRecurse( $this->getRawText() ); |
— | — | @@ -82,7 +68,6 @@ |
83 | 69 | # TODO: getSize( ) |
84 | 70 | |
85 | 71 | # TODO: WikiPage::getUndoText( Revision $undo, Revision $undoafter = null ) |
86 | | - # TODO: WikiPage::replaceSection( $section, $text, $sectionTitle = '', $edittime = null ) |
87 | 72 | # TODO: WikiPage::getAutosummary( $oldtext, $text, $flags ) |
88 | 73 | |
89 | 74 | # TODO: EditPage::getPreloadedText( $preload ) // $wgParser->getPreloadText |
— | — | @@ -94,23 +79,50 @@ |
95 | 80 | |
96 | 81 | } |
97 | 82 | |
98 | | -class TextContent extends Content { |
99 | | - public function __construct( $text, Title $title = null, $revId = null, $modelName = null ) { |
100 | | - parent::__construct($title, $revId, $modelName); |
| 83 | +/** |
| 84 | + * Content object implementation for representing flat text. The |
| 85 | + */ |
| 86 | +abstract class TextContent extends Content { |
| 87 | + public function __construct( $text, $modelName = null ) { |
| 88 | + parent::__construct($modelName); |
101 | 89 | |
102 | 90 | $this->mText = $text; |
103 | 91 | } |
104 | 92 | |
105 | | - public function getSearchText( $obj ) { |
| 93 | + /** |
| 94 | + * Returns the text represented by this Content object, as a string. |
| 95 | + * |
| 96 | + * @return String the raw text |
| 97 | + */ |
| 98 | + public function getRawData( ) { |
| 99 | + $text = $this->mText; |
| 100 | + return $text; |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * Returns the text represented by this Content object, as a string. |
| 105 | + * |
| 106 | + * @return String the raw text |
| 107 | + */ |
| 108 | + public function getSearchText( ) { #FIXME: use! |
106 | 109 | return $this->getRawData(); |
107 | 110 | } |
108 | 111 | |
109 | | - public function getWikitextForTransclusion( $obj ) { |
| 112 | + /** |
| 113 | + * Returns the text represented by this Content object, as a string. |
| 114 | + * |
| 115 | + * @return String the raw text |
| 116 | + */ |
| 117 | + public function getWikitextForTransclusion( ) { #FIXME: use! |
110 | 118 | return $this->getRawData(); |
111 | 119 | } |
112 | 120 | |
113 | | - |
114 | | - public function getParserOutput( ParserOptions $options = null ) { |
| 121 | + /** |
| 122 | + * Returns a generic ParserOutput object, wrapping the HTML returned by getHtml(). |
| 123 | + * |
| 124 | + * @return ParserOutput representing the HTML form of the text |
| 125 | + */ |
| 126 | + public function getParserOutput( Title $title = null, $revId = null, ParserOptions $options = null ) { |
115 | 127 | # generic implementation, relying on $this->getHtml() |
116 | 128 | |
117 | 129 | $html = $this->getHtml( $options ); |
— | — | @@ -123,53 +135,39 @@ |
124 | 136 | return $po; |
125 | 137 | } |
126 | 138 | |
127 | | - public function getHtml( ParserOptions $options ) { |
128 | | - $html = ""; |
129 | | - $html .= "<pre class=\"mw-code\" dir=\"ltr\">\n"; |
130 | | - $html .= htmlspecialchars( $this->getRawData() ); |
131 | | - $html .= "\n</pre>\n"; |
| 139 | + protected abstract function getHtml( ); |
132 | 140 | |
133 | | - return $html; |
134 | | - } |
135 | | - |
136 | | - |
137 | | - public function getRawData( ) { |
138 | | - $text = $this->mText; |
139 | | - return $text; |
140 | | - } |
141 | | - |
142 | | - public function getRedirectChain() { |
143 | | - #XXX: really do this for all text, or just in WikitextContent? |
144 | | - $text = $this->getRawData(); |
145 | | - return Title::newFromRedirectArray( $text ); |
146 | | - } |
147 | 141 | } |
148 | 142 | |
149 | 143 | class WikitextContent extends TextContent { |
150 | | - public function __construct( $text, Title $title, $revId = null) { |
151 | | - parent::__construct($text, $title, $revId, CONTENT_MODEL_WIKITEXT); |
| 144 | + public function __construct( $text ) { |
| 145 | + parent::__construct($text, CONTENT_MODEL_WIKITEXT); |
152 | 146 | |
153 | | - $this->mDefaultParserOptions = null; |
| 147 | + $this->mDefaultParserOptions = null; #TODO: use per-class static member?! |
154 | 148 | } |
155 | 149 | |
| 150 | + protected function getHtml( ) { |
| 151 | + throw new MWException( "getHtml() not implemented for wikitext. Use getParserOutput()->getText()." ); |
| 152 | + } |
| 153 | + |
156 | 154 | public function getDefaultParserOptions() { |
157 | 155 | global $wgUser, $wgContLang; |
158 | 156 | |
159 | | - if ( !$this->mDefaultParserOptions ) { |
160 | | - #TODO: use static member?! |
| 157 | + if ( !$this->mDefaultParserOptions ) { #TODO: use per-class static member?! |
161 | 158 | $this->mDefaultParserOptions = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang ); |
162 | 159 | } |
163 | 160 | |
164 | 161 | return $this->mDefaultParserOptions; |
165 | 162 | } |
166 | 163 | |
167 | | - public function getParserOutput( ParserOptions $options = null ) { |
| 164 | + /** |
| 165 | + * Returns a ParserOutput object reesulting from parsing the content's text using $wgParser |
| 166 | + * |
| 167 | + * @return ParserOutput representing the HTML form of the text |
| 168 | + */ |
| 169 | + public function getParserOutput( Title $title = null, $revId = null, ParserOptions $options = null ) { |
168 | 170 | global $wgParser; |
169 | 171 | |
170 | | - #TODO: quick local cache: if $options is NULL, use ->mParserOutput! |
171 | | - #FIXME: need setParserOutput, so we can use stuff from the parser cache?? |
172 | | - #FIXME: ...or we somehow need to know the parser cache key?? |
173 | | - |
174 | 172 | if ( !$options ) { |
175 | 173 | $options = $this->getDefaultParserOptions(); |
176 | 174 | } |
— | — | @@ -190,80 +188,64 @@ |
191 | 189 | |
192 | 190 | $text = $this->getRawData(); |
193 | 191 | $sect = $wgParser->getSection( $text, $section, false ); |
194 | | - $title = Title::newFromDBkey( $this->mTitle->getText() . '#' . $section, $this->mTitle->getNamespace() ); #FIXME: get rid of titles here |
195 | 192 | |
196 | | - return new WikitextContent( $sect, $title ); |
| 193 | + return new WikitextContent( $sect ); |
197 | 194 | } |
198 | 195 | |
199 | 196 | /** |
200 | | - * Replaces the section with the given id. |
| 197 | + * Replaces a section in the wikitext |
201 | 198 | * |
202 | | - * @param String $sectionId the section's id |
203 | | - * @param Content $with the section's new content |
204 | | - * @return Boolean true if te section was replaced sucessfully, false otherwise |
205 | | - */ |
206 | | - #FIXME: implement replaceSection(), use in WikiPage |
207 | | - |
208 | | - /** |
209 | | - * @param $section empty/null/false or a section number (0, 1, 2, T1, T2...) |
210 | | - * @param $text String: new text of the section |
| 199 | + * @param $section empty/null/false or a section number (0, 1, 2, T1, T2...), or "new" |
| 200 | + * @param $with Content: new content of the section |
211 | 201 | * @param $sectionTitle String: new section's subject, only if $section is 'new' |
212 | | - * @param $edittime String: revision timestamp or null to use the current revision |
213 | 202 | * @return string Complete article text, or null if error |
214 | 203 | */ |
215 | | - /*public function replaceSection( $section, $text, $sectionTitle = '', $edittime = null ) { #FIXME: adopt this! |
| 204 | + public function replaceSection( $section, Content $with, $sectionTitle = '' ) { |
| 205 | + global $wgParser; |
| 206 | + |
216 | 207 | wfProfileIn( __METHOD__ ); |
217 | 208 | |
218 | | - if ( strval( $section ) == '' ) { |
219 | | - // Whole-page edit; let the whole text through |
220 | | - } else { |
221 | | - // Bug 30711: always use current version when adding a new section |
222 | | - if ( is_null( $edittime ) || $section == 'new' ) { |
223 | | - $oldtext = $this->getRawText(); |
224 | | - if ( $oldtext === false ) { |
225 | | - wfDebug( __METHOD__ . ": no page text\n" ); |
226 | | - wfProfileOut( __METHOD__ ); |
227 | | - return null; |
228 | | - } |
229 | | - } else { |
230 | | - $dbw = wfGetDB( DB_MASTER ); |
231 | | - $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime ); |
| 209 | + $myModelName = $this->getModelName(); |
| 210 | + $sectionModelName = $with->getModelName(); |
232 | 211 | |
233 | | - if ( !$rev ) { |
234 | | - wfDebug( "WikiPage::replaceSection asked for bogus section (page: " . |
235 | | - $this->getId() . "; section: $section; edittime: $edittime)\n" ); |
236 | | - wfProfileOut( __METHOD__ ); |
237 | | - return null; |
238 | | - } |
| 212 | + if ( $sectionModelName != $myModelName ) { |
| 213 | + throw new MWException( "Incompatible content model for section: document uses $myModelName, section uses $sectionModelName." ); |
| 214 | + } |
239 | 215 | |
240 | | - $oldtext = $rev->getText(); |
241 | | - } |
| 216 | + $oldtext = $this->getRawData(); |
| 217 | + $text = $with->getRawData(); |
242 | 218 | |
243 | | - if ( $section == 'new' ) { |
244 | | - # Inserting a new section |
245 | | - $subject = $sectionTitle ? wfMsgForContent( 'newsectionheaderdefaultlevel', $sectionTitle ) . "\n\n" : ''; |
246 | | - if ( wfRunHooks( 'PlaceNewSection', array( $this, $oldtext, $subject, &$text ) ) ) { |
247 | | - $text = strlen( trim( $oldtext ) ) > 0 |
248 | | - ? "{$oldtext}\n\n{$subject}{$text}" |
249 | | - : "{$subject}{$text}"; |
250 | | - } |
251 | | - } else { |
252 | | - # Replacing an existing section; roll out the big guns |
253 | | - global $wgParser; |
254 | | - |
255 | | - $text = $wgParser->replaceSection( $oldtext, $section, $text ); |
| 219 | + if ( $section == 'new' ) { |
| 220 | + # Inserting a new section |
| 221 | + $subject = $sectionTitle ? wfMsgForContent( 'newsectionheaderdefaultlevel', $sectionTitle ) . "\n\n" : ''; |
| 222 | + if ( wfRunHooks( 'PlaceNewSection', array( $this, $oldtext, $subject, &$text ) ) ) { |
| 223 | + $text = strlen( trim( $oldtext ) ) > 0 |
| 224 | + ? "{$oldtext}\n\n{$subject}{$text}" |
| 225 | + : "{$subject}{$text}"; |
256 | 226 | } |
| 227 | + } else { |
| 228 | + # Replacing an existing section; roll out the big guns |
| 229 | + global $wgParser; |
| 230 | + |
| 231 | + $text = $wgParser->replaceSection( $oldtext, $section, $text ); |
257 | 232 | } |
258 | 233 | |
| 234 | + $newContent = new WikitextContent( $text ); |
| 235 | + |
259 | 236 | wfProfileOut( __METHOD__ ); |
260 | | - return $text; |
261 | | - } */ |
| 237 | + return $newContent; |
| 238 | + } |
262 | 239 | |
| 240 | + public function getRedirectChain() { |
| 241 | + $text = $this->getRawData(); |
| 242 | + return Title::newFromRedirectArray( $text ); |
| 243 | + } |
| 244 | + |
263 | 245 | } |
264 | 246 | |
265 | 247 | class MessageContent extends TextContent { |
266 | 248 | public function __construct( $msg_key, $params = null, $options = null ) { |
267 | | - parent::__construct(null, null, null, CONTENT_MODEL_WIKITEXT); |
| 249 | + parent::__construct(null, CONTENT_MODEL_WIKITEXT); |
268 | 250 | |
269 | 251 | $this->mMessageKey = $msg_key; |
270 | 252 | |
— | — | @@ -275,13 +257,19 @@ |
276 | 258 | $this->mHtmlOptions = null; |
277 | 259 | } |
278 | 260 | |
279 | | - |
280 | | - public function getHtml( ParserOptions $options ) { |
| 261 | + /** |
| 262 | + * Returns the message as rendered HTML, using the options supplied to the constructor plus "parse". |
| 263 | + */ |
| 264 | + protected function getHtml( ) { |
281 | 265 | $opt = array_merge( $this->mOptions, array('parse') ); |
| 266 | + |
282 | 267 | return wfMsgExt( $this->mMessageKey, $this->mParameters, $opt ); |
283 | 268 | } |
284 | 269 | |
285 | 270 | |
| 271 | + /** |
| 272 | + * Returns the message as raw text, using the options supplied to the constructor minus "parse" and "parseinline". |
| 273 | + */ |
286 | 274 | public function getRawData( ) { |
287 | 275 | $opt = array_diff( $this->mOptions, array('parse', 'parseinline') ); |
288 | 276 | |
— | — | @@ -292,11 +280,11 @@ |
293 | 281 | |
294 | 282 | |
295 | 283 | class JavaScriptContent extends TextContent { |
296 | | - public function __construct( $text, Title $title, $revId = null ) { |
297 | | - parent::__construct($text, $title, $revId, CONTENT_MODEL_JAVASCRIPT); |
| 284 | + public function __construct( $text ) { |
| 285 | + parent::__construct($text, CONTENT_MODEL_JAVASCRIPT); |
298 | 286 | } |
299 | 287 | |
300 | | - public function getHtml( ParserOptions $options ) { |
| 288 | + protected function getHtml( ) { |
301 | 289 | $html = ""; |
302 | 290 | $html .= "<pre class=\"mw-code mw-js\" dir=\"ltr\">\n"; |
303 | 291 | $html .= htmlspecialchars( $this->getRawData() ); |
— | — | @@ -308,11 +296,11 @@ |
309 | 297 | } |
310 | 298 | |
311 | 299 | class CssContent extends TextContent { |
312 | | - public function __construct( $text, Title $title, $revId = null ) { |
313 | | - parent::__construct($text, $title, $revId, CONTENT_MODEL_CSS); |
| 300 | + public function __construct( $text ) { |
| 301 | + parent::__construct($text, CONTENT_MODEL_CSS); |
314 | 302 | } |
315 | 303 | |
316 | | - public function getHtml( ParserOptions $options ) { |
| 304 | + protected function getHtml( ) { |
317 | 305 | $html = ""; |
318 | 306 | $html .= "<pre class=\"mw-code mw-css\" dir=\"ltr\">\n"; |
319 | 307 | $html .= htmlspecialchars( $this->getRawData() ); |
— | — | @@ -322,10 +310,8 @@ |
323 | 311 | } |
324 | 312 | } |
325 | 313 | |
326 | | -#FIXME: special type for redirects?! |
327 | | -#FIXME: special type for message-based pseudo-content? with raw html? |
328 | | - |
329 | | -#TODO: MultipartMultipart < WikipageContent (Main + Links + X) |
330 | | -#TODO: LinksContent < LanguageLinksContent, CategoriesContent |
| 314 | +#FUTURE: special type for redirects?! |
| 315 | +#FUTURE: MultipartMultipart < WikipageContent (Main + Links + X) |
| 316 | +#FUTURE: LinksContent < LanguageLinksContent, CategoriesContent |
331 | 317 | #EXAMPLE: CoordinatesContent |
332 | 318 | #EXAMPLE: WikidataContent |
Index: branches/Wikidata/phase3/includes/ContentHandler.php |
— | — | @@ -29,11 +29,13 @@ |
30 | 30 | return null; |
31 | 31 | } |
32 | 32 | |
33 | | - public static function makeContent( $text, Title $title, $format = null, $revId = null ) { |
34 | | - $handler = ContentHandler::getForTitle( $title ); |
| 33 | + public static function makeContent( $text, Title $title, $modelName = null, $format = null ) { |
| 34 | + if ( !$modelName ) { |
| 35 | + $modelName = $title->getContentModelName(); |
| 36 | + } |
35 | 37 | |
36 | | - #FIXME: pass revid? |
37 | | - return $handler->unserialize( $text, $title, $format ); |
| 38 | + $handler = ContentHandler::getForModelName( $modelName ); |
| 39 | + return $handler->unserialize( $text, $format ); |
38 | 40 | } |
39 | 41 | |
40 | 42 | public static function getDefaultModelFor( Title $title ) { |
— | — | @@ -141,11 +143,11 @@ |
142 | 144 | return $this->mSupportedFormats[0]; |
143 | 145 | } |
144 | 146 | |
145 | | - public abstract function serialize( Content $content, Title $title, $format = null ); |
| 147 | + public abstract function serialize( Content $content, $format = null ); |
146 | 148 | |
147 | | - public abstract function unserialize( $blob, Title $title, $format = null ); #FIXME: ...and revId? |
| 149 | + public abstract function unserialize( $blob, $format = null ); |
148 | 150 | |
149 | | - public abstract function newContent( Title $title ); |
| 151 | + public abstract function emptyContent(); |
150 | 152 | |
151 | 153 | # public abstract function doPreSaveTransform( $title, $obj ); #TODO... |
152 | 154 | |
— | — | @@ -199,13 +201,6 @@ |
200 | 202 | return $de; |
201 | 203 | } |
202 | 204 | |
203 | | - public function getIndexUpdateJobs( Title $title, ParserOutput $parserOutput, $recursive = true ) { |
204 | | - # for wikitext, create a LinksUpdate object |
205 | | - # for wikidata: serialize arrays to json |
206 | | - $update = new LinksUpdate( $title, $parserOutput, $recursive ); |
207 | | - return $update; |
208 | | - } |
209 | | - |
210 | 205 | #XXX: is the native model for wikitext a string or the parser output? parse early or parse late? |
211 | 206 | |
212 | 207 | #TODO: how to handle extra message for JS/CSS previews?? |
— | — | @@ -221,7 +216,8 @@ |
222 | 217 | parent::__construct( $modelName, $formats ); |
223 | 218 | } |
224 | 219 | |
225 | | - public function serialize( Content $content, Title $title, $format = null ) { |
| 220 | + public function serialize( Content $content, $format = null ) { |
| 221 | + #FIXME: assert format |
226 | 222 | return $content->getRawData(); |
227 | 223 | } |
228 | 224 | |
— | — | @@ -232,12 +228,13 @@ |
233 | 229 | parent::__construct( $modelName, array( 'application/x-wikitext' ) ); #FIXME: mime |
234 | 230 | } |
235 | 231 | |
236 | | - public function unserialize( $text, Title $title, $format = null ) { |
237 | | - return new WikitextContent($text, $title); |
| 232 | + public function unserialize( $text, $format = null ) { |
| 233 | + #FIXME: assert format |
| 234 | + return new WikitextContent($text); |
238 | 235 | } |
239 | 236 | |
240 | | - public function newContent( Title $title) { |
241 | | - return new WikitextContent("", $title); |
| 237 | + public function emptyContent() { |
| 238 | + return new WikitextContent(""); |
242 | 239 | } |
243 | 240 | |
244 | 241 | } |
— | — | @@ -248,12 +245,12 @@ |
249 | 246 | parent::__construct( $modelName, array( 'text/javascript' ) ); |
250 | 247 | } |
251 | 248 | |
252 | | - public function unserialize( $text, Title $title, $format = null ) { |
253 | | - return new JavaScriptContent($text, $title); |
| 249 | + public function unserialize( $text, $format = null ) { |
| 250 | + return new JavaScriptContent($text); |
254 | 251 | } |
255 | 252 | |
256 | | - public function newContent( Title $title) { |
257 | | - return new JavaScriptContent("", $title); |
| 253 | + public function emptyContent() { |
| 254 | + return new JavaScriptContent(""); |
258 | 255 | } |
259 | 256 | } |
260 | 257 | |
— | — | @@ -263,12 +260,12 @@ |
264 | 261 | parent::__construct( $modelName, array( 'text/css' ) ); |
265 | 262 | } |
266 | 263 | |
267 | | - public function unserialize( $text, Title $title, $format = null ) { |
268 | | - return new CssContent($text, $title); |
| 264 | + public function unserialize( $text, $format = null ) { |
| 265 | + return new CssContent($text); |
269 | 266 | } |
270 | 267 | |
271 | | - public function newContent( Title $title) { |
272 | | - return new CssContent("", $title); |
| 268 | + public function emptyContent() { |
| 269 | + return new CssContent(""); |
273 | 270 | } |
274 | 271 | |
275 | 272 | } |
Index: branches/Wikidata/phase3/includes/EditPage.php |
— | — | @@ -1299,10 +1299,12 @@ |
1300 | 1300 | |
1301 | 1301 | if ( $this->isConflict ) { |
1302 | 1302 | wfDebug( __METHOD__ . ": conflict! getting section '$this->section' for time '$this->edittime' (article time '{$timestamp}')\n" ); |
1303 | | - $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $sectionTitle, $this->edittime ); |
| 1303 | + $cnt = $this->mArticle->replaceSection( $this->section, $this->textbox1, $sectionTitle, $this->edittime ); |
| 1304 | + $text = ContentHandler::getContentText($cnt); #FIXME: use Content object throughout, make edit form aware of content model and serialization format |
1304 | 1305 | } else { |
1305 | 1306 | wfDebug( __METHOD__ . ": getting section '$this->section'\n" ); |
1306 | | - $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $sectionTitle ); |
| 1307 | + $cnt = $this->mArticle->replaceSection( $this->section, $this->textbox1, $sectionTitle ); |
| 1308 | + $text = ContentHandler::getContentText($cnt); #FIXME: use Content object throughout, make edit form aware of content model and serialization format |
1307 | 1309 | } |
1308 | 1310 | if ( is_null( $text ) ) { |
1309 | 1311 | wfDebug( __METHOD__ . ": activating conflict; section replace failed.\n" ); |
Index: branches/Wikidata/phase3/includes/WikiPage.php |
— | — | @@ -1127,18 +1127,21 @@ |
1128 | 1128 | * @param $text String: new text of the section |
1129 | 1129 | * @param $sectionTitle String: new section's subject, only if $section is 'new' |
1130 | 1130 | * @param $edittime String: revision timestamp or null to use the current revision |
1131 | | - * @return string Complete article text, or null if error |
| 1131 | + * @return Content new complete article content, or null if error |
1132 | 1132 | */ |
1133 | | - public function replaceSection( $section, $text, $sectionTitle = '', $edittime = null ) { #FIXME: move to Content object! |
| 1133 | + public function replaceSection( $section, $text, $sectionTitle = '', $edittime = null ) { |
1134 | 1134 | wfProfileIn( __METHOD__ ); |
1135 | 1135 | |
| 1136 | + $sectionContent = ContentHandler::makeContent( $text, $this->getTitle() ); #XXX: could make section title, but that's not required. |
| 1137 | + |
1136 | 1138 | if ( strval( $section ) == '' ) { |
1137 | 1139 | // Whole-page edit; let the whole text through |
| 1140 | + $newContent = $sectionContent; |
1138 | 1141 | } else { |
1139 | 1142 | // Bug 30711: always use current version when adding a new section |
1140 | 1143 | if ( is_null( $edittime ) || $section == 'new' ) { |
1141 | | - $oldtext = $this->getRawText(); |
1142 | | - if ( $oldtext === false ) { |
| 1144 | + $oldContent = $this->getContent(); |
| 1145 | + if ( ! $oldContent ) { |
1143 | 1146 | wfDebug( __METHOD__ . ": no page text\n" ); |
1144 | 1147 | wfProfileOut( __METHOD__ ); |
1145 | 1148 | return null; |
— | — | @@ -1154,27 +1157,14 @@ |
1155 | 1158 | return null; |
1156 | 1159 | } |
1157 | 1160 | |
1158 | | - $oldtext = $rev->getText(); |
| 1161 | + $oldContent = $rev->getContent(); |
1159 | 1162 | } |
1160 | 1163 | |
1161 | | - if ( $section == 'new' ) { |
1162 | | - # Inserting a new section |
1163 | | - $subject = $sectionTitle ? wfMsgForContent( 'newsectionheaderdefaultlevel', $sectionTitle ) . "\n\n" : ''; |
1164 | | - if ( wfRunHooks( 'PlaceNewSection', array( $this, $oldtext, $subject, &$text ) ) ) { |
1165 | | - $text = strlen( trim( $oldtext ) ) > 0 |
1166 | | - ? "{$oldtext}\n\n{$subject}{$text}" |
1167 | | - : "{$subject}{$text}"; |
1168 | | - } |
1169 | | - } else { |
1170 | | - # Replacing an existing section; roll out the big guns |
1171 | | - global $wgParser; |
1172 | | - |
1173 | | - $text = $wgParser->replaceSection( $oldtext, $section, $text ); |
1174 | | - } |
| 1164 | + $newContent = $oldContent->replaceSection( $section, $sectionContent, $sectionTitle ); |
1175 | 1165 | } |
1176 | 1166 | |
1177 | 1167 | wfProfileOut( __METHOD__ ); |
1178 | | - return $text; |
| 1168 | + return $newContent; |
1179 | 1169 | } |
1180 | 1170 | |
1181 | 1171 | /** |
— | — | @@ -2831,7 +2821,9 @@ |
2832 | 2822 | */ |
2833 | 2823 | function __construct( Page $page, ParserOptions $parserOptions, $revid, $useParserCache, $content = null ) { |
2834 | 2824 | if ( is_string($content) ) { #BC: old style call |
2835 | | - $content = ContentHandler::makeContent( $content, $page->getTitle(), null, $this->revid ); #FIXME: format? from revision? |
| 2825 | + $modelName = $page->getRevision()->getContentModelName(); |
| 2826 | + $format = $page->getRevision()->getContentFormat(); |
| 2827 | + $content = ContentHandler::makeContent( $content, $page->getTitle(), $modelName, $format ); |
2836 | 2828 | } |
2837 | 2829 | |
2838 | 2830 | $this->page = $page; |