Index: trunk/extensions/CodeReview/ui/SpecialCode.php |
— | — | @@ -50,6 +50,22 @@ |
51 | 51 | private function getViewFrom( $subpage ) { |
52 | 52 | global $wgRequest; |
53 | 53 | |
| 54 | + // Defines the classes to use for each view type. |
| 55 | + // The first class name is used if no additional parameters are provided. |
| 56 | + // The second, if defined, is used if there is an additional parameter. If |
| 57 | + // there is no second class defined, then the first class is used in both |
| 58 | + // cases. |
| 59 | + static $paramClasses |
| 60 | + = array( |
| 61 | + 'tag' => array( "CodeTagListView", "CodeRevisionTagView" ), |
| 62 | + 'author' => array( "CodeAuthorListView", "CodeRevisionAuthorView" ), |
| 63 | + 'status' => array( "CodeStatusListView", "CodeRevisionStatusView" ), |
| 64 | + 'comments' => array( "CodeCommentsListView" ), |
| 65 | + 'statuschanges' => array( "CodeStatusChangeListView" ), |
| 66 | + 'releasenotes' => array( "CodeReleaseNotes" ), |
| 67 | + 'stats' => array( "CodeRepoStatsView" ), |
| 68 | + ); |
| 69 | + |
54 | 70 | # Remove stray slashes |
55 | 71 | $subpage = preg_replace( '/\/$/', '', $subpage ); |
56 | 72 | if ( $subpage == '' ) { |
— | — | @@ -71,59 +87,25 @@ |
72 | 88 | case 1: |
73 | 89 | $view = new CodeRevisionListView( $repo ); |
74 | 90 | break; |
75 | | - case 2: |
76 | | - if ( $params[1] === 'tag' ) { |
77 | | - $view = new CodeTagListView( $repo ); |
78 | | - break; |
79 | | - } elseif ( $params[1] === 'author' ) { |
80 | | - $view = new CodeAuthorListView( $repo ); |
81 | | - break; |
82 | | - } elseif ( $params[1] === 'stats' ) { |
83 | | - $view = new CodeRepoStatsView( $repo ); |
84 | | - break; |
85 | | - } elseif ( $params[1] === 'status' ) { |
86 | | - $view = new CodeStatusListView( $repo ); |
87 | | - break; |
88 | | - } elseif ( $params[1] === 'comments' ) { |
89 | | - $view = new CodeCommentsListView( $repo ); |
90 | | - break; |
91 | | - } elseif ( $params[1] === 'statuschanges' ) { |
92 | | - $view = new CodeStatusChangeListView( $repo ); |
93 | | - break; |
94 | | - } elseif ( $params[1] === 'releasenotes' ) { |
95 | | - $view = new CodeReleaseNotes( $repo ); |
96 | | - break; |
97 | | - } else if ( $wgRequest->wasPosted() && !$wgRequest->getCheck( 'wpPreview' ) ) { |
| 91 | + case 2: // drop through... |
| 92 | + case 3: |
| 93 | + if ( isset( $paramClasses[$params[1]] ) ) { |
| 94 | + $row = $paramClasses[$params[1]]; |
| 95 | + if ( isset( $params[2] ) && isset( $row[1] ) ) { |
| 96 | + $view = new $row[1]( $repo, $params[2] ); |
| 97 | + } else { |
| 98 | + $view = new $row[0]( $repo ); |
| 99 | + } |
| 100 | + } elseif ( $wgRequest->wasPosted() && !$wgRequest->getCheck( 'wpPreview' ) ) { |
98 | 101 | # This is not really a view, but we return it nonetheless. |
99 | 102 | # Add any tags, Set status, Adds comments |
100 | 103 | $view = new CodeRevisionCommitter( $repo, $params[1] ); |
101 | | - break; |
102 | | - } else { // revision details |
| 104 | + } elseif ( empty( $params[1] ) ) { |
| 105 | + $view = new CodeRevisionListView( $repo ); |
| 106 | + } else { |
103 | 107 | $view = new CodeRevisionView( $repo, $params[1] ); |
104 | | - break; |
105 | 108 | } |
106 | | - case 3: |
107 | | - if ( $params[1] === 'tag' ) { |
108 | | - $view = new CodeRevisionTagView( $repo, $params[2] ); |
109 | | - break; |
110 | | - } elseif ( $params[1] === 'author' ) { |
111 | | - $view = new CodeRevisionAuthorView( $repo, $params[2] ); |
112 | | - break; |
113 | | - } elseif ( $params[1] === 'status' ) { |
114 | | - $view = new CodeRevisionStatusView( $repo, $params[2] ); |
115 | | - break; |
116 | | - } elseif ( $params[1] === 'comments' ) { |
117 | | - $view = new CodeCommentsListView( $repo ); |
118 | | - break; |
119 | | - } else { |
120 | | - # Nonsense parameters, back out |
121 | | - if ( empty( $params[1] ) ) { |
122 | | - $view = new CodeRevisionListView( $repo ); |
123 | | - } else { |
124 | | - $view = new CodeRevisionView( $repo, $params[1] ); |
125 | | - } |
126 | | - break; |
127 | | - } |
| 109 | + break; |
128 | 110 | case 4: |
129 | 111 | if ( $params[1] === 'author' && $params[3] === 'link' ) { |
130 | 112 | $view = new CodeRevisionAuthorLink( $repo, $params[2] ); |