From: daniel
Date: Fri, 14 Sep 2012 11:13:29 +0000 (+0200)
Subject: get rid of Revision::getText
X-Git-Tag: 1.31.0-rc.0~22097^2^2~19^2
X-Git-Url: http://git.cyclocoop.org/%22.%28%24lien.?a=commitdiff_plain;h=ff03cf38ccceaa6485d72450ba1427396861af27;p=lhc%2Fweb%2Fwiklou.git
get rid of Revision::getText
Change-Id: Ia0b16813fa1688b6faccbe8ca81b1099001b1f3b
---
diff --git a/includes/FeedUtils.php b/includes/FeedUtils.php
index 242f65c397..b0a0e2b9c3 100644
--- a/includes/FeedUtils.php
+++ b/includes/FeedUtils.php
@@ -172,16 +172,36 @@ class FeedUtils {
} else {
$rev = Revision::newFromId( $newid );
if( $wgFeedDiffCutoff <= 0 || is_null( $rev ) ) {
- $newtext = '';
+ $newContent = ContentHandler::getForTitle( $title )->makeEmptyContent();
} else {
- $newtext = $rev->getText();
+ $newContent = $rev->getContent();
}
- if ( $wgFeedDiffCutoff <= 0 || strlen( $newtext ) > $wgFeedDiffCutoff ) {
+
+ if ( $newContent instanceof TextContent ) {
+ // only textual content has a "source view".
+ $text = $newContent->getNativeData();
+
+ if ( $wgFeedDiffCutoff <= 0 || strlen( $text ) > $wgFeedDiffCutoff ) {
+ $html = null;
+ } else {
+ $html = nl2br( htmlspecialchars( $text ) );
+ }
+ } else {
+ //XXX: we could get an HTML representation of the content via getParserOutput, but that may
+ // contain JS magic and generally may not be suitable for inclusion in a feed.
+ // Perhaps Content should have a getDescriptiveHtml method and/or a getSourceText method.
+ //Compare also ApiFeedContributions::feedItemDesc
+ $html = null;
+ }
+
+ if ( $html === null ) {
+
// Omit large new page diffs, bug 29110
+ // Also use diff link for non-textual content
$diffText = self::getDiffLink( $title, $newid );
} else {
$diffText = '' . wfMessage( 'newpage' )->text() . '
' .
- '' . nl2br( htmlspecialchars( $newtext ) ) . '
';
+ '' . $html . '
';
}
}
$completeText .= $diffText;
diff --git a/includes/Import.php b/includes/Import.php
index 5f59b1c122..3035005569 100644
--- a/includes/Import.php
+++ b/includes/Import.php
@@ -1017,6 +1017,7 @@ class WikiRevision {
var $model = null;
var $format = null;
var $text = "";
+ var $content = null;
var $comment = "";
var $minor = false;
var $type = "";
@@ -1209,11 +1210,32 @@ class WikiRevision {
/**
* @return string
+ *
+ * @deprecated Since 1.WD, use getContent() instead.
*/
function getText() {
+ wfDeprecated( "Use getContent() instead." );
+
return $this->text;
}
+ /**
+ * @return Content
+ */
+ function getContent() {
+ if ( is_null( $this->content ) ) {
+ $this->content =
+ ContentHandler::makeContent(
+ $this->text,
+ $this->getTitle(),
+ $this->getModel(),
+ $this->getFormat()
+ );
+ }
+
+ return $this->content;
+ }
+
/**
* @return String
*/
@@ -1377,7 +1399,7 @@ class WikiRevision {
'page' => $pageId,
'content_model' => $this->getModel(),
'content_format' => $this->getFormat(),
- 'text' => $this->getText(),
+ 'text' => $this->getContent()->serialize( $this->getFormat() ), //XXX: just set 'content' => $this->getContent()?
'comment' => $this->getComment(),
'user' => $userId,
'user_text' => $userText,
diff --git a/includes/api/ApiFeedContributions.php b/includes/api/ApiFeedContributions.php
index 1cf760aea9..fb6a06ffcb 100644
--- a/includes/api/ApiFeedContributions.php
+++ b/includes/api/ApiFeedContributions.php
@@ -130,10 +130,22 @@ class ApiFeedContributions extends ApiBase {
protected function feedItemDesc( $revision ) {
if( $revision ) {
$msg = wfMessage( 'colon-separator' )->inContentLanguage()->text();
+ $content = $revision->getContent();
+
+ if ( $content instanceof TextContent ) {
+ // only textual content has a "source view".
+ $html = nl2br( htmlspecialchars( $content->getNativeData() ) );
+ } else {
+ //XXX: we could get an HTML representation of the content via getParserOutput, but that may
+ // contain JS magic and generally may not be suitable for inclusion in a feed.
+ // Perhaps Content should have a getDescriptiveHtml method and/or a getSourceText method.
+ //Compare also FeedUtils::formatDiffRow.
+ $html = '';
+ }
+
return '' . htmlspecialchars( $revision->getUserText() ) . $msg .
htmlspecialchars( FeedItem::stripComment( $revision->getComment() ) ) .
- "
\n
\n" .
- nl2br( htmlspecialchars( $revision->getText() ) ) . "
";
+ "
\n
\n" . $html . "
";
}
return '';
}
diff --git a/includes/job/DoubleRedirectJob.php b/includes/job/DoubleRedirectJob.php
index 2d12908841..ebbd8343b6 100644
--- a/includes/job/DoubleRedirectJob.php
+++ b/includes/job/DoubleRedirectJob.php
@@ -124,8 +124,6 @@ class DoubleRedirectJob extends Job {
$newTitle = Title::makeTitle( $newTitle->getNamespace(), $newTitle->getDBkey(),
$currentDest->getFragment() );
- $text = ContentHandler::getContentText( $content ); #FIXME: get rid of this!
-
# Fix the text
$newContent = $content->updateRedirect( $newTitle );
diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php
index 69d113138a..ec89cd72b8 100644
--- a/maintenance/Maintenance.php
+++ b/maintenance/Maintenance.php
@@ -1144,7 +1144,8 @@ abstract class Maintenance {
$title = $titleObj->getPrefixedDBkey();
$this->output( "$title..." );
# Update searchindex
- $u = new SearchUpdate( $pageId, $titleObj->getText(), $rev->getText() );
+ # TODO: pass the Content object to SearchUpdate, let the search engine decide how to deal with it.
+ $u = new SearchUpdate( $pageId, $titleObj->getText(), $rev->getContent()->getTextForSearchIndex() );
$u->doUpdate();
$this->output( "\n" );
}
diff --git a/maintenance/compareParsers.php b/maintenance/compareParsers.php
index a3337173c2..1f3ac1c3b3 100644
--- a/maintenance/compareParsers.php
+++ b/maintenance/compareParsers.php
@@ -114,15 +114,24 @@ class CompareParsers extends DumpIterator {
$parser1 = new $parser1Name();
$parser2 = new $parser2Name();
- $output1 = $parser1->parse( $rev->getText(), $title, $this->options );
- $output2 = $parser2->parse( $rev->getText(), $title, $this->options );
+ $content = $rev->getContent();
+
+ if ( $content->getModel() !== CONTENT_MODEL_WIKITEXT ) {
+ $this->error( "Page {$title->getPrefixedText()} does not contain wikitext but {$content->getModel()}\n" );
+ return;
+ }
+
+ $text = strval( $content->getNativeData() );
+
+ $output1 = $parser1->parse( $text, $title, $this->options );
+ $output2 = $parser2->parse( $text, $title, $this->options );
if ( $output1->getText() != $output2->getText() ) {
$this->failed++;
$this->error( "Parsing for {$title->getPrefixedText()} differs\n" );
if ( $this->saveFailed ) {
- file_put_contents( $this->saveFailed . '/' . rawurlencode( $title->getPrefixedText() ) . ".txt", $rev->getText());
+ file_put_contents( $this->saveFailed . '/' . rawurlencode( $title->getPrefixedText() ) . ".txt", $text );
}
if ( $this->showDiff ) {
$this->output( wfDiff( $this->stripParameters( $output1->getText() ), $this->stripParameters( $output2->getText() ), '' ) );
diff --git a/maintenance/dumpIterator.php b/maintenance/dumpIterator.php
index 3657f960f7..870d632126 100644
--- a/maintenance/dumpIterator.php
+++ b/maintenance/dumpIterator.php
@@ -168,7 +168,7 @@ class SearchDump extends DumpIterator {
* @param $rev Revision
*/
public function processRevision( $rev ) {
- if ( preg_match( $this->getOption( 'regex' ), $rev->getText() ) ) {
+ if ( preg_match( $this->getOption( 'regex' ), $rev->getContent()->getTextForSearchIndex() ) ) {
$this->output( $rev->getTitle() . " matches at edit from " . $rev->getTimestamp() . "\n" );
}
}
diff --git a/maintenance/getText.php b/maintenance/getText.php
index 3e2f854010..f6adfe2be1 100644
--- a/maintenance/getText.php
+++ b/maintenance/getText.php
@@ -52,12 +52,12 @@ class GetTextMaint extends Maintenance {
$titleText = $title->getPrefixedText();
$this->error( "Page $titleText does not exist.\n", true );
}
- $text = $rev->getText( $this->hasOption( 'show-private' ) ? Revision::RAW : Revision::FOR_PUBLIC );
- if ( $text === false ) {
+ $content = $rev->getContent( $this->hasOption( 'show-private' ) ? Revision::RAW : Revision::FOR_PUBLIC );
+ if ( $content === false ) {
$titleText = $title->getPrefixedText();
$this->error( "Couldn't extract the text from $titleText.\n", true );
}
- $this->output( $text );
+ $this->output( $content->serialize() );
}
}
diff --git a/maintenance/preprocessDump.php b/maintenance/preprocessDump.php
index 5952fd960c..87fc997454 100644
--- a/maintenance/preprocessDump.php
+++ b/maintenance/preprocessDump.php
@@ -78,8 +78,14 @@ class PreprocessDump extends DumpIterator {
* @param $rev Revision
*/
public function processRevision( $rev ) {
+ $content = $rev->getContent( Revision::RAW );
+
+ if ( $content->getModel() !== CONTENT_MODEL_WIKITEXT ) {
+ return;
+ }
+
try {
- $this->mPreprocessor->preprocessToObj( $rev->getText(), 0 );
+ $this->mPreprocessor->preprocessToObj( strval( $content->getNativeData() ), 0 );
}
catch(Exception $e) {
$this->error("Caught exception " . $e->getMessage() . " in " . $rev->getTitle()->getPrefixedText() );
diff --git a/maintenance/renderDump.php b/maintenance/renderDump.php
index 24bedfa4b4..ad9a380f7b 100644
--- a/maintenance/renderDump.php
+++ b/maintenance/renderDump.php
@@ -100,10 +100,10 @@ class DumpRenderer extends Maintenance {
$this->output( sprintf( "%s\n", $filename, $display ) );
$user = new User();
- $parser = new $wgParserConf['class']();
$options = ParserOptions::newFromUser( $user );
- $output = $parser->parse( $rev->getText(), $title, $options );
+ $content = $rev->getContent();
+ $output = $content->getParserOutput( $title, null, $options );
file_put_contents( $filename,
"