jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/392187 )

Change subject: IntroducesIndexContentLookup
......................................................................


IntroducesIndexContentLookup

Change-Id: I8bd3a2494ad78168d4ed569c766eb642794972cb
---
M extension.json
M includes/Context.php
M includes/Pagination/PaginationFactory.php
M includes/Parser/PagesTagParser.php
A includes/index/DatabaseIndexContentLookup.php
A includes/index/IndexContentLookup.php
M includes/index/ProofreadIndexPage.php
M includes/page/PageContentBuilder.php
M includes/page/PageDisplayHandler.php
M tests/phpunit/ContextTest.php
M tests/phpunit/Pagination/PaginationFactoryTest.php
M tests/phpunit/ProofreadPageTestCase.php
A tests/phpunit/index/IndexContentLookupMock.php
M tests/phpunit/index/ProofreadIndexPageTest.php
M tests/phpunit/page/PageContentBuilderTest.php
M tests/phpunit/page/PageDisplayHandlerTest.php
16 files changed, 220 insertions(+), 132 deletions(-)

Approvals:
  jenkins-bot: Verified
  Tpt: Looks good to me, approved



diff --git a/extension.json b/extension.json
index 1a2eba4..8e2de1e 100644
--- a/extension.json
+++ b/extension.json
@@ -55,6 +55,8 @@
                "ProofreadIndexPage": "includes/index/ProofreadIndexPage.php",
                "ProofreadPage\\Index\\CustomIndexField": 
"includes/index/CustomIndexField.php",
                "ProofreadPage\\Index\\CustomIndexFieldsParser": 
"includes/index/CustomIndexFieldsParser.php",
+               "ProofreadPage\\Index\\IndexContentLookup": 
"includes/index/IndexContentLookup.php",
+               "ProofreadPage\\Index\\DatabaseIndexContentLookup": 
"includes/index/DatabaseIndexContentLookup.php",
                "ProofreadPage\\Index\\IndexContent": 
"includes/index/IndexContent.php",
                "ProofreadPage\\Index\\IndexRedirectContent": 
"includes/index/IndexRedirectContent.php",
                "ProofreadPage\\Index\\IndexContentHandler": 
"includes/index/IndexContentHandler.php",
@@ -96,6 +98,7 @@
                "ApiQueryProofreadInfo": "ApiQueryProofreadInfo.php",
                "ProofreadPage\\FileProviderMock": 
"tests/phpunit/FileProviderMock.php",
                "ProofreadPage\\Page\\IndexForPageLookupMock": 
"tests/phpunit/page/IndexForPageLookupMock.php",
+               "ProofreadPage\\Index\\IndexContentLookupMock": 
"tests/phpunit/index/IndexContentLookupMock.php",
                "ProofreadPageTestCase": 
"tests/phpunit/ProofreadPageTestCase.php",
                "FixProofreadPagePagesContentModel": 
"maintenance/fixProofreadPagePagesContentModel.php",
                "FixProofreadIndexPagesContentModel": 
"maintenance/fixProofreadIndexPagesContentModel.php"
diff --git a/includes/Context.php b/includes/Context.php
index 4644bfb..00730f2 100644
--- a/includes/Context.php
+++ b/includes/Context.php
@@ -3,6 +3,8 @@
 namespace ProofreadPage;
 
 use ProofreadPage\Index\CustomIndexFieldsParser;
+use ProofreadPage\Index\DatabaseIndexContentLookup;
+use ProofreadPage\Index\IndexContentLookup;
 use ProofreadPage\Page\DatabaseIndexForPageLookup;
 use ProofreadPage\Page\IndexForPageLookup;
 use ProofreadPage\Pagination\PaginationFactory;
@@ -45,21 +47,29 @@
        private $indexForPageLookup;
 
        /**
+        * @var IndexContentLookup
+        */
+       private $indexContentLookup;
+
+       /**
         * @param int $pageNamespaceId
         * @param int $indexNamespaceId
         * @param FileProvider $fileProvider
         * @param CustomIndexFieldsParser $customIndexFieldsParser
         * @param IndexForPageLookup $indexForPageLookup
+        * @param IndexContentLookup $indexContentLookup
         */
        public function __construct(
                $pageNamespaceId, $indexNamespaceId, FileProvider $fileProvider,
-               CustomIndexFieldsParser $customIndexFieldsParser, 
IndexForPageLookup $indexForPageLookup
+               CustomIndexFieldsParser $customIndexFieldsParser, 
IndexForPageLookup $indexForPageLookup,
+               IndexContentLookup $indexContentLookup
        ) {
                $this->pageNamespaceId = $pageNamespaceId;
                $this->indexNamespaceId = $indexNamespaceId;
                $this->fileProvider = $fileProvider;
                $this->customIndexFieldsParser = $customIndexFieldsParser;
                $this->indexForPageLookup = $indexForPageLookup;
+               $this->indexContentLookup = $indexContentLookup;
        }
 
        /**
@@ -105,6 +115,13 @@
        }
 
        /**
+        * @return IndexContentLookup
+        */
+       public function getIndexContentLookup() {
+               return $this->indexContentLookup;
+       }
+
+       /**
         * @param bool $purge
         * @return Context
         */
@@ -118,7 +135,8 @@
                        $defaultContext = new self( $pageNamespaceId, 
$indexNamespaceId,
                                new FileProvider( $repoGroup ),
                                new CustomIndexFieldsParser(),
-                               new DatabaseIndexForPageLookup( 
$indexNamespaceId, $repoGroup )
+                               new DatabaseIndexForPageLookup( 
$indexNamespaceId, $repoGroup ),
+                               new DatabaseIndexContentLookup()
                        );
                }
 
diff --git a/includes/Pagination/PaginationFactory.php 
b/includes/Pagination/PaginationFactory.php
index 0faee37..18802e4 100644
--- a/includes/Pagination/PaginationFactory.php
+++ b/includes/Pagination/PaginationFactory.php
@@ -52,7 +52,8 @@
                }
 
                // check if it is using pagelist
