[MediaWiki-commits] [Gerrit] mediawiki...ProofreadPage[master]: Refactors TagParsers

2017-08-11 Thread Tpt (Code Review)
Tpt has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/371484 )

Change subject: Refactors TagParsers
..

Refactors TagParsers

Change-Id: I5234dd05280af661c5ca7e00b3116eb8d4415e15
---
M ProofreadPage.body.php
M extension.json
M includes/Context.php
M includes/Pagination/FilePagination.php
M includes/Pagination/PaginationFactory.php
M includes/Parser/PagelistTagParser.php
M includes/Parser/PagequalityTagParser.php
M includes/Parser/PagesTagParser.php
D includes/Parser/ParserEntryPoint.php
D includes/Parser/TagParser.php
M tests/phpunit/Pagination/FilePaginationTest.php
M tests/phpunit/Pagination/PaginationFactoryTest.php
12 files changed, 170 insertions(+), 160 deletions(-)


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

diff --git a/ProofreadPage.body.php b/ProofreadPage.body.php
index 56b01ed..7571830 100644
--- a/ProofreadPage.body.php
+++ b/ProofreadPage.body.php
@@ -21,10 +21,12 @@
 
 use ProofreadPage\Context;
 use ProofreadPage\FileNotFoundException;
-use ProofreadPage\Index\EditIndexPage;
 use ProofreadPage\Page\PageContent;
 use ProofreadPage\Page\PageContentBuilder;
 use ProofreadPage\Pagination\PageNotInPaginationException;
+use ProofreadPage\Parser\PagelistTagParser;
+use ProofreadPage\Parser\PagequalityTagParser;
+use ProofreadPage\Parser\PagesTagParser;
 
 /*
  @todo :
@@ -107,13 +109,25 @@
 * @return bool hook return value
 */
public static function onParserFirstCallInit( Parser $parser ) {
-   $parser->setHook(
-   'pagelist', [ 'ProofreadPage\Parser\ParserEntryPoint', 
'renderPagelistTag' ]
-   );
-   $parser->setHook( 'pages', [ 
'ProofreadPage\Parser\ParserEntryPoint', 'renderPagesTag' ] );
-   $parser->setHook(
-   'pagequality', [ 
'ProofreadPage\Parser\ParserEntryPoint', 'renderPagequalityTag' ]
-   );
+   $context = Context::getDefaultContext( true );
+   $parser->setHook( 'pagelist', function ( $input, array $args, 
Parser $parser ) use ( $context ) {
+   $tagParser = new PagelistTagParser( $parser,
+   $context->getPageNamespaceId(), 
$context->getIndexNamespaceId(), $context->getFileProvider()
+   );
+   return $tagParser->render( $input, $args );
+   } );
+   $parser->setHook( 'pages', function ( $input, array $args, 
Parser $parser ) use ( $context ) {
+   $tagParser = new PagesTagParser( $parser,
+   $context->getPageNamespaceId(), 
$context->getIndexNamespaceId(),
+   $context->getPaginationFactory(), 
$context->getCustomIndexFieldsParser()
+   );
+   return $tagParser->render( $input, $args );
+   } );
+   $parser->setHook( 'pagequality',
+   function ( $input, array $args, Parser $parser ) use ( 
$context ) {
+   $tagParser = new PagequalityTagParser();
+   return $tagParser->render( $input, $args );
+} );
return true;
}
 
diff --git a/extension.json b/extension.json
index 266871c..aef8046 100644
--- a/extension.json
+++ b/extension.json
@@ -76,8 +76,6 @@
"ProofreadPage\\Page\\PageViewAction": 
"includes/page/PageViewAction.php",
"ProofreadPage\\Page\\PageDifferenceEngine": 
"includes/page/PageDifferenceEngine.php",
"ProofreadPage\\Page\\PageDisplayHandler": 
"includes/page/PageDisplayHandler.php",
-   "ProofreadPage\\Parser\\ParserEntryPoint": 
"includes/Parser/ParserEntryPoint.php",
-   "ProofreadPage\\Parser\\TagParser": 
"includes/Parser/TagParser.php",
"ProofreadPage\\Parser\\PagelistTagParser": 
"includes/Parser/PagelistTagParser.php",
"ProofreadPage\\Parser\\PagesTagParser": 
"includes/Parser/PagesTagParser.php",
"ProofreadPage\\Parser\\PagequalityTagParser": 
"includes/Parser/PagequalityTagParser.php",
diff --git a/includes/Context.php b/includes/Context.php
index 0bbd60d..71d7dce 100644
--- a/includes/Context.php
+++ b/includes/Context.php
@@ -33,6 +33,11 @@
private $fileProvider;
 
/**
+* @var PaginationFactory
+*/
+   private $paginationFactory;
+
+   /**
 * @var CustomIndexFieldsParser
 */
