r88961 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88960‎ | r88961 | r88962 >
Date:09:34, 27 May 2011
Author:happydog
Status:ok
Tags:
Comment:
[CodeReview] Simplifying SpecialCode::getViewFrom(), as there is a bunch of duplication there. Now the class names are defined in a static array, so we can use a simple bit of logic to decide which class to instantiate, instead of two very similar and very long if/else blocks.
Modified paths:
  • /trunk/extensions/CodeReview/ui/SpecialCode.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/ui/SpecialCode.php
@@ -50,6 +50,22 @@
5151 private function getViewFrom( $subpage ) {
5252 global $wgRequest;
5353
 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+
5470 # Remove stray slashes
5571 $subpage = preg_replace( '/\/$/', '', $subpage );
5672 if ( $subpage == '' ) {
@@ -71,59 +87,25 @@
7288 case 1:
7389 $view = new CodeRevisionListView( $repo );
7490 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' ) ) {
98101 # This is not really a view, but we return it nonetheless.
99102 # Add any tags, Set status, Adds comments
100103 $view = new CodeRevisionCommitter( $repo, $params[1] );
101 - break;
102 - } else { // revision details
 104+ } elseif ( empty( $params[1] ) ) {
 105+ $view = new CodeRevisionListView( $repo );
 106+ } else {
103107 $view = new CodeRevisionView( $repo, $params[1] );
104 - break;
105108 }
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;
128110 case 4:
129111 if ( $params[1] === 'author' && $params[3] === 'link' ) {
130112 $view = new CodeRevisionAuthorLink( $repo, $params[2] );

Status & tagging log