Aude has uploaded a new change for review. https://gerrit.wikimedia.org/r/90272
Change subject: Cleanup namespaces and code style issues in content classes ...................................................................... Cleanup namespaces and code style issues in content classes Change-Id: Id20201c4e5c4edb08dc8038668365dad343fafa3 --- M repo/includes/content/EntityContent.php M repo/includes/content/EntityHandler.php M repo/includes/content/ItemContent.php M repo/includes/content/ItemHandler.php M repo/includes/content/PropertyContent.php M repo/includes/content/PropertyHandler.php 6 files changed, 110 insertions(+), 135 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/72/90272/1 diff --git a/repo/includes/content/EntityContent.php b/repo/includes/content/EntityContent.php index bf2c395..32daffa 100644 --- a/repo/includes/content/EntityContent.php +++ b/repo/includes/content/EntityContent.php @@ -2,14 +2,21 @@ namespace Wikibase; +use AbstractContent; +use Content; +use MWException; +use ParserOptions; use ParserOutput; +use Status; +use Title; +use User; use ValueFormatters\FormatterOptions; -use ValueFormatters\Test\FormatterOptionsTest; +//use ValueFormatters\Test\FormatterOptionsTest; use ValueFormatters\ValueFormatter; +use ValueFormatters\ValueFormatterFactory; use Wikibase\Lib\SnakFormatter; -use WikiPage, Title, User, Status, ParserOptions; -use \ValueFormatters\ValueFormatterFactory; use Wikibase\Repo\WikibaseRepo; +use WikiPage; /** * Abstract content object for articles representing Wikibase entities. @@ -19,7 +26,7 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < [email protected] > */ -abstract class EntityContent extends \AbstractContent { +abstract class EntityContent extends AbstractContent { /** * @since 0.1 @@ -110,7 +117,7 @@ * * @return Entity */ - public abstract function getEntity(); + abstract public function getEntity(); /** * Returns a ParserOutput object containing the HTML. @@ -124,7 +131,9 @@ * * @return ParserOutput */ - public function getParserOutput( Title $title, $revId = null, ParserOptions $options = null, $generateHtml = true ) { + public function getParserOutput( Title $title, $revId = null, ParserOptions $options = null, + $generateHtml = true + ) { $formatterOptions = new FormatterOptions(); //TODO: Language Fallback, etc if ( $options !== null ) { @@ -254,7 +263,7 @@ * * @return int */ - public function getSize() { + public function getSize() { return strlen( serialize( $this->getNativeData() ) ); } @@ -265,7 +274,7 @@ * * @see Content::equals */ - public function equals( \Content $that = null ) { + public function equals( Content $that = null ) { if ( is_null( $that ) ) { return false; } @@ -311,7 +320,7 @@ * * @return boolean */ - public function isEmpty() { + public function isEmpty() { return $this->getEntity()->isEmpty(); } @@ -361,7 +370,7 @@ * * @return bool whether the user is allowed to edit this item. */ - public function userCanEdit( \User $user = null, $doExpensiveQueries = true ) { + public function userCanEdit( User $user = null, $doExpensiveQueries = true ) { return $this->userCan( 'edit', $user, $doExpensiveQueries ); } @@ -427,7 +436,7 @@ */ public function grabFreshId() { if ( !$this->isNew() ) { - throw new \MWException( "This entity already has an ID!" ); + throw new MWException( "This entity already has an ID!" ); } wfProfileIn( __METHOD__ ); @@ -484,7 +493,7 @@ if ( ( $flags & EDIT_NEW ) == EDIT_NEW ) { if ( $this->isNew() ) { $this->grabFreshId(); - } else if ( $this->getTitle()->exists() ) { + } elseif ( $this->getTitle()->exists() ) { wfProfileOut( __METHOD__ ); return Status::newFatal( 'edit-already-exists' ); } @@ -557,11 +566,13 @@ return $status; } - // If editEntity is set, check whether the current revision is still what the EditEntity though it was. + // If editEntity is set, check whether the current revision is still what + // the EditEntity thought it was. // If it isn't, then someone managed to squeeze in an edit after we checked for conflicts. if ( $this->editEntity !== null && $page->getRevision() !== null ) { - if ( $page->getRevision()->getId() !== $this->editEntity->getCurrentRevisionId() ) { - wfDebugLog( __CLASS__, __FUNCTION__ . ': encountered late edit conflict: current revision changed after regular conflict check.' ); + if ( $page->getRevision()->getId() !== $this->editEntity->getCurrentRevisionId() ) { + wfDebugLog( __CLASS__, __FUNCTION__ . ': encountered late edit conflict: ' + . 'current revision changed after regular conflict check.' ); $status->fatal('edit-conflict'); } } @@ -576,9 +587,9 @@ * * @since 0.1 * - * @param \Status $status + * @param Status $status */ - protected final function addLabelUniquenessConflicts( Status $status ) { + final protected function addLabelUniquenessConflicts( Status $status ) { $labels = array(); $entity = $this->getEntity(); diff --git a/repo/includes/content/EntityHandler.php b/repo/includes/content/EntityHandler.php index 23d7155..9c25746 100644 --- a/repo/includes/content/EntityHandler.php +++ b/repo/includes/content/EntityHandler.php @@ -1,38 +1,26 @@ <?php namespace Wikibase; -use MWException, WikiPage, Title, Content; + +use Content; +use ContentHandler; +use MWContentSerializationException; +use MWException; use Revision; +use Title; +use WikiPage; /** * Base handler class for Wikibase\Entity content classes. * TODO: interface for enforcing singleton * - * 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 - * * @since 0.1 - * - * @file - * @ingroup WikibaseRepo * * @licence GNU GPL v2+ * @author Daniel Kinzler * @author Jeroen De Dauw < [email protected] > */ -abstract class EntityHandler extends \ContentHandler { +abstract class EntityHandler extends ContentHandler { /** * Returns the name of the EntityContent deriving class. @@ -41,7 +29,7 @@ * * @return string */ - protected abstract function getContentClass(); + abstract protected function getContentClass(); public function __construct( $modelId ) { $formats = array( @@ -94,7 +82,7 @@ * @throws MWException * @return string */ - public function serializeContent( \Content $content, $format = null ) { + public function serializeContent( Content $content, $format = null ) { if ( is_null( $format ) ) { $format = $this->getDefaultFormat(); @@ -111,7 +99,8 @@ $blob = json_encode( $data ); break; default: - throw new MWException( "serialization format $format is not supported for Wikibase content model" ); + throw new MWException( "serialization format $format is not supported for " + . "Wikibase content model" ); } return $blob; @@ -138,12 +127,13 @@ $data = json_decode( $blob, true ); //FIXME: suppress notice on failed serialization! break; default: - throw new MWException( "serialization format $format is not supported for Wikibase content model" ); + throw new MWException( "serialization format $format is not supported " + . "for Wikibase content model" ); break; } if ( $data === false || $data === null ) { - throw new \MWContentSerializationException( 'failed to deserialize' ); + throw new MWContentSerializationException( 'failed to deserialize' ); } return $data; @@ -170,8 +160,8 @@ * @return bool true if $title represents a page in the appropriate entity namespace. */ public function canBeUsedOn( Title $title ) { - $ns = $this->getEntityNamespace(); - return $ns === $title->getNamespace(); + $namespace = $this->getEntityNamespace(); + return $namespace === $title->getNamespace(); } /** @@ -231,8 +221,10 @@ } /** - * Returns the name of the special page responsible for creating a page for this type of entity content. + * Returns the name of the special page responsible for creating a page + * for this type of entity content. * Returns null if there is no such special page. + * * @since 0.2 * * @return string|null @@ -266,7 +258,9 @@ * * @return Content|bool Content on success, false on failure */ - public function getUndoContent( Revision $latestRevision, Revision $newerRevision, Revision $olderRevision ) { + public function getUndoContent( Revision $latestRevision, Revision $newerRevision, + Revision $olderRevision + ) { /** * @var EntityContent $latestContent * @var EntityContent $olderContent @@ -305,5 +299,5 @@ * * @return string */ - public abstract function getEntityType(); + abstract public function getEntityType(); } diff --git a/repo/includes/content/ItemContent.php b/repo/includes/content/ItemContent.php index 5a566f0..80fa085 100644 --- a/repo/includes/content/ItemContent.php +++ b/repo/includes/content/ItemContent.php @@ -1,32 +1,25 @@ <?php namespace Wikibase; -use Title, WikiPage, User, MWException, Content, Status, ParserOptions, ParserOutput, DataUpdate; + +use Content; +use DatabaseBase; +use DataUpdate; +use Message; +use MWException; +use ParserOptions; +use ParserOutput; +use SiteSQLStore; +use Status; +use Title; +use User; use Wikibase\Repo\WikibaseRepo; +use WikiPage; /** * Content object for articles representing Wikibase items. * - * 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 - * * @since 0.1 - * - * @file - * @ingroup WikibaseRepo - * @ingroup Content * * @licence GNU GPL v2+ * @author Jeroen De Dauw < [email protected] > @@ -40,9 +33,11 @@ protected $item; /** - * Constructor. - * Do not use to construct new stuff from outside of this class, use the static newFoobar methods. - * In other words: treat as protected (which it was, but now cannot be since we derive from Content). + * Do not use to construct new stuff from outside of this class, + * use the static newFoobar methods. + * + * In other words: treat as protected (which it was, but now cannot + * be since we derive from Content). * * @since 0.1 * @@ -142,10 +137,11 @@ * also be used for saving. This will preserve transactional integrity * and avoid race conditions. */ - protected function addSiteLinkConflicts( Status $status, \DatabaseBase $db = null ) { + protected function addSiteLinkConflicts( Status $status, DatabaseBase $db = null ) { wfProfileIn( __METHOD__ ); - $conflicts = StoreFactory::getStore()->newSiteLinkCache()->getConflictsForItem( $this->getItem(), $db ); + $siteLinkCache = StoreFactory::getStore()->newSiteLinkCache(); + $conflicts = $siteLinkCache->getConflictsForItem( $this->getItem(), $db ); foreach ( $conflicts as $conflict ) { $msg = $this->getConflictMessage( $conflict ); @@ -168,20 +164,22 @@ protected function getConflictMessage( array $conflict ) { $id = new EntityId( Item::ENTITY_TYPE, $conflict['itemId'] ); + $entityContentFactory = WikibaseRepo::getDefaultInstance()->getEntityContentFactory(); + /** * @var WikiPage $ipsPage */ - $conflictingPage = WikibaseRepo::getDefaultInstance()->getEntityContentFactory()->getWikiPageForId( $id ); + $conflictingPage = $entityContentFactory->getWikiPageForId( $id ); - $siteSqlStore = \SiteSQLStore::newInstance(); + $siteSqlStore = SiteSQLStore::newInstance(); $site = $siteSqlStore->getSite( $conflict['siteId'] ); $pageUrl = $site->getPageUrl( $conflict['sitePage'] ); // $pageUrl shouldn't be a raw param (it's causing the link not to be parsed) - return new \Message( + return new Message( 'wikibase-error-sitelink-already-used', array( - $pageUrl, + $pageUrl, $conflict['sitePage'], $conflictingPage->getTitle()->getFullText(), $conflict['siteId'], @@ -207,8 +205,11 @@ * * @return int: One of WikiPage::DELETE_* constants */ - public function delete( $reason = '', $suppress = false, $id = 0, $commit = true, &$error = '', User $user = null ) { - return $this->getWikiPage()->doDeleteArticleReal( $reason, $suppress, $id, $commit, $error, $user ); + public function delete( $reason = '', $suppress = false, $id = 0, $commit = true, + &$error = '', User $user = null + ) { + return $this->getWikiPage()->doDeleteArticleReal( $reason, $suppress, $id, $commit, + $error, $user ); } /** @@ -243,7 +244,7 @@ * * @return DataUpdate[] */ - public function getDeletionUpdates( \WikiPage $page, \ParserOutput $parserOutput = null ) { + public function getDeletionUpdates( WikiPage $page, ParserOutput $parserOutput = null ) { return array_merge( parent::getDeletionUpdates( $page, $parserOutput ), array( new ItemDeletionUpdate( $this ) ) diff --git a/repo/includes/content/ItemHandler.php b/repo/includes/content/ItemHandler.php index 4530ca0..55d49b5 100644 --- a/repo/includes/content/ItemHandler.php +++ b/repo/includes/content/ItemHandler.php @@ -2,8 +2,11 @@ namespace Wikibase; -use User, Title, WikiPage, RequestContext; +use RequestContext; +use Title; +use User; use Wikibase\Repo\WikibaseRepo; +use WikiPage; /** * Content handler for Wikibase items. @@ -65,7 +68,8 @@ } /** - * Get the item corresponding to the provided site and title pair, or null if there is no such item. + * Get the item corresponding to the provided site and title pair, + * or null if there is no such item. * * @since 0.1 * diff --git a/repo/includes/content/PropertyContent.php b/repo/includes/content/PropertyContent.php index 7f6f947..37ba15b 100644 --- a/repo/includes/content/PropertyContent.php +++ b/repo/includes/content/PropertyContent.php @@ -1,33 +1,22 @@ <?php namespace Wikibase; -use Title, Content, ParserOptions, ParserOutput, WikiPage, User, Status, DataUpdate; -use \ValueFormatters\ValueFormatterFactory; + +use Content; +use DataUpdate; +use ParserOptions; +use ParserOutput; +use Status; +use Title; +use User; +use ValueFormatters\ValueFormatterFactory; use Wikibase\Repo\WikibaseRepo; +use WikiPage; /** * Content object for articles representing Wikibase properties. * - * 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 - * * @since 0.1 - * - * @file - * @ingroup WikibaseRepo - * @ingroup Content * * @licence GNU GPL v2+ * @author Jeroen De Dauw < [email protected] > @@ -41,9 +30,12 @@ protected $property; /** - * Constructor. - * Do not use to construct new stuff from outside of this class, use the static newFoobar methods. - * In other words: treat as protected (which it was, but now cannot be since we derive from Content). + * Do not use to construct new stuff from outside of this class, + * use the static newFoobar methods. + * + * In other words: treat as protected (which it was, but now + * cannot be since we derive from Content). + * * @protected * * @since 0.1 diff --git a/repo/includes/content/PropertyHandler.php b/repo/includes/content/PropertyHandler.php index e7875cd..ba53247 100644 --- a/repo/includes/content/PropertyHandler.php +++ b/repo/includes/content/PropertyHandler.php @@ -1,30 +1,14 @@ <?php namespace Wikibase; -use Title, ParserOutput; + +use ParserOutput; +use Title; /** * Content handler for Wikibase items. * - * 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 - * * @since 0.1 - * - * @file - * @ingroup WikibaseRepo * * @licence GNU GPL v2+ * @author Jeroen De Dauw < [email protected] > @@ -83,17 +67,6 @@ $entity = EntityFactory::singleton()->newFromBlob( Property::ENTITY_TYPE, $blob, $format ); return PropertyContent::newFromProperty( $entity ); } - - /** - * @see ContentHandler::getDiffEngineClass - * - * @since 0.1 - * - * @return string - */ -// protected function getDiffEngineClass() { -// return '\Wikibase\PropertyDiffView'; -// } /** * @see EntityHandler::getSpecialPageForCreation -- To view, visit https://gerrit.wikimedia.org/r/90272 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id20201c4e5c4edb08dc8038668365dad343fafa3 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Aude <[email protected]> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
