From: daniel Date: Fri, 8 Jun 2012 06:31:28 +0000 (+0200) Subject: getting rid of getRawText() X-Git-Tag: 1.31.0-rc.0~22097^2^2~138 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=commitdiff_plain;h=2ce15203a684f29bdcc70a624e80e434dc1b8106;p=lhc%2Fweb%2Fwiklou.git getting rid of getRawText() --- diff --git a/includes/Revision.php b/includes/Revision.php index 84826c966a..059953a011 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -883,7 +883,7 @@ class Revision { * * @deprecated since 1.WD. Instead, use Revision::getContent( Revision::RAW ) or Revision::getSerializedData() as appropriate. */ - public function getRawText() { #FIXME: deprecated, replace usage! + public function getRawText() { wfDeprecated( __METHOD__, "1.WD" ); return $this->getText( self::RAW ); diff --git a/includes/WikiPage.php b/includes/WikiPage.php index 1612cc7600..df53ca7d47 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -663,7 +663,7 @@ class WikiPage extends Page { * @return String|bool The text of the current revision. False on failure * @deprecated as of 1.WD, getContent() should be used instead. */ - public function getRawText() { #@todo: deprecated, replace usage! + public function getRawText() { wfDeprecated( __METHOD__, '1.WD' ); return $this->getText( Revision::RAW ); diff --git a/includes/resourceloader/ResourceLoaderWikiModule.php b/includes/resourceloader/ResourceLoaderWikiModule.php index f08af95ed9..446559a1f5 100644 --- a/includes/resourceloader/ResourceLoaderWikiModule.php +++ b/includes/resourceloader/ResourceLoaderWikiModule.php @@ -82,7 +82,16 @@ abstract class ResourceLoaderWikiModule extends ResourceLoaderModule { if ( !$revision ) { return null; } - return $revision->getRawText(); #FIXME: get raw data from content object after checking the type; + + $content = $revision->getContent( Revision::RAW ); + $model = $content->getModel(); + + if ( $model !== CONTENT_MODEL_CSS && $model !== CONTENT_MODEL_JAVASCRIPT ) { + wfDebug( __METHOD__ . "bad content model #$model for JS/CSS page!\n" ); + return null; + } + + return $content->getNativeData(); //NOTE: this is safe, we know it's JS or CSS } /* Methods */ diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php index 18d1dbc0be..e902c64758 100644 --- a/languages/LanguageConverter.php +++ b/languages/LanguageConverter.php @@ -907,7 +907,11 @@ class LanguageConverter { if ( $title && $title->exists() ) { $revision = Revision::newFromTitle( $title ); if ( $revision ) { - $txt = $revision->getRawText(); + if ( $revision->getContentModel() == CONTENT_MODEL_WIKITEXT ) { + $txt = $revision->getContent( Revision::RAW )->getNativeData(); + } + + //@todo: in the future, use a specialized content model, perhaps based on json! } } } diff --git a/maintenance/populateRevisionLength.php b/maintenance/populateRevisionLength.php index cec91fb029..56e0ca1aaf 100644 --- a/maintenance/populateRevisionLength.php +++ b/maintenance/populateRevisionLength.php @@ -67,16 +67,16 @@ class PopulateRevisionLength extends LoggedUpdateMaintenance { # Go through and update rev_len from these rows. foreach ( $res as $row ) { $rev = new Revision( $row ); - $text = $rev->getRawText(); #FIXME: go via Content object; #FIXME: get size via Content object - if ( !is_string( $text ) ) { + $content = $rev->getContent(); + if ( !$content ) { # This should not happen, but sometimes does (bug 20757) - $this->output( "Text of revision {$row->rev_id} unavailable!\n" ); + $this->output( "Content of revision {$row->rev_id} unavailable!\n" ); $missing++; } else { # Update the row... $db->update( 'revision', - array( 'rev_len' => strlen( $text ) ), + array( 'rev_len' => $content->getSize() ), array( 'rev_id' => $row->rev_id ), __METHOD__ ); $count++; diff --git a/maintenance/populateRevisionSha1.php b/maintenance/populateRevisionSha1.php index 1d8e4c8ba6..af9006b05e 100644 --- a/maintenance/populateRevisionSha1.php +++ b/maintenance/populateRevisionSha1.php @@ -136,14 +136,14 @@ class PopulateRevisionSha1 extends LoggedUpdateMaintenance { $rev = ( $table === 'archive' ) ? Revision::newFromArchiveRow( $row ) : new Revision( $row ); - $text = $rev->getRawText(); + $text = $rev->getSerializedData(); } catch ( MWException $e ) { - $this->output( "Text of revision with {$idCol}={$row->$idCol} unavailable!\n" ); + $this->output( "Data of revision with {$idCol}={$row->$idCol} unavailable!\n" ); return false; // bug 22624? } if ( !is_string( $text ) ) { # This should not happen, but sometimes does (bug 20757) - $this->output( "Text of revision with {$idCol}={$row->$idCol} unavailable!\n" ); + $this->output( "Data of revision with {$idCol}={$row->$idCol} unavailable!\n" ); return false; } else { $db->update( $table, @@ -167,10 +167,10 @@ class PopulateRevisionSha1 extends LoggedUpdateMaintenance { $this->output( "Text of revision with timestamp {$row->ar_timestamp} unavailable!\n" ); return false; // bug 22624? } - $text = $rev->getRawText(); + $text = $rev->getSerializedData(); if ( !is_string( $text ) ) { # This should not happen, but sometimes does (bug 20757) - $this->output( "Text of revision with timestamp {$row->ar_timestamp} unavailable!\n" ); + $this->output( "Data of revision with timestamp {$row->ar_timestamp} unavailable!\n" ); return false; } else { # Archive table as no PK, but (NS,title,time) should be near unique. diff --git a/tests/phpunit/includes/WikitextContentTest.php.orig b/tests/phpunit/includes/WikitextContentTest.php.orig deleted file mode 100644 index b0e9c8dc9d..0000000000 --- a/tests/phpunit/includes/WikitextContentTest.php.orig +++ /dev/null @@ -1,438 +0,0 @@ -context = new RequestContext( new FauxRequest() ); - $this->context->setTitle( Title::newFromText( "Test" ) ); - } - - public function newContent( $text ) { - return new WikitextContent( $text ); - } - - public function dataGetParserOutput() { - return array( - array("hello ''world''\n", "

hello world\n

"), - // @todo: more...? - ); - } - - /** - * @dataProvider dataGetParserOutput - */ - public function testGetParserOutput( $text, $expectedHtml ) { - $content = $this->newContent( $text ); - - $po = $content->getParserOutput( $this->context ); - - $this->assertEquals( $expectedHtml, $po->getText() ); - } - - public function dataGetSecondaryDataUpdates() { - return array( - // @todo: more...? - ); - } - - /** - * @dataProvider dataGetParserOutput - */ - public function testGetSecondaryDataUpdates( $text, $expectedLinks ) { - $content = $this->newContent( "hello [[world]]\n" ); - - $updates = $content->getSecondaryDataUpdates( $this->context ); - - $this->assertEquals( 1, count( $updates ) ); - $this->assertEquals( "LinksUpdate", get_class( $updates[0] ) ); - } - - static $sections = - -"Intro - -== stuff == -hello world - -== test == -just a test - -== foo == -more stuff -"; - - public function dataGetSection() { - return array( - array( WikitextContentTest::$sections, - "0", - "Intro" - ), - array( WikitextContentTest::$sections, - "2", -"== test == -just a test" - ), - array( WikitextContentTest::$sections, - "8", - false - ), - ); - } - - /** - * @dataProvider dataGetSection - */ - public function testGetSection( $text, $sectionId, $expectedText ) { - $content = $this->newContent( $text ); - - $sectionContent = $content->getSection( $sectionId ); - - $this->assertEquals( $expectedText, is_null( $sectionContent ) ? null : $sectionContent->getNativeData() ); - } - - public function dataReplaceSection() { - return array( - array( WikitextContentTest::$sections, - "0", - "No more", - null, - trim( preg_replace( '/^Intro/sm', 'No more', WikitextContentTest::$sections ) ) - ), - array( WikitextContentTest::$sections, - "", - "No more", - null, - "No more" - ), - array( WikitextContentTest::$sections, - "2", - "== TEST ==\nmore fun", - null, - trim( preg_replace( '/^== test ==.*== foo ==/sm', "== TEST ==\nmore fun\n\n== foo ==", WikitextContentTest::$sections ) ) - ), - array( WikitextContentTest::$sections, - "8", - "No more", - null, - WikitextContentTest::$sections - ), - array( WikitextContentTest::$sections, - "new", - "No more", - "New", - trim( WikitextContentTest::$sections ) . "\n\n\n== New ==\n\nNo more" - ), - ); - } - - /** - * @dataProvider dataReplaceSection - */ - public function testReplaceSection( $text, $section, $with, $sectionTitle, $expected ) { - $content = $this->newContent( $text ); - $c = $content->replaceSection( $section, $this->newContent( $with ), $sectionTitle ); - - $this->assertEquals( $expected, is_null( $c ) ? null : $c->getNativeData() ); - } - - public function testAddSectionHeader( ) { - $content = $this->newContent( 'hello world' ); - $content = $content->addSectionHeader( 'test' ); - - $this->assertEquals( "== test ==\n\nhello world", $content->getNativeData() ); - } - - public function dataPreSaveTransform() { - return array( - array( 'hello this is ~~~', - "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]", - ), - array( 'hello \'\'this\'\' is ~~~', - 'hello \'\'this\'\' is ~~~', - ), - ); - } - - /** - * @dataProvider dataPreSaveTransform - */ - public function testPreSaveTransform( $text, $expected ) { - global $wgUser, $wgContLang; - $options = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang ); - - $content = $this->newContent( $text ); - $content = $content->preSaveTransform( $this->context->getTitle(), $this->context->getUser(), $options ); - - $this->assertEquals( $expected, $content->getNativeData() ); - } - - public function dataPreloadTransform() { - return array( - array( 'hello this is ~~~', - "hello this is ~~~", - ), - array( 'hello \'\'this\'\' is foobar', - 'hello \'\'this\'\' is bar', - ), - ); - } - - /** - * @dataProvider dataPreloadTransform - */ - public function testPreloadTransform( $text, $expected ) { - global $wgUser, $wgContLang; - $options = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang ); - - $content = $this->newContent( $text ); - $content = $content->preloadTransform( $this->context->getTitle(), $options ); - - $this->assertEquals( $expected, $content->getNativeData() ); - } - - public function dataGetRedirectTarget() { - return array( - array( '#REDIRECT [[Test]]', - 'Test', - ), - array( '#REDIRECT Test', - null, - ), - array( '* #REDIRECT [[Test]]', - null, - ), - ); - } - - /** - * @dataProvider dataGetRedirectTarget - */ - public function testGetRedirectTarget( $text, $expected ) { - $content = $this->newContent( $text ); - $t = $content->getRedirectTarget( ); - - if ( is_null( $expected ) ) $this->assertNull( $t, "text should not have generated a redirect target: $text" ); - else $this->assertEquals( $expected, $t->getPrefixedText() ); - } - - /** - * @dataProvider dataGetRedirectTarget - */ - public function isRedirect( $text, $expected ) { - $content = $this->newContent( $text ); - - $this->assertEquals( !is_null($expected), $content->isRedirect() ); - } - - - /** - * @todo: test needs database! - */ - /* - public function getRedirectChain() { - $text = $this->getNativeData(); - return Title::newFromRedirectArray( $text ); - } - */ - - /** - * @todo: test needs database! - */ - /* - public function getUltimateRedirectTarget() { - $text = $this->getNativeData(); - return Title::newFromRedirectRecurse( $text ); - } - */ - - - public function dataIsCountable() { - return array( - array( '', - null, - 'any', - true - ), - array( 'Foo', - null, - 'any', - true - ), - array( 'Foo', - null, - 'comma', - false - ), - array( 'Foo, bar', - null, - 'comma', - true - ), - array( 'Foo', - null, - 'link', - false - ), - array( 'Foo [[bar]]', - null, - 'link', - true - ), - array( 'Foo', - true, - 'link', - true - ), - array( 'Foo [[bar]]', - false, - 'link', - false - ), - array( '#REDIRECT [[bar]]', - true, - 'any', - false - ), - array( '#REDIRECT [[bar]]', - true, - 'comma', - false - ), - array( '#REDIRECT [[bar]]', - true, - 'link', - false - ), - ); - } - - - /** - * @dataProvider dataIsCountable - */ - public function testIsCountable( $text, $hasLinks, $mode, $expected ) { - global $wgArticleCountMethod; - - $old = $wgArticleCountMethod; - $wgArticleCountMethod = $mode; - - $content = $this->newContent( $text ); - - $v = $content->isCountable( $hasLinks, $this->context ); - $wgArticleCountMethod = $old; - - $this->assertEquals( $expected, $v, "isCountable() returned unexpected value " . var_export( $v, true ) - . " instead of " . var_export( $expected, true ) . " in mode `$mode` for text \"$text\"" ); - } - - public function dataGetTextForSummary() { - return array( - array( "hello\nworld.", - 16, - 'hello world.', - ), - array( 'hello world.', - 8, - 'hello...', - ), - array( '[[hello world]].', - 8, - 'hel...', - ), - ); - } - - /** - * @dataProvider dataGetTextForSummary - */ - public function testGetTextForSummary( $text, $maxlength, $expected ) { - $content = $this->newContent( $text ); - - $this->assertEquals( $expected, $content->getTextForSummary( $maxlength ) ); - } - - - public function testGetTextForSearchIndex( ) { - $content = $this->newContent( "hello world." ); - - $this->assertEquals( "hello world.", $content->getTextForSearchIndex() ); - } - - public function testCopy() { - $content = $this->newContent( "hello world." ); - $copy = $content->copy(); - - $this->assertTrue( $content->equals( $copy ), "copy must be equal to original" ); - $this->assertEquals( "hello world.", $copy->getNativeData() ); - } - - public function testGetSize( ) { - $content = $this->newContent( "hello world." ); - - $this->assertEquals( 12, $content->getSize() ); - } - - public function testGetNativeData( ) { - $content = $this->newContent( "hello world." ); - - $this->assertEquals( "hello world.", $content->getNativeData() ); - } - - public function testGetWikitextForTransclusion( ) { - $content = $this->newContent( "hello world." ); - - $this->assertEquals( "hello world.", $content->getWikitextForTransclusion() ); - } - - # ================================================================================================================= - - public function testGetModel() { - $content = $this->newContent( "hello world." ); - - $this->assertEquals( CONTENT_MODEL_WIKITEXT, $content->getModel() ); - } - - public function testGetContentHandler() { - $content = $this->newContent( "hello world." ); - - $this->assertEquals( CONTENT_MODEL_WIKITEXT, $content->getContentHandler()->getModelID() ); - } - - public function dataIsEmpty( ) { - return array( - array( '', true ), - array( ' ', false ), - array( '0', false ), - array( 'hallo welt.', false ), - ); - } - - /** - * @dataProvider dataIsEmpty - */ - public function testIsEmpty( $text, $empty ) { - $content = $this->newContent( $text ); - - $this->assertEquals( $empty, $content->isEmpty() ); - } - - public function dataEquals( ) { - return array( - array( new WikitextContent( "hallo" ), null, false ), - array( new WikitextContent( "hallo" ), new WikitextContent( "hallo" ), true ), - array( new WikitextContent( "hallo" ), new JavascriptContent( "hallo" ), false ), - array( new WikitextContent( "hallo" ), new WikitextContent( "HALLO" ), false ), - ); - } - - /** - * @dataProvider dataEquals - */ - public function testEquals( Content $a, Content $b = null, $equal = false ) { - $this->assertEquals( $equal, $a->equals( $b ) ); - } - -}