Index: branches/Wikidata/phase3/includes/Content.php |
— | — | @@ -47,10 +47,30 @@ |
48 | 48 | return null; |
49 | 49 | } |
50 | 50 | |
51 | | - public function getSection( $section ) { #FIXME: should this return text? or a Content object? or what?? |
| 51 | + /** |
| 52 | + * Returns the section with the given id. |
| 53 | + * |
| 54 | + * The default implementation returns null. |
| 55 | + * |
| 56 | + * @param String $sectionId the section's id |
| 57 | + * @return Content|Boolean|null the section, or false if no such section exist, or null if sections are not supported |
| 58 | + */ |
| 59 | + public function getSection( $sectionId ) { |
52 | 60 | return null; |
53 | 61 | } |
54 | 62 | |
| 63 | + /** |
| 64 | + * Replaces the section with the given id. |
| 65 | + * |
| 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. |
| 71 | + */ |
| 72 | + public function replaceSection( $sectionId ) { |
| 73 | + } |
| 74 | + |
55 | 75 | #XXX: is the native model for wikitext a string or the parser output? parse early or parse late? |
56 | 76 | |
57 | 77 | |
— | — | @@ -67,6 +87,11 @@ |
68 | 88 | |
69 | 89 | # TODO: EditPage::getPreloadedText( $preload ) // $wgParser->getPreloadText |
70 | 90 | |
| 91 | + |
| 92 | + # TODO: tie into API to provide contentModel for Revisions |
| 93 | + # TODO: tie into API to provide serialized version and contentFormat for Revisions |
| 94 | + # TODO: tie into API edit interface |
| 95 | + |
71 | 96 | } |
72 | 97 | |
73 | 98 | class TextContent extends Content { |
— | — | @@ -114,7 +139,7 @@ |
115 | 140 | } |
116 | 141 | |
117 | 142 | public function getRedirectChain() { |
118 | | - #XXX: really do this for all text, or just in WikitextContent |
| 143 | + #XXX: really do this for all text, or just in WikitextContent? |
119 | 144 | $text = $this->getRawData(); |
120 | 145 | return Title::newFromRedirectArray( $text ); |
121 | 146 | } |
— | — | @@ -154,13 +179,86 @@ |
155 | 180 | return $po; |
156 | 181 | } |
157 | 182 | |
| 183 | + /** |
| 184 | + * Returns the section with the given id. |
| 185 | + * |
| 186 | + * @param String $sectionId the section's id |
| 187 | + * @return Content|false|null the section, or false if no such section exist, or null if sections are not supported |
| 188 | + */ |
158 | 189 | public function getSection( $section ) { |
159 | 190 | global $wgParser; |
160 | 191 | |
161 | 192 | $text = $this->getRawData(); |
162 | | - return $wgParser->getSection( $text, $section, false ); |
| 193 | + $sect = $wgParser->getSection( $text, $section, false ); |
| 194 | + $title = Title::newFromDBkey( $this->mTitle->getText() . '#' . $section, $this->mTitle->getNamespace() ); #FIXME: get rid of titles here |
| 195 | + |
| 196 | + return new WikitextContent( $sect, $title ); |
163 | 197 | } |
164 | 198 | |
| 199 | + /** |
| 200 | + * Replaces the section with the given id. |
| 201 | + * |
| 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 |
| 211 | + * @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 | + * @return string Complete article text, or null if error |
| 214 | + */ |
| 215 | + /*public function replaceSection( $section, $text, $sectionTitle = '', $edittime = null ) { #FIXME: adopt this! |
| 216 | + wfProfileIn( __METHOD__ ); |
| 217 | + |
| 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 ); |
| 232 | + |
| 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 | + } |
| 239 | + |
| 240 | + $oldtext = $rev->getText(); |
| 241 | + } |
| 242 | + |
| 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 ); |
| 256 | + } |
| 257 | + } |
| 258 | + |
| 259 | + wfProfileOut( __METHOD__ ); |
| 260 | + return $text; |
| 261 | + } */ |
| 262 | + |
165 | 263 | } |
166 | 264 | |
167 | 265 | class MessageContent extends TextContent { |
Index: branches/Wikidata/phase3/includes/ContentHandler.php |
— | — | @@ -145,6 +145,8 @@ |
146 | 146 | |
147 | 147 | public abstract function unserialize( $blob, Title $title, $format = null ); #FIXME: ...and revId? |
148 | 148 | |
| 149 | + public abstract function newContent( Title $title ); |
| 150 | + |
149 | 151 | # public abstract function doPreSaveTransform( $title, $obj ); #TODO... |
150 | 152 | |
151 | 153 | /** |
— | — | @@ -208,6 +210,8 @@ |
209 | 211 | |
210 | 212 | #TODO: how to handle extra message for JS/CSS previews?? |
211 | 213 | #TODO: Article::showCssOrJsPage ---> specialized classes! |
| 214 | + |
| 215 | + #XXX: ImagePage and CategoryPage... wrappers that use ContentHandler? or ContentHandler creates wrappers? |
212 | 216 | } |
213 | 217 | |
214 | 218 | |
— | — | @@ -232,6 +236,10 @@ |
233 | 237 | return new WikitextContent($text, $title); |
234 | 238 | } |
235 | 239 | |
| 240 | + public function newContent( Title $title) { |
| 241 | + return new WikitextContent("", $title); |
| 242 | + } |
| 243 | + |
236 | 244 | } |
237 | 245 | |
238 | 246 | class JavaScriptContentHandler extends TextContentHandler { |
— | — | @@ -244,6 +252,9 @@ |
245 | 253 | return new JavaScriptContent($text, $title); |
246 | 254 | } |
247 | 255 | |
| 256 | + public function newContent( Title $title) { |
| 257 | + return new JavaScriptContent("", $title); |
| 258 | + } |
248 | 259 | } |
249 | 260 | |
250 | 261 | class CssContentHandler extends TextContentHandler { |
— | — | @@ -256,4 +267,8 @@ |
257 | 268 | return new CssContent($text, $title); |
258 | 269 | } |
259 | 270 | |
| 271 | + public function newContent( Title $title) { |
| 272 | + return new CssContent("", $title); |
| 273 | + } |
| 274 | + |
260 | 275 | } |