[MediaWiki-commits] [Gerrit] mediawiki...ProofreadPage[master]: Uses IndexContent in ProofreadIndexPage

2017-06-17 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/355883 )

Change subject: Uses IndexContent in ProofreadIndexPage
..


Uses IndexContent in ProofreadIndexPage

Change-Id: I85b0aaa72fcf696c903f80c48701624c1e9ef305
---
M includes/index/EditIndexPage.php
M includes/index/ProofreadIndexPage.php
M includes/page/PageContentBuilder.php
M tests/phpunit/index/IndexContentHandlerTest.php
M tests/phpunit/index/ProofreadIndexPageTest.php
5 files changed, 89 insertions(+), 68 deletions(-)

Approvals:
  jenkins-bot: Verified
  Tpt: Looks good to me, approved
  Amritsreekumar: Looks good to me, but someone else must approve



diff --git a/includes/index/EditIndexPage.php b/includes/index/EditIndexPage.php
index 819389e..909b96f 100644
--- a/includes/index/EditIndexPage.php
+++ b/includes/index/EditIndexPage.php
@@ -2,6 +2,7 @@
 
 namespace ProofreadPage\Index;
 
+use ContentHandler;
 use EditPage;
 use Html;
 use OutputPage;
@@ -41,8 +42,7 @@
$inputAttributes['readonly'] = '';
}
 
-   $index = new ProofreadIndexPage( $this->mTitle, 
ProofreadIndexPage::getDataConfig(), $this->textbox1 );
-   $entries = $index->getIndexEntries();
+   $entries = $this->getActualContent()->getIndexEntries();
 
$out->addHTML( Html::openElement( 'table', [ 'id' => 
'prp-formTable' ] ) );
$i = 10;
@@ -178,7 +178,7 @@
 * @see EditPage::internalAttemptSave
 */
public function internalAttemptSave( &$result, $bot = false ) {
-   $index = new ProofreadIndexPage( $this->mTitle, 
ProofreadIndexPage::getDataConfig(), $this->textbox1 );
+   $index = $this->getActualContent();
 
// Get list of pages titles
$links = $index->getLinksToPageNamespace();
@@ -198,4 +198,12 @@
 
return parent::internalAttemptSave( $result, $bot );
}
+
+   private function getActualContent() {
+   return new ProofreadIndexPage(
+   $this->mTitle,
+   ProofreadIndexPage::getDataConfig(),
+   ContentHandler::getForModelID( $this->contentModel 
)->unserializeContent( $this->textbox1, $this->contentFormat )
+   );
+   }
 }
diff --git a/includes/index/ProofreadIndexPage.php 
b/includes/index/ProofreadIndexPage.php
index e1543f6..b82374e 100644
--- a/includes/index/ProofreadIndexPage.php
+++ b/includes/index/ProofreadIndexPage.php
@@ -21,6 +21,7 @@
 
 use ProofreadPage\Context;
 use ProofreadPage\FileNotFoundException;
+use ProofreadPage\Index\IndexContent;
 use ProofreadPage\Pagination\PageList;
 
 /**
@@ -34,14 +35,9 @@
protected $title;
 
/**
-* @var string content of the page
+* @var IndexContent|null content of the page
 */
-   protected $text;
-
-   /**
-* @var ProofreadIndexEntry[] entries of the page
-*/
-   protected $entries;
+   protected $content;
 
/**
 * @var array configuration array
@@ -51,12 +47,12 @@
/**
 * @param Title $title Reference to a Title object.
 * @param array $config the configuration array (see 
ProofreadIndexPage::getDataConfig)
-* @param string $text content of the page. Warning: only done for 
EditProofreadIndexPage use.
+* @param IndexContent|null $content content of the page. Warning: only 
done for EditProofreadIndexPage use.
 */