private $customIndexFieldsParser;
@@ -50,6 +55,7 @@
$this->pageNamespaceId = $pageNamespaceId;
$this->indexNamespaceId = $indexNamespaceId;
$this->fileProvider = $fileProvider;
+   $this->paginationFactory = new PaginationFactory( 
$pageNamespaceId, $fileProvider );

[MediaWiki-commits] [Gerrit] mediawiki...ProofreadPage[master]: Refactors TagParsers

2017-08-10 Thread Tpt (Code Review)
Tpt has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/371131 )

Change subject: Refactors TagParsers
..

Refactors TagParsers

Change-Id: I794beef218568e1db0c627bda0ad8f17e5f7a251
---
M ProofreadPage.body.php
M includes/Pagination/FilePagination.php
M includes/Pagination/PaginationFactory.php
M includes/Parser/PagelistTagParser.php
M includes/Parser/PagequalityTagParser.php
M includes/Parser/PagesTagParser.php
D includes/Parser/ParserEntryPoint.php
D includes/Parser/TagParser.php
M tests/phpunit/Pagination/FilePaginationTest.php
M tests/phpunit/Pagination/PaginationFactoryTest.php
10 files changed, 141 insertions(+), 146 deletions(-)


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

diff --git a/ProofreadPage.body.php b/ProofreadPage.body.php
index eda957a..0193fd0 100644
--- a/ProofreadPage.body.php
+++ b/ProofreadPage.body.php
@@ -21,10 +21,12 @@
 
 use ProofreadPage\Context;
 use ProofreadPage\FileNotFoundException;
-use ProofreadPage\Index\EditIndexPage;
 use ProofreadPage\Page\PageContent;
 use ProofreadPage\Page\PageContentBuilder;
 use ProofreadPage\Pagination\PageNotInPaginationException;
+use ProofreadPage\Parser\PagelistTagParser;
+use ProofreadPage\Parser\PagequalityTagParser;
+use ProofreadPage\Parser\PagesTagParser;
 
 /*
  @todo :
@@ -107,13 +109,25 @@
 * @return boolean hook return value
 */
public static function onParserFirstCallInit( Parser $parser ) {
-   $parser->setHook(
-   'pagelist', [ 'ProofreadPage\Parser\ParserEntryPoint', 
'renderPagelistTag' ]
-   );
-   $parser->setHook( 'pages', [ 
'ProofreadPage\Parser\ParserEntryPoint', 'renderPagesTag' ] );
-   $parser->setHook(
-   'pagequality', [ 
'ProofreadPage\Parser\ParserEntryPoint', 'renderPagequalityTag' ]
-   );
+   $context = Context::getDefaultContext( true );
+   $parser->setHook( 'pagelist', function ( $input, array $args, 
Parser $parser ) use ( $context ) {
+   $tagParser = new PagelistTagParser( $parser,
+   $context->getPageNamespaceId(), 
$context->getIndexNamespaceId(), $context->getFileProvider()
+   );
+   return $tagParser->render( $input, $args );
+   } );
+   $parser->setHook( 'pages', function ( $input, array $args, 
Parser $parser ) use ( $context ) {
+   $tagParser = new PagesTagParser( $parser,
+   $context->getPageNamespaceId(), 
$context->getIndexNamespaceId(),
+   $context->getPaginationFactory()
+   );
+   return $tagParser->render( $input, $args );
+   } );
+   $parser->setHook( 'pagequality',
+   function ( $input, array $args, Parser $parser ) use ( 
$context ) {
+   $tagParser = new PagequalityTagParser();
+   return $tagParser->render( $input, $args );
+} );
return true;
}
 
diff --git a/includes/Pagination/FilePagination.php 
b/includes/Pagination/FilePagination.php
index 48a6e7a..7ef1990 100644
--- a/includes/Pagination/FilePagination.php
+++ b/includes/Pagination/FilePagination.php
@@ -32,23 +32,23 @@
private $pages = [];
 
/**
-* @var Context
+* @var int
 */
-   private $context;
+   private $pageNamespaceId;
 
/**
 * @param ProofreadIndexPage $index
 * @param PageList $pageList representation of the  tag that 
configure page numbers
 * @param File $file the pagination file
-* @param Context $context the current context
+* @param int $pageNamespaceId
 */
public function __construct(
-   ProofreadIndexPage $index, PageList $pageList, File $file, 
Context $context
+   ProofreadIndexPage $index, PageList $pageList, File $file, 
$pageNamespaceId
) {
parent::__construct( $index );
 
$this->pageList = $pageList;
-   $this->context = $context;
+   $this->pageNamespaceId = $pageNamespaceId;
 
if ( $file->isMultipage() ) {
$this->numberOfPages = $file->pageCount();
@@ -128,7 +128,7 @@
 */
private function buildPageTitleFromPageNumber( $pageNumber ) {
return Title::makeTitle(
-   $this->context->getPageNamespaceId(),
+   $this->pageNamespaceId,
$this->index->getTitle()->getText() . '/' . $pageNumber
);
}
diff --git a/includes/Pagination/PaginationFactory.php 
b/includes/Pagination/PaginationFactory.php