r75340 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75339‎ | r75340 | r75341 >
Date:20:24, 24 October 2010
Author:hashar
Status:ok
Tags:
Comment:
moving view choice logic to its own function
Modified paths:
  • /trunk/extensions/CodeReview/ui/SpecialCode.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/ui/SpecialCode.php
@@ -7,7 +7,7 @@
88 }
99
1010 function execute( $subpage ) {
11 - global $wgOut, $wgRequest, $wgUser, $wgExtensionAssetsPath, $wgCodeReviewStyleVersion;
 11+ global $wgOut, $wgUser, $wgExtensionAssetsPath, $wgCodeReviewStyleVersion;
1212
1313 if ( !$this->userCanExecute( $wgUser ) ) {
1414 $this->displayRestrictionError();
@@ -16,6 +16,30 @@
1717
1818 $this->setHeaders();
1919 $wgOut->addStyle( "$wgExtensionAssetsPath/CodeReview/codereview.css?$wgCodeReviewStyleVersion" );
 20+
 21+ if( $view = self::getViewFrom( $subpage ) ) {
 22+ $view->execute();
 23+ } else {
 24+ $wgOut->addWikiText( wfMsg( 'nosuchactiontext' ) );
 25+ $wgOut->returnToMain( null, SpecialPage::getTitleFor( 'Code' ) );
 26+ return;
 27+ }
 28+
 29+ // Add subtitle for easy navigation
 30+ if ( $view instanceof CodeView && ( $repo = $view->getRepo() ) ) {
 31+ $wgOut->setSubtitle(
 32+ wfMsgExt( 'codereview-subtitle', 'parse', CodeRepoListView::getNavItem( $repo ) )
 33+ );
 34+ }
 35+ }
 36+
 37+ /**
 38+ * Get a view object from a sub page path.
 39+ * @return View object or null if no valid action could be found
 40+ */
 41+ private static function getViewFrom( $subpage ) {
 42+ global $wgRequest;
 43+
2044 # Remove stray slashes
2145 $subpage = preg_replace( '/\/$/', '', $subpage );
2246 if ( $subpage == '' ) {
@@ -49,10 +73,10 @@
5074 $view = new CodeReleaseNotes( $params[0] );
5175 break;
5276 } else if ( $wgRequest->wasPosted() && !$wgRequest->getCheck( 'wpPreview' ) ) {
 77+ # This is not really a view, but we return it nonetheless.
5378 # Add any tags, Set status, Adds comments
54 - $submit = new CodeRevisionCommitter( $params[0], $params[1] );
55 - $submit->execute();
56 - return;
 79+ $view = new CodeRevisionCommitter( $params[0], $params[1] );
 80+ break;
5781 } else { // revision details
5882 $view = new CodeRevisionView( $params[0], $params[1] );
5983 break;
@@ -89,27 +113,18 @@
90114 $view = new CodeRevisionView( $params[0], $params[1], $params[3] );
91115 break;
92116 }
93 - $wgOut->addWikiText( wfMsg( 'nosuchactiontext' ) );
94 - $wgOut->returnToMain( null, SpecialPage::getTitleFor( 'Code' ) );
95 - return;
 117+ return null;
96118 }
97119
98120 // If a repository was specified, but it does not exist, redirect to the
99121 // repository list with an appropriate message.
100122 if ( !$view->mRepo ) {
101123 $view = new CodeRepoListView();
 124+ global $wgOut;
102125 $wgOut->addWikiMsg( 'code-repo-not-found', wfEscapeWikiText( $params[0] ) );
103126 }
104127 }
105 - $view->execute();
106 -
107 - // Add subtitle for easy navigation
108 - global $wgOut;
109 - if ( $view instanceof CodeView && ( $repo = $view->getRepo() ) ) {
110 - $wgOut->setSubtitle(
111 - wfMsgExt( 'codereview-subtitle', 'parse', CodeRepoListView::getNavItem( $repo ) )
112 - );
113 - }
 128+ return $view;
114129 }
115130 }
116131

Status & tagging log