-               $pagelist = $indexPage->getContent()->getPagelistTagContent();
+               $indexContent = 
$this->context->getIndexContentLookup()->getIndexContent( $indexPage );
+               $pagelist = $indexContent->getPagelistTagContent();
                if ( $pagelist !== null && $file && $file->isMultipage() ) {
                        return new FilePagination(
                                $indexPage,
@@ -61,7 +62,7 @@
                                $this->context
                        );
                } else {
-                       $links = $indexPage->getContent()->getLinksToNamespace(
+                       $links = $indexContent->getLinksToNamespace(
                                
Context::getDefaultContext()->getPageNamespaceId()
                        );
                        $pages = [];
diff --git a/includes/Parser/PagesTagParser.php 
b/includes/Parser/PagesTagParser.php
index e7f5053..cc09615 100644
--- a/includes/Parser/PagesTagParser.php
+++ b/includes/Parser/PagesTagParser.php
@@ -63,7 +63,7 @@
                        return $this->formatError( 'proofreadpage_nosuch_index' 
);
                }
                $indexPage = ProofreadIndexPage::newFromTitle( $indexTitle );
-               $indexContent = $indexPage->getContent();
+               $indexContent = 
$this->context->getIndexContentLookup()->getIndexContent( $indexPage );
                $pagination = $this->context->getPaginationFactory()
                        ->getPaginationForIndexPage( $indexPage );
                $language = $this->parser->getTargetLanguage();
diff --git a/includes/index/DatabaseIndexContentLookup.php 
b/includes/index/DatabaseIndexContentLookup.php
new file mode 100644
index 0000000..8598ebf
--- /dev/null
+++ b/includes/index/DatabaseIndexContentLookup.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace ProofreadPage\Index;
+
+use ProofreadIndexPage;
+use Revision;
+
+/**
+ * @licence GNU GPL v2+
+ *
+ * Allows to retrieve the content of the Index: page
+ */
+class DatabaseIndexContentLookup implements IndexContentLookup {
+
+       private $cache = [];
+
+       /**
+        * @see IndexContentLookup::getIndexContent
+        */
+       public function getIndexContent( ProofreadIndexPage $index ) {
+               $cacheKey = $index->getTitle()->getDBkey();
+
+               if ( !array_key_exists( $cacheKey, $this->cache ) ) {
+                       $rev = Revision::newFromTitle( $index->getTitle() );
+                       if ( $rev === null ) {
+                               $this->cache[$cacheKey] = new IndexContent( [] 
);
+                       } else {
+                               $content = $rev->getContent();
+                               if ( $content instanceof IndexContent ) {
+                                       $this->cache[$cacheKey] = $content;
+                               } else {
+                                       $this->cache[$cacheKey] = new 
IndexContent( [] );
+                               }
+                       }
+               }
+
+               return $this->cache[$cacheKey];
+       }
+}
diff --git a/includes/index/IndexContentLookup.php 
b/includes/index/IndexContentLookup.php
new file mode 100644
index 0000000..2eedca7
--- /dev/null
+++ b/includes/index/IndexContentLookup.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace ProofreadPage\Index;
+
+use ProofreadIndexPage;
+
+/**
+ * @licence GNU GPL v2+
+ *
+ * Allows to retrieve the content of the Index: page
+ */
+interface IndexContentLookup {
+
+       /**
+        * Returns content of the page
+        * @return IndexContent
+        */
+       public function getIndexContent( ProofreadIndexPage $index );
+}
diff --git a/includes/index/ProofreadIndexPage.php 
b/includes/index/ProofreadIndexPage.php
index c403b26..aced236 100644
--- a/includes/index/ProofreadIndexPage.php
+++ b/includes/index/ProofreadIndexPage.php
@@ -19,8 +19,6 @@
  * @ingroup ProofreadPage
  */
 
-use ProofreadPage\Index\IndexContent;
-
 /**
  * An index page
  */
@@ -32,18 +30,10 @@
        protected $title;
 
        /**
-        * @var IndexContent|null content of the page
-        */
-       protected $content;
-
-       /**
         * @param Title $title Reference to a Title object.
-        * @param IndexContent|null $content content of the page. Warning: only 
done for
-        *   EditProofreadIndexPage use.
         */
-       public function __construct( Title $title, IndexContent $content = null 
) {
+       public function __construct( Title $title ) {
                $this->title = $title;
-               $this->content = $content;
        }
 
        /**
@@ -71,39 +61,5 @@
         */
        public function equals( ProofreadIndexPage $that ) {
                return $this->title->equals( $that->getTitle() );
-       }
-
-       /**
-        * Return content of the page
-        * @return IndexContent
-        */
-       public function getContent() {
-               if ( $this->content === null ) {
-                       $rev = Revision::newFromTitle( $this->title );
-                       if ( $rev === null ) {
-                               $this->content = new IndexContent( [] );
-                       } else {
-                               $content = $rev->getContent();
-                               if ( $content instanceof IndexContent ) {
-                                       $this->content = $content;
-                               } else {
-                                       $this->content = new IndexContent( [] );
-                               }
-                       }
-               }
-               return $this->content;
-       }
-
-       /**
-        * Return mime type of the file linked to the index page
-        * @return string|null
-        */
-       public function getMimeType() {
-               if ( preg_match( "/^.*\.(.{2,5})$/", $this->title->getText(), 
$m ) ) {
-                       $mimeMagic = MimeMagic::singleton();
-                       return $mimeMagic->guessTypesForExtension( $m[1] );
-               } else {
-                       return null;
-               }
        }
 }
diff --git a/includes/page/PageContentBuilder.php 
b/includes/page/PageContentBuilder.php
index add144d..21fa621 100644
--- a/includes/page/PageContentBuilder.php
+++ b/includes/page/PageContentBuilder.php
@@ -60,11 +60,12 @@
                        } // should not happen
 
                        $indexFieldsParser = 
$this->context->getCustomIndexFieldsParser();
+                       $indexContent = 
$this->context->getIndexContentLookup()->getIndexContent( $index );
                        $header = 
