jenkins-bot has submitted this change and it was merged. Change subject: Hygiene: Split reference classes for one class per file ......................................................................
Hygiene: Split reference classes for one class per file Change-Id: Ia96eb500e7e0036829a14a2d07a0f8c2acdee5c4 --- M autoload.php M includes/Model/Reference.php A includes/Model/URLReference.php A includes/Model/WikiReference.php 4 files changed, 170 insertions(+), 158 deletions(-) Approvals: Matthias Mullie: Looks good to me, approved jenkins-bot: Verified diff --git a/autoload.php b/autoload.php index 1a1b3e2..be2d1e8 100644 --- a/autoload.php +++ b/autoload.php @@ -224,10 +224,10 @@ 'Flow\\Model\\PostSummary' => __DIR__ . '/includes/Model/PostSummary.php', 'Flow\\Model\\Reference' => __DIR__ . '/includes/Model/Reference.php', 'Flow\\Model\\TopicListEntry' => __DIR__ . '/includes/Model/TopicListEntry.php', - 'Flow\\Model\\URLReference' => __DIR__ . '/includes/Model/Reference.php', + 'Flow\\Model\\URLReference' => __DIR__ . '/includes/Model/URLReference.php', 'Flow\\Model\\UUID' => __DIR__ . '/includes/Model/UUID.php', 'Flow\\Model\\UserTuple' => __DIR__ . '/includes/Model/UserTuple.php', - 'Flow\\Model\\WikiReference' => __DIR__ . '/includes/Model/Reference.php', + 'Flow\\Model\\WikiReference' => __DIR__ . '/includes/Model/WikiReference.php', 'Flow\\Model\\Workflow' => __DIR__ . '/includes/Model/Workflow.php', 'Flow\\NewTopicFormatter' => __DIR__ . '/includes/Notifications/Formatter.php', 'Flow\\NotificationController' => __DIR__ . '/includes/Notifications/Controller.php', diff --git a/includes/Model/Reference.php b/includes/Model/Reference.php index d45eee6..45b84b1 100644 --- a/includes/Model/Reference.php +++ b/includes/Model/Reference.php @@ -135,159 +135,3 @@ $this->getIdentifier(); } } - -class WikiReference extends Reference { - const TYPE_FILE = 'file'; - const TYPE_TEMPLATE = 'template'; - - protected $target; - - /** - * @param UUID $srcWorkflow ID of the source Workflow - * @param Title $srcTitle Title of the reference's target. - * @param string $objectType Output of getRevisionType for the AbstractRevision that this reference comes from. - * @param UUID $objectId Unique identifier for the revisioned object containing the reference. - * @param string $type Type of reference - * @param Title $targetTitle Title of the reference's target. - */ - public function __construct( UUID $srcWorkflow, Title $srcTitle, $objectType, UUID $objectId, $type, Title $targetTitle ) { - $this->target = $targetTitle; - - $this->validTypes = array_merge( $this->validTypes, - array( - self::TYPE_FILE, - self::TYPE_TEMPLATE, - ) - ); - - parent::__construct( $srcWorkflow, $srcTitle, $objectType, $objectId, $type ); - } - - /** - * Gets the storage row for this WikiReference - * - * @return array - */ - public function getStorageRow() { - return parent::getStorageRow() + array( - 'ref_target_namespace' => $this->target->getNamespace(), - 'ref_target_title' => $this->target->getDBkey(), - ); - } - - /** - * Instantiates a WikiReference object from a storage row. - * - * @param \StdClass $row - * @return WikiReference - */ - public static function fromStorageRow( $row ) { - $workflow = UUID::create( $row['ref_src_workflow_id'] ); - $objectType = $row['ref_src_object_type']; - $objectId = UUID::create( $row['ref_src_object_id'] ); - $srcTitle = self::makeTitle( $row['ref_src_namespace'], $row['ref_src_title'] ); - $targetTitle = self::makeTitle( $row['ref_target_namespace'], $row['ref_target_title'] ); - $type = $row['ref_type']; - - return new WikiReference( $workflow, $srcTitle, $objectType, $objectId, $type, $targetTitle ); - } - - /** - * Gets the storage row from an object. - * Helper for BasicObjectMapper. - */ - public static function toStorageRow( WikiReference $object ) { - return $object->getStorageRow(); - } - - /** - * Many loaded references typically point to the same Title, cache those instead - * of generating a bunch of duplicate title classes. - */ - public static function makeTitle( $namespace, $title ) { - try { - return Workflow::getFromTitleCache( wfWikiId(), $namespace, $title ); - } catch ( InvalidInputException $e ) { - // duplicate Title::makeTitleSafe which returns null on failure, - // but only for InvalidInputException - return null; - } - } - - public function getTitle() { - return $this->target; - } - - public function getTargetIdentifier() { - return 'title:' . $this->getTitle()->getPrefixedDBKey(); - } -} - -class URLReference extends Reference { - protected $url; - - /** - * @param UUID $srcWorkflow ID of the source Workflow - * @param Title $srcTitle Title of the page that the Workflow exists on - * @param String $objectType Output of getRevisionType for the AbstractRevision that this reference comes from. - * @param UUID $objectId Unique identifier for the revisioned object containing the reference. - * @param string $type Type of reference - * @param string $url URL of the reference's target. - * @throws InvalidInputException - */ - public function __construct( UUID $srcWorkflow, Title $srcTitle, $objectType, UUID $objectId, $type, $url ) { - $this->url = $url; - - if ( !is_array( wfParseUrl( $url ) ) ) { - throw new InvalidInputException( - "Invalid URL $url specified for reference " . get_class( $this ) - ); - } - - parent::__construct( $srcWorkflow, $srcTitle, $objectType, $objectId, $type ); - } - - /** - * Gets the storage row for this URLReference - * - * @return array - */ - public function getStorageRow() { - return parent::getStorageRow() + array( - 'ref_target' => $this->url, - ); - } - - /** - * Instantiates a URLReference object from a storage row. - * - * @param \StdClass $row - * @return URLReference - */ - public static function fromStorageRow( $row ) { - $workflow = UUID::create( $row['ref_src_workflow_id'] ); - $objectType = $row['ref_src_object_type']; - $objectId = UUID::create( $row['ref_src_object_id'] ); - $url = $row['ref_target']; - $type = $row['ref_type']; - $srcTitle = Title::makeTitle( $row['ref_src_namespace'], $row['ref_src_title'] ); - - return new URLReference( $workflow, $srcTitle, $objectType, $objectId, $type, $url ); - } - - /** - * Gets the storage row from an object. - * Helper for BasicObjectMapper. - */ - public static function toStorageRow( URLReference $object ) { - return $object->getStorageRow(); - } - - public function getUrl() { - return $this->url; - } - - public function getTargetIdentifier() { - return 'url:' . $this->getUrl(); - } -} diff --git a/includes/Model/URLReference.php b/includes/Model/URLReference.php new file mode 100644 index 0000000..e707347 --- /dev/null +++ b/includes/Model/URLReference.php @@ -0,0 +1,75 @@ +<?php + +namespace Flow\Model; + +use Flow\Exception\InvalidInputException; +use Title; + +class URLReference extends Reference { + protected $url; + + /** + * @param UUID $srcWorkflow ID of the source Workflow + * @param Title $srcTitle Title of the page that the Workflow exists on + * @param String $objectType Output of getRevisionType for the AbstractRevision that this reference comes from. + * @param UUID $objectId Unique identifier for the revisioned object containing the reference. + * @param string $type Type of reference + * @param string $url URL of the reference's target. + * @throws InvalidInputException + */ + public function __construct( UUID $srcWorkflow, Title $srcTitle, $objectType, UUID $objectId, $type, $url ) { + $this->url = $url; + + if ( !is_array( wfParseUrl( $url ) ) ) { + throw new InvalidInputException( + "Invalid URL $url specified for reference " . get_class( $this ) + ); + } + + parent::__construct( $srcWorkflow, $srcTitle, $objectType, $objectId, $type ); + } + + /** + * Gets the storage row for this URLReference + * + * @return array + */ + public function getStorageRow() { + return parent::getStorageRow() + array( + 'ref_target' => $this->url, + ); + } + + /** + * Instantiates a URLReference object from a storage row. + * + * @param \StdClass $row + * @return URLReference + */ + public static function fromStorageRow( $row ) { + $workflow = UUID::create( $row['ref_src_workflow_id'] ); + $objectType = $row['ref_src_object_type']; + $objectId = UUID::create( $row['ref_src_object_id'] ); + $url = $row['ref_target']; + $type = $row['ref_type']; + $srcTitle = Title::makeTitle( $row['ref_src_namespace'], $row['ref_src_title'] ); + + return new URLReference( $workflow, $srcTitle, $objectType, $objectId, $type, $url ); + } + + /** + * Gets the storage row from an object. + * Helper for BasicObjectMapper. + */ + public static function toStorageRow( URLReference $object ) { + return $object->getStorageRow(); + } + + public function getUrl() { + return $this->url; + } + + public function getTargetIdentifier() { + return 'url:' . $this->getUrl(); + } +} diff --git a/includes/Model/WikiReference.php b/includes/Model/WikiReference.php new file mode 100644 index 0000000..8dcf090 --- /dev/null +++ b/includes/Model/WikiReference.php @@ -0,0 +1,93 @@ +<?php + +namespace Flow\Model; + +use Flow\Exception\InvalidInputException; +use Title; + +class WikiReference extends Reference { + const TYPE_FILE = 'file'; + const TYPE_TEMPLATE = 'template'; + + protected $target; + + /** + * @param UUID $srcWorkflow ID of the source Workflow + * @param Title $srcTitle Title of the reference's target. + * @param string $objectType Output of getRevisionType for the AbstractRevision that this reference comes from. + * @param UUID $objectId Unique identifier for the revisioned object containing the reference. + * @param string $type Type of reference + * @param Title $targetTitle Title of the reference's target. + */ + public function __construct( UUID $srcWorkflow, Title $srcTitle, $objectType, UUID $objectId, $type, Title $targetTitle ) { + $this->target = $targetTitle; + + $this->validTypes = array_merge( $this->validTypes, + array( + self::TYPE_FILE, + self::TYPE_TEMPLATE, + ) + ); + + parent::__construct( $srcWorkflow, $srcTitle, $objectType, $objectId, $type ); + } + + /** + * Gets the storage row for this WikiReference + * + * @return array + */ + public function getStorageRow() { + return parent::getStorageRow() + array( + 'ref_target_namespace' => $this->target->getNamespace(), + 'ref_target_title' => $this->target->getDBkey(), + ); + } + + /** + * Instantiates a WikiReference object from a storage row. + * + * @param \StdClass $row + * @return WikiReference + */ + public static function fromStorageRow( $row ) { + $workflow = UUID::create( $row['ref_src_workflow_id'] ); + $objectType = $row['ref_src_object_type']; + $objectId = UUID::create( $row['ref_src_object_id'] ); + $srcTitle = self::makeTitle( $row['ref_src_namespace'], $row['ref_src_title'] ); + $targetTitle = self::makeTitle( $row['ref_target_namespace'], $row['ref_target_title'] ); + $type = $row['ref_type']; + + return new WikiReference( $workflow, $srcTitle, $objectType, $objectId, $type, $targetTitle ); + } + + /** + * Gets the storage row from an object. + * Helper for BasicObjectMapper. + */ + public static function toStorageRow( WikiReference $object ) { + return $object->getStorageRow(); + } + + /** + * Many loaded references typically point to the same Title, cache those instead + * of generating a bunch of duplicate title classes. + */ + public static function makeTitle( $namespace, $title ) { + try { + return Workflow::getFromTitleCache( wfWikiId(), $namespace, $title ); + } catch ( InvalidInputException $e ) { + // duplicate Title::makeTitleSafe which returns null on failure, + // but only for InvalidInputException + return null; + } + } + + public function getTitle() { + return $this->target; + } + + public function getTargetIdentifier() { + return 'title:' . $this->getTitle()->getPrefixedDBKey(); + } +} -- To view, visit https://gerrit.wikimedia.org/r/188306 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ia96eb500e7e0036829a14a2d07a0f8c2acdee5c4 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org> Gerrit-Reviewer: Matthias Mullie <mmul...@wikimedia.org> Gerrit-Reviewer: SG <shah...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits