https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113490
Revision: 113490
Author: daniel
Date: 2012-03-09 17:51:10 +0000 (Fri, 09 Mar 2012)
Log Message:
-----------
prep getSection, replaceSection
Modified Paths:
--------------
branches/Wikidata/phase3/includes/Content.php
branches/Wikidata/phase3/includes/ContentHandler.php
Modified: branches/Wikidata/phase3/includes/Content.php
===================================================================
--- branches/Wikidata/phase3/includes/Content.php 2012-03-09 17:39:21 UTC
(rev 113489)
+++ branches/Wikidata/phase3/includes/Content.php 2012-03-09 17:51:10 UTC
(rev 113490)
@@ -47,10 +47,30 @@
return null;
}
- public function getSection( $section ) { #FIXME: should this return text?
or a Content object? or what??
+ /**
+ * Returns the section with the given id.
+ *
+ * The default implementation returns null.
+ *
+ * @param String $sectionId the section's id
+ * @return Content|Boolean|null the section, or false if no such section
exist, or null if sections are not supported
+ */
+ public function getSection( $sectionId ) {
return null;
}
+ /**
+ * Replaces the section with the given id.
+ *
+ * The default implementation returns $this.
+ *
+ * @param String $sectionId the section's id
+ * @param Content $with the section's new content
+ * @return Content a new content object with the section replaced, or this
content object if the section couldn't be replaced.
+ */
+ public function replaceSection( $sectionId ) {
+ }
+
#XXX: is the native model for wikitext a string or the parser output?
parse early or parse late?
@@ -67,6 +87,11 @@
# TODO: EditPage::getPreloadedText( $preload ) // $wgParser->getPreloadText
+
+ # TODO: tie into API to provide contentModel for Revisions
+ # TODO: tie into API to provide serialized version and contentFormat for
Revisions
+ # TODO: tie into API edit interface
+
}
class TextContent extends Content {
@@ -114,7 +139,7 @@
}
public function getRedirectChain() {
- #XXX: really do this for all text, or just in WikitextContent
+ #XXX: really do this for all text, or just in WikitextContent?
$text = $this->getRawData();
return Title::newFromRedirectArray( $text );
}
@@ -154,13 +179,86 @@
return $po;
}
+ /**
+ * Returns the section with the given id.
+ *
+ * @param String $sectionId the section's id
+ * @return Content|false|null the section, or false if no such section
exist, or null if sections are not supported
+ */
public function getSection( $section ) {
global $wgParser;
$text = $this->getRawData();
- return $wgParser->getSection( $text, $section, false );
+ $sect = $wgParser->getSection( $text, $section, false );
+ $title = Title::newFromDBkey( $this->mTitle->getText() . '#' .
$section, $this->mTitle->getNamespace() ); #FIXME: get rid of titles here
+
+ return new WikitextContent( $sect, $title );
}
+ /**
+ * Replaces the section with the given id.
+ *
+ * @param String $sectionId the section's id
+ * @param Content $with the section's new content
+ * @return Boolean true if te section was replaced sucessfully, false
otherwise
+ */
+ #FIXME: implement replaceSection(), use in WikiPage
+
+ /**
+ * @param $section empty/null/false or a section number (0, 1, 2, T1,
T2...)
+ * @param $text String: new text of the section
+ * @param $sectionTitle String: new section's subject, only if $section is
'new'
+ * @param $edittime String: revision timestamp or null to use the current
revision
+ * @return string Complete article text, or null if error
+ */
+ /*public function replaceSection( $section, $text, $sectionTitle = '',
$edittime = null ) { #FIXME: adopt this!
+ wfProfileIn( __METHOD__ );
+
+ if ( strval( $section ) == '' ) {
+ // Whole-page edit; let the whole text through
+ } else {
+ // Bug 30711: always use current version when adding a new section
+ if ( is_null( $edittime ) || $section == 'new' ) {
+ $oldtext = $this->getRawText();
+ if ( $oldtext === false ) {
+ wfDebug( __METHOD__ . ": no page text\n" );
+ wfProfileOut( __METHOD__ );
+ return null;
+ }
+ } else {
+ $dbw = wfGetDB( DB_MASTER );
+ $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle,
$edittime );
+
+ if ( !$rev ) {
+ wfDebug( "WikiPage::replaceSection asked for bogus section
(page: " .
+ $this->getId() . "; section: $section; edittime:
$edittime)\n" );
+ wfProfileOut( __METHOD__ );
+ return null;
+ }
+
+ $oldtext = $rev->getText();
+ }
+
+ if ( $section == 'new' ) {
+ # Inserting a new section
+ $subject = $sectionTitle ? wfMsgForContent(
'newsectionheaderdefaultlevel', $sectionTitle ) . "\n\n" : '';
+ if ( wfRunHooks( 'PlaceNewSection', array( $this, $oldtext,
$subject, &$text ) ) ) {
+ $text = strlen( trim( $oldtext ) ) > 0
+ ? "{$oldtext}\n\n{$subject}{$text}"
+ : "{$subject}{$text}";
+ }
+ } else {
+ # Replacing an existing section; roll out the big guns
+ global $wgParser;
+
+ $text = $wgParser->replaceSection( $oldtext, $section, $text );
+ }
+ }
+
+ wfProfileOut( __METHOD__ );
+ return $text;
+ } */
+
}
class MessageContent extends TextContent {
Modified: branches/Wikidata/phase3/includes/ContentHandler.php
===================================================================
--- branches/Wikidata/phase3/includes/ContentHandler.php 2012-03-09
17:39:21 UTC (rev 113489)
+++ branches/Wikidata/phase3/includes/ContentHandler.php 2012-03-09
17:51:10 UTC (rev 113490)
@@ -145,6 +145,8 @@
public abstract function unserialize( $blob, Title $title, $format = null
); #FIXME: ...and revId?
+ public abstract function newContent( Title $title );
+
# public abstract function doPreSaveTransform( $title, $obj ); #TODO...
/**
@@ -208,6 +210,8 @@
#TODO: how to handle extra message for JS/CSS previews??
#TODO: Article::showCssOrJsPage ---> specialized classes!
+
+ #XXX: ImagePage and CategoryPage... wrappers that use ContentHandler? or
ContentHandler creates wrappers?
}
@@ -232,6 +236,10 @@
return new WikitextContent($text, $title);
}
+ public function newContent( Title $title) {
+ return new WikitextContent("", $title);
+ }
+
}
class JavaScriptContentHandler extends TextContentHandler {
@@ -244,6 +252,9 @@
return new JavaScriptContent($text, $title);
}
+ public function newContent( Title $title) {
+ return new JavaScriptContent("", $title);
+ }
}
class CssContentHandler extends TextContentHandler {
@@ -256,4 +267,8 @@
return new CssContent($text, $title);
}
+ public function newContent( Title $title) {
+ return new CssContent("", $title);
+ }
+
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs