Jdlrobson has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/375075 )
Change subject: Hygiene: Refactor execute function ...................................................................... Hygiene: Refactor execute function Trying to make sense of all the commands - the list is extremely long - as is the execute function. This refactors execute to 2 private functions More will follow if this is deemed a good idea. Change-Id: I3dd4507dcd9d3b350c49f3ee8a8262e4a01f8836 --- M Collection.body.php 1 file changed, 79 insertions(+), 59 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Collection refs/changes/75/375075/1 diff --git a/Collection.body.php b/Collection.body.php index 2a4a816..ec591ce 100644 --- a/Collection.body.php +++ b/Collection.body.php @@ -218,42 +218,7 @@ $this->postZIP( $collection, $partner ); return; case 'save_collection': - if ( $request->getVal( 'abort' ) ) { - $out->redirect( SkinTemplate::makeSpecialUrl( 'Book' ) ); - return; - } - if ( !$user->matchEditToken( $request->getVal( 'token' ) ) ) { - return; - } - $colltype = $request->getVal( 'colltype' ); - $prefixes = self::getBookPagePrefixes(); - $title = null; - if ( $colltype == 'personal' ) { - $collname = $request->getVal( 'pcollname' ); - if ( !$user->isAllowed( 'collectionsaveasuserpage' ) || empty( $collname ) ) { - return; - } - $title = Title::newFromText( $prefixes['user-prefix'] . $collname ); - } elseif ( $colltype == 'community' ) { - $collname = $request->getVal( 'ccollname' ); - if ( !$user->isAllowed( 'collectionsaveascommunitypage' ) || empty( $collname ) ) { - return; - } - $title = Title::newFromText( $prefixes['community-prefix'] . $collname ); - } - if ( !$title ) { - return; - } - if ( $this->saveCollection( $title, $request->getBool( 'overwrite' ) ) ) { - $out->redirect( $title->getFullURL() ); - } else { - $this->renderSaveOverwritePage( - $colltype, - $title, - $request->getVal( 'pcollname' ), - $request->getVal( 'ccollname' ) - ); - } + $this->processSaveCollectionCommand(); return; case 'render': $this->renderCollection( @@ -299,29 +264,7 @@ $this->postZIP( CollectionSession::getCollection(), $partner ); return; case 'suggest': - $add = $request->getVal( 'add' ); - $ban = $request->getVal( 'ban' ); - $remove = $request->getVal( 'remove' ); - $addselected = $request->getVal( 'addselected' ); - - if ( $request->getVal( 'resetbans' ) ) { - CollectionSuggest::run( 'resetbans' ); - } elseif ( isset( $add ) ) { - CollectionSuggest::run( 'add', $add ); - } elseif ( isset( $ban ) ) { - CollectionSuggest::run( 'ban', $ban ); - } elseif ( isset( $remove ) ) { - CollectionSuggest::run( 'remove', $remove ); - } elseif ( isset( $addselected ) ) { - $articleList = $request->getArray( 'articleList' ); - if ( !is_null( $articleList ) ) { - CollectionSuggest::run( 'addAll', $articleList ); - } else { - CollectionSuggest::run(); - } - } else { - CollectionSuggest::run(); - } + $this->processSuggestActionCommand(); return; case '': $this->renderSpecialPage(); @@ -332,6 +275,83 @@ } /** + * Processes the suggest command + */ + private function processSuggestCommand() { + $request = $this->getRequest(); + + $add = $request->getVal( 'add' ); + $ban = $request->getVal( 'ban' ); + $remove = $request->getVal( 'remove' ); + $addselected = $request->getVal( 'addselected' ); + + if ( $request->getVal( 'resetbans' ) ) { + CollectionSuggest::run( 'resetbans' ); + } elseif ( isset( $add ) ) { + CollectionSuggest::run( 'add', $add ); + } elseif ( isset( $ban ) ) { + CollectionSuggest::run( 'ban', $ban ); + } elseif ( isset( $remove ) ) { + CollectionSuggest::run( 'remove', $remove ); + } elseif ( isset( $addselected ) ) { + $articleList = $request->getArray( 'articleList' ); + if ( !is_null( $articleList ) ) { + CollectionSuggest::run( 'addAll', $articleList ); + } else { + CollectionSuggest::run(); + } + } else { + CollectionSuggest::run(); + } + } + + /** + * Processes the save book command + */ + private function processSaveCollectionCommand() { + $out = $this->getOutput(); + $request = $this->getRequest(); + $user = $this->getUser(); + + if ( $request->getVal( 'abort' ) ) { + $out->redirect( SkinTemplate::makeSpecialUrl( 'Book' ) ); + return; + } + if ( !$user->matchEditToken( $request->getVal( 'token' ) ) ) { + return; + } + $colltype = $request->getVal( 'colltype' ); + $prefixes = self::getBookPagePrefixes(); + $title = null; + if ( $colltype == 'personal' ) { + $collname = $request->getVal( 'pcollname' ); + if ( !$user->isAllowed( 'collectionsaveasuserpage' ) || empty( $collname ) ) { + return; + } + $title = Title::newFromText( $prefixes['user-prefix'] . $collname ); + } elseif ( $colltype == 'community' ) { + $collname = $request->getVal( 'ccollname' ); + if ( !$user->isAllowed( 'collectionsaveascommunitypage' ) || empty( $collname ) ) { + return; + } + $title = Title::newFromText( $prefixes['community-prefix'] . $collname ); + } + if ( !$title ) { + return; + } + if ( $this->saveCollection( $title, $request->getBool( 'overwrite' ) ) ) { + $out->redirect( $title->getFullURL() ); + } else { + $this->renderSaveOverwritePage( + $colltype, + $title, + $request->getVal( 'pcollname' ), + $request->getVal( 'ccollname' ) + ); + } + } + + /** * @param string $referer * @param string $par * @return mixed -- To view, visit https://gerrit.wikimedia.org/r/375075 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3dd4507dcd9d3b350c49f3ee8a8262e4a01f8836 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Collection Gerrit-Branch: master Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits