Index: trunk/extensions/CodeReview/CodeRevision.php |
— | — | @@ -45,12 +45,12 @@ |
46 | 46 | return $this->mStatus; |
47 | 47 | } |
48 | 48 | |
49 | | - function getPossibleStates() { |
| 49 | + static function getPossibleStates() { |
50 | 50 | return array( 'new', 'fixme', 'resolved', 'ok' ); |
51 | 51 | } |
52 | 52 | |
53 | 53 | function isValidStatus( $status ) { |
54 | | - return in_array( $status, $this->getPossibleStates(), true ); |
| 54 | + return in_array( $status, self::getPossibleStates(), true ); |
55 | 55 | } |
56 | 56 | |
57 | 57 | function setStatus( $status ) { |
Index: trunk/extensions/CodeReview/CodeReview.php |
— | — | @@ -50,6 +50,9 @@ |
51 | 51 | $wgAutoloadClasses['CodeRevisionTagger'] = $dir . 'CodeRevisionTagger.php'; |
52 | 52 | $wgAutoloadClasses['CodeRevisionTagView'] = $dir . 'CodeRevisionTagView.php'; |
53 | 53 | $wgAutoloadClasses['CodeRevisionView'] = $dir . 'CodeRevisionView.php'; |
| 54 | +$wgAutoloadClasses['CodeRevisionAuthorListView'] = $dir . 'CodeRevisionAuthorListView.php'; |
| 55 | +$wgAutoloadClasses['CodeRevisionStatusListView'] = $dir . 'CodeRevisionStatusListView.php'; |
| 56 | +$wgAutoloadClasses['CodeRevisionTagListView'] = $dir . 'CodeRevisionTagListView.php'; |
54 | 57 | $wgAutoloadClasses['CodeComment'] = $dir . 'CodeComment.php'; |
55 | 58 | $wgAutoloadClasses['SpecialCode'] = $dir . 'SpecialCode.php'; |
56 | 59 | $wgAutoloadClasses['CodeView'] = $dir . 'SpecialCode.php'; |
Index: trunk/extensions/CodeReview/CodeRevisionAuthorListView.php |
— | — | @@ -0,0 +1,21 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +// Special:Code/MediaWiki/author |
| 5 | +class CodeRevisionAuthorListView extends CodeView { |
| 6 | + function __construct( $repoName ) { |
| 7 | + parent::__construct(); |
| 8 | + $this->mRepo = CodeRepository::newFromName( $repoName ); |
| 9 | + } |
| 10 | + |
| 11 | + function execute() { |
| 12 | + global $wgOut; |
| 13 | + $authors = $this->mRepo->getAuthorList(); |
| 14 | + $name = $this->mRepo->getName(); |
| 15 | + $text = ''; |
| 16 | + foreach( $authors as $user ) { |
| 17 | + $text .= "* [[Special:Code/$name/author/$user|$user]]\n"; |
| 18 | + } |
| 19 | + $wgOut->addWikiText( $text ); |
| 20 | + } |
| 21 | +} |
| 22 | + |
Property changes on: trunk/extensions/CodeReview/CodeRevisionAuthorListView.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 23 | + native |
Index: trunk/extensions/CodeReview/CodeRepository.php |
— | — | @@ -69,18 +69,64 @@ |
70 | 70 | return false; |
71 | 71 | } |
72 | 72 | |
73 | | - function getLastStoredRev(){ |
| 73 | + function getLastStoredRev() { |
74 | 74 | $dbr = wfGetDB( DB_SLAVE ); |
75 | 75 | $row = $dbr->selectField( |
76 | 76 | 'code_rev', |
77 | 77 | 'MAX(cr_id)', |
78 | | - array( |
79 | | - 'cr_repo_id' => $this->getId(), |
80 | | - ), |
| 78 | + array( 'cr_repo_id' => $this->getId() ), |
81 | 79 | __METHOD__ |
82 | 80 | ); |
83 | 81 | return intval( $row ); |
84 | 82 | } |
| 83 | + |
| 84 | + function getAuthorList() { |
| 85 | + global $wgMemc; |
| 86 | + $key = wfMemcKey( 'codereview', 'authors', $this->getId() ); |
| 87 | + $authors = $wgMemc->get( $key ); |
| 88 | + if( is_array($authors) ) { |
| 89 | + return $authors; |
| 90 | + } |
| 91 | + $dbr = wfGetDB( DB_SLAVE ); |
| 92 | + $res = $dbr->select( |
| 93 | + 'code_rev', |
| 94 | + array( 'cr_author', 'COUNT(*) AS commits' ), |
| 95 | + array( 'cr_repo_id' => $this->getId() ), |
| 96 | + __METHOD__, |
| 97 | + array( 'GROUP BY' => 'cr_author', |
| 98 | + 'ORDER BY' => 'commits DESC', 'LIMIT' => 500 ) |
| 99 | + ); |
| 100 | + $authors = array(); |
| 101 | + while( $row = $dbr->fetchObject( $res ) ) { |
| 102 | + $authors[] = $row->cr_author; |
| 103 | + } |
| 104 | + $wgMemc->set( $key, $authors, 3600*24*3 ); |
| 105 | + return $authors; |
| 106 | + } |
| 107 | + |
| 108 | + function getTagList() { |
| 109 | + global $wgMemc; |
| 110 | + $key = wfMemcKey( 'codereview', 'tags', $this->getId() ); |
| 111 | + $tags = $wgMemc->get( $key ); |
| 112 | + if( is_array($tags) ) { |
| 113 | + return $tags; |
| 114 | + } |
| 115 | + $dbr = wfGetDB( DB_SLAVE ); |
| 116 | + $res = $dbr->select( |
| 117 | + 'code_tags', |
| 118 | + array( 'ct_tag', 'COUNT(*) AS revs' ), |
| 119 | + array( 'ct_repo_id' => $this->getId() ), |
| 120 | + __METHOD__, |
| 121 | + array( 'GROUP BY' => 'ct_tag', |
| 122 | + 'ORDER BY' => 'revs DESC', 'LIMIT' => 500 ) |
| 123 | + ); |
| 124 | + $tags = array(); |
| 125 | + while( $row = $dbr->fetchObject( $res ) ) { |
| 126 | + $tags[] = $row->ct_tag; |
| 127 | + } |
| 128 | + $wgMemc->set( $key, $tags, 3600*24*3 ); |
| 129 | + return $tags; |
| 130 | + } |
85 | 131 | |
86 | 132 | /** |
87 | 133 | * Load a particular revision out of the DB |
Index: trunk/extensions/CodeReview/SpecialCode.php |
— | — | @@ -23,17 +23,28 @@ |
24 | 24 | $view = new CodeRevisionListView( $params[0] ); |
25 | 25 | break; |
26 | 26 | case 2: |
27 | | - $view = new CodeRevisionView( $params[0], $params[1] ); |
28 | | - break; |
29 | 27 | case 3: |
| 28 | + if( is_numeric( $params[1] ) ) { |
| 29 | + $view = new CodeRevisionView( $params[0], $params[1] ); |
| 30 | + break; |
| 31 | + } |
30 | 32 | if( $params[1] == 'tag' ) { |
31 | | - $view = new CodeRevisionTagView( $params[0], $params[2] ); |
| 33 | + if( empty($params[2]) ) |
| 34 | + $view = new CodeRevisionTagListView( $params[0] ); |
| 35 | + else |
| 36 | + $view = new CodeRevisionTagView( $params[0], $params[2] ); |
32 | 37 | break; |
33 | 38 | } elseif( $params[1] == 'author' ) { |
34 | | - $view = new CodeRevisionAuthorView( $params[0], $params[2] ); |
| 39 | + if( empty($params[2]) ) |
| 40 | + $view = new CodeRevisionAuthorListView( $params[0] ); |
| 41 | + else |
| 42 | + $view = new CodeRevisionAuthorView( $params[0], $params[2] ); |
35 | 43 | break; |
36 | 44 | } elseif( $params[1] == 'status' ) { |
37 | | - $view = new CodeRevisionStatusView( $params[0], $params[2] ); |
| 45 | + if( empty($params[2]) ) |
| 46 | + $view = new CodeRevisionStatusListView( $params[0] ); |
| 47 | + else |
| 48 | + $view = new CodeRevisionStatusView( $params[0], $params[2] ); |
38 | 49 | break; |
39 | 50 | } else { |
40 | 51 | throw new MWException( "Unexpected number of parameters" ); |
Index: trunk/extensions/CodeReview/CodeRevisionTagListView.php |
— | — | @@ -0,0 +1,21 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +// Special:Code/MediaWiki/tag |
| 5 | +class CodeRevisionTagListView extends CodeView { |
| 6 | + function __construct( $repoName ) { |
| 7 | + parent::__construct(); |
| 8 | + $this->mRepo = CodeRepository::newFromName( $repoName ); |
| 9 | + } |
| 10 | + |
| 11 | + function execute() { |
| 12 | + global $wgOut; |
| 13 | + $tags = $this->mRepo->getTagList(); |
| 14 | + $name = $this->mRepo->getName(); |
| 15 | + $text = ''; |
| 16 | + foreach( $tags as $tag ) { |
| 17 | + $text .= "* [[Special:Code/$name/tag/$tag|$tag]]\n"; |
| 18 | + } |
| 19 | + $wgOut->addWikiText( $text ); |
| 20 | + } |
| 21 | +} |
| 22 | + |
Property changes on: trunk/extensions/CodeReview/CodeRevisionTagListView.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 23 | + native |
Index: trunk/extensions/CodeReview/CodeRevisionStatusListView.php |
— | — | @@ -0,0 +1,21 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +// Special:Code/MediaWiki/status |
| 5 | +class CodeRevisionStatusListView extends CodeView { |
| 6 | + function __construct( $repoName ) { |
| 7 | + parent::__construct(); |
| 8 | + $this->mRepo = CodeRepository::newFromName( $repoName ); |
| 9 | + } |
| 10 | + |
| 11 | + function execute() { |
| 12 | + global $wgOut; |
| 13 | + $name = $this->mRepo->getName(); |
| 14 | + $states = CodeRevision::getPossibleStates(); |
| 15 | + $text = ''; |
| 16 | + foreach( $states as $state ) { |
| 17 | + $text .= "* [[Special:Code/$name/status/$state|$state]]\n"; |
| 18 | + } |
| 19 | + $wgOut->addWikiText( $text ); |
| 20 | + } |
| 21 | +} |
| 22 | + |
Property changes on: trunk/extensions/CodeReview/CodeRevisionStatusListView.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 23 | + native |
Index: trunk/extensions/CodeReview/CodeRevisionView.php |
— | — | @@ -191,7 +191,7 @@ |
192 | 192 | } |
193 | 193 | |
194 | 194 | function buildStatusList() { |
195 | | - $states = $this->mRev->getPossibleStates(); |
| 195 | + $states = CodeRevision::getPossibleStates(); |
196 | 196 | $out = ''; |
197 | 197 | foreach( $states as $state ) { |
198 | 198 | $list[$state] = $this->statusDesc( $state ); |