jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/392194 )
Change subject: Removes ProofreadPagePage and ProofreadIndexPage ...................................................................... Removes ProofreadPagePage and ProofreadIndexPage Change-Id: Ib77a4a0aae7c92fc38e4f97d9caa55d659768d2d --- M ProofreadPage.body.php M extension.json M includes/FileProvider.php M includes/Pagination/FilePagination.php M includes/Pagination/PagePagination.php M includes/Pagination/Pagination.php M includes/Pagination/PaginationFactory.php M includes/Parser/PagelistTagParser.php M includes/Parser/PagesTagParser.php M includes/index/DatabaseIndexContentLookup.php M includes/index/IndexContentLookup.php D includes/index/ProofreadIndexPage.php M includes/page/DatabaseIndexForPageLookup.php M includes/page/EditPagePage.php M includes/page/IndexForPageLookup.php M includes/page/PageContentBuilder.php M includes/page/PageDisplayHandler.php M includes/page/PageEditAction.php M includes/page/PageSubmitAction.php M includes/page/PageViewAction.php D includes/page/ProofreadPagePage.php M tests/phpunit/FileProviderTest.php M tests/phpunit/Pagination/FilePaginationTest.php M tests/phpunit/Pagination/PagePaginationTest.php M tests/phpunit/Pagination/PaginationFactoryTest.php M tests/phpunit/ProofreadPageTestCase.php M tests/phpunit/index/IndexContentLookupMock.php D tests/phpunit/index/ProofreadIndexPageTest.php M tests/phpunit/page/DatabaseIndexForPageLookupTest.php M tests/phpunit/page/IndexForPageLookupMock.php M tests/phpunit/page/PageContentBuilderTest.php M tests/phpunit/page/PageDisplayHandlerTest.php D tests/phpunit/page/ProofreadPagePageTest.php 33 files changed, 322 insertions(+), 589 deletions(-) Approvals: jenkins-bot: Verified Tpt: Looks good to me, approved diff --git a/ProofreadPage.body.php b/ProofreadPage.body.php index c088bc1..8e7a3b6 100644 --- a/ProofreadPage.body.php +++ b/ProofreadPage.body.php @@ -123,13 +123,13 @@ * @param Title $title */ public static function loadIndex( $title ) { - $title->prpIndexPage = null; + $title->prpIndexTitle = null; $result = ProofreadIndexDbConnector::getRowsFromTitle( $title ); foreach ( $result as $x ) { $refTitle = Title::makeTitle( $x->page_namespace, $x->page_title ); if ( $refTitle !== null && $refTitle->inNamespace( self::getIndexNamespaceId() ) ) { - $title->prpIndexPage = ProofreadIndexPage::newFromTitle( $refTitle ); + $title->prpIndexTitle = $refTitle; return; } } @@ -149,7 +149,7 @@ self::getIndexNamespaceId(), $image->getTitle()->getText() ); if ( $indexTitle !== null ) { - $title->prpIndexPage = ProofreadIndexPage::newFromTitle( $indexTitle ); + $title->prpIndexTitle = $indexTitle; } } } @@ -295,8 +295,8 @@ */ private static function updateIndexOfPage( Title $title, $deleted = false ) { self::loadIndex( $title ); - if ( $title->prpIndexPage !== null ) { - $indexTitle = $title->prpIndexPage->getTitle(); + if ( $title->prpIndexTitle !== null ) { + $indexTitle = $title->prpIndexTitle; $indexTitle->invalidateCache(); $index = WikiPage::factory( $indexTitle ); if ( $index ) { @@ -325,22 +325,22 @@ } /* check if there is an index */ - if ( !isset( $title->prpIndexPage ) ) { + if ( !isset( $title->prpIndexTitle ) ) { self::loadIndex( $title ); } - if ( $title->prpIndexPage === null ) { + if ( $title->prpIndexTitle === null ) { return true; } /** * invalidate the cache of the index page */ - $title->prpIndexPage->getTitle()->invalidateCache(); + $title->prpIndexTitle->invalidateCache(); /** * update pr_index iteratively */ - $indexId = $title->prpIndexPage->getTitle()->getArticleID(); + $indexId = $title->prpIndexTitle->getArticleID(); $indexData = ProofreadIndexDbConnector::getIndexDataFromIndexPageId( $indexId ); if ( $indexData ) { ProofreadIndexDbConnector::replaceIndexById( $indexData, $indexId, $article ); @@ -421,9 +421,9 @@ if ( $nt->inNamespace( self::getPageNamespaceId() ) ) { self::loadIndex( $nt ); - if ( $nt->prpIndexPage !== null - && ( !isset( $ot->prpIndexPage ) || - ( $nt->prpIndexPage->getTitle()->equals( $ot->prpIndexPage->getTitle() ) ) ) + if ( $nt->prpIndexTitle !== null + && ( !isset( $ot->prpIndexTitle ) || + ( $nt->prpIndexTitle->equals( $ot->prpIndexTitle ) ) ) ) { self::updateIndexOfPage( $nt ); } @@ -463,12 +463,10 @@ // read the list of pages $pages = []; $pagination = - Context::getDefaultContext()->getPaginationFactory()->getPaginationForIndexPage( - ProofreadIndexPage::newFromTitle( $indexTitle ) - ); + Context::getDefaultContext()->getPaginationFactory()->getPaginationForIndexTitle( $indexTitle ); foreach ( $pagination as $page ) { - if ( $deletedPage === null || !$page->getTitle()->equals( $deletedPage ) ) { - array_push( $pages, $page->getTitle()->getDBkey() ); + if ( $deletedPage === null || !$page->equals( $deletedPage ) ) { + $pages[] = $page->getDBkey(); } } @@ -622,9 +620,7 @@ $pageContentBuilder = new PageContentBuilder( RequestContext::getMain(), Context::getDefaultContext() ); - $content = $pageContentBuilder->buildDefaultContentForPage( - new ProofreadPagePage( $title ) - ); + $content = $pageContentBuilder->buildDefaultContentForPageTitle( $title ); $text = $content->serialize(); return true; @@ -702,22 +698,21 @@ */ public static function onSkinTemplateNavigation( SkinTemplate &$skin, array &$links ) { $title = $skin->getTitle(); - if ( !$title->inNamespace( self::getPageNamespaceId() ) ) { + if ( $title === null || !$title->inNamespace( self::getPageNamespaceId() ) ) { return true; } - $page = ProofreadPagePage::newFromTitle( $title ); // Image link try { $fileProvider = Context::getDefaultContext()->getFileProvider(); - $image = $fileProvider->getForPagePage( $page ); + $image = $fileProvider->getFileForPageTitle( $title ); $imageUrl = null; if ( $image->isMultipage() ) { $transformAttributes = [ 'width' => $image->getWidth() ]; try { - $transformAttributes['page'] = $fileProvider->getPageNumberForPagePage( $page ); + $transformAttributes['page'] = $fileProvider->getPageNumberForPageTitle( $title ); } catch ( PageNumberNotFoundException $e ) { // We do not care } @@ -744,16 +739,16 @@ } // Prev, Next and Index links - $indexPage = Context::getDefaultContext()->getIndexForPageLookup()->getIndexForPage( $page ); - if ( $indexPage !== null ) { + $indexTitle = Context::getDefaultContext() + ->getIndexForPageLookup()->getIndexForPageTitle( $title ); + if ( $indexTitle !== null ) { $pagination = Context::getDefaultContext() - ->getPaginationFactory()->getPaginationForIndexPage( $indexPage ); + ->getPaginationFactory()->getPaginationForIndexTitle( $indexTitle ); try { - $pageNumber = $pagination->getPageNumber( $page ); + $pageNumber = $pagination->getPageNumber( $title ); try { - $prevPage = $pagination->getPage( $pageNumber - 1 ); - $prevTitle = $prevPage->getTitle(); + $prevTitle = $pagination->getPageTitle( $pageNumber - 1 ); $links['namespaces']['proofreadPagePrevLink'] = [ 'class' => ( $skin->skinname === 'vector' ) ? 'icon' : '', 'href' => self::getLinkUrlForTitle( $prevTitle ), @@ -764,8 +759,7 @@ } // if the previous page does not exits try { - $nextPage = $pagination->getPage( $pageNumber + 1 ); - $nextTitle = $nextPage->getTitle(); + $nextTitle = $pagination->getPageTitle( $pageNumber + 1 ); $links['namespaces']['proofreadPageNextLink'] = [ 'class' => ( $skin->skinname === 'vector' ) ? 'icon' : '', 'href' => self::getLinkUrlForTitle( $nextTitle ), @@ -774,13 +768,12 @@ } catch ( OutOfBoundsException $e ) { } // if the next page does not exits - } - catch ( PageNotInPaginationException $e ) { + } catch ( PageNotInPaginationException $e ) { } $links['namespaces']['proofreadPageIndexLink'] = [ 'class' => ( $skin->skinname === 'vector' ) ? 'icon' : '', - 'href' => $indexPage->getTitle()->getLinkURL(), + 'href' => $indexTitle->getLinkURL(), 'text' => wfMessage( 'proofreadpage_index' )->plain() ]; } diff --git a/extension.json b/extension.json index 8e2de1e..ea80d0f 100644 --- a/extension.json +++ b/extension.json @@ -52,7 +52,6 @@ "ProofreadPage\\PageNumberNotFoundException": "includes/PageNumberNotFoundException.php", "ProofreadPage\\FileProvider": "includes/FileProvider.php", "ProofreadPage\\Link": "includes/Link.php", - "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", @@ -76,7 +75,6 @@ "ProofreadPageDbConnector": "includes/page/ProofreadPageDbConnector.php", "ProofreadPage\\Page\\EditPagePage": "includes/page/EditPagePage.php", "ProofreadPage\\Page\\PageContentBuilder": "includes/page/PageContentBuilder.php", - "ProofreadPagePage": "includes/page/ProofreadPagePage.php", "ProofreadPage\\Page\\PageContent": "includes/page/PageContent.php", "ProofreadPage\\Page\\PageLevel": "includes/page/PageLevel.php", "ProofreadPage\\Page\\PageContentHandler": "includes/page/PageContentHandler.php", diff --git a/includes/FileProvider.php b/includes/FileProvider.php index 037dea9..d07189f 100644 --- a/includes/FileProvider.php +++ b/includes/FileProvider.php @@ -3,8 +3,6 @@ namespace ProofreadPage; use File; -use ProofreadIndexPage; -use ProofreadPagePage; use RepoGroup; use Title; @@ -41,48 +39,48 @@ } /** - * @param ProofreadIndexPage $page + * @param Title $indexTitle * @return File * @throws FileNotFoundException */ - public function getForIndexPage( ProofreadIndexPage $page ) { + public function getFileForIndexTitle( Title $indexTitle ) { return $this->getFileFromTitle( - Title::makeTitle( NS_FILE, $page->getTitle()->getText() ) + Title::makeTitle( NS_FILE, $indexTitle->getText() ) ); } /** - * @param ProofreadPagePage $page + * @param Title $pageTitle * @return File * @throws FileNotFoundException */ - public function getForPagePage( ProofreadPagePage $page ) { + public function getFileForPageTitle( Title $pageTitle ) { // try to get an image with the same name as the file return $this->getFileFromTitle( - // use the base name as file name - Title::makeTitle( NS_FILE, strtok( $page->getTitle()->getText(), '/' ) ) + // use the base name as file name + Title::makeTitle( NS_FILE, strtok( $pageTitle->getText(), '/' ) ) ); } /** - * @param ProofreadPagePage $page + * @param Title $pageTitle * @return int * @throws PageNumberNotFoundException */ - public function getPageNumberForPagePage( ProofreadPagePage $page ) { - $parts = explode( '/', $page->getTitle()->getText() ); + public function getPageNumberForPageTitle( Title $pageTitle ) { + $parts = explode( '/', $pageTitle->getText() ); if ( count( $parts ) === 1 ) { throw new PageNumberNotFoundException( - $page->getTitle()->getFullText() . ' does not provide a page number.' + $pageTitle->getFullText() . ' does not provide a page number.' ); } - $number = $page->getTitle()->getPageLanguage()->parseFormattedNumber( end( $parts ) ); + $number = $pageTitle->getPageLanguage()->parseFormattedNumber( end( $parts ) ); if ( $number > 0 ) { // Valid page numbers are integer > 0. return (int)$number; } throw new PageNumberNotFoundException( - $page->getTitle()->getFullText() . ' does not provide a valid page number.' + $pageTitle->getFullText() . ' does not provide a valid page number.' ); } } diff --git a/includes/Pagination/FilePagination.php b/includes/Pagination/FilePagination.php index d3519e4..5eee3c8 100644 --- a/includes/Pagination/FilePagination.php +++ b/includes/Pagination/FilePagination.php @@ -4,10 +4,8 @@ use File; use OutOfBoundsException; -use ProofreadIndexPage; use ProofreadPage\Context; use ProofreadPage\PageNumberNotFoundException; -use ProofreadPagePage; use Title; /** @@ -16,6 +14,11 @@ * Pagination of a book based on a multipage file */ class FilePagination extends Pagination { + + /** + * @var Title + */ + private $indexTitle; /** * @var PageList representation of the <pagelist> tag @@ -28,7 +31,7 @@ private $numberOfPages = 0; /** - * @var ProofreadPagePage[] cache of build pages of the pagination as $pageNumber => $page array + * @var Title[] cache of build pages of the pagination as $pageNumber => $page array */ private $pages = []; @@ -38,16 +41,15 @@ private $context; /** - * @param ProofreadIndexPage $index + * @param Title $indexTitle * @param PageList $pageList representation of the <pagelist> tag that configure page numbers * @param File $file the pagination file * @param Context $context the current context */ public function __construct( - ProofreadIndexPage $index, PageList $pageList, File $file, Context $context + Title $indexTitle, PageList $pageList, File $file, Context $context ) { - parent::__construct( $index ); - + $this->indexTitle = $indexTitle; $this->pageList = $pageList; $this->context = $context; @@ -59,18 +61,18 @@ /** * @see ProofreadPagination::getPageNumber */ - public function getPageNumber( ProofreadPagePage $page ) { - $index = $this->context->getIndexForPageLookup()->getIndexForPage( $page ); - if ( $index === null || !$this->index->equals( $index ) ) { + public function getPageNumber( Title $pageTitle ) { + $indexTitle = $this->context->getIndexForPageLookup()->getIndexForPageTitle( $pageTitle ); + if ( $indexTitle === null || !$this->indexTitle->equals( $indexTitle ) ) { throw new PageNotInPaginationException( - $page->getTitle()->getFullText() . ' does not belong to the pagination' + $pageTitle->getFullText() . ' does not belong to the pagination' ); } try { - return $this->context->getFileProvider()->getPageNumberForPagePage( $page ); + return $this->context->getFileProvider()->getPageNumberForPageTitle( $pageTitle ); } catch ( PageNumberNotFoundException $e ) { throw new PageNotInPaginationException( - $page->getTitle()->getFullText() . ' does not have page numbers' + $pageTitle->getFullText() . ' does not have page numbers' ); } } @@ -95,9 +97,9 @@ } /** - * @see ProofreadPagination::getPage + * @see ProofreadPagination::getPageTitle */ - public function getPage( $pageNumber ) { + public function getPageTitle( $pageNumber ) { if ( !$this->pageNumberExists( $pageNumber ) ) { throw new OutOfBoundsException( 'There is no page number ' . $pageNumber . ' in the pagination.' @@ -105,7 +107,7 @@ } if ( !array_key_exists( $pageNumber, $this->pages ) ) { - $this->pages[$pageNumber] = $this->buildPagePage( $pageNumber ); + $this->pages[$pageNumber] = $this->buildPageTitle( $pageNumber ); } return $this->pages[$pageNumber]; @@ -113,21 +115,21 @@ /** * @param integer $pageNumber - * @return ProofreadPagePage + * @return Title */ - private function buildPagePage( $pageNumber ) { - $i18nNumber = $this->index->getTitle()->getPageLanguage()->formatNum( $pageNumber, true ); + private function buildPageTitle( $pageNumber ) { + $i18nNumber = $this->indexTitle->getPageLanguage()->formatNum( $pageNumber, true ); $title = $this->buildPageTitleFromPageNumber( $i18nNumber ); // fallback to arabic number if ( $i18nNumber !== $pageNumber && !$title->exists() ) { $arabicTitle = $this->buildPageTitleFromPageNumber( $pageNumber ); if ( $arabicTitle->exists() ) { - return ProofreadPagePage::newFromTitle( $arabicTitle ); + return $arabicTitle; } } - return ProofreadPagePage::newFromTitle( $title ); + return $title; } /** @@ -137,7 +139,7 @@ private function buildPageTitleFromPageNumber( $pageNumber ) { return Title::makeTitle( $this->context->getPageNamespaceId(), - $this->index->getTitle()->getText() . '/' . $pageNumber + $this->indexTitle->getText() . '/' . $pageNumber ); } diff --git a/includes/Pagination/PagePagination.php b/includes/Pagination/PagePagination.php index 4bb276d..b276ed2 100644 --- a/includes/Pagination/PagePagination.php +++ b/includes/Pagination/PagePagination.php @@ -3,8 +3,7 @@ use InvalidArgumentException; use OutOfBoundsException; -use ProofreadIndexPage; -use ProofreadPagePage; +use Title; /** * @licence GNU GPL v2+ @@ -14,7 +13,7 @@ class PagePagination extends Pagination { /** - * @var ProofreadPagePage[] + * @var Title[] */ private $pages = []; @@ -24,14 +23,11 @@ private $pageNumbers = []; /** - * @param ProofreadIndexPage $index - * @param ProofreadPagePage[] $pages the ordered pages + * @param Title[] $pages the ordered pages * @param PageNumber[] $pageNumbers with $pageNumbers[i] the page number of the page $pages[i] * @throws InvalidArgumentException */ - public function __construct( ProofreadIndexPage $index, array $pages, array $pageNumbers ) { - parent::__construct( $index ); - + public function __construct( array $pages, array $pageNumbers ) { if ( count( $pages ) !== count( $pageNumbers ) ) { throw new InvalidArgumentException( 'The number of page numbers is not the same as the number of pages' @@ -45,9 +41,9 @@ /** * @see ProofreadPagination::getPageNumber */ - public function getPageNumber( ProofreadPagePage $page ) { - foreach ( $this->pages as $i => $page2 ) { - if ( $page->equals( $page2 ) ) { + public function getPageNumber( Title $pageTitle ) { + foreach ( $this->pages as $i => $pageTitle2 ) { + if ( $pageTitle->equals( $pageTitle2 ) ) { return $i + 1; } } @@ -74,9 +70,9 @@ } /** - * @see ProofreadPagination::getPage + * @see ProofreadPagination::getPageTitle */ - public function getPage( $pageNumber ) { + public function getPageTitle( $pageNumber ) { if ( !$this->pageNumberExists( $pageNumber ) ) { throw new OutOfBoundsException( 'There is no page number ' . $pageNumber . ' in the pagination.' diff --git a/includes/Pagination/Pagination.php b/includes/Pagination/Pagination.php index 54da436..f226c01 100644 --- a/includes/Pagination/Pagination.php +++ b/includes/Pagination/Pagination.php @@ -4,8 +4,7 @@ use Iterator; use OutOfBoundsException; -use ProofreadIndexPage; -use ProofreadPagePage; +use Title; /** * @licence GNU GPL v2+ @@ -15,39 +14,18 @@ abstract class Pagination implements Iterator { /** - * @var ProofreadIndexPage - */ - protected $index; - - /** * @var integer position of the iterator */ private $position = 1; /** - * @param ProofreadIndexPage $index - */ - public function __construct( ProofreadIndexPage $index ) { - $this->index = $index; - } - - /** - * Returns the index page - * - * @return ProofreadIndexPage - */ - public function getIndex() { - return $this->index; - } - - /** * Returns the internal page number * - * @param ProofreadPagePage $page + * @param Title $pageTitle * @return integer * @throws PageNotInPaginationException */ - abstract public function getPageNumber( ProofreadPagePage $page ); + abstract public function getPageNumber( Title $pageTitle ); /** * Returns the page number as it should be displayed from an internal page number @@ -69,10 +47,10 @@ * Returns the page number $pageNumber of the book * * @param int $pageNumber page number - * @return ProofreadPagePage + * @return Title * @throws OutOfBoundsException */ - abstract public function getPage( $pageNumber ); + abstract public function getPageTitle( $pageNumber ); /** * Returns if a page number $pageNumber exits @@ -106,10 +84,10 @@ /** * @see Iterator::current * - * @return ProofreadPagePage + * @return Title */ public function current() { - return $this->getPage( $this->position ); + return $this->getPageTitle( $this->position ); } /** diff --git a/includes/Pagination/PaginationFactory.php b/includes/Pagination/PaginationFactory.php index 18802e4..a8d0c8e 100644 --- a/includes/Pagination/PaginationFactory.php +++ b/includes/Pagination/PaginationFactory.php @@ -2,10 +2,9 @@ namespace ProofreadPage\Pagination; -use ProofreadIndexPage; use ProofreadPage\Context; use ProofreadPage\FileNotFoundException; -use ProofreadPagePage; +use Title; /** * @licence GNU GPL v2+ @@ -27,40 +26,35 @@ } /** - * @param ProofreadIndexPage $indexPage + * @param Title $indexTitle * @return Pagination */ - public function getPaginationForIndexPage( ProofreadIndexPage $indexPage ) { - $key = $indexPage->getTitle()->getDBkey(); + public function getPaginationForIndexTitle( Title $indexTitle ) { + $key = $indexTitle->getDBkey(); if ( !array_key_exists( $key, $this->paginations ) ) { - $this->paginations[$key] = $this->buildPaginationForIndexPage( $indexPage ); + $this->paginations[$key] = $this->buildPaginationForIndexTitle( $indexTitle ); } return $this->paginations[$key]; } /** - * @param ProofreadIndexPage $indexPage + * @param Title $indexTitle * @return Pagination */ - private function buildPaginationForIndexPage( ProofreadIndexPage $indexPage ) { + private function buildPaginationForIndexTitle( Title $indexTitle ) { try { - $file = $this->context->getFileProvider()->getForIndexPage( $indexPage ); + $file = $this->context->getFileProvider()->getFileForIndexTitle( $indexTitle ); } catch ( FileNotFoundException $e ) { $file = false; } // check if it is using pagelist - $indexContent = $this->context->getIndexContentLookup()->getIndexContent( $indexPage ); + $indexContent = $this->context->getIndexContentLookup()->getIndexContentForTitle( $indexTitle ); $pagelist = $indexContent->getPagelistTagContent(); if ( $pagelist !== null && $file && $file->isMultipage() ) { - return new FilePagination( - $indexPage, - $pagelist, - $file, - $this->context - ); + return new FilePagination( $indexTitle, $pagelist, $file, $this->context ); } else { $links = $indexContent->getLinksToNamespace( Context::getDefaultContext()->getPageNamespaceId() @@ -68,10 +62,10 @@ $pages = []; $pageNumbers = []; foreach ( $links as $link ) { - $pages[] = ProofreadPagePage::newFromTitle( $link->getTarget() ); + $pages[] = $link->getTarget(); $pageNumbers[] = new PageNumber( $link->getLabel() ); } - return new PagePagination( $indexPage, $pages, $pageNumbers ); + return new PagePagination( $pages, $pageNumbers ); } } } diff --git a/includes/Parser/PagelistTagParser.php b/includes/Parser/PagelistTagParser.php index 7800b55..999f7d4 100644 --- a/includes/Parser/PagelistTagParser.php +++ b/includes/Parser/PagelistTagParser.php @@ -2,7 +2,6 @@ namespace ProofreadPage\Parser; -use ProofreadIndexPage; use ProofreadPage\FileNotFoundException; use ProofreadPage\Pagination\FilePagination; use ProofreadPage\Pagination\PageList; @@ -23,10 +22,9 @@ if ( !$title->inNamespace( $this->context->getIndexNamespaceId() ) ) { return ''; } - $index = ProofreadIndexPage::newFromTitle( $title ); $pageList = new PageList( $args ); try { - $image = $this->context->getFileProvider()->getForIndexPage( $index ); + $image = $this->context->getFileProvider()->getFileForIndexTitle( $title ); } catch ( FileNotFoundException $e ) { return $this->formatError( 'proofreadpage_nosuch_file' ); } @@ -34,7 +32,7 @@ return $this->formatError( 'proofreadpage_nosuch_file' ); } - $pagination = new FilePagination( $index, $pageList, $image, $this->context ); + $pagination = new FilePagination( $title, $pageList, $image, $this->context ); $count = $pagination->getNumberOfPages(); $return = ''; @@ -71,7 +69,7 @@ } $view = $txt . '</span>' . $view; } - $pageTitle = $pagination->getPage( $i )->getTitle(); + $pageTitle = $pagination->getPageTitle( $i ); if ( $pageNumber->isEmpty() || !$title ) { $return .= $view . ' '; diff --git a/includes/Parser/PagesTagParser.php b/includes/Parser/PagesTagParser.php index cc09615..9232f96 100644 --- a/includes/Parser/PagesTagParser.php +++ b/includes/Parser/PagesTagParser.php @@ -3,11 +3,9 @@ namespace ProofreadPage\Parser; use OutOfBoundsException; -use ProofreadIndexPage; use ProofreadPage\Context; use ProofreadPage\Pagination\FilePagination; use ProofreadPageDbConnector; -use ProofreadPagePage; use Title; /** @@ -62,10 +60,8 @@ if ( $indexTitle === null || !$indexTitle->exists() ) { return $this->formatError( 'proofreadpage_nosuch_index' ); } - $indexPage = ProofreadIndexPage::newFromTitle( $indexTitle ); - $indexContent = $this->context->getIndexContentLookup()->getIndexContent( $indexPage ); - $pagination = $this->context->getPaginationFactory() - ->getPaginationForIndexPage( $indexPage ); + $indexContent = $this->context->getIndexContentLookup()->getIndexContentForTitle( $indexTitle ); + $pagination = $this->context->getPaginationFactory()->getPaginationForIndexTitle( $indexTitle ); $language = $this->parser->getTargetLanguage(); $this->parser->getOutput()->addTemplate( $indexTitle, $indexTitle->getArticleID(), $indexTitle->getLatestRevID() @@ -150,43 +146,35 @@ if ( $step == 1 || $num % $step == $mod ) { $pagenum = $pagination->getDisplayedPageNumber( $num ) ->getFormattedPageNumber( $language ); - $pages[] = [ $pagination->getPage( $num )->getTitle(), $pagenum ]; + $pages[] = [ $pagination->getPageTitle( $num ), $pagenum ]; } } } else { - $adding = true; - - $fromPage = null; + $fromTitle = null; if ( $from ) { $fromTitle = Title::makeTitleSafe( $this->context->getPageNamespaceId(), $from ); - if ( $fromTitle !== null ) { - $fromPage = ProofreadPagePage::newFromTitle( $fromTitle ); - $adding = false; - } } - $toPage = null; + $toTitle = null; if ( $to ) { $toTitle = Title::makeTitleSafe( $this->context->getPageNamespaceId(), $to ); - if ( $toTitle !== null ) { - $toPage = ProofreadPagePage::newFromTitle( $toTitle ); - } } + $adding = ( $fromTitle === null ); $i = 1; foreach ( $pagination as $link ) { - if ( $fromPage !== null && $fromPage->equals( $link ) ) { + if ( $fromTitle !== null && $fromTitle->equals( $link ) ) { $adding = true; } if ( $adding ) { $pagenum = $pagination->getDisplayedPageNumber( $i ) ->getFormattedPageNumber( $language ); - $pages[] = [ $link->getTitle(), $pagenum ]; + $pages[] = [ $link, $pagenum ]; } - if ( $toPage !== null && $toPage->equals( $link ) ) { + if ( $toTitle !== null && $toTitle->equals( $link ) ) { $adding = false; } $i++; @@ -250,7 +238,7 @@ /* table of Contents */ $header = 'toc'; try { - $firstpage = $pagination->getPage( 1 )->getTitle(); + $firstpage = $pagination->getPageTitle( 1 ); $this->parser->getOutput()->addTemplate( $firstpage, $firstpage->getArticleID(), diff --git a/includes/index/DatabaseIndexContentLookup.php b/includes/index/DatabaseIndexContentLookup.php index 8598ebf..36cd727 100644 --- a/includes/index/DatabaseIndexContentLookup.php +++ b/includes/index/DatabaseIndexContentLookup.php @@ -2,8 +2,8 @@ namespace ProofreadPage\Index; -use ProofreadIndexPage; use Revision; +use Title; /** * @licence GNU GPL v2+ @@ -15,13 +15,13 @@ private $cache = []; /** - * @see IndexContentLookup::getIndexContent + * @see IndexContentLookup::getIndexContentForTitle */ - public function getIndexContent( ProofreadIndexPage $index ) { - $cacheKey = $index->getTitle()->getDBkey(); + public function getIndexContentForTitle( Title $indexTitle ) { + $cacheKey = $indexTitle->getDBkey(); if ( !array_key_exists( $cacheKey, $this->cache ) ) { - $rev = Revision::newFromTitle( $index->getTitle() ); + $rev = Revision::newFromTitle( $indexTitle ); if ( $rev === null ) { $this->cache[$cacheKey] = new IndexContent( [] ); } else { diff --git a/includes/index/IndexContentLookup.php b/includes/index/IndexContentLookup.php index 2eedca7..e644cb1 100644 --- a/includes/index/IndexContentLookup.php +++ b/includes/index/IndexContentLookup.php @@ -2,7 +2,7 @@ namespace ProofreadPage\Index; -use ProofreadIndexPage; +use Title; /** * @licence GNU GPL v2+ @@ -15,5 +15,5 @@ * Returns content of the page * @return IndexContent */ - public function getIndexContent( ProofreadIndexPage $index ); + public function getIndexContentForTitle( Title $indexTitle ); } diff --git a/includes/index/ProofreadIndexPage.php b/includes/index/ProofreadIndexPage.php deleted file mode 100644 index aced236..0000000 --- a/includes/index/ProofreadIndexPage.php +++ /dev/null @@ -1,65 +0,0 @@ -<?php -/** - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * http://www.gnu.org/copyleft/gpl.html - * - * @file - * @ingroup ProofreadPage - */ - -/** - * An index page - */ -class ProofreadIndexPage { - - /** - * @var Title - */ - protected $title; - - /** - * @param Title $title Reference to a Title object. - */ - public function __construct( Title $title ) { - $this->title = $title; - } - - /** - * Create a new ProofreadIndexPage from a Title object - * @param Title $title - * @return ProofreadIndexPage - */ - public static function newFromTitle( Title $title ) { - return new self( $title ); - } - - /** - * Return Title of the index page - * @return Title - */ - public function getTitle() { - return $this->title; - } - - /** - * Check if two ProofreadIndexPage are equals - * - * @param ProofreadIndexPage $that - * @return bool - */ - public function equals( ProofreadIndexPage $that ) { - return $this->title->equals( $that->getTitle() ); - } -} diff --git a/includes/page/DatabaseIndexForPageLookup.php b/includes/page/DatabaseIndexForPageLookup.php index a918611..1c5a402 100644 --- a/includes/page/DatabaseIndexForPageLookup.php +++ b/includes/page/DatabaseIndexForPageLookup.php @@ -3,8 +3,6 @@ namespace ProofreadPage\Page; use ProofreadIndexDbConnector; -use ProofreadIndexPage; -use ProofreadPagePage; use RepoGroup; use Title; @@ -37,17 +35,17 @@ } /** - * @see IndexForPageLookup::getIndexForPage + * @see IndexForPageLookup::getIndexForPageTitle */ - public function getIndexForPage( ProofreadPagePage $page ) { - $cacheKey = $page->getTitle()->getDBkey(); + public function getIndexForPageTitle( Title $pageTitle ) { + $cacheKey = $pageTitle->getDBkey(); if ( !array_key_exists( $cacheKey, $this->cache ) ) { - $indexTitle = $this->findIndexTitle( $page->getTitle() ); + $indexTitle = $this->findIndexTitle( $pageTitle ); if ( $indexTitle === null ) { $this->cache[$cacheKey] = null; } else { - $this->cache[$cacheKey] = ProofreadIndexPage::newFromTitle( $indexTitle ); + $this->cache[$cacheKey] = $indexTitle; } } return $this->cache[$cacheKey]; diff --git a/includes/page/EditPagePage.php b/includes/page/EditPagePage.php index fc6e559..b196cea 100644 --- a/includes/page/EditPagePage.php +++ b/includes/page/EditPagePage.php @@ -8,18 +8,12 @@ use MWException; use OOUI; use ProofreadPage\Context; -use ProofreadPagePage; use User; /** * @licence GNU GPL v2+ */ class EditPagePage extends EditPage { - - /** - * @var ProofreadPagePage - */ - private $pagePage; /** * @var PageContentBuilder @@ -33,14 +27,12 @@ /** * @param Article $article - * @param ProofreadPagePage $pagePage * @param Context $context * @throws MWException */ - public function __construct( Article $article, ProofreadPagePage $pagePage, Context $context ) { + public function __construct( Article $article, Context $context ) { parent::__construct( $article ); - $this->pagePage = $pagePage; $this->pageContentBuilder = new PageContentBuilder( $this->context, $context ); $this->pageDisplayHandler = new PageDisplayHandler( $context ); } @@ -66,7 +58,7 @@ */ protected function getContentObject( $defContent = null ) { if ( !$this->mTitle->exists() ) { - return $this->pageContentBuilder->buildDefaultContentForPage( $this->pagePage ); + return $this->pageContentBuilder->buildDefaultContentForPageTitle( $this->getTitle() ); } return parent::getContentObject( $defContent ); } @@ -78,7 +70,7 @@ $out = $this->context->getOutput(); // custom CSS for preview - $css = $this->pageDisplayHandler->getCustomCss( $this->pagePage ); + $css = $this->pageDisplayHandler->getCustomCss( $this->getTitle() ); if ( $css !== '' ) { $out->addInlineStyle( $css ); } @@ -114,7 +106,7 @@ $inputAttributes + [ 'rows' => '2', 'tabindex' => '1' ] ); // the 3 textarea tabindex are set to 1 because summary tabindex is 1 too - $out->addHTML( $this->pageDisplayHandler->buildPageContainerEnd( $this->pagePage ) ); + $out->addHTML( $this->pageDisplayHandler->buildPageContainerEnd( $this->getTitle() ) ); $out->addModules( 'ext.proofreadpage.page.edit' ); $out->addModuleStyles( [ 'ext.proofreadpage.base', 'ext.proofreadpage.page' ] ); diff --git a/includes/page/IndexForPageLookup.php b/includes/page/IndexForPageLookup.php index 4dce31a..8f92da3 100644 --- a/includes/page/IndexForPageLookup.php +++ b/includes/page/IndexForPageLookup.php @@ -2,8 +2,7 @@ namespace ProofreadPage\Page; -use ProofreadIndexPage; -use ProofreadPagePage; +use Title; /** * @licence GNU GPL v2+ @@ -14,8 +13,7 @@ /** * Return index of the page - * @param ProofreadPagePage $page - * @return ProofreadIndexPage|null + * @return Title|null */ - public function getIndexForPage( ProofreadPagePage $page ); + public function getIndexForPageTitle( Title $pageTitle ); } diff --git a/includes/page/PageContentBuilder.php b/includes/page/PageContentBuilder.php index 21fa621..a6ec68b 100644 --- a/includes/page/PageContentBuilder.php +++ b/includes/page/PageContentBuilder.php @@ -8,7 +8,7 @@ use ProofreadPage\FileNotFoundException; use ProofreadPage\PageNumberNotFoundException; use ProofreadPage\Pagination\PageNotInPaginationException; -use ProofreadPagePage; +use Title; use WikitextContent; /** @@ -38,29 +38,28 @@ } /** - * @param ProofreadPagePage $page + * @param Title $pageTitle * @return PageContent */ - public function buildDefaultContentForPage( ProofreadPagePage $page ) { - $index = $this->context->getIndexForPageLookup()->getIndexForPage( $page ); + public function buildDefaultContentForPageTitle( Title $pageTitle ) { + $indexTitle = $this->context->getIndexForPageLookup()->getIndexForPageTitle( $pageTitle ); $body = ''; // default header and footer - if ( $index !== null ) { + if ( $indexTitle !== null ) { $params = []; try { - $pagination = $this->context->getPaginationFactory() - ->getPaginationForIndexPage( $index ); - $pageNumber = $pagination->getPageNumber( $page ); + $pagination = $this->context->getPaginationFactory()->getPaginationForIndexTitle( $indexTitle ); + $pageNumber = $pagination->getPageNumber( $pageTitle ); $displayedPageNumber = $pagination->getDisplayedPageNumber( $pageNumber ); $params['pagenum'] = $displayedPageNumber - ->getFormattedPageNumber( $page->getTitle()->getPageLanguage() ); + ->getFormattedPageNumber( $pageTitle->getPageLanguage() ); } catch ( PageNotInPaginationException $e ) { } catch ( OutOfBoundsException $e ) { } // should not happen $indexFieldsParser = $this->context->getCustomIndexFieldsParser(); - $indexContent = $this->context->getIndexContentLookup()->getIndexContent( $index ); + $indexContent = $this->context->getIndexContentLookup()->getIndexContentForTitle( $indexTitle ); $header = $indexFieldsParser->parseCustomIndexFieldWithVariablesReplacedWithIndexEntries( $indexContent, 'header', $params ); @@ -77,12 +76,12 @@ // Extract text layer try { $fileProvider = $this->context->getFileProvider(); - $image = $fileProvider->getForPagePage( $page ); + $image = $fileProvider->getFileForPageTitle( $pageTitle ); if ( $image->exists() ) { $pageNumber = 1; if ( $image->isMultipage() ) { try { - $pageNumber = $fileProvider->getPageNumberForPagePage( $page ); + $pageNumber = $fileProvider->getPageNumberForPageTitle( $pageTitle ); } catch ( PageNumberNotFoundException $e ) { } } diff --git a/includes/page/PageDisplayHandler.php b/includes/page/PageDisplayHandler.php index c6502ff..cc70981 100644 --- a/includes/page/PageDisplayHandler.php +++ b/includes/page/PageDisplayHandler.php @@ -7,8 +7,8 @@ use ProofreadPage\Context; use ProofreadPage\FileNotFoundException; use ProofreadPage\PageNumberNotFoundException; -use ProofreadPagePage; use Sanitizer; +use Title; /** * @licence GNU GPL v2+ @@ -36,14 +36,14 @@ /** * Return the scan image width for display - * @param ProofreadPagePage $page + * @param Title $pageTitle * @return int */ - public function getImageWidth( ProofreadPagePage $page ) { - $index = $this->context->getIndexForPageLookup()->getIndexForPage( $page ); - if ( $index !== null ) { + public function getImageWidth( Title $pageTitle ) { + $indexTitle = $this->context->getIndexForPageLookup()->getIndexForPageTitle( $pageTitle ); + if ( $indexTitle !== null ) { try { - $indexContent = $this->context->getIndexContentLookup()->getIndexContent( $index ); + $indexContent = $this->context->getIndexContentLookup()->getIndexContentForTitle( $indexTitle ); $width = $this->context->getCustomIndexFieldsParser()->parseCustomIndexField( $indexContent, 'width' )->getStringValue(); @@ -60,16 +60,16 @@ /** * Return custom CSS for the page * Is protected against XSS - * @param ProofreadPagePage $page + * @param Title $pageTitle * @return string */ - public function getCustomCss( ProofreadPagePage $page ) { - $index = $this->context->getIndexForPageLookup()->getIndexForPage( $page ); - if ( $index === null ) { + public function getCustomCss( Title $pageTitle ) { + $indexTitle = $this->context->getIndexForPageLookup()->getIndexForPageTitle( $pageTitle ); + if ( $indexTitle === null ) { return ''; } try { - $indexContent = $this->context->getIndexContentLookup()->getIndexContent( $index ); + $indexContent = $this->context->getIndexContentLookup()->getIndexContentForTitle( $indexTitle ); $css = $this->context->getCustomIndexFieldsParser()->parseCustomIndexField( $indexContent, 'css' ); @@ -95,25 +95,25 @@ * Return the part of the page container that after page cnotent * @return string */ - public function buildPageContainerEnd( ProofreadPagePage $page ) { + public function buildPageContainerEnd( Title $pageTitle ) { return Html::closeElement( 'div' ) . Html::openElement( 'div', [ 'class' => 'prp-page-image' ] ) . - $this->buildImageHtml( $page, [ 'max-width' => $this->getImageWidth( $page ) ] ) . + $this->buildImageHtml( $pageTitle, [ 'max-width' => $this->getImageWidth( $pageTitle ) ] ) . Html::closeElement( 'div' ) . Html::closeElement( 'div' ); } /** * Return HTML for the image - * @param ProofreadPagePage $page + * @param Title $pageTitle * @param array $options * @return null|string */ - private function buildImageHtml( ProofreadPagePage $page, $options ) { + private function buildImageHtml( Title $pageTitle, $options ) { $fileProvider = $this->context->getFileProvider(); try { - $image = $fileProvider->getForPagePage( $page ); + $image = $fileProvider->getFileForPageTitle( $pageTitle ); } catch ( FileNotFoundException $e ) { return null; } @@ -130,7 +130,7 @@ if ( $image->isMultipage() ) { try { - $transformAttributes['page'] = $fileProvider->getPageNumberForPagePage( $page ); + $transformAttributes['page'] = $fileProvider->getPageNumberForPageTitle( $pageTitle ); } catch ( PageNumberNotFoundException $e ) { } } diff --git a/includes/page/PageEditAction.php b/includes/page/PageEditAction.php index fb6048e..21018c7 100644 --- a/includes/page/PageEditAction.php +++ b/includes/page/PageEditAction.php @@ -4,7 +4,6 @@ use EditAction; use ProofreadPage\Context; -use ProofreadPagePage; /** * @licence GNU GPL v2+ @@ -17,8 +16,7 @@ * @see FormlessAction:show */ public function show() { - $pagePage = ProofreadPagePage::newFromTitle( $this->getTitle() ); - $editor = new EditPagePage( $this->page, $pagePage, Context::getDefaultContext() ); + $editor = new EditPagePage( $this->page, Context::getDefaultContext() ); $editor->edit(); } } diff --git a/includes/page/PageSubmitAction.php b/includes/page/PageSubmitAction.php index 68a9ba2..548d812 100644 --- a/includes/page/PageSubmitAction.php +++ b/includes/page/PageSubmitAction.php @@ -3,7 +3,6 @@ namespace ProofreadPage\Page; use ProofreadPage\Context; -use ProofreadPagePage; use SubmitAction; /** @@ -17,8 +16,7 @@ * @see FormlessAction:show */ public function show() { - $pagePage = ProofreadPagePage::newFromTitle( $this->getTitle() ); - $editor = new EditPagePage( $this->page, $pagePage, Context::getDefaultContext() ); + $editor = new EditPagePage( $this->page, Context::getDefaultContext() ); $editor->edit(); } } diff --git a/includes/page/PageViewAction.php b/includes/page/PageViewAction.php index 1dfd22b..41296ac 100644 --- a/includes/page/PageViewAction.php +++ b/includes/page/PageViewAction.php @@ -3,7 +3,6 @@ namespace ProofreadPage\Page; use ProofreadPage\Context; -use ProofreadPagePage; use Revision; use ViewAction; @@ -37,13 +36,12 @@ return; } - $page = ProofreadPagePage::newFromTitle( $wikiPage->getTitle() ); $pageDisplayHandler = new PageDisplayHandler( Context::getDefaultContext() ); // render HTML $out->addHTML( $pageDisplayHandler->buildPageContainerBegin() ); $this->page->view(); - $out->addHTML( $pageDisplayHandler->buildPageContainerEnd( $page ) ); + $out->addHTML( $pageDisplayHandler->buildPageContainerEnd( $title ) ); // add modules $out->addModules( 'ext.proofreadpage.ve.pageTarget.init' ); @@ -53,7 +51,7 @@ ] ); // custom CSS - $css = $pageDisplayHandler->getCustomCss( $page ); + $css = $pageDisplayHandler->getCustomCss( $title ); if ( $css !== '' ) { $out->addInlineStyle( $css ); } diff --git a/includes/page/ProofreadPagePage.php b/includes/page/ProofreadPagePage.php deleted file mode 100644 index 75343d5..0000000 --- a/includes/page/ProofreadPagePage.php +++ /dev/null @@ -1,65 +0,0 @@ -<?php -/** - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * http://www.gnu.org/copyleft/gpl.html - * - * @file - * @ingroup ProofreadPage - */ - -/** - * The content of a page page - */ -class ProofreadPagePage { - - /** - * @var Title - */ - protected $title; - - /** - * @param Title $title Reference to a Title object - */ - public function __construct( Title $title ) { - $this->title = $title; - } - - /** - * Create a new ProofreadPagePage from a Title object - * @param Title $title - * @return ProofreadPagePage - */ - public static function newFromTitle( Title $title ) { - return new self( $title ); - } - - /** - * Check if two ProofreadPagePage are equals - * - * @param ProofreadPagePage $that - * @return bool - */ - public function equals( ProofreadPagePage $that ) { - return $this->title->equals( $that->getTitle() ); - } - - /** - * Returns Title of the index page - * @return Title - */ - public function getTitle() { - return $this->title; - } -} diff --git a/tests/phpunit/FileProviderTest.php b/tests/phpunit/FileProviderTest.php index 3b0373d..b1ab1a9 100644 --- a/tests/phpunit/FileProviderTest.php +++ b/tests/phpunit/FileProviderTest.php @@ -3,8 +3,6 @@ namespace ProofreadPage; use File; -use ProofreadIndexPage; -use ProofreadPagePage; use ProofreadPageTestCase; use Title; @@ -23,10 +21,10 @@ /** * @dataProvider indexFileProvider */ - public function testGetForIndexPage( - ProofreadIndexPage $index, File $file, FileProvider $fileProvider + public function testGetFileForIndexTitle( + Title $indexTitle, File $file, FileProvider $fileProvider ) { - $this->assertEquals( $file, $fileProvider->getForIndexPage( $index ) ); + $this->assertEquals( $file, $fileProvider->getFileForIndexTitle( $indexTitle ) ); } public function indexFileProvider() { @@ -37,7 +35,7 @@ return [ [ - $this->newIndexPage( 'LoremIpsum.djvu' ), + Title::makeTitle( $this->getIndexNamespaceId(), 'LoremIpsum.djvu' ), $this->getFileFromName( 'LoremIpsum.djvu' ), $fileProvider ], @@ -48,10 +46,10 @@ * @expectedException \ProofreadPage\FileNotFoundException * @dataProvider indexFileNotFoundProvider */ - public function testGetForIndexPageWithFileNotFound( - ProofreadIndexPage $index, FileProvider $fileProvider + public function testGetFileForIndexPageWithFileNotFound( + Title $indexTitle, FileProvider $fileProvider ) { - $fileProvider->getForIndexPage( $index ); + $fileProvider->getFileForIndexTitle( $indexTitle ); } public function indexFileNotFoundProvider() { @@ -62,11 +60,11 @@ return [ [ - $this->newIndexPage( 'LoremIpsum2.djvu' ), + Title::makeTitle( $this->getIndexNamespaceId(), 'LoremIpsum2.djvu' ), $fileProvider ], [ - $this->newIndexPage( 'Test' ), + Title::makeTitle( $this->getIndexNamespaceId(), 'Test' ), $fileProvider ], ]; @@ -75,10 +73,10 @@ /** * @dataProvider pageFileProvider */ - public function testGetForPagePage( - ProofreadPagePage $page, File $file, FileProvider $fileProvider + public function testFileGetForPageTitle( + Title $pageTitle, File $file, FileProvider $fileProvider ) { - $this->assertEquals( $file, $fileProvider->getForPagePage( $page ) ); + $this->assertEquals( $file, $fileProvider->getFileForPageTitle( $pageTitle ) ); } public function pageFileProvider() { @@ -89,22 +87,22 @@ return [ [ - $this->newPagePage( 'LoremIpsum.djvu/4' ), + Title::makeTitle( $this->getPageNamespaceId(), 'LoremIpsum.djvu/4' ), $this->getFileFromName( 'LoremIpsum.djvu' ), $fileProvider ], [ - $this->newPagePage( 'LoremIpsum.djvu/djvu/1' ), + Title::makeTitle( $this->getPageNamespaceId(), 'LoremIpsum.djvu/djvu/1' ), $this->getFileFromName( 'LoremIpsum.djvu' ), $fileProvider ], [ - $this->newPagePage( 'LoremIpsum.djvu' ), + Title::makeTitle( $this->getPageNamespaceId(), 'LoremIpsum.djvu' ), $this->getFileFromName( 'LoremIpsum.djvu' ), $fileProvider ], [ - $this->newPagePage( 'Test.jpg' ), + Title::makeTitle( $this->getPageNamespaceId(), 'Test.jpg' ), $this->getFileFromName( 'Test.jpg' ), $fileProvider ], @@ -116,9 +114,9 @@ * @dataProvider pageFileNotFoundProvider */ public function testGetForPagePageWithFileNotFound( - ProofreadPagePage $page, FileProvider $fileProvider + Title $pageTitle, FileProvider $fileProvider ) { - $fileProvider->getForPagePage( $page ); + $fileProvider->getFileForPageTitle( $pageTitle ); } public function pageFileNotFoundProvider() { @@ -129,20 +127,20 @@ return [ [ - $this->newPagePage( 'LoremIpsum2.djvu/4' ), + Title::makeTitle( $this->getPageNamespaceId(), 'LoremIpsum2.djvu/4' ), $fileProvider ], [ - $this->newPagePage( 'Test' ), + Title::makeTitle( $this->getPageNamespaceId(), 'Test' ), $fileProvider ], ]; } - public function testGetPageNumberForPagePage() { + public function testGetPageNumberForPageTitle() { $fileProvider = new FileProviderMock( [] ); - $this->assertEquals( 1, $fileProvider->getPageNumberForPagePage( - $this->newPagePage( 'Test.djvu/1' ) + $this->assertEquals( 1, $fileProvider->getPageNumberForPageTitle( + Title::makeTitle( $this->getPageNamespaceId(), 'Test.djvu/1' ) ) ); } @@ -151,7 +149,9 @@ */ public function testGetPageNumberForPageNumberNotFound() { $fileProvider = new FileProviderMock( [] ); - $fileProvider->getPageNumberForPagePage( $this->newPagePage( 'Test.djvu' ) ); + $fileProvider->getPageNumberForPageTitle( + Title::makeTitle( $this->getPageNamespaceId(), 'Test.djvu' ) + ); } /** @@ -159,7 +159,9 @@ */ public function testGetPageNumberForPageNotANumber() { $fileProvider = new FileProviderMock( [] ); - $fileProvider->getPageNumberForPagePage( $this->newPagePage( 'Test.djvu/foo' ) ); + $fileProvider->getPageNumberForPageTitle( + Title::makeTitle( $this->getPageNamespaceId(), 'Test.djvu/foo' ) + ); } /** @@ -167,6 +169,8 @@ */ public function testGetPageNumberForPageBadNumber() { $fileProvider = new FileProviderMock( [] ); - $fileProvider->getPageNumberForPagePage( $this->newPagePage( 'Test.djvu/-1' ) ); + $fileProvider->getPageNumberForPageTitle( + Title::makeTitle( $this->getPageNamespaceId(), 'Test.djvu/-1' ) + ); } } diff --git a/tests/phpunit/Pagination/FilePaginationTest.php b/tests/phpunit/Pagination/FilePaginationTest.php index 8c0a320..f5ce725 100644 --- a/tests/phpunit/Pagination/FilePaginationTest.php +++ b/tests/phpunit/Pagination/FilePaginationTest.php @@ -5,7 +5,6 @@ use InvalidArgumentException; use MediaHandler; use OutOfBoundsException; -use ProofreadPagePage; use ProofreadPageTestCase; use Title; @@ -16,12 +15,11 @@ class FilePaginationTest extends ProofreadPageTestCase { public function testGetPageNumber() { - $index = $this->newIndexPage( 'LoremIpsum.djvu' ); $context = $this->getContext( [ - 'LoremIpsum.djvu/2' => $index + 'LoremIpsum.djvu/2' => Title::makeTitle( $this->getIndexNamespaceId(), 'LoremIpsum.djvu' ) ] ); $pagination = new FilePagination( - $index, + Title::makeTitle( $this->getIndexNamespaceId(), 'LoremIpsum.djvu' ), new PageList( [] ), $context->getFileProvider()->getFileFromTitle( Title::makeTitle( NS_MEDIA, 'LoremIpsum.djvu' ) @@ -29,7 +27,7 @@ $context ); $this->assertEquals( 2, $pagination->getPageNumber( - $this->newPagePage( 'LoremIpsum.djvu/2' ) + Title::makeTitle( $this->getPageNamespaceId(), 'LoremIpsum.djvu/2' ) ) ); } @@ -38,15 +36,15 @@ * @dataProvider getPageNumberWithFailureProvider */ public function testGetPageNumberWithFailure( - Pagination $pagination, ProofreadPagePage $page + Pagination $pagination, Title $pageTitle ) { - $pagination->getPageNumber( $page ); + $pagination->getPageNumber( $pageTitle ); } public function getPageNumberWithFailureProvider() { - $index = $this->newIndexPage( 'LoremIpsum.djvu' ); $pagination = new FilePagination( - $index, new PageList( [] ), + Title::makeTitle( $this->getIndexNamespaceId(), 'LoremIpsum.djvu' ), + new PageList( [] ), $this->getContext()->getFileProvider()->getFileFromTitle( Title::makeTitle( NS_MEDIA, 'LoremIpsum.djvu' ) ), @@ -55,15 +53,15 @@ return [ [ $pagination, - $this->newPagePage( 'Test.djvu/2' ) + Title::makeTitle( $this->getPageNamespaceId(), 'Test.djvu/2' ) ], [ $pagination, - $this->newPagePage( 'Test2.djvu/2' ) + Title::makeTitle( $this->getPageNamespaceId(), 'Test2.djvu/2' ) ], [ $pagination, - $this->newPagePage( '42.jpg' ) + Title::makeTitle( $this->getPageNamespaceId(), '42.jpg' ) ], ]; } @@ -72,10 +70,10 @@ if ( MediaHandler::getHandler( 'image/vnd.djvu' ) === false ) { $this->markTestSkipped( 'There is no support for DjVu files, please enable it.' ); } - $index = $this->newIndexPage( 'LoremIpsum.djvu' ); $pageNumber = new PageNumber( 'TOC' ); $pagination = new FilePagination( - $index, new PageList( [ '1' => 'TOC' ] ), + Title::makeTitle( $this->getIndexNamespaceId(), 'LoremIpsum.djvu' ), + new PageList( [ '1' => 'TOC' ] ), $this->getContext()->getFileProvider()->getFileFromTitle( Title::makeTitle( NS_MEDIA, 'LoremIpsum.djvu' ) ), @@ -88,10 +86,10 @@ if ( MediaHandler::getHandler( 'image/vnd.djvu' ) === false ) { $this->markTestSkipped( 'There is no support for DjVu files, please enable it.' ); } - $index = $this->newIndexPage( 'LoremIpsum.djvu' ); $pageNumber = new PageNumber( 1 ); $pagination = new FilePagination( - $index, new PageList( [] ), + Title::makeTitle( $this->getIndexNamespaceId(), 'LoremIpsum.djvu' ), + new PageList( [] ), $this->getContext()->getFileProvider()->getFileFromTitle( Title::makeTitle( NS_MEDIA, 'LoremIpsum.djvu' ) ), @@ -104,8 +102,7 @@ * @expectedException OutOfBoundsException */ public function testGetDisplayedPageNumberWithFailure() { - $index = $this->newIndexPage(); - $pagination = new PagePagination( $index, [], [] ); + $pagination = new PagePagination( [], [] ); $pagination->getDisplayedPageNumber( 3 ); } @@ -113,9 +110,9 @@ if ( MediaHandler::getHandler( 'image/vnd.djvu' ) === false ) { $this->markTestSkipped( 'There is no support for DjVu files, please enable it.' ); } - $index = $this->newIndexPage( 'LoremIpsum.djvu' ); $pagination = new FilePagination( - $index, new PageList( [] ), + Title::makeTitle( $this->getIndexNamespaceId(), 'LoremIpsum.djvu' ), + new PageList( [] ), $this->getContext()->getFileProvider()->getFileFromTitle( Title::makeTitle( NS_MEDIA, 'LoremIpsum.djvu' ) ), @@ -124,49 +121,49 @@ $this->assertEquals( 5, $pagination->getNumberOfPages() ); } - public function testGetPage() { + public function testGetPageTitle() { if ( MediaHandler::getHandler( 'image/vnd.djvu' ) === false ) { $this->markTestSkipped( 'There is no support for DjVu files, please enable it.' ); } - $index = $this->newIndexPage( 'LoremIpsum.djvu' ); - $page = $this->newPagePage( 'LoremIpsum.djvu/2' ); $pagination = new FilePagination( - $index, new PageList( [] ), + Title::makeTitle( $this->getIndexNamespaceId(), 'LoremIpsum.djvu' ), + new PageList( [] ), $this->getContext()->getFileProvider()->getFileFromTitle( Title::makeTitle( NS_MEDIA, 'LoremIpsum.djvu' ) ), $this->getContext() ); - $this->assertEquals( $page, $pagination->getPage( 2 ) ); + $this->assertEquals( + Title::makeTitle( $this->getPageNamespaceId(), 'LoremIpsum.djvu/2' ), + $pagination->getPageTitle( 2 ) + ); } /** * @expectedException OutOfBoundsException */ - public function testGetPageWithFailure() { + public function testGetPageTitleWithFailure() { if ( MediaHandler::getHandler( 'image/vnd.djvu' ) === false ) { $this->markTestSkipped( 'There is no support for DjVu files, please enable it.' ); } - $index = $this->newIndexPage( 'LoremIpsum.djvu' ); $pagination = new FilePagination( - $index, new PageList( [] ), + Title::makeTitle( $this->getIndexNamespaceId(), 'LoremIpsum.djvu' ), + new PageList( [] ), $this->getContext()->getFileProvider()->getFileFromTitle( Title::makeTitle( NS_MEDIA, 'LoremIpsum.djvu' ) ), $this->getContext() ); - $pagination->getPage( 42 ); + $pagination->getPageTitle( 42 ); } public function testIterator() { if ( MediaHandler::getHandler( 'image/vnd.djvu' ) === false ) { $this->markTestSkipped( 'There is no support for DjVu files, please enable it.' ); } - $index = $this->newIndexPage( 'LoremIpsum.djvu' ); - $page1 = $this->newPagePage( 'LoremIpsum.djvu/1' ); - $page2 = $this->newPagePage( 'LoremIpsum.djvu/2' ); $pagination = new FilePagination( - $index, new PageList( [] ), + Title::makeTitle( $this->getIndexNamespaceId(), 'LoremIpsum.djvu' ), + new PageList( [] ), $this->getContext()->getFileProvider()->getFileFromTitle( Title::makeTitle( NS_MEDIA, 'LoremIpsum.djvu' ) ), @@ -177,9 +174,15 @@ $pagination->next(); $this->assertEquals( 2, $pagination->key() ); $this->assertTrue( $pagination->valid() ); - $this->assertEquals( $page2, $pagination->current() ); + $this->assertEquals( + Title::makeTitle( $this->getPageNamespaceId(), 'LoremIpsum.djvu/2' ), + $pagination->current() + ); $pagination->rewind(); $this->assertEquals( 1, $pagination->key() ); - $this->assertEquals( $page1, $pagination->current() ); + $this->assertEquals( + Title::makeTitle( $this->getPageNamespaceId(), 'LoremIpsum.djvu/1' ), + $pagination->current() + ); } } diff --git a/tests/phpunit/Pagination/PagePaginationTest.php b/tests/phpunit/Pagination/PagePaginationTest.php index ffdbe12..f014353 100644 --- a/tests/phpunit/Pagination/PagePaginationTest.php +++ b/tests/phpunit/Pagination/PagePaginationTest.php @@ -5,6 +5,7 @@ use InvalidArgumentException; use OutOfBoundsException; use ProofreadPageTestCase; +use Title; /** * @group ProofreadPage @@ -13,14 +14,11 @@ class PagePaginationTest extends ProofreadPageTestCase { public function testGetPageNumber() { - $index = $this->newIndexPage(); - $page = $this->newPagePage( 'Test 2.tiff' ); $pagination = new PagePagination( - $index, [ - $this->newPagePage( 'Test 1.jpg' ), - $page, - $this->newPagePage( 'Test:3.png' ) + Title::makeTitle( $this->getPageNamespaceId(), 'Test 1.jpg' ), + Title::makeTitle( $this->getPageNamespaceId(), 'Test 2.tiff' ), + Title::makeTitle( $this->getPageNamespaceId(), 'Test:3.png' ) ], [ new PageNumber( 'TOC' ), @@ -29,7 +27,7 @@ ] ); $this->assertEquals( 2, $pagination->getPageNumber( - $this->newPagePage( 'Test 2.tiff' ) + Title::makeTitle( $this->getPageNamespaceId(), 'Test 2.tiff' ) ) ); } @@ -37,19 +35,16 @@ * @expectedException InvalidArgumentException */ public function testGetPageNumberWithFailure() { - $index = $this->newIndexPage(); - $pagination = new PagePagination( $index, [], [] ); + $pagination = new PagePagination( [], [] ); $pagination->getPageNumber( - $this->newPagePage( 'Test 2.tiff' ) + Title::makeTitle( $this->getPageNamespaceId(), 'Test 2.tiff' ) ); } public function testGetDisplayedPageNumber() { - $index = $this->newIndexPage(); $pageNumber = new PageNumber( 'TOC' ); $pagination = new PagePagination( - $index, - [ $this->newPagePage( 'Test 1.jpg' ) ], + [ Title::makeTitle( $this->getPageNamespaceId(), 'Test 1.jpg' ) ], [ $pageNumber ] ); $this->assertEquals( $pageNumber, $pagination->getDisplayedPageNumber( 1 ) ); @@ -59,19 +54,16 @@ * @expectedException OutOfBoundsException */ public function testGetDisplayedPageNumberWithFailure() { - $index = $this->newIndexPage(); - $pagination = new PagePagination( $index, [], [] ); + $pagination = new PagePagination( [], [] ); $pagination->getDisplayedPageNumber( 3 ); } public function testGetNumberOfPages() { - $index = $this->newIndexPage(); $pagination = new PagePagination( - $index, [ - $this->newPagePage( 'Test 1.jpg' ), - $this->newPagePage( 'Test 2.jpg' ), - $this->newPagePage( 'Test:3.png' ) + Title::makeTitle( $this->getPageNamespaceId(), 'Test 1.jpg' ), + Title::makeTitle( $this->getPageNamespaceId(), 'Test 2.jpg' ), + Title::makeTitle( $this->getPageNamespaceId(), 'Test:3.png' ) ], [ new PageNumber( 'TOC' ), @@ -82,15 +74,12 @@ $this->assertEquals( 3, $pagination->getNumberOfPages() ); } - public function testGetPage() { - $index = $this->newIndexPage(); - $page = $this->newPagePage( 'Test 1.jpg' ); + public function testGetPageTitle() { $pagination = new PagePagination( - $index, [ - $this->newPagePage( 'Test 1.jpg' ), - $this->newPagePage( 'Test 2.tiff' ), - $this->newPagePage( 'Test:3.png' ) + Title::makeTitle( $this->getPageNamespaceId(), 'Test 1.jpg' ), + Title::makeTitle( $this->getPageNamespaceId(), 'Test 2.tiff' ), + Title::makeTitle( $this->getPageNamespaceId(), 'Test:3.png' ) ], [ new PageNumber( 'TOC' ), @@ -98,25 +87,26 @@ new PageNumber( '2' ) ] ); - $this->assertEquals( $page, $pagination->getPage( 1 ) ); + $this->assertEquals( + Title::makeTitle( $this->getPageNamespaceId(), 'Test 1.jpg' ), + $pagination->getPageTitle( 1 ) + ); } /** * @expectedException OutOfBoundsException */ - public function testGetPageWithFailure() { - $index = $this->newIndexPage(); - $pagination = new PagePagination( $index, [], [] ); - $pagination->getPage( 3 ); + public function testGetPageTitleWithFailure() { + $pagination = new PagePagination( [], [] ); + $pagination->getPageTitle( 3 ); } public function testIterator() { - $index = $this->newIndexPage(); - $page1 = $this->newPagePage( 'Test 1.jpg' ); - $page2 = $this->newPagePage( 'Test 2.jpg' ); $pagination = new PagePagination( - $index, - [ $page1, $page2 ], + [ + Title::makeTitle( $this->getPageNamespaceId(), 'Test 1.jpg' ), + Title::makeTitle( $this->getPageNamespaceId(), 'Test 2.jpg' ) + ], [ new PageNumber( '1' ), new PageNumber( '2' ) ] ); @@ -128,6 +118,8 @@ $this->assertFalse( $pagination->valid() ); $pagination->rewind(); $this->assertEquals( 1, $pagination->key() ); - $this->assertEquals( $page1, $pagination->current() ); + $this->assertEquals( + Title::makeTitle( $this->getPageNamespaceId(), 'Test 1.jpg' ), $pagination->current() + ); } } diff --git a/tests/phpunit/Pagination/PaginationFactoryTest.php b/tests/phpunit/Pagination/PaginationFactoryTest.php index 77ff105..3ef26d7 100644 --- a/tests/phpunit/Pagination/PaginationFactoryTest.php +++ b/tests/phpunit/Pagination/PaginationFactoryTest.php @@ -26,7 +26,7 @@ ] ); $pageList = new PageList( [ '1to2' => '-', '3' => '1', '4to5' => 'roman' ] ); $pagination = new FilePagination( - $this->newIndexPage( 'LoremIpsum.djvu' ), + Title::makeTitle( $this->getIndexNamespaceId(), 'LoremIpsum.djvu' ), $pageList, $context->getFileProvider()->getFileFromTitle( Title::makeTitle( NS_MEDIA, 'LoremIpsum.djvu' ) @@ -35,20 +35,19 @@ ); $this->assertEquals( $pagination, - $context->getPaginationFactory()->getPaginationForIndexPage( - $this->newIndexPage( 'LoremIpsum.djvu' ) + $context->getPaginationFactory()->getPaginationForIndexTitle( + Title::makeTitle( $this->getIndexNamespaceId(), 'LoremIpsum.djvu' ) ) ); } public function testGetPaginationWithoutPagelist() { - $index = $this->newIndexPage( 'Test' ); + $indexTitle = Title::makeTitle( $this->getIndexNamespaceId(), 'Test' ); $pagination = new PagePagination( - $index, [ - $this->newPagePage( Title::newFromText( 'Page:Test 1.jpg' ) ), - $this->newPagePage( Title::newFromText( 'Page:Test 2.tiff' ) ), - $this->newPagePage( Title::newFromText( 'Page:Test:3.png' ) ) + Title::newFromText( 'Page:Test 1.jpg' ), + Title::newFromText( 'Page:Test 2.tiff' ), + Title::newFromText( 'Page:Test:3.png' ) ], [ new PageNumber( 'TOC' ), @@ -59,13 +58,13 @@ $this->assertEquals( $pagination, $this->getContext( [], [ - 'Test' => new IndexContent( [ + $indexTitle->getDBkey() => 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 ) + ] )->getPaginationFactory()->getPaginationForIndexTitle( $indexTitle ) ); } } diff --git a/tests/phpunit/ProofreadPageTestCase.php b/tests/phpunit/ProofreadPageTestCase.php index 969720d..a5b71a4 100644 --- a/tests/phpunit/ProofreadPageTestCase.php +++ b/tests/phpunit/ProofreadPageTestCase.php @@ -101,7 +101,7 @@ } /** - * @param ProofreadIndexPage[] $indexForPage + * @param Title[] $indexForPage * @param IndexContent[] $indexContent * @return Context */ @@ -114,30 +114,6 @@ new IndexForPageLookupMock( $indexForPage ), new IndexContentLookupMock( $indexContent ) ); - } - - /** - * Constructor of a new ProofreadPagePage - * @param Title|string $title - * @return ProofreadPagePage - */ - public function newPagePage( $title = 'test.jpg' ) { - if ( is_string( $title ) ) { - $title = Title::makeTitle( $this->getPageNamespaceId(), $title ); - } - return ProofreadPagePage::newFromTitle( $title ); - } - - /** - * Constructor of a new ProofreadIndexPage - * @param Title|string $title - * @return ProofreadIndexPage - */ - protected function newIndexPage( $title = 'test.djvu' ) { - if ( is_string( $title ) ) { - $title = Title::makeTitle( $this->getIndexNamespaceId(), $title ); - } - return new ProofreadIndexPage( $title ); } /** diff --git a/tests/phpunit/index/IndexContentLookupMock.php b/tests/phpunit/index/IndexContentLookupMock.php index 23fc291..0299cd7 100644 --- a/tests/phpunit/index/IndexContentLookupMock.php +++ b/tests/phpunit/index/IndexContentLookupMock.php @@ -2,7 +2,7 @@ namespace ProofreadPage\Index; -use ProofreadIndexPage; +use Title; /** * @licence GNU GPL v2+ @@ -16,13 +16,12 @@ } /** - * Returns content of the page - * @return IndexContent + * @see IndexContentLookup::getIndexContentForTitle */ - public function getIndexContent( ProofreadIndexPage $index ) { - if ( !array_key_exists( $index->getTitle()->getDBkey(), $this->contentForIndex ) ) { + public function getIndexContentForTitle( Title $indexTitle ) { + if ( !array_key_exists( $indexTitle->getDBkey(), $this->contentForIndex ) ) { return null; } - return $this->contentForIndex[ $index->getTitle()->getDBkey() ]; + return $this->contentForIndex[ $indexTitle->getDBkey() ]; } } diff --git a/tests/phpunit/index/ProofreadIndexPageTest.php b/tests/phpunit/index/ProofreadIndexPageTest.php deleted file mode 100644 index ac887c6..0000000 --- a/tests/phpunit/index/ProofreadIndexPageTest.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php - -/** - * @group ProofreadPage - * @covers ProofreadIndexPage - */ -class ProofreadIndexPageTest extends ProofreadPageTestCase { - - public function testEquals() { - $page = $this->newIndexPage( 'Test.djvu' ); - $page2 = $this->newIndexPage( 'Test.djvu' ); - $page3 = $this->newIndexPage( 'Test2.djvu' ); - $this->assertTrue( $page->equals( $page2 ) ); - $this->assertTrue( $page2->equals( $page ) ); - $this->assertFalse( $page->equals( $page3 ) ); - $this->assertFalse( $page3->equals( $page ) ); - } - - public function testGetTitle() { - $title = Title::makeTitle( $this->getIndexNamespaceId(), 'Test.djvu' ); - $page = ProofreadIndexPage::newFromTitle( $title ); - $this->assertEquals( $title, $page->getTitle() ); - } -} diff --git a/tests/phpunit/page/DatabaseIndexForPageLookupTest.php b/tests/phpunit/page/DatabaseIndexForPageLookupTest.php index 1a8656b..5836a0c 100644 --- a/tests/phpunit/page/DatabaseIndexForPageLookupTest.php +++ b/tests/phpunit/page/DatabaseIndexForPageLookupTest.php @@ -4,6 +4,7 @@ use ProofreadPageTestCase; use RepoGroup; +use Title; /** * @group ProofreadPage @@ -21,13 +22,17 @@ $repoGroupMock ); $this->assertEquals( - $this->newIndexPage( 'LoremIpsum.djvu' ), - $lookup->getIndexForPage( $this->newPagePage( 'LoremIpsum.djvu/2' ) ) + Title::makeTitle( $this->getIndexNamespaceId(), 'LoremIpsum.djvu' ), + $lookup->getIndexForPageTitle( + Title::makeTitle( $this->getPageNamespaceId(), 'LoremIpsum.djvu/2' ) + ) ); } public function testGetIndexForPageNotFound() { $lookup = new DatabaseIndexForPageLookup( $this->getIndexNamespaceId(), RepoGroup::singleton() ); - $this->assertNull( $lookup->getIndexForPage( $this->newPagePage( 'FooBar' ) ) ); + $this->assertNull( $lookup->getIndexForPageTitle( + Title::makeTitle( $this->getPageNamespaceId(), 'FooBar' ) + ) ); } } diff --git a/tests/phpunit/page/IndexForPageLookupMock.php b/tests/phpunit/page/IndexForPageLookupMock.php index 8a015eb..52f4241 100644 --- a/tests/phpunit/page/IndexForPageLookupMock.php +++ b/tests/phpunit/page/IndexForPageLookupMock.php @@ -2,7 +2,7 @@ namespace ProofreadPage\Page; -use ProofreadPagePage; +use Title; /** * @licence GNU GPL v2+ @@ -18,12 +18,12 @@ } /** - * @see IndexForPageLookup::getIndexForPage + * @see IndexForPageLookup::getIndexForPageTitle */ - public function getIndexForPage( ProofreadPagePage $page ) { - if ( !array_key_exists( $page->getTitle()->getDBkey(), $this->indexForPage ) ) { + public function getIndexForPageTitle( Title $pageTitle ) { + if ( !array_key_exists( $pageTitle->getDBkey(), $this->indexForPage ) ) { return null; } - return $this->indexForPage[ $page->getTitle()->getDBkey() ]; + return $this->indexForPage[ $pageTitle->getDBkey() ]; } } diff --git a/tests/phpunit/page/PageContentBuilderTest.php b/tests/phpunit/page/PageContentBuilderTest.php index f335951..20b8fb9 100644 --- a/tests/phpunit/page/PageContentBuilderTest.php +++ b/tests/phpunit/page/PageContentBuilderTest.php @@ -4,12 +4,11 @@ use IContextSource; use MediaHandler; -use ProofreadIndexPage; use ProofreadPage\FileNotFoundException; use ProofreadPage\Index\IndexContent; -use ProofreadPagePage; use ProofreadPageTestCase; use RequestContext; +use Title; use User; use WikitextContent; @@ -43,19 +42,23 @@ /** * @dataProvider buildDefaultContentForPageProvider */ - public function testBuildDefaultContentForPage( - ProofreadPagePage $page, ProofreadIndexPage $index = null, + public function testBuildDefaultContentForPageTitle( + $pageTitle, $indexTitle = null, IndexContent $indexContent = null, PageContent $defaultContent ) { - $indexContents = []; - if ( $indexContent !== null ) { - $indexContents[$index->getTitle()->getDBkey()] = $indexContent; + $pageTitle = Title::makeTitle( $this->getPageNamespaceId(), $pageTitle ); + if ( $indexTitle !== null ) { + $indexTitle = Title::makeTitle( $this->getIndexNamespaceId(), $indexTitle ); + $context = $this->getContext( [ + $pageTitle->getDBkey() => $indexTitle + ], [ + $indexTitle->getDBkey() => $indexContent + ] ); + } else { + $context = $this->getContext(); } - $context = $this->getContext( [ - $page->getTitle()->getDBkey() => $index - ], $indexContents ); try { - $image = $context->getFileProvider()->getForPagePage( $page ); + $image = $context->getFileProvider()->getFileForPageTitle( $pageTitle ); } catch ( FileNotFoundException $e ) { $image = false; } @@ -65,15 +68,15 @@ } $contentBuilder = new PageContentBuilder( $this->context, $context ); $this->assertEquals( - $defaultContent, $contentBuilder->buildDefaultContentForPage( $page ) + $defaultContent, $contentBuilder->buildDefaultContentForPageTitle( $pageTitle ) ); } public function buildDefaultContentForPageProvider() { return [ [ - $this->newPagePage( 'Test.djvu/1' ), - $this->newIndexPage( 'Test.djvu' ), + 'Test.djvu/1', + 'Test.djvu', new IndexContent( [ 'Title' => new WikitextContent( 'Test book' ), 'Header' => new WikitextContent( '{{{title}}}' ) @@ -81,14 +84,14 @@ self::newContent( 'Test book', '', '<references />', 1 ), ], [ - $this->newPagePage( 'LoremIpsum.djvu/2' ), + 'LoremIpsum.djvu/2', null, null, self::newContent( '', "Lorem ipsum \n2 \n", '<references/>', 1 ), ], [ - $this->newPagePage( 'LoremIpsum.djvu/2' ), - $this->newIndexPage( 'LoremIpsum.djvu' ), + 'LoremIpsum.djvu/2' , + 'LoremIpsum.djvu' , new IndexContent( [ 'Title' => new WikitextContent( 'Test book' ), 'Pages' => new WikitextContent( '<pagelist/>' ), @@ -97,8 +100,8 @@ self::newContent( '2', "Lorem ipsum \n2 \n", '<references />', 1 ), ], [ - $this->newPagePage( 'LoremIpsum.djvu/2' ), - $this->newIndexPage( 'LoremIpsum.djvu' ), + 'LoremIpsum.djvu/2', + 'LoremIpsum.djvu', new IndexContent( [ 'Title' => new WikitextContent( 'Test book' ), 'Pages' => new WikitextContent( '<pagelist 1to5=roman />' ), diff --git a/tests/phpunit/page/PageDisplayHandlerTest.php b/tests/phpunit/page/PageDisplayHandlerTest.php index 04e4c20..3bd5faf 100644 --- a/tests/phpunit/page/PageDisplayHandlerTest.php +++ b/tests/phpunit/page/PageDisplayHandlerTest.php @@ -4,38 +4,42 @@ use ProofreadPage\Index\IndexContent; use ProofreadPageTestCase; +use Title; use WikitextContent; /** * @group ProofreadPage - * @covers ProofreadPagePage + * @covers PageDisplayHandler */ class PageDisplayHandlerTest extends ProofreadPageTestCase { public function testGetImageWidth() { $handler = new PageDisplayHandler( $this->getContext( [ - 'Test.jpg' => $this->newIndexPage( 'Test' ) + 'Test.jpg' => Title::makeTitle( $this->getIndexNamespaceId(), 'Test' ) ], [ 'Test' => new IndexContent( [ 'width' => new WikitextContent( '500' ) ] ) ] ) ); - $this->assertEquals( 500, $handler->getImageWidth( $this->newPagePage( 'Test.jpg' ) ) ); + $this->assertEquals( + 500, + $handler->getImageWidth( Title::makeTitle( $this->getPageNamespaceId(), 'Test.jpg' ) ) + ); } public function testGetImageWidthWithDefault() { $handler = new PageDisplayHandler( $this->getContext( [ - 'Test.jpg' => $this->newIndexPage( 'Test' ) + 'Test.jpg' => Title::makeTitle( $this->getIndexNamespaceId(), 'Test' ) ], [ 'Test' => new IndexContent( [ 'title' => new WikitextContent( '500' ) ] ) ] ) ); $this->assertEquals( PageDisplayHandler::DEFAULT_IMAGE_WIDTH, - $handler->getImageWidth( $this->newPagePage( 'Test.jpg' ) ) + $handler->getImageWidth( Title::makeTitle( $this->getPageNamespaceId(), 'Test.jpg' ) ) ); } public function testGetCustomCss() { $handler = new PageDisplayHandler( $this->getContext( [ - 'Test.jpg' => $this->newIndexPage( 'Test' ) + 'Test.jpg' => Title::makeTitle( $this->getIndexNamespaceId(), 'Test' ) ], [ 'Test' => new IndexContent( [ 'CSS' => new WikitextContent( 'width:300px;' ) @@ -43,13 +47,13 @@ ] ) ); $this->assertEquals( 'width:300px;', - $handler->getCustomCss( $this->newPagePage( 'Test.jpg' ) ) + $handler->getCustomCss( Title::makeTitle( $this->getPageNamespaceId(), 'Test.jpg' ) ) ); } public function testGetCustomCssWithInsecureInput() { $handler = new PageDisplayHandler( $this->getContext( [ - 'Test.jpg' => $this->newIndexPage( 'Test' ) + 'Test.jpg' => Title::makeTitle( $this->getIndexNamespaceId(), 'Test' ) ], [ 'Test' => new IndexContent( [ 'CSS' => new WikitextContent( 'background: url(\'/my-bad-url.jpg\');' ) @@ -57,13 +61,13 @@ ] ) ); $this->assertEquals( '/* insecure input */', - $handler->getCustomCss( $this->newPagePage( 'Test.jpg' ) ) + $handler->getCustomCss( Title::makeTitle( $this->getPageNamespaceId(), 'Test.jpg' ) ) ); } public function testGetCustomCssWithEscaping() { $handler = new PageDisplayHandler( $this->getContext( [ - 'Test.jpg' => $this->newIndexPage( 'Test' ) + 'Test.jpg' => Title::makeTitle( $this->getIndexNamespaceId(), 'Test' ) ], [ 'Test' => new IndexContent( [ 'CSS' => new WikitextContent( 'width:300px;<style>' ) @@ -71,7 +75,7 @@ ] ) ); $this->assertEquals( 'width:300px;<style>', - $handler->getCustomCss( $this->newPagePage( 'Test.jpg' ) ) + $handler->getCustomCss( Title::makeTitle( $this->getPageNamespaceId(), 'Test.jpg' ) ) ); } } diff --git a/tests/phpunit/page/ProofreadPagePageTest.php b/tests/phpunit/page/ProofreadPagePageTest.php deleted file mode 100644 index 25a38b0..0000000 --- a/tests/phpunit/page/ProofreadPagePageTest.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php - -/** - * @group ProofreadPage - * @covers ProofreadPagePage - */ -class ProofreadPagePageTest extends ProofreadPageTestCase { - - public function testEquals() { - $page = $this->newPagePage( 'Test.djvu' ); - $page2 = $this->newPagePage( 'Test.djvu' ); - $page3 = $this->newPagePage( 'Test2.djvu' ); - $this->assertTrue( $page->equals( $page2 ) ); - $this->assertTrue( $page2->equals( $page ) ); - $this->assertFalse( $page->equals( $page3 ) ); - $this->assertFalse( $page3->equals( $page ) ); - } - - public function testGetTitle() { - $title = Title::makeTitle( $this->getPageNamespaceId(), 'Test.djvu' ); - $page = $this->newPagePage( $title ); - $this->assertEquals( $title, $page->getTitle() ); - } -} -- To view, visit https://gerrit.wikimedia.org/r/392194 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ib77a4a0aae7c92fc38e4f97d9caa55d659768d2d Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/ProofreadPage Gerrit-Branch: master Gerrit-Owner: Tpt <thoma...@hotmail.fr> 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