Daniel Kinzler has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/359184 )
Change subject: Deprecate Content::getNativeData, add TextContent::getText
......................................................................
Deprecate Content::getNativeData, add TextContent::getText
getNativeData() is under-specified - callers can do nothing with the
value returned by getNativeData without knowing the concrete Content
class. If the know the concrete class, the should use a specialized
getter.
Basically, getNativeData is overly generic, an example of plymorphism
done wrong. My bad. Sorry about that. Can we fix it now?
Bug: T155582
Change-Id: I6cf13e6cfe57124ff5af71761d3988bc3c82795d
---
M RELEASE-NOTES-1.30
M includes/api/ApiParse.php
M includes/api/ApiQueryRevisionsBase.php
M includes/content/AbstractContent.php
M includes/content/Content.php
M includes/content/ContentHandler.php
M includes/content/CssContent.php
M includes/content/JavaScriptContent.php
M includes/content/JsonContent.php
M includes/content/MessageContent.php
M includes/content/TextContent.php
M includes/content/TextContentHandler.php
M includes/content/WikitextContent.php
M includes/specials/SpecialUndelete.php
M languages/LanguageConverter.php
M maintenance/compareParsers.php
M maintenance/preprocessDump.php
M tests/phpunit/includes/RevisionStorageTest.php
M tests/phpunit/includes/api/ApiEditPageTest.php
M tests/phpunit/includes/content/ContentHandlerTest.php
M tests/phpunit/includes/content/JavaScriptContentTest.php
M tests/phpunit/includes/content/TextContentTest.php
M tests/phpunit/includes/content/WikitextContentHandlerTest.php
M tests/phpunit/includes/content/WikitextContentTest.php
M tests/phpunit/includes/import/ImportTest.php
M tests/phpunit/includes/page/WikiPageTest.php
M tests/phpunit/mocks/content/DummyContentForTesting.php
M tests/phpunit/mocks/content/DummyNonTextContent.php
28 files changed, 152 insertions(+), 91 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/84/359184/1
diff --git a/RELEASE-NOTES-1.30 b/RELEASE-NOTES-1.30
index cd800da..7f63bc7 100644
--- a/RELEASE-NOTES-1.30
+++ b/RELEASE-NOTES-1.30
@@ -88,6 +88,7 @@
deprecated. There are no known callers.
* File::getStreamHeaders() was deprecated.
* MediaHandler::getStreamHeaders() was deprecated.
+* Content::getNativeData() was deprecated.
* The ExtractThumbParameters hook (deprecated in 1.21) was removed.
* The OutputPage::addParserOutputNoText and ::getHeadLinks methods (both
deprecated in 1.24) were removed.
diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php
index 91e49ab..3f1a79c 100644
--- a/includes/api/ApiParse.php
+++ b/includes/api/ApiParse.php
@@ -477,12 +477,12 @@
}
if ( isset( $prop['parsetree'] ) || $params['generatexml'] ) {
- if ( $this->content->getModel() !=
CONTENT_MODEL_WIKITEXT ) {
+ if ( !$this->content instanceof WikitextContent ) {
$this->dieWithError(
'apierror-parsetree-notwikitext', 'notwikitext' );
}
$wgParser->startExternalParse( $titleObj, $popts,
Parser::OT_PREPROCESS );
- $dom = $wgParser->preprocessToDom(
$this->content->getNativeData() );
+ $dom = $wgParser->preprocessToDom(
$this->content->getText() );
if ( is_callable( [ $dom, 'saveXML' ] ) ) {
$xml = $dom->saveXML();
} else {
diff --git a/includes/api/ApiQueryRevisionsBase.php
b/includes/api/ApiQueryRevisionsBase.php
index 696ec87..440df36 100644
--- a/includes/api/ApiQueryRevisionsBase.php
+++ b/includes/api/ApiQueryRevisionsBase.php
@@ -278,8 +278,8 @@
}
if ( $this->fld_parsetree || ( $this->fld_content &&
$this->generateXML ) ) {
if ( $content ) {
- if ( $content->getModel() ===
CONTENT_MODEL_WIKITEXT ) {
- $t = $content->getNativeData(); # note:
don't set $text
+ if ( $content instanceof WikitextContent ) {
+ $t = $content->getText(); # note: don't
set $text
$wgParser->startExternalParse(
$title,
@@ -312,8 +312,8 @@
if ( $this->expandTemplates && !$this->parseContent ) {
# XXX: implement template expansion for all
content types in ContentHandler?
- if ( $content->getModel() ===
CONTENT_MODEL_WIKITEXT ) {
- $text = $content->getNativeData();
+ if ( $content instanceof WikitextContent ) {
+ $text = $content->getText();
$text = $wgParser->preprocess(
$text,
diff --git a/includes/content/AbstractContent.php
b/includes/content/AbstractContent.php
index 811b241..9f14853 100644
--- a/includes/content/AbstractContent.php
+++ b/includes/content/AbstractContent.php
@@ -197,7 +197,7 @@
return false;
}
- return $this->getNativeData() === $that->getNativeData();
+ return $this == $that;
}
/**
diff --git a/includes/content/Content.php b/includes/content/Content.php
index 6a0a63b..093bf99 100644
--- a/includes/content/Content.php
+++ b/includes/content/Content.php
@@ -77,6 +77,9 @@
*
* @since 1.21
*
+ * @deprecated since 1.30. For TextContent, use getText(). For other
content
+ * models, use specialized getters.
+ *
* @return mixed The native representation of the content. Could be a
* string, a nested array structure, an object, a binary blob...
* anything, really.
diff --git a/includes/content/ContentHandler.php
b/includes/content/ContentHandler.php
index 85894ed..3aca9b5 100644
--- a/includes/content/ContentHandler.php
+++ b/includes/content/ContentHandler.php
@@ -84,7 +84,7 @@
}
if ( $content instanceof TextContent ) {
- return $content->getNativeData();
+ return $content->getText();
}
wfDebugLog( 'ContentHandler', 'Accessing ' .
$content->getModel() . ' content as text!' );
diff --git a/includes/content/CssContent.php b/includes/content/CssContent.php
index b4f5196..fce8880 100644
--- a/includes/content/CssContent.php
+++ b/includes/content/CssContent.php
@@ -61,7 +61,7 @@
global $wgParser;
// @todo Make pre-save transformation optional for script pages
- $text = $this->getNativeData();
+ $text = $this->getText();
$pst = $wgParser->preSaveTransform( $text, $title, $user,
$popts );
return new static( $pst );
@@ -73,7 +73,7 @@
protected function getHtml() {
$html = "";
$html .= "<pre class=\"mw-code mw-css\" dir=\"ltr\">\n";
- $html .= htmlspecialchars( $this->getNativeData() );
+ $html .= htmlspecialchars( $this->getText() );
$html .= "\n</pre>\n";
return $html;
@@ -99,7 +99,7 @@
return $this->redirectTarget;
}
$this->redirectTarget = null;
- $text = $this->getNativeData();
+ $text = $this->getText();
if ( strpos( $text, '/* #REDIRECT */' ) === 0 ) {
// Extract the title from the url
preg_match( '/title=(.*?)&action=raw/', $text, $matches
);
diff --git a/includes/content/JavaScriptContent.php
b/includes/content/JavaScriptContent.php
index 6d23656..8a9f017 100644
--- a/includes/content/JavaScriptContent.php
+++ b/includes/content/JavaScriptContent.php
@@ -60,7 +60,7 @@
// @todo Make pre-save transformation optional for script pages
// See bug #32858
- $text = $this->getNativeData();
+ $text = $this->getText();
$pst = $wgParser->preSaveTransform( $text, $title, $user,
$popts );
return new static( $pst );
@@ -72,7 +72,7 @@
protected function getHtml() {
$html = "";
$html .= "<pre class=\"mw-code mw-js\" dir=\"ltr\">\n";
- $html .= htmlspecialchars( $this->getNativeData() );
+ $html .= htmlspecialchars( $this->getText() );
$html .= "\n</pre>\n";
return $html;
@@ -101,7 +101,7 @@
return $this->redirectTarget;
}
$this->redirectTarget = null;
- $text = $this->getNativeData();
+ $text = $this->getText();
if ( strpos( $text, '/* #REDIRECT */' ) === 0 ) {
// Extract the title from the url
preg_match( '/title=(.*?)\\\\u0026action=raw/', $text,
$matches );
diff --git a/includes/content/JsonContent.php b/includes/content/JsonContent.php
index 14c8182..f2b9f03 100644
--- a/includes/content/JsonContent.php
+++ b/includes/content/JsonContent.php
@@ -35,7 +35,7 @@
*/
public function getJsonData() {
wfDeprecated( __METHOD__, '1.25' );
- return FormatJson::decode( $this->getNativeData(), true );
+ return FormatJson::decode( $this->getText(), true );
}
/**
@@ -48,7 +48,7 @@
*/
public function getData() {
if ( $this->jsonParse === null ) {
- $this->jsonParse = FormatJson::parse(
$this->getNativeData() );
+ $this->jsonParse = FormatJson::parse( $this->getText()
);
}
return $this->jsonParse;
}
diff --git a/includes/content/MessageContent.php
b/includes/content/MessageContent.php
index 4b58989..421342e 100644
--- a/includes/content/MessageContent.php
+++ b/includes/content/MessageContent.php
@@ -80,9 +80,20 @@
/**
* Returns the message object, with any parameters already substituted.
*
+ * @deprecated since 1.30, use getMessage() instead.
+ *
* @return Message The message object.
*/
public function getNativeData() {
+ return $this->getMessage();
+ }
+
+ /**
+ * Returns the message object, with any parameters already substituted.
+ *
+ * @return Message The message object.
+ */
+ public function getMessage() {
// NOTE: Message objects are mutable. Cloning here makes
MessageContent immutable.
return clone $this->mMessage;
}
diff --git a/includes/content/TextContent.php b/includes/content/TextContent.php
index 7bb4def..926402f 100644
--- a/includes/content/TextContent.php
+++ b/includes/content/TextContent.php
@@ -68,7 +68,7 @@
public function getTextForSummary( $maxlength = 250 ) {
global $wgContLang;
- $text = $this->getNativeData();
+ $text = $this->getText();
$truncatedtext = $wgContLang->truncate(
preg_replace( "/[\n\r]/", ' ', $text ),
@@ -83,7 +83,7 @@
* @return int
*/
public function getSize() {
- $text = $this->getNativeData();
+ $text = $this->getText();
return strlen( $text );
}
@@ -114,9 +114,20 @@
/**
* Returns the text represented by this Content object, as a string.
*
- * @return string The raw text.
+ * @deprecated since 1.30, use getMessage() instead.
+ *
+ * @return string The raw text. Subclasses may guarantee a specific
syntax here.
*/
public function getNativeData() {
+ return $this->getText();
+ }
+
+ /**
+ * Returns the text represented by this Content object, as a string.
+ *
+ * @return string The raw text.
+ */
+ public function getText() {
return $this->mText;
}
@@ -126,7 +137,7 @@
* @return string The raw text.
*/
public function getTextForSearchIndex() {
- return $this->getNativeData();
+ return $this->getText();
}
/**
@@ -141,7 +152,7 @@
$wikitext = $this->convert( CONTENT_MODEL_WIKITEXT, 'lossy' );
if ( $wikitext ) {
- return $wikitext->getNativeData();
+ return $wikitext->getText();
} else {
return false;
}
@@ -177,7 +188,7 @@
* @return Content
*/
public function preSaveTransform( Title $title, User $user,
ParserOptions $popts ) {
- $text = $this->getNativeData();
+ $text = $this->getText();
$pst = self::normalizeLineEndings( $text );
return ( $text === $pst ) ? $this : new static( $pst,
$this->getModel() );
@@ -206,8 +217,8 @@
$lang = $wgContLang;
}
- $otext = $this->getNativeData();
- $ntext = $that->getNativeData();
+ $otext = $this->getText();
+ $ntext = $that->getText();
# Note: Use native PHP diff, external engines don't give us
abstract output
$ota = explode( "\n", $lang->segmentForDiff( $otext ) );
@@ -242,7 +253,7 @@
if ( in_array( $this->getModel(), $wgTextModelsToParse ) ) {
// parse just to get links etc into the database, HTML
is replaced below.
- $output = $wgParser->parse( $this->getNativeData(),
$title, $options, true, true, $revId );
+ $output = $wgParser->parse( $this->getText(), $title,
$options, true, true, $revId );
}
if ( $generateHtml ) {
@@ -288,7 +299,7 @@
* @return string An HTML representation of the content
*/
protected function getHighlightHtml() {
- return htmlspecialchars( $this->getNativeData() );
+ return htmlspecialchars( $this->getText() );
}
/**
@@ -315,11 +326,37 @@
if ( $toHandler instanceof TextContentHandler ) {
// NOTE: ignore content serialization format - it's
just text anyway.
- $text = $this->getNativeData();
+ $text = $this->getText();
$converted = $toHandler->unserializeContent( $text );
}
return $converted;
}
+ /**
+ * @since 1.21
+ *
+ * @param Content $that
+ *
+ * @return bool
+ *
+ * @see Content::equals
+ */
+ public function equals( Content $that = null ) {
+ if ( is_null( $that ) ) {
+ return false;
+ }
+
+ if ( $that === $this ) {
+ return true;
+ }
+
+ if ( $that->getModel() !== $this->getModel() ) {
+ return false;
+ }
+
+ /** @var TextContent $that */
+ return $this->getText() === $that->getText();
+ }
+
}
diff --git a/includes/content/TextContentHandler.php
b/includes/content/TextContentHandler.php
index 698a37b..482ff65 100644
--- a/includes/content/TextContentHandler.php
+++ b/includes/content/TextContentHandler.php
@@ -47,7 +47,7 @@
public function serializeContent( Content $content, $format = null ) {
$this->checkFormat( $format );
- return $content->getNativeData();
+ return $content->getText();
}
/**
diff --git a/includes/content/WikitextContent.php
b/includes/content/WikitextContent.php
index d649baf..7e9b6cc 100644
--- a/includes/content/WikitextContent.php
+++ b/includes/content/WikitextContent.php
@@ -47,7 +47,7 @@
public function getSection( $sectionId ) {
global $wgParser;
- $text = $this->getNativeData();
+ $text = $this->getText();
$sect = $wgParser->getSection( $text, $sectionId, false );
if ( $sect === false ) {
@@ -78,8 +78,8 @@
"section uses $sectionModelId." );
}
- $oldtext = $this->getNativeData();
- $text = $with->getNativeData();
+ $oldtext = $this->getText();
+ $text = $with->getText();
if ( strval( $sectionId ) === '' ) {
return $with; # XXX: copy first?
@@ -118,7 +118,7 @@
$text = wfMessage( 'newsectionheaderdefaultlevel' )
->rawParams( $header )->inContentLanguage()->text();
$text .= "\n\n";
- $text .= $this->getNativeData();
+ $text .= $this->getText();
return new static( $text );
}
@@ -136,7 +136,7 @@
public function preSaveTransform( Title $title, User $user,
ParserOptions $popts ) {
global $wgParser;
- $text = $this->getNativeData();
+ $text = $this->getText();
$pst = $wgParser->preSaveTransform( $text, $title, $user,
$popts );
return ( $text === $pst ) ? $this : new static( $pst );
@@ -155,7 +155,7 @@
public function preloadTransform( Title $title, ParserOptions $popts,
$params = [] ) {
global $wgParser;
- $text = $this->getNativeData();
+ $text = $this->getText();
$plt = $wgParser->getPreloadText( $text, $title, $popts,
$params );
return new static( $plt );
@@ -179,12 +179,12 @@
if ( $wgMaxRedirects < 1 ) {
// redirects are disabled, so quit early
- $this->redirectTargetAndText = [ null,
$this->getNativeData() ];
+ $this->redirectTargetAndText = [ null, $this->getText()
];
return $this->redirectTargetAndText;
}
$redir = MagicWord::get( 'redirect' );
- $text = ltrim( $this->getNativeData() );
+ $text = ltrim( $this->getText() );
if ( $redir->matchStartAndRemove( $text ) ) {
// Extract the first link and see if it's usable
// Ensure that it really does come directly after
#REDIRECT
@@ -200,7 +200,7 @@
$title = Title::newFromText( $m[1] );
// If the title is a redirect to bad special
pages or is invalid, return null
if ( !$title instanceof Title ||
!$title->isValidRedirectTarget() ) {
- $this->redirectTargetAndText = [ null,
$this->getNativeData() ];
+ $this->redirectTargetAndText = [ null,
$this->getText() ];
return $this->redirectTargetAndText;
}
@@ -209,7 +209,7 @@
}
}
- $this->redirectTargetAndText = [ null, $this->getNativeData() ];
+ $this->redirectTargetAndText = [ null, $this->getText() ];
return $this->redirectTargetAndText;
}
@@ -248,7 +248,7 @@
# so the regex has to be fairly general
$newText = preg_replace( '/ \[ \[ [^\]]* \] \] /x',
'[[' . $target->getFullText() . ']]',
- $this->getNativeData(), 1 );
+ $this->getText(), 1 );
return new static( $newText );
}
@@ -275,7 +275,7 @@
case 'any':
return true;
case 'comma':
- $text = $this->getNativeData();
+ $text = $this->getText();
return strpos( $text, ',' ) !== false;
case 'link':
if ( $hasLinks === null ) { # not known, find
out
@@ -364,7 +364,7 @@
* @see Content::matchMagicWord()
*/
public function matchMagicWord( MagicWord $word ) {
- return $word->match( $this->getNativeData() );
+ return $word->match( $this->getText() );
}
}
diff --git a/includes/specials/SpecialUndelete.php
b/includes/specials/SpecialUndelete.php
index fa38506..82c1567 100644
--- a/includes/specials/SpecialUndelete.php
+++ b/includes/specials/SpecialUndelete.php
@@ -437,7 +437,7 @@
'cols' => 80,
'rows' => 25
],
- $content->getNativeData() . "\n"
+ $content->getText() . "\n"
);
$previewButton = Xml::element( 'input', [
diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php
index 5382df4..32abb42 100644
--- a/languages/LanguageConverter.php
+++ b/languages/LanguageConverter.php
@@ -942,7 +942,7 @@
$revision = Revision::newFromTitle( $title );
if ( $revision ) {
if ( $revision->getContentModel() ==
CONTENT_MODEL_WIKITEXT ) {
- $txt = $revision->getContent(
Revision::RAW )->getNativeData();
+ $txt = $revision->getContent(
Revision::RAW )->getText();
}
// @todo in the future, use a
specialized content model, perhaps based on json!
diff --git a/maintenance/compareParsers.php b/maintenance/compareParsers.php
index f2540c7..0e2e07f 100644
--- a/maintenance/compareParsers.php
+++ b/maintenance/compareParsers.php
@@ -145,7 +145,7 @@
return;
}
- $text = strval( $content->getNativeData() );
+ $text = strval( $content->getText() );
$output1 = $parser1->parse( $text, $title, $this->options );
$output2 = $parser2->parse( $text, $title, $this->options );
diff --git a/maintenance/preprocessDump.php b/maintenance/preprocessDump.php
index 17d97b0..6a19463 100644
--- a/maintenance/preprocessDump.php
+++ b/maintenance/preprocessDump.php
@@ -81,12 +81,12 @@
public function processRevision( $rev ) {
$content = $rev->getContent( Revision::RAW );
- if ( $content->getModel() !== CONTENT_MODEL_WIKITEXT ) {
+ if ( $content instanceof WikitextContent ) {
return;
}
try {
- $this->mPreprocessor->preprocessToObj( strval(
$content->getNativeData() ), 0 );
+ $this->mPreprocessor->preprocessToObj( strval(
$content->getText() ), 0 );
} catch ( Exception $e ) {
$this->error( "Caught exception " . $e->getMessage() .
" in "
. $rev->getTitle()->getPrefixedText() );
diff --git a/tests/phpunit/includes/RevisionStorageTest.php
b/tests/phpunit/includes/RevisionStorageTest.php
index 642ada2..b96d439 100644
--- a/tests/phpunit/includes/RevisionStorageTest.php
+++ b/tests/phpunit/includes/RevisionStorageTest.php
@@ -299,7 +299,7 @@
$orig = $this->makeRevision( [ 'text' => 'hello hello.' ] );
$rev = Revision::newFromId( $orig->getId() );
- $this->assertEquals( 'hello hello.',
$rev->getContent()->getNativeData() );
+ $this->assertEquals( 'hello hello.',
$rev->getContent()->getText() );
}
/**
@@ -435,7 +435,7 @@
'new null revision shold have a different id from the
original revision' );
$this->assertEquals( $orig->getTextId(), $rev->getTextId(),
'new null revision shold have the same text id as the
original revision' );
- $this->assertEquals( 'some testing text',
$rev->getContent()->getNativeData() );
+ $this->assertEquals( 'some testing text',
$rev->getContent()->getText() );
}
public static function provideUserWasLastToEdit() {
diff --git a/tests/phpunit/includes/api/ApiEditPageTest.php
b/tests/phpunit/includes/api/ApiEditPageTest.php
index e091153..7328613 100644
--- a/tests/phpunit/includes/api/ApiEditPageTest.php
+++ b/tests/phpunit/includes/api/ApiEditPageTest.php
@@ -160,7 +160,7 @@
$content = $page->getContent();
$this->assertNotNull( $content, 'Page should have been created'
);
- $text = $content->getNativeData();
+ $text = $content->getText();
$this->assertEquals( $expected, $text );
}
@@ -184,7 +184,7 @@
$this->assertEquals( 'Success', $re['edit']['result'] );
$newtext = WikiPage::factory( Title::newFromText( $name ) )
->getContent( Revision::RAW )
- ->getNativeData();
+ ->getText();
$this->assertEquals( "==section 1==\nnew content 1\n\n==section
2==\ncontent2", $newtext );
// Test that we raise a 'nosuchsection' error
@@ -224,7 +224,7 @@
// Check the page text is correct
$text = WikiPage::factory( Title::newFromText( $name ) )
->getContent( Revision::RAW )
- ->getNativeData();
+ ->getText();
$this->assertEquals( "== header ==\n\ntest", $text );
// Now on one that does
@@ -240,7 +240,7 @@
$this->assertEquals( 'Success', $re2['edit']['result'] );
$text = WikiPage::factory( Title::newFromText( $name ) )
->getContent( Revision::RAW )
- ->getNativeData();
+ ->getText();
$this->assertEquals( "== header ==\n\ntest\n\n== header
==\n\ntest", $text );
}
diff --git a/tests/phpunit/includes/content/ContentHandlerTest.php
b/tests/phpunit/includes/content/ContentHandlerTest.php
index 403bee1..e550a99 100644
--- a/tests/phpunit/includes/content/ContentHandlerTest.php
+++ b/tests/phpunit/includes/content/ContentHandlerTest.php
@@ -208,7 +208,7 @@
$content = new WikitextContent( "hello world" );
$text = ContentHandler::getContentText( $content );
- $this->assertEquals( $content->getNativeData(), $text );
+ $this->assertEquals( $content->getText(), $text );
}
/**
@@ -254,9 +254,9 @@
public static function dataMakeContent() {
return [
- [ 'hallo', 'Help:Test', null, null,
CONTENT_MODEL_WIKITEXT, 'hallo', false ],
- [ 'hallo', 'MediaWiki:Test.js', null, null,
CONTENT_MODEL_JAVASCRIPT, 'hallo', false ],
- [ serialize( 'hallo' ), 'Dummy:Test', null, null,
"testing", 'hallo', false ],
+ [ 'hallo', 'Help:Test', null, null,
CONTENT_MODEL_WIKITEXT, false ],
+ [ 'hallo', 'MediaWiki:Test.js', null, null,
CONTENT_MODEL_JAVASCRIPT, false ],
+ [ serialize( 'hallo' ), 'Dummy:Test', null, null,
"testing", false ],
[
'hallo',
@@ -264,7 +264,6 @@
null,
CONTENT_FORMAT_WIKITEXT,
CONTENT_MODEL_WIKITEXT,
- 'hallo',
false
],
[
@@ -273,19 +272,17 @@
null,
CONTENT_FORMAT_JAVASCRIPT,
CONTENT_MODEL_JAVASCRIPT,
- 'hallo',
false
],
- [ serialize( 'hallo' ), 'Dummy:Test', null, "testing",
"testing", 'hallo', false ],
+ [ serialize( 'hallo' ), 'Dummy:Test', null, "testing",
"testing", false ],
- [ 'hallo', 'Help:Test', CONTENT_MODEL_CSS, null,
CONTENT_MODEL_CSS, 'hallo', false ],
+ [ 'hallo', 'Help:Test', CONTENT_MODEL_CSS, null,
CONTENT_MODEL_CSS, false ],
[
'hallo',
'MediaWiki:Test.js',
CONTENT_MODEL_CSS,
null,
CONTENT_MODEL_CSS,
- 'hallo',
false
],
[
@@ -294,13 +291,12 @@
CONTENT_MODEL_CSS,
null,
CONTENT_MODEL_CSS,
- serialize( 'hallo' ),
false
],
- [ 'hallo', 'Help:Test', CONTENT_MODEL_WIKITEXT,
"testing", null, null, true ],
- [ 'hallo', 'MediaWiki:Test.js', CONTENT_MODEL_CSS,
"testing", null, null, true ],
- [ 'hallo', 'Dummy:Test', CONTENT_MODEL_JAVASCRIPT,
"testing", null, null, true ],
+ [ 'hallo', 'Help:Test', CONTENT_MODEL_WIKITEXT,
"testing", null, true ],
+ [ 'hallo', 'MediaWiki:Test.js', CONTENT_MODEL_CSS,
"testing", null, true ],
+ [ 'hallo', 'Dummy:Test', CONTENT_MODEL_JAVASCRIPT,
"testing", null, true ],
];
}
@@ -309,7 +305,7 @@
* @covers ContentHandler::makeContent
*/
public function testMakeContent( $data, $title, $modelId, $format,
- $expectedModelId, $expectedNativeData, $shouldFail
+ $expectedModelId, $shouldFail
) {
$title = Title::newFromText( $title );
LinkCache::singleton()->addBadLinkObj( $title );
@@ -321,7 +317,7 @@
}
$this->assertEquals( $expectedModelId,
$content->getModel(), 'bad model id' );
- $this->assertEquals( $expectedNativeData,
$content->getNativeData(), 'bads native data' );
+ $this->assertEquals( $data, $content->serialize(), 'bad
serialized data' );
} catch ( MWException $ex ) {
if ( !$shouldFail ) {
$this->fail( "ContentHandler::makeContent
failed unexpectedly: " . $ex->getMessage() );
diff --git a/tests/phpunit/includes/content/JavaScriptContentTest.php
b/tests/phpunit/includes/content/JavaScriptContentTest.php
index 1c746bc..47da062 100644
--- a/tests/phpunit/includes/content/JavaScriptContentTest.php
+++ b/tests/phpunit/includes/content/JavaScriptContentTest.php
@@ -247,7 +247,7 @@
$content = new JavaScriptContent( $oldText );
$newContent = $content->updateRedirect( $target );
- $this->assertEquals( $expectedText,
$newContent->getNativeData() );
+ $this->assertEquals( $expectedText, $newContent->getText() );
}
public static function provideUpdateRedirect() {
diff --git a/tests/phpunit/includes/content/TextContentTest.php
b/tests/phpunit/includes/content/TextContentTest.php
index b290f8f..15faf09 100644
--- a/tests/phpunit/includes/content/TextContentTest.php
+++ b/tests/phpunit/includes/content/TextContentTest.php
@@ -39,6 +39,10 @@
parent::tearDown();
}
+ /**
+ * @param string $text
+ * @return TextContent
+ */
public function newContent( $text ) {
return new TextContent( $text );
}
@@ -126,7 +130,7 @@
$options
);
- $this->assertEquals( $expected, $content->getNativeData() );
+ $this->assertEquals( $expected, $content->getText() );
}
public static function dataPreloadTransform() {
@@ -149,7 +153,7 @@
$content = $this->newContent( $text );
$content = $content->preloadTransform(
$this->context->getTitle(), $options );
- $this->assertEquals( $expected, $content->getNativeData() );
+ $this->assertEquals( $expected, $content->getText() );
}
public static function dataGetRedirectTarget() {
@@ -275,7 +279,7 @@
$copy = $content->copy();
$this->assertTrue( $content->equals( $copy ), 'copy must be
equal to original' );
- $this->assertEquals( 'hello world.', $copy->getNativeData() );
+ $this->assertEquals( 'hello world.', $copy->getText() );
}
/**
@@ -285,6 +289,15 @@
$content = $this->newContent( 'hello world.' );
$this->assertEquals( 12, $content->getSize() );
+ }
+
+ /**
+ * @covers TextContent::getText
+ */
+ public function testGetText() {
+ $content = $this->newContent( 'hello world.' );
+
+ $this->assertEquals( 'hello world.', $content->getText() );
}
/**
@@ -456,7 +469,7 @@
$this->assertFalse( $converted, "conversion to $model
was expected to fail!" );
} else {
$this->assertInstanceOf( 'Content', $converted );
- $this->assertEquals( $expectedNative,
$converted->getNativeData() );
+ $this->assertEquals( $expectedNative,
$converted->getText() );
}
}
diff --git a/tests/phpunit/includes/content/WikitextContentHandlerTest.php
b/tests/phpunit/includes/content/WikitextContentHandlerTest.php
index 290b11a..0e18bf9 100644
--- a/tests/phpunit/includes/content/WikitextContentHandlerTest.php
+++ b/tests/phpunit/includes/content/WikitextContentHandlerTest.php
@@ -40,10 +40,10 @@
*/
public function testUnserializeContent() {
$content = $this->handler->unserializeContent( 'hello world' );
- $this->assertEquals( 'hello world', $content->getNativeData() );
+ $this->assertEquals( 'hello world', $content->getText() );
$content = $this->handler->unserializeContent( 'hello world',
CONTENT_FORMAT_WIKITEXT );
- $this->assertEquals( 'hello world', $content->getNativeData() );
+ $this->assertEquals( 'hello world', $content->getText() );
try {
$this->handler->unserializeContent( 'hello world',
'dummy/foo' );
@@ -60,7 +60,7 @@
$content = $this->handler->makeEmptyContent();
$this->assertTrue( $content->isEmpty() );
- $this->assertEquals( '', $content->getNativeData() );
+ $this->assertEquals( '', $content->getText() );
}
public static function dataIsSupportedFormat() {
@@ -166,7 +166,7 @@
$merged = $this->handler->merge3( $oldContent, $myContent,
$yourContent );
- $this->assertEquals( $expected, $merged ?
$merged->getNativeData() : $merged );
+ $this->assertEquals( $expected, $merged ? $merged->getText() :
$merged );
}
public static function dataGetAutosummary() {
diff --git a/tests/phpunit/includes/content/WikitextContentTest.php
b/tests/phpunit/includes/content/WikitextContentTest.php
index b9ce997..d0f5b8f 100644
--- a/tests/phpunit/includes/content/WikitextContentTest.php
+++ b/tests/phpunit/includes/content/WikitextContentTest.php
@@ -128,7 +128,7 @@
$sectionContent = $content->getSection( $sectionId );
if ( is_object( $sectionContent ) ) {
- $sectionText = $sectionContent->getNativeData();
+ $sectionText = $sectionContent->getText();
} else {
$sectionText = $sectionContent;
}
@@ -182,7 +182,7 @@
$content = $this->newContent( $text );
$c = $content->replaceSection( $section, $this->newContent(
$with ), $sectionTitle );
- $this->assertEquals( $expected, is_null( $c ) ? null :
$c->getNativeData() );
+ $this->assertEquals( $expected, is_null( $c ) ? null :
$c->getText() );
}
/**
@@ -192,7 +192,7 @@
$content = $this->newContent( 'hello world' );
$content = $content->addSectionHeader( 'test' );
- $this->assertEquals( "== test ==\n\nhello world",
$content->getNativeData() );
+ $this->assertEquals( "== test ==\n\nhello world",
$content->getText() );
}
public static function dataPreSaveTransform() {
diff --git a/tests/phpunit/includes/import/ImportTest.php
b/tests/phpunit/includes/import/ImportTest.php
index 53d91c6..283b4c7 100644
--- a/tests/phpunit/includes/import/ImportTest.php
+++ b/tests/phpunit/includes/import/ImportTest.php
@@ -33,7 +33,7 @@
$title = Title::newFromText( $title );
$this->assertTrue( $title->exists() );
- $this->assertEquals( WikiPage::factory( $title
)->getContent()->getNativeData(), $text );
+ $this->assertEquals( WikiPage::factory( $title
)->getContent()->getText(), $text );
}
public function getUnknownTagsXML() {
diff --git a/tests/phpunit/includes/page/WikiPageTest.php
b/tests/phpunit/includes/page/WikiPageTest.php
index 556a348..d83df01 100644
--- a/tests/phpunit/includes/page/WikiPageTest.php
+++ b/tests/phpunit/includes/page/WikiPageTest.php
@@ -248,7 +248,7 @@
$rev = $page->getRevision();
$this->assertEquals( $page->getLatest(), $rev->getId() );
- $this->assertEquals( "some text",
$rev->getContent()->getNativeData() );
+ $this->assertEquals( "some text", $rev->getContent()->getText()
);
}
/**
@@ -264,7 +264,7 @@
$this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT );
$content = $page->getContent();
- $this->assertEquals( "some text", $content->getNativeData() );
+ $this->assertEquals( "some text", $content->getText() );
}
/**
@@ -680,7 +680,7 @@
$content = ContentHandler::makeContent( $with,
$page->getTitle(), $page->getContentModel() );
$c = $page->replaceSectionContent( $section, $content,
$sectionTitle );
- $this->assertEquals( $expected, is_null( $c ) ? null : trim(
$c->getNativeData() ) );
+ $this->assertEquals( $expected, is_null( $c ) ? null : trim(
$c->getText() ) );
}
/**
@@ -696,7 +696,7 @@
$content = ContentHandler::makeContent( $with,
$page->getTitle(), $page->getContentModel() );
$c = $page->replaceSectionAtRev( $section, $content,
$sectionTitle, $baseRevId );
- $this->assertEquals( $expected, is_null( $c ) ? null : trim(
$c->getNativeData() ) );
+ $this->assertEquals( $expected, is_null( $c ) ? null : trim(
$c->getText() ) );
}
/* @todo FIXME: fix this!
@@ -864,7 +864,7 @@
$page = new WikiPage( $page->getTitle() );
$this->assertEquals( $rev2->getSha1(),
$page->getRevision()->getSha1(),
"rollback did not revert to the correct revision" );
- $this->assertEquals( "one\n\ntwo",
$page->getContent()->getNativeData() );
+ $this->assertEquals( "one\n\ntwo",
$page->getContent()->getText() );
}
/**
@@ -919,7 +919,7 @@
$page = new WikiPage( $page->getTitle() );
$this->assertEquals( $rev1->getSha1(),
$page->getRevision()->getSha1(),
"rollback did not revert to the correct revision" );
- $this->assertEquals( "one",
$page->getContent()->getNativeData() );
+ $this->assertEquals( "one", $page->getContent()->getText() );
}
/**
@@ -988,7 +988,7 @@
$page = new WikiPage( $page->getTitle() );
$this->assertEquals( $rev1->getSha1(),
$page->getRevision()->getSha1(),
"rollback did not revert to the correct revision" );
- $this->assertEquals( "one",
$page->getContent()->getNativeData() );
+ $this->assertEquals( "one", $page->getContent()->getText() );
}
public static function provideGetAutoDeleteReason() {
diff --git a/tests/phpunit/mocks/content/DummyContentForTesting.php
b/tests/phpunit/mocks/content/DummyContentForTesting.php
index cdb3f78..2b4332a 100644
--- a/tests/phpunit/mocks/content/DummyContentForTesting.php
+++ b/tests/phpunit/mocks/content/DummyContentForTesting.php
@@ -102,7 +102,7 @@
public function getParserOutput( Title $title, $revId = null,
ParserOptions $options = null, $generateHtml = true
) {
- return new ParserOutput( $this->getNativeData() );
+ return new ParserOutput( $this->getText() );
}
/**
@@ -116,6 +116,6 @@
*/
protected function fillParserOutput( Title $title, $revId,
ParserOptions $options, $generateHtml, ParserOutput
&$output ) {
- $output = new ParserOutput( $this->getNativeData() );
+ $output = new ParserOutput( $this->getText() );
}
}
diff --git a/tests/phpunit/mocks/content/DummyNonTextContent.php
b/tests/phpunit/mocks/content/DummyNonTextContent.php
index afc1a4a..1b725a1 100644
--- a/tests/phpunit/mocks/content/DummyNonTextContent.php
+++ b/tests/phpunit/mocks/content/DummyNonTextContent.php
@@ -102,7 +102,7 @@
public function getParserOutput( Title $title, $revId = null,
ParserOptions $options = null, $generateHtml = true
) {
- return new ParserOutput( $this->getNativeData() );
+ return new ParserOutput( $this->getText() );
}
/**
@@ -116,6 +116,6 @@
*/
protected function fillParserOutput( Title $title, $revId,
ParserOptions $options, $generateHtml, ParserOutput
&$output ) {
- $output = new ParserOutput( $this->getNativeData() );
+ $output = new ParserOutput( $this->getText() );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/359184
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6cf13e6cfe57124ff5af71761d3988bc3c82795d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits