r113490 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113489‎ | r113490 | r113491 >
Date:17:51, 9 March 2012
Author:daniel
Status:deferred
Tags:
Comment:
prep getSection, replaceSection
Modified paths:
  • /branches/Wikidata/phase3/includes/Content.php (modified) (history)
  • /branches/Wikidata/phase3/includes/ContentHandler.php (modified) (history)

Diff [purge]

Index: branches/Wikidata/phase3/includes/Content.php
@@ -47,10 +47,30 @@
4848 return null;
4949 }
5050
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 ) {
5260 return null;
5361 }
5462
 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+
5575 #XXX: is the native model for wikitext a string or the parser output? parse early or parse late?
5676
5777
@@ -67,6 +87,11 @@
6888
6989 # TODO: EditPage::getPreloadedText( $preload ) // $wgParser->getPreloadText
7090
 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+
7196 }
7297
7398 class TextContent extends Content {
@@ -114,7 +139,7 @@
115140 }
116141
117142 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?
119144 $text = $this->getRawData();
120145 return Title::newFromRedirectArray( $text );
121146 }
@@ -154,13 +179,86 @@
155180 return $po;
156181 }
157182
 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+ */
158189 public function getSection( $section ) {
159190 global $wgParser;
160191
161192 $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 );
163197 }
164198
 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+
165263 }
166264
167265 class MessageContent extends TextContent {
Index: branches/Wikidata/phase3/includes/ContentHandler.php
@@ -145,6 +145,8 @@
146146
147147 public abstract function unserialize( $blob, Title $title, $format = null ); #FIXME: ...and revId?
148148
 149+ public abstract function newContent( Title $title );
 150+
149151 # public abstract function doPreSaveTransform( $title, $obj ); #TODO...
150152
151153 /**
@@ -208,6 +210,8 @@
209211
210212 #TODO: how to handle extra message for JS/CSS previews??
211213 #TODO: Article::showCssOrJsPage ---> specialized classes!
 214+
 215+ #XXX: ImagePage and CategoryPage... wrappers that use ContentHandler? or ContentHandler creates wrappers?
212216 }
213217
214218
@@ -232,6 +236,10 @@
233237 return new WikitextContent($text, $title);
234238 }
235239
 240+ public function newContent( Title $title) {
 241+ return new WikitextContent("", $title);
 242+ }
 243+
236244 }
237245
238246 class JavaScriptContentHandler extends TextContentHandler {
@@ -244,6 +252,9 @@
245253 return new JavaScriptContent($text, $title);
246254 }
247255
 256+ public function newContent( Title $title) {
 257+ return new JavaScriptContent("", $title);
 258+ }
248259 }
249260
250261 class CssContentHandler extends TextContentHandler {
@@ -256,4 +267,8 @@
257268 return new CssContent($text, $title);
258269 }
259270
 271+ public function newContent( Title $title) {
 272+ return new CssContent("", $title);
 273+ }
 274+
260275 }

Status & tagging log