-   public function __construct( Title $title, $config, $text = null ) {
+   public function __construct( Title $title, $config, IndexContent 
$content = null ) {
$this->title = $title;
$this->config = $config;
-   $this->text = $text;
+   $this->content = $content;
}
 
/**
@@ -65,7 +61,7 @@
 * @return ProofreadIndexPage
 */
public static function newFromTitle( Title $title ) {
-   return new self( $title, self::getDataConfig(), null );
+   return new self( $title, self::getDataConfig() );
}
 
/**
@@ -102,18 +98,23 @@
 
/**
 * Return content of the page
-* @return string
+* @return IndexContent
 */
-   protected function getText() {
-   if ( $this->text === null ) {
+   private function getContent() {
+   if ( $this->content === null ) {
$rev = Revision::newFromTitle( $this->title );
if ( $rev === null ) {
-   $this->text = '';
+   $this->content = new IndexContent( [] );
} else {
-   $this->text = ContentHandler::getContentText( 
$rev->getContent() );
+   $content = $rev->getContent();

[MediaWiki-commits] [Gerrit] mediawiki...ProofreadPage[master]: Uses IndexContent in ProofreadIndexPage

2017-05-27 Thread Tpt (Code Review)
Tpt has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/355883 )

Change subject: Uses IndexContent in ProofreadIndexPage
..

Uses IndexContent in ProofreadIndexPage

Change-Id: I85b0aaa72fcf696c903f80c48701624c1e9ef305
---
M includes/index/EditIndexPage.php
M includes/index/ProofreadIndexPage.php
M includes/page/PageContentBuilder.php
M tests/phpunit/index/IndexContentHandlerTest.php
M tests/phpunit/index/ProofreadIndexPageTest.php
5 files changed, 89 insertions(+), 68 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ProofreadPage 
refs/changes/83/355883/1

diff --git a/includes/index/EditIndexPage.php b/includes/index/EditIndexPage.php
index 819389e..909b96f 100644
--- a/includes/index/EditIndexPage.php
+++ b/includes/index/EditIndexPage.php
@@ -2,6 +2,7 @@
 
 namespace ProofreadPage\Index;
 
+use ContentHandler;
 use EditPage;
 use Html;
 use OutputPage;
@@ -41,8 +42,7 @@
$inputAttributes['readonly'] = '';
}
 
-   $index = new ProofreadIndexPage( $this->mTitle, 
ProofreadIndexPage::getDataConfig(), $this->textbox1 );
-   $entries = $index->getIndexEntries();
+   $entries = $this->getActualContent()->getIndexEntries();
 
$out->addHTML( Html::openElement( 'table', [ 'id' => 
'prp-formTable' ] ) );
$i = 10;
@@ -178,7 +178,7 @@
 * @see EditPage::internalAttemptSave
 */
public function internalAttemptSave( &$result, $bot = false ) {
-   $index = new ProofreadIndexPage( $this->mTitle, 
ProofreadIndexPage::getDataConfig(), $this->textbox1 );
+   $index = $this->getActualContent();
 
// Get list of pages titles
$links = $index->getLinksToPageNamespace();
@@ -198,4 +198,12 @@
 
return parent::internalAttemptSave( $result, $bot );
}
+
+   private function getActualContent() {
+   return new ProofreadIndexPage(
+   $this->mTitle,
+   ProofreadIndexPage::getDataConfig(),
+   ContentHandler::getForModelID( $this->contentModel 
)->unserializeContent( $this->textbox1, $this->contentFormat )
+   );
+   }
 }
diff --git a/includes/index/ProofreadIndexPage.php 
b/includes/index/ProofreadIndexPage.php
index e1543f6..b82374e 100644
--- a/includes/index/ProofreadIndexPage.php
+++ b/includes/index/ProofreadIndexPage.php
@@ -21,6 +21,7 @@
 
 use ProofreadPage\Context;
 use ProofreadPage\FileNotFoundException;
+use ProofreadPage\Index\IndexContent;
 use ProofreadPage\Pagination\PageList;
 
 /**
@@ -34,14 +35,9 @@
protected $title;
 
/**
-* @var string content of the page
+* @var IndexContent|null content of the page
 */
-   protected $text;
-
-   /**
-* @var ProofreadIndexEntry[] entries of the page
-*/
-   protected $entries;
+   protected $content;
 
/**
 * @var array configuration array
@@ -51,12 +47,12 @@
/**
 * @param Title $title Reference to a Title object.
 * @param array $config the configuration array (see 
ProofreadIndexPage::getDataConfig)
-* @param string $text content of the page. Warning: only done for 
EditProofreadIndexPage use.
+* @param IndexContent|null $content content of the page. Warning: only 
done for EditProofreadIndexPage use.
 */
-   public function __construct( Title $title, $config, $text = null ) {
+   public function __construct( Title $title, $config, IndexContent 
$content = null ) {
$this->title = $title;
$this->config = $config;
-   $this->text = $text;
+   $this->content = $content;
}
 
/**
@@ -65,7 +61,7 @@
 * @return ProofreadIndexPage
 */
public static function newFromTitle( Title $title ) {
-   return new self( $title, self::getDataConfig(), null );
+   return new self( $title, self::getDataConfig() );
}
 
/**
@@ -102,18 +98,23 @@
 
/**
 * Return content of the page
-* @return string
+* @return IndexContent
 */
-   protected function getText() {
-   if ( $this->text === null ) {
+   private function getContent() {
+   if ( $this->content === null ) {
$rev = Revision::newFromTitle( $this->title );
if ( $rev === null ) {
-   $this->text = '';
+   $this->content = new IndexContent( [] );
} else {
-   $this->text = ContentHandler::getContentText( 
$rev->getContent() );
+   $content = $rev->getContent();
+   if ( $content