/**
* Returns the length of the text in this revision, or null if unknown.
*
- * @return int
+ * @return int|null
*/
public function getSize() {
- return $this->mRecord->getSize();
+ try {
+ return $this->mRecord->getSize();
+ } catch ( RevisionAccessException $ex ) {
+ return null;
+ }
}
/**
* Returns the base36 sha1 of the content in this revision, or null if unknown.
*
- * @return string
+ * @return string|null
*/
public function getSha1() {
- // XXX: we may want to drop all the hashing logic, it's not worth the overhead.
- return $this->mRecord->getSha1();
+ try {
+ return $this->mRecord->getSha1();
+ } catch ( RevisionAccessException $ex ) {
+ return null;
+ }
}
/**
$comment = CommentStoreComment::newUnsavedComment( $summary, null );
- $title = Title::newFromID( $pageId );
+ $title = Title::newFromID( $pageId, Title::GAID_FOR_UPDATE );
+ if ( $title === null ) {
+ return null;
+ }
+
$rec = self::getRevisionStore()->newNullRevision( $dbw, $title, $comment, $minor, $user );
return new Revision( $rec );
}
/**
+ * @throws RevisionAccessException if the size was unknown and could not be calculated.
* @return int The nominal revision size, never null. May be computed on the fly.
*/
public function getSize() {
}
/**
+ * @throws RevisionAccessException if the hash was unknown and could not be calculated.
* @return string The revision hash, never null. May be computed on the fly.
*/
public function getSha1() {
*
* MCR migration note: this replaces Revision::getSize
*
+ * @throws RevisionAccessException if the size was unknown and could not be calculated.
* @return int
*/
abstract public function getSize();
*
* MCR migration note: this replaces Revision::getSha1
*
+ * @throws RevisionAccessException if the hash was unknown and could not be calculated.
* @return string
*/
abstract public function getSha1();
}
/**
+ * @throws RevisionAccessException if the size was unknown and could not be calculated.
* @return string The nominal revision size, never null. May be computed on the fly.
*/
public function getSize() {
}
/**
+ * @throws RevisionAccessException if the hash was unknown and could not be calculated.
* @return string The revision hash, never null. May be computed on the fly.
*/
public function getSha1() {
$linkRenderer = $this->getLinkRenderer();
$mainResultWidget = new FullSearchResultWidget( $this, $linkRenderer );
- if ( $search->getFeatureData( 'enable-new-crossproject-page' ) ) {
+ // Default (null) on. Can be explicitly disabled.
+ if ( $search->getFeatureData( 'enable-new-crossproject-page' ) !== false ) {
$sidebarResultWidget = new InterwikiSearchResultWidget( $this, $linkRenderer );
$sidebarResultsWidget = new InterwikiSearchResultSetWidget(
$this,
* Renders one or more SearchResultSets into a sidebar grouped by
* interwiki prefix. Includes a per-wiki header indicating where
* the results are from.
+ *
+ * @deprecated since 1.31. Use InterwikiSearchResultSetWidget
*/
class SimpleSearchResultSetWidget implements SearchResultSetWidget {
/** @var SpecialSearch */
LinkRenderer $linkRenderer,
InterwikiLookup $iwLookup
) {
+ wfDeprecated( __METHOD__, '1.31' );
$this->specialSearch = $specialSearch;
$this->resultWidget = $resultWidget;
$this->linkRenderer = $linkRenderer;
/**
* Renders a simple one-line result
+ *
+ * @deprecated since 1.31. Use other result widgets.
*/
class SimpleSearchResultWidget implements SearchResultWidget {
/** @var SpecialSearch */
protected $linkRenderer;
public function __construct( SpecialSearch $specialSearch, LinkRenderer $linkRenderer ) {
+ wfDeprecated( __METHOD__, '1.31' );
$this->specialSearch = $specialSearch;
$this->linkRenderer = $linkRenderer;
}
$this->assertEquals( __METHOD__, $rev->getContent()->getNativeData() );
}
+ /**
+ * @covers Revision::newNullRevision
+ */
+ public function testNewNullRevision_badPage() {
+ $dbw = wfGetDB( DB_MASTER );
+ $rev = Revision::newNullRevision( $dbw, -1, 'a null revision', false );
+
+ $this->assertNull( $rev );
+ }
+
/**
* @covers Revision::insertOn
*/
<?php
use MediaWiki\Storage\BlobStoreFactory;
+use MediaWiki\Storage\MutableRevisionRecord;
+use MediaWiki\Storage\RevisionAccessException;
+use MediaWiki\Storage\RevisionRecord;
use MediaWiki\Storage\RevisionStore;
+use MediaWiki\Storage\SlotRecord;
use MediaWiki\Storage\SqlBlobStore;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\LoadBalancer;
);
}
+ /**
+ * @covers Revision::getSize
+ */
+ public function testGetSize() {
+ $title = $this->getMockTitle();
+
+ $rec = new MutableRevisionRecord( $title );
+ $rev = new Revision( $rec, 0, $title );
+
+ $this->assertSame( 0, $rev->getSize(), 'Size of no slots is 0' );
+
+ $rec->setSize( 13 );
+ $this->assertSame( 13, $rev->getSize() );
+ }
+
+ /**
+ * @covers Revision::getSize
+ */
+ public function testGetSize_failure() {
+ $title = $this->getMockTitle();
+
+ $rec = $this->getMockBuilder( RevisionRecord::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $rec->method( 'getSize' )
+ ->willThrowException( new RevisionAccessException( 'Oops!' ) );
+
+ $rev = new Revision( $rec, 0, $title );
+ $this->assertNull( $rev->getSize() );
+ }
+
+ /**
+ * @covers Revision::getSha1
+ */
+ public function testGetSha1() {
+ $title = $this->getMockTitle();
+
+ $rec = new MutableRevisionRecord( $title );
+ $rev = new Revision( $rec, 0, $title );
+
+ $emptyHash = SlotRecord::base36Sha1( '' );
+ $this->assertSame( $emptyHash, $rev->getSha1(), 'Sha1 of no slots is hash of empty string' );
+
+ $rec->setSha1( 'deadbeef' );
+ $this->assertSame( 'deadbeef', $rev->getSha1() );
+ }
+
+ /**
+ * @covers Revision::getSha1
+ */
+ public function testGetSha1_failure() {
+ $title = $this->getMockTitle();
+
+ $rec = $this->getMockBuilder( RevisionRecord::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $rec->method( 'getSha1' )
+ ->willThrowException( new RevisionAccessException( 'Oops!' ) );
+
+ $rev = new Revision( $rec, 0, $title );
+ $this->assertNull( $rev->getSha1() );
+ }
+
+ /**
+ * @covers Revision::getContent
+ */
+ public function testGetContent() {
+ $title = $this->getMockTitle();
+
+ $rec = new MutableRevisionRecord( $title );
+ $rev = new Revision( $rec, 0, $title );
+
+ $this->assertNull( $rev->getContent(), 'Content of no slots is null' );
+
+ $content = new TextContent( 'Hello Kittens!' );
+ $rec->setContent( 'main', $content );
+ $this->assertSame( $content, $rev->getContent() );
+ }
+
+ /**
+ * @covers Revision::getContent
+ */
+ public function testGetContent_failure() {
+ $title = $this->getMockTitle();
+
+ $rec = $this->getMockBuilder( RevisionRecord::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $rec->method( 'getContent' )
+ ->willThrowException( new RevisionAccessException( 'Oops!' ) );
+
+ $rev = new Revision( $rec, 0, $title );
+ $this->assertNull( $rev->getContent() );
+ }
+
}