$indexFieldsParser->parseCustomIndexFieldWithVariablesReplacedWithIndexEntries(
-                                       $index->getContent(), 'header', $params
-                               );
+                               $indexContent, 'header', $params
+                       );
                        $footer = 
$indexFieldsParser->parseCustomIndexFieldWithVariablesReplacedWithIndexEntries(
-                               $index->getContent(), 'footer', $params
+                               $indexContent, 'footer', $params
                        );
                } else {
                        $header = $this->contextSource->msg( 
'proofreadpage_default_header' )
diff --git a/includes/page/PageDisplayHandler.php 
b/includes/page/PageDisplayHandler.php
index 98252b7..c6502ff 100644
--- a/includes/page/PageDisplayHandler.php
+++ b/includes/page/PageDisplayHandler.php
@@ -43,8 +43,9 @@
                $index = 
$this->context->getIndexForPageLookup()->getIndexForPage( $page );
                if ( $index !== null ) {
                        try {
+                               $indexContent = 
$this->context->getIndexContentLookup()->getIndexContent( $index );
                                $width = 
$this->context->getCustomIndexFieldsParser()->parseCustomIndexField(
-                                       $index->getContent(), 'width'
+                                       $indexContent, 'width'
                                )->getStringValue();
                                if ( is_numeric( $width ) ) {
                                        return $width;
@@ -68,8 +69,9 @@
                        return '';
                }
                try {
+                       $indexContent = 
$this->context->getIndexContentLookup()->getIndexContent( $index );
                        $css = 
$this->context->getCustomIndexFieldsParser()->parseCustomIndexField(
-                               $index->getContent(), 'css'
+                               $indexContent, 'css'
                        );
                        return Sanitizer::escapeHtmlAllowEntities(
                                Sanitizer::checkCss( $css->getStringValue() )
diff --git a/tests/phpunit/ContextTest.php b/tests/phpunit/ContextTest.php
index 76ba53d..e750026 100644
--- a/tests/phpunit/ContextTest.php
+++ b/tests/phpunit/ContextTest.php
@@ -3,6 +3,7 @@
 namespace ProofreadPage;
 
 use ProofreadPage\Index\CustomIndexFieldsParser;
+use ProofreadPage\Index\IndexContentLookupMock;
 use ProofreadPage\Page\IndexForPageLookupMock;
 use ProofreadPageTestCase;
 
@@ -50,7 +51,8 @@
 
        private function buildDummyContext() {
                return new Context( 42, 44,
-                       new FileProviderMock( [] ), new 
CustomIndexFieldsParser(), new IndexForPageLookupMock( [] )
+                       new FileProviderMock( [] ), new 
CustomIndexFieldsParser(), new IndexForPageLookupMock( [] ),
+                       new IndexContentLookupMock( [] )
                );
        }
 }
diff --git a/tests/phpunit/Pagination/PaginationFactoryTest.php 
b/tests/phpunit/Pagination/PaginationFactoryTest.php
index f3cb7bc..77ff105 100644
--- a/tests/phpunit/Pagination/PaginationFactoryTest.php
+++ b/tests/phpunit/Pagination/PaginationFactoryTest.php
@@ -3,8 +3,10 @@
 namespace ProofreadPage\Pagination;
 
 use MediaHandler;
+use ProofreadPage\Index\IndexContent;
 use ProofreadPageTestCase;
 use Title;
+use WikitextContent;
 
 /**
  * @group ProofreadPage
@@ -16,31 +18,31 @@
                if ( MediaHandler::getHandler( 'image/vnd.djvu' ) === false ) {
                        $this->markTestSkipped( 'There is no support for DjVu 
files, please enable it.' );
                }
-               $page = $this->newIndexPage(
-                       'LoremIpsum.djvu',
-                       "{{\n|Pages=<pagelist 1to2=-/> <pagelist 3=1 4to5=roman 
/>\n|Author=[[Author:Me]]\n}}"
-               );
+               $context = $this->getContext( [], [
+                       'LoremIpsum.djvu' => new IndexContent( [
+                               'Pages' => new WikitextContent( '<pagelist 
1to2=-/> <pagelist 3=1 4to5=roman />' ),
+                               'Author' => new WikitextContent( 
'[[Author:Me]]' )
+                       ] )
+               ] );
                $pageList = new PageList( [ '1to2' => '-', '3' => '1', '4to5' 
=> 'roman' ] );
                $pagination = new FilePagination(
-                       $page,
+                       $this->newIndexPage( 'LoremIpsum.djvu' ),
                        $pageList,
-                       
$this->getContext()->getFileProvider()->getFileFromTitle(
+                       $context->getFileProvider()->getFileFromTitle(
                                Title::makeTitle( NS_MEDIA, 'LoremIpsum.djvu' )
                        ),
-                       $this->getContext()
+                       $context
                );
                $this->assertEquals(
                        $pagination,
-                       
$this->getContext()->getPaginationFactory()->getPaginationForIndexPage( $page )
+                       
$context->getPaginationFactory()->getPaginationForIndexPage(
+                               $this->newIndexPage( 'LoremIpsum.djvu' )
+                       )
                );
        }
 
        public function testGetPaginationWithoutPagelist() {
-               $index = $this->newIndexPage(
-                       'Test',
-                       "{{\n|Pages=[[Page:Test 1.jpg|TOC]] [[Page:Test 
2.tiff|1]] " .
-                       "[[Page:Test:3.png|2]]\n|Author=[[Author:Me]]\n}}"
-               );
+               $index = $this->newIndexPage( 'Test' );
                $pagination = new PagePagination(
                        $index,
                        [
@@ -56,10 +58,13 @@
                );
                $this->assertEquals(
                        $pagination,
-                       $this->getContext( [
-                               'Page:Test_1.jpg' => $index,
-                               'Page:Test_2.tiff' => $index,
-                               'Page:Test:3.png' => $index,
+                       $this->getContext( [], [
+                               'Test' => new IndexContent( [
+                                       'Pages' => new WikitextContent(
+                                               '[[Page:Test 1.jpg|TOC]] 
[[Page:Test 2.tiff|1]][[Page:Test:3.png|2]]'
+                                       ),
+                                       'Author' => new WikitextContent( 
'[[Author:Me]]' )
+                               ] )
                        ] )->getPaginationFactory()->getPaginationForIndexPage( 
$index )
                );
        }
diff --git a/tests/phpunit/ProofreadPageTestCase.php 
b/tests/phpunit/ProofreadPageTestCase.php
index 5a42dea..969720d 100644
--- a/tests/phpunit/ProofreadPageTestCase.php
+++ b/tests/phpunit/ProofreadPageTestCase.php
@@ -5,6 +5,7 @@
 use ProofreadPage\FileProviderMock;
 use ProofreadPage\Index\CustomIndexFieldsParser;
 use ProofreadPage\Index\IndexContent;
+use ProofreadPage\Index\IndexContentLookupMock;
 use ProofreadPage\Page\IndexForPageLookupMock;
 use ProofreadPage\ProofreadPageInit;
 
@@ -101,15 +102,17 @@
 
        /**
         * @param ProofreadIndexPage[] $indexForPage
+        * @param IndexContent[] $indexContent
         * @return Context
         */
-       protected function getContext( array $indexForPage = [] ) {
+       protected function getContext( array $indexForPage = [], array 
$indexContent = [] ) {
                return new Context(
                        ProofreadPageInit::getNamespaceId( 'page' ),
                        ProofreadPageInit::getNamespaceId( 'index' ),
                        $this->getFileProvider(),
                        new CustomIndexFieldsParser( 
self::$customIndexFieldsConfiguration ),
-                       new IndexForPageLookupMock( $indexForPage )
+                       new IndexForPageLookupMock( $indexForPage ),
+                       new IndexContentLookupMock( $indexContent )
                );
        }
 
@@ -128,18 +131,13 @@
        /**
         * Constructor of a new ProofreadIndexPage
         * @param Title|string $title
-        * @param string|IndexContent|null $content
         * @return ProofreadIndexPage
         */
-       protected function newIndexPage( $title = 'test.djvu', $content = null 
) {
+       protected function newIndexPage( $title = 'test.djvu' ) {
                if ( is_string( $title ) ) {
                        $title = Title::makeTitle( 
$this->getIndexNamespaceId(), $title );
                }
-               if ( is_string( $content ) ) {
-                       $content = ContentHandler::getForModelID( 
CONTENT_MODEL_PROOFREAD_INDEX )
-                               ->unserializeContent( $content );
-               }
-               return new ProofreadIndexPage( $title, $content );
+               return new ProofreadIndexPage( $title );
        }
 
        /**
diff --git a/tests/phpunit/index/IndexContentLookupMock.php 
b/tests/phpunit/index/IndexContentLookupMock.php
new file mode 100644
index 0000000..23fc291
--- /dev/null
+++ b/tests/phpunit/index/IndexContentLookupMock.php
@@ -0,0 +1,28 @@
+<?php
+
+namespace ProofreadPage\Index;
+
+use ProofreadIndexPage;
+
+/**
+ * @licence GNU GPL v2+
+ */
+class IndexContentLookupMock implements IndexContentLookup {
+
+       private $contentForIndex = [];
+
+       public function __construct( $contentForIndex ) {
+               $this->contentForIndex = $contentForIndex;
+       }
+
+       /**
+        * Returns content of the page
+        * @return IndexContent
+        */
+       public function getIndexContent( ProofreadIndexPage $index ) {
+               if ( !array_key_exists( $index->getTitle()->getDBkey(), 
$this->contentForIndex ) ) {
+                       return null;
+               }
+               return $this->contentForIndex[ $index->getTitle()->getDBkey() ];
+       }
+}
diff --git a/tests/phpunit/index/ProofreadIndexPageTest.php 
b/tests/phpunit/index/ProofreadIndexPageTest.php
index 416170e..ac887c6 100644
--- a/tests/phpunit/index/ProofreadIndexPageTest.php
+++ b/tests/phpunit/index/ProofreadIndexPageTest.php
@@ -21,19 +21,4 @@
                $page = ProofreadIndexPage::newFromTitle( $title );
                $this->assertEquals( $title, $page->getTitle() );
        }
-
-       public function mimeTypesProvider() {
-               return [
-                       [ 'image/vnd.djvu', 'Test.djvu' ],
-                       [ 'application/pdf', 'Test.pdf' ],
-                       [ null, 'Test' ]
-               ];
-       }
-
-       /**
-        * @dataProvider mimeTypesProvider
-        */
-       public function testGetMimeType( $mime, $name ) {
-               $this->assertEquals( $mime, $this->newIndexPage( $name 
)->getMimeType() );
-       }
 }
diff --git a/tests/phpunit/page/PageContentBuilderTest.php 
b/tests/phpunit/page/PageContentBuilderTest.php
index a6aa5d1..f335951 100644
--- a/tests/phpunit/page/PageContentBuilderTest.php
+++ b/tests/phpunit/page/PageContentBuilderTest.php
@@ -6,6 +6,7 @@
 use MediaHandler;
 use ProofreadIndexPage;
 use ProofreadPage\FileNotFoundException;
+use ProofreadPage\Index\IndexContent;
 use ProofreadPagePage;
 use ProofreadPageTestCase;
 use RequestContext;
@@ -43,11 +44,16 @@
         * @dataProvider buildDefaultContentForPageProvider
         */
        public function testBuildDefaultContentForPage(
-               ProofreadPagePage $page, ProofreadIndexPage $index = null, 
PageContent $defaultContent
+               ProofreadPagePage $page, ProofreadIndexPage $index = null,
+               IndexContent $indexContent = null, PageContent $defaultContent
        ) {
+               $indexContents = [];
+               if ( $indexContent !== null ) {
+                       $indexContents[$index->getTitle()->getDBkey()] = 
$indexContent;
+               }
                $context = $this->getContext( [
                        $page->getTitle()->getDBkey() => $index
-               ] );
+               ], $indexContents );
                try {
                        $image = $context->getFileProvider()->getForPagePage( 
$page );
                } catch ( FileNotFoundException $e ) {
@@ -67,28 +73,37 @@
                return [
                        [
                                $this->newPagePage( 'Test.djvu/1' ),
-                               $this->newIndexPage( 'Test.djvu', 
"{{\n|Title=Test book\n|Header={{{title}}}\n}}" ),
+                               $this->newIndexPage( 'Test.djvu' ),
+                               new IndexContent( [
+                                       'Title' => new WikitextContent( 'Test 
book' ),
+                                       'Header' => new WikitextContent( 
'{{{title}}}' )
+                               ] ),
                                self::newContent( 'Test book', '', '<references 
/>', 1 ),
                        ],
                        [
                                $this->newPagePage( 'LoremIpsum.djvu/2' ),
                                null,
+                               null,
                                self::newContent( '', "Lorem ipsum \n2 \n", 
'<references/>', 1 ),
                        ],
                        [
                                $this->newPagePage( 'LoremIpsum.djvu/2' ),
-                               $this->newIndexPage( 'LoremIpsum.djvu',
-                                       "{{\n|Title=Test 
book\n|Pages=<pagelist/>\n|Header={{{pagenum}}}\n}}"
-                               ),
+                               $this->newIndexPage( 'LoremIpsum.djvu' ),
+                               new IndexContent( [
+                                       'Title' => new WikitextContent( 'Test 
book' ),
+                                       'Pages' => new WikitextContent( 
'<pagelist/>' ),
+                                       'Header' => new WikitextContent( 
'{{{pagenum}}}' )
+                               ] ),
                                self::newContent( '2', "Lorem ipsum \n2 \n", 
'<references />', 1 ),
                        ],
                        [
                                $this->newPagePage( 'LoremIpsum.djvu/2' ),
-                               $this->newIndexPage(
-                                       'LoremIpsum.djvu',
-                                       "{{\n|Title=Test book\n|Pages=<pagelist 
1to5=roman />\n" .
-                                       "|Header={{{pagenum}}}\n}}"
-                               ),
+                               $this->newIndexPage( 'LoremIpsum.djvu' ),
+                               new IndexContent( [
+                                       'Title' => new WikitextContent( 'Test 
book' ),
+                                       'Pages' => new WikitextContent( 
'<pagelist 1to5=roman />' ),
+                                       'Header' => new WikitextContent( 
'{{{pagenum}}}' )
+                               ] ),
                                self::newContent( 'ii', "Lorem ipsum \n2 \n", 
'<references />', 1 ),
                        ],
                ];
diff --git a/tests/phpunit/page/PageDisplayHandlerTest.php 
b/tests/phpunit/page/PageDisplayHandlerTest.php
index 71f2804..04e4c20 100644
--- a/tests/phpunit/page/PageDisplayHandlerTest.php
+++ b/tests/phpunit/page/PageDisplayHandlerTest.php
@@ -2,7 +2,9 @@
 
 namespace ProofreadPage\Page;
 
+use ProofreadPage\Index\IndexContent;
 use ProofreadPageTestCase;
+use WikitextContent;
 
 /**
  * @group ProofreadPage
@@ -11,51 +13,65 @@
 class PageDisplayHandlerTest extends ProofreadPageTestCase {
 
        public function testGetImageWidth() {
-               $index = $this->newIndexPage( 'Test', "{{\n|width= 500 \n}}" );
-               $page = $this->newPagePage( 'Test.jpg' );
                $handler = new PageDisplayHandler( $this->getContext( [
-                       $page->getTitle()->getDBkey() => $index
+                       'Test.jpg' => $this->newIndexPage( 'Test' )
+               ], [
+                       'Test' => new IndexContent( [ 'width' => new 
WikitextContent( '500' ) ] )
                ] ) );
-               $this->assertEquals( 500, $handler->getImageWidth( $page ) );
+               $this->assertEquals( 500, $handler->getImageWidth( 
$this->newPagePage( 'Test.jpg' ) ) );
        }
 
        public function testGetImageWidthWithDefault() {
-               $index = $this->newIndexPage( 'Test', "{{\n|title=500\n}}" );
-               $page = $this->newPagePage( 'Test.jpg' );
                $handler = new PageDisplayHandler( $this->getContext( [
-                       $page->getTitle()->getDBkey() => $index
+                       'Test.jpg' => $this->newIndexPage( 'Test' )
+               ], [
+                       'Test' => new IndexContent( [ 'title' => new 
WikitextContent( '500' ) ] )
                ] ) );
-               $this->assertEquals( PageDisplayHandler::DEFAULT_IMAGE_WIDTH, 
$handler->getImageWidth( $page ) );
+               $this->assertEquals(
+                       PageDisplayHandler::DEFAULT_IMAGE_WIDTH,
+                       $handler->getImageWidth( $this->newPagePage( 'Test.jpg' 
) )
+               );
        }
 
        public function testGetCustomCss() {
-               $index = $this->newIndexPage( 'Test', "{{\n|CSS= width:300px; 
\n}}" );
-               $page = $this->newPagePage( 'Test.jpg' );
                $handler = new PageDisplayHandler( $this->getContext( [
-                       $page->getTitle()->getDBkey() => $index
+                       'Test.jpg' => $this->newIndexPage( 'Test' )
+               ], [
+                       'Test' => new IndexContent( [
+                               'CSS' => new WikitextContent( 'width:300px;' )
+                       ] )
                ] ) );
-               $this->assertEquals( 'width:300px;', $handler->getCustomCss( 
$page ) );
+               $this->assertEquals(
+                       'width:300px;',
+                       $handler->getCustomCss( $this->newPagePage( 'Test.jpg' 
) )
+               );
        }
 
        public function testGetCustomCssWithInsecureInput() {
-               $index = $this->newIndexPage(
-                       'Test', "{{\n|CSS= background: 
url('/my-bad-url.jpg');\n}}"
-               );
-               $page = $this->newPagePage( 'Test.jpg' );
                $handler = new PageDisplayHandler( $this->getContext( [
-                       $page->getTitle()->getDBkey() => $index
+                       'Test.jpg' => $this->newIndexPage( 'Test' )
+               ], [
+                       'Test' => new IndexContent( [
+                               'CSS' => new WikitextContent( 'background: 
url(\'/my-bad-url.jpg\');' )
+                       ] )
                ] ) );
-               $this->assertEquals( '/* insecure input */', 
$handler->getCustomCss( $page ) );
+               $this->assertEquals(
+                       '/* insecure input */',
+                       $handler->getCustomCss( $this->newPagePage( 'Test.jpg' 
) )
+               );
        }
 
        public function testGetCustomCssWithEscaping() {
-               $index = $this->newIndexPage(
-                       'Test', "{{\n|CSS= width:300px;<style> \n}}"
-               );
-               $page = $this->newPagePage( 'Test.jpg' );
                $handler = new PageDisplayHandler( $this->getContext( [
-                       $page->getTitle()->getDBkey() => $index
+                       'Test.jpg' => $this->newIndexPage( 'Test' )
+               ], [
+                       'Test' => new IndexContent( [
+                               'CSS' => new WikitextContent( 
'width:300px;<style>' )
+                       ] )
                ] ) );
-               $this->assertEquals( 'width:300px;&lt;style&gt;', 
$handler->getCustomCss( $page ) );
+               $this->assertEquals(
+                       'width:300px;&lt;style&gt;',
+                       $handler->getCustomCss( $this->newPagePage( 'Test.jpg' 
) )
+               );
        }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/392187
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I8bd3a2494ad78168d4ed569c766eb642794972cb
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/ProofreadPage
Gerrit-Branch: master
Gerrit-Owner: Tpt <thoma...@hotmail.fr>
Gerrit-Reviewer: Samwilson <s...@samwilson.id.au>
Gerrit-Reviewer: Tpt <thoma...@hotmail.fr>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to