jenkins-bot has submitted this change and it was merged. Change subject: Move special page code out of Lib ......................................................................
Move special page code out of Lib This moves SpecialWikibaseQueryPage and SpecialWikibasePage out of lib. There was one page in Client using those, which now got the code inlined. After inlining it, further refactoring was done to remove now not needed complexity. Change-Id: I5b3e76af8b29e9da4a392e42f3dc9c2016fbf04f --- M client/includes/specials/SpecialUnconnectedPages.php M repo/includes/specials/SpecialDispatchStats.php M repo/includes/specials/SpecialEntitiesWithoutPage.php M repo/includes/specials/SpecialEntityData.php M repo/includes/specials/SpecialItemByTitle.php M repo/includes/specials/SpecialItemResolver.php M repo/includes/specials/SpecialItemsWithoutSitelinks.php M repo/includes/specials/SpecialListDatatypes.php R repo/includes/specials/SpecialWikibasePage.php R repo/includes/specials/SpecialWikibaseQueryPage.php M repo/includes/specials/SpecialWikibaseRepoPage.php 11 files changed, 156 insertions(+), 88 deletions(-) Approvals: Hoo man: Looks good to me, but someone else must approve WikidataJenkins: Verified Daniel Kinzler: Looks good to me, but someone else must approve Thiemo Mättig (WMDE): Looks good to me, approved jenkins-bot: Verified diff --git a/client/includes/specials/SpecialUnconnectedPages.php b/client/includes/specials/SpecialUnconnectedPages.php index 06e7d05..2b33183 100644 --- a/client/includes/specials/SpecialUnconnectedPages.php +++ b/client/includes/specials/SpecialUnconnectedPages.php @@ -6,9 +6,10 @@ use Html; use Linker; use MWException; +use SpecialPage; use Title; use Wikibase\Client\WikibaseClient; -use Wikibase\Lib\Specials\SpecialWikibaseQueryPage; +use Wikibase\DataModel\Entity\EntityId; use Wikibase\NamespaceChecker; /** @@ -18,12 +19,10 @@ * @licence GNU GPL v2+ * @author John Erling Blad < [email protected] > */ -class SpecialUnconnectedPages extends SpecialWikibaseQueryPage { +class SpecialUnconnectedPages extends SpecialPage { /** * The title as a string to start search at - * - * @since 0.4 * * @var string */ @@ -32,18 +31,12 @@ /** * The startPage as a title to start search at * - * @since 0.4 - * - * @var Title + * @var Title|null */ private $startTitle = null; /** - * The namespaceChecker - * - * @since 0.4 - * - * @var NamespaceChecker + * @var NamespaceChecker|null */ private $namespaceChecker = null; @@ -58,20 +51,47 @@ public function __construct() { parent::__construct( 'UnconnectedPages' ); - } /** - * @see SpecialWikibasePage::execute + * @return string + */ + public function getDescription() { + return $this->msg( 'special-' . strtolower( $this->getName() ) )->text(); + } + + public function setHeaders() { + $out = $this->getOutput(); + $out->setArticleRelated( false ); + $out->setPageTitle( $this->getDescription() ); + } + + /** + * @see SpecialPage::execute * - * @since 0.4 + * @param null|string $subPage */ public function execute( $subPage ) { - if ( !parent::execute( $subPage ) ) { - return false; + $this->setHeaders(); + + $contLang = $this->getContext()->getLanguage(); + $this->outputHeader( $contLang->lc( 'wikibase-' . $this->getName() ) . '-summary' ); + + // If the user is authorized, display the page, if not, show an error. + if ( !$this->userCanExecute( $this->getUser() ) ) { + $this->displayRestrictionError(); } - $output = $this->getOutput(); + $this->setFieldsFromRequestData( $subPage ); + + $this->addFormToOutput(); + + $this->showQuery(); + } + + private function setFieldsFromRequestData( $subPage ) { + $subPage = is_null( $subPage ) ? '' : $subPage; + $request = $this->getRequest(); $this->startPage = $request->getText( 'page', $subPage ); @@ -80,7 +100,9 @@ } $this->iwData = $request->getText( 'iwdata', '' ); + } + private function addFormToOutput() { $out = ''; if ( $this->startPage !== '' && $this->startTitle === null ) { @@ -88,59 +110,127 @@ } $out .= Html::openElement( - 'form', - array( - 'action' => $this->getPageTitle()->getLocalURL(), - 'name' => 'unconnectedpages', - 'id' => 'wbc-unconnectedpages-form' + 'form', + array( + 'action' => $this->getPageTitle()->getLocalURL(), + 'name' => 'unconnectedpages', + 'id' => 'wbc-unconnectedpages-form' + ) ) - ) - . Html::openElement( 'fieldset' ) - . Html::element( 'legend', array(), $this->msg( 'wikibase-unconnectedpages-legend' )->text() ) - . Html::openElement( 'p' ) - . Html::element( 'label', array( 'for' => 'language' ), $this->msg( 'wikibase-unconnectedpages-page' )->text() ) - . ' ' - . Html::input( - 'page', - $this->startPage, - 'text', - array( - 'id' => 'page' + . Html::openElement( 'fieldset' ) + . Html::element( 'legend', array(), $this->msg( 'wikibase-unconnectedpages-legend' )->text() ) + . Html::openElement( 'p' ) + . Html::element( 'label', array( 'for' => 'language' ), $this->msg( 'wikibase-unconnectedpages-page' )->text() ) + . ' ' + . Html::input( + 'page', + $this->startPage, + 'text', + array( + 'id' => 'page' + ) ) - ) - . Html::input( - 'submit', - $this->msg( 'wikibase-unconnectedpages-submit' )->text(), - 'submit', - array( - 'id' => 'wbc-unconnectedpages-submit', - 'class' => 'wbc-input-button' + . Html::input( + 'submit', + $this->msg( 'wikibase-unconnectedpages-submit' )->text(), + 'submit', + array( + 'id' => 'wbc-unconnectedpages-submit', + 'class' => 'wbc-input-button' + ) ) - ) - . ' ' - . Html::input( - 'iwdata', - 'only', - 'checkbox', - array( - 'id' => 'wbc-unconnectedpages-iwdata', - 'class' => 'wbc-input-button', - $this->iwData === 'only' ? 'checked' : 'unchecked' => '' + . ' ' + . Html::input( + 'iwdata', + 'only', + 'checkbox', + array( + 'id' => 'wbc-unconnectedpages-iwdata', + 'class' => 'wbc-input-button', + $this->iwData === 'only' ? 'checked' : 'unchecked' => '' + ) ) - ) - . ' ' - . Html::element( 'label', array( 'for' => 'wbc-unconnectedpages-iwdata' ), $this->msg( 'wikibase-unconnectedpages-iwdata-label' )->text() ) - . Html::closeElement( 'p' ) - . Html::closeElement( 'fieldset' ) - . Html::closeElement( 'form' ); - $output->addHTML( $out ); + . ' ' + . Html::element( 'label', array( 'for' => 'wbc-unconnectedpages-iwdata' ), $this->msg( 'wikibase-unconnectedpages-iwdata-label' )->text() ) + . Html::closeElement( 'p' ) + . Html::closeElement( 'fieldset' ) + . Html::closeElement( 'form' ); + $this->getOutput()->addHTML( $out ); + } + + private function showQuery() { $query = array(); if ( $this->iwData === 'only' ) { $query['iwdata'] = $this->iwData; } - $this->showQuery( $query ); + $paging = false; + $out = $this->getOutput(); + + list( $limit, $offset ) = $this->getRequest()->getLimitOffset(); + + $result = $this->getResult( $offset, $limit + 1 ); + + $numRows = count( $result ); + + $out->addHTML( Html::openElement( 'div', array( 'class' => 'mw-spcontent' ) ) ); + + if ( $numRows > 0 ) { + $out->addHTML( $this->msg( 'showingresults' )->numParams( + // do not format the one extra row, if exist + min( $numRows, $limit ), + $offset + 1 )->parseAsBlock() ); + // Disable the "next" link when we reach the end + $paging = $this->getLanguage()->viewPrevNext( + $this->getPageTitle( $this->startPage ), + $offset, + $limit, + $query, + $numRows <= $limit + ); + $out->addHTML( Html::rawElement( 'p', array(), $paging ) ); + } else { + // No results to show, so don't bother with "showing X of Y" etc. + // -- just let the user know and give up now + $out->addWikiMsg( 'specialpage-empty' ); + $out->addHTML( Html::closeElement( 'div' ) ); + } + + $this->outputResults( + $result, + // do not format the one extra row, if it exist + min( $numRows, $limit ), + $offset + ); + + if( $paging ) { + $out->addHTML( Html::rawElement( 'p', array(), $paging ) ); + } + + $out->addHTML( Html::closeElement( 'div' ) ); + } + + /** + * Format and output report results using the given information plus OutputPage + * + * @param EntityId[] $results + * @param integer $num number of available result rows + * @param integer $offset paging offset + */ + private function outputResults( array $results, $num, $offset ) { + if ( $num > 0 ) { + $html = Html::openElement( 'ol', array( 'start' => $offset + 1, 'class' => 'special' ) ); + for ( $i = 0; $i < $num; $i++ ) { + $line = $this->formatRow( $results[$i] ); + if ( $line ) { + $html .= Html::rawElement( 'li', array(), $line ); + } + } + $html .= Html::closeElement( 'ol' ); + + $this->getOutput()->addHTML( $html ); + } } /** @@ -159,7 +249,7 @@ * * @since 0.4 * - * @return \Wikibase\NamespaceChecker + * @return NamespaceChecker */ public function getNamespaceChecker() { $settings = WikibaseClient::getDefaultInstance()->getSettings(); @@ -204,7 +294,6 @@ * @since 0.4 */ public function getResult( $offset = 0, $limit = 0 ) { - $dbr = wfGetDB( DB_SLAVE ); $conds = $this->buildConditionals( $dbr ); @@ -252,12 +341,7 @@ return $entries; } - /** - * @see SpecialWikibaseQueryPage::formatRow - * - * @since 0.4 - */ - protected function formatRow( $entry ) { + private function formatRow( $entry ) { try { $out = Linker::linkKnown( $entry['title'] ); if ( $entry['num'] > 0 ) { @@ -269,15 +353,6 @@ wfWarn( "Error formatting result row: " . $e->getMessage() ); return false; } - } - - /** - * @see SpecialWikibaseQueryPage::getTitleForNavigation - * - * @since 0.4 - */ - protected function getTitleForNavigation() { - return $this->getPageTitle( $this->startPage ); } } diff --git a/repo/includes/specials/SpecialDispatchStats.php b/repo/includes/specials/SpecialDispatchStats.php index e11222a..bf2c923 100644 --- a/repo/includes/specials/SpecialDispatchStats.php +++ b/repo/includes/specials/SpecialDispatchStats.php @@ -3,7 +3,6 @@ namespace Wikibase\Repo\Specials; use Html; -use Wikibase\Lib\Specials\SpecialWikibasePage; /** * Page for displaying diagnostics about the dispatch process. diff --git a/repo/includes/specials/SpecialEntitiesWithoutPage.php b/repo/includes/specials/SpecialEntitiesWithoutPage.php index be0b1c6..57cc960 100644 --- a/repo/includes/specials/SpecialEntitiesWithoutPage.php +++ b/repo/includes/specials/SpecialEntitiesWithoutPage.php @@ -4,7 +4,6 @@ use Html; use Wikibase\EntityFactory; -use Wikibase\Lib\Specials\SpecialWikibaseQueryPage; use Wikibase\Repo\WikibaseRepo; use Wikibase\Utils; use XmlSelect; diff --git a/repo/includes/specials/SpecialEntityData.php b/repo/includes/specials/SpecialEntityData.php index 37fc6f0..b4f4876 100644 --- a/repo/includes/specials/SpecialEntityData.php +++ b/repo/includes/specials/SpecialEntityData.php @@ -6,7 +6,6 @@ use Wikibase\EntityFactory; use Wikibase\Lib\Serializers\SerializationOptions; use Wikibase\Lib\Serializers\SerializerFactory; -use Wikibase\Lib\Specials\SpecialWikibasePage; use Wikibase\Repo\LinkedData\EntityDataRequestHandler; use Wikibase\Repo\LinkedData\EntityDataSerializationService; use Wikibase\Repo\LinkedData\EntityDataUriManager; diff --git a/repo/includes/specials/SpecialItemByTitle.php b/repo/includes/specials/SpecialItemByTitle.php index 2832633..c6b3f97 100644 --- a/repo/includes/specials/SpecialItemByTitle.php +++ b/repo/includes/specials/SpecialItemByTitle.php @@ -1,6 +1,7 @@ <?php namespace Wikibase\Repo\Specials; + use Html; use Site; use SiteStore; diff --git a/repo/includes/specials/SpecialItemResolver.php b/repo/includes/specials/SpecialItemResolver.php index 393d56c..f6f1af2 100644 --- a/repo/includes/specials/SpecialItemResolver.php +++ b/repo/includes/specials/SpecialItemResolver.php @@ -2,8 +2,6 @@ namespace Wikibase\Repo\Specials; -use Wikibase\Lib\Specials\SpecialWikibasePage; - /** * Base for special pages that resolve certain arguments to an item. * diff --git a/repo/includes/specials/SpecialItemsWithoutSitelinks.php b/repo/includes/specials/SpecialItemsWithoutSitelinks.php index 13cb4c5..283022a 100644 --- a/repo/includes/specials/SpecialItemsWithoutSitelinks.php +++ b/repo/includes/specials/SpecialItemsWithoutSitelinks.php @@ -2,7 +2,6 @@ namespace Wikibase\Repo\Specials; -use Wikibase\Lib\Specials\SpecialWikibaseQueryPage; use Wikibase\Repo\WikibaseRepo; /** diff --git a/repo/includes/specials/SpecialListDatatypes.php b/repo/includes/specials/SpecialListDatatypes.php index 23f4393..2440311 100644 --- a/repo/includes/specials/SpecialListDatatypes.php +++ b/repo/includes/specials/SpecialListDatatypes.php @@ -3,7 +3,6 @@ namespace Wikibase\Repo\Specials; use Html; -use Wikibase\Lib\Specials\SpecialWikibasePage; use Wikibase\Repo\WikibaseRepo; /** diff --git a/lib/includes/specials/SpecialWikibasePage.php b/repo/includes/specials/SpecialWikibasePage.php similarity index 98% rename from lib/includes/specials/SpecialWikibasePage.php rename to repo/includes/specials/SpecialWikibasePage.php index b1c1760..5d28e8c 100644 --- a/lib/includes/specials/SpecialWikibasePage.php +++ b/repo/includes/specials/SpecialWikibasePage.php @@ -1,6 +1,6 @@ <?php -namespace Wikibase\Lib\Specials; +namespace Wikibase\Repo\Specials; use Html; use SpecialPage; diff --git a/lib/includes/specials/SpecialWikibaseQueryPage.php b/repo/includes/specials/SpecialWikibaseQueryPage.php similarity index 98% rename from lib/includes/specials/SpecialWikibaseQueryPage.php rename to repo/includes/specials/SpecialWikibaseQueryPage.php index 8a1fbf8..06d04de 100644 --- a/lib/includes/specials/SpecialWikibaseQueryPage.php +++ b/repo/includes/specials/SpecialWikibaseQueryPage.php @@ -1,6 +1,6 @@ <?php -namespace Wikibase\Lib\Specials; +namespace Wikibase\Repo\Specials; use Html; use Linker; diff --git a/repo/includes/specials/SpecialWikibaseRepoPage.php b/repo/includes/specials/SpecialWikibaseRepoPage.php index 4fdd089..3e6b122 100644 --- a/repo/includes/specials/SpecialWikibaseRepoPage.php +++ b/repo/includes/specials/SpecialWikibaseRepoPage.php @@ -16,7 +16,6 @@ use Wikibase\EntityRevision; use Wikibase\Lib\Store\EntityRevisionLookup; use Wikibase\EntityTitleLookup; -use Wikibase\Lib\Specials\SpecialWikibasePage; use Wikibase\Repo\WikibaseRepo; use Wikibase\Lib\Store\EntityStore; use Wikibase\Summary; -- To view, visit https://gerrit.wikimedia.org/r/136834 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I5b3e76af8b29e9da4a392e42f3dc9c2016fbf04f Gerrit-PatchSet: 8 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Jeroen De Dauw <[email protected]> Gerrit-Reviewer: Addshore <[email protected]> Gerrit-Reviewer: Adrian Lang <[email protected]> Gerrit-Reviewer: Aude <[email protected]> Gerrit-Reviewer: Daniel Kinzler <[email protected]> Gerrit-Reviewer: Hoo man <[email protected]> Gerrit-Reviewer: Jeroen De Dauw <[email protected]> Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]> Gerrit-Reviewer: Tobias Gritschacher <[email protected]> Gerrit-Reviewer: WikidataJenkins <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
