r41481 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41480‎ | r41481 | r41482 >
Date:15:12, 1 October 2008
Author:aaron
Status:old (Comments)
Tags:
Comment:
Make repo/author, repo/status, and repo/tag links work if nothing else specified by listing out possible links
Modified paths:
  • /trunk/extensions/CodeReview/CodeRepository.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeReview.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeRevision.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeRevisionAuthorListView.php (added) (history)
  • /trunk/extensions/CodeReview/CodeRevisionStatusListView.php (added) (history)
  • /trunk/extensions/CodeReview/CodeRevisionTagListView.php (added) (history)
  • /trunk/extensions/CodeReview/CodeRevisionView.php (modified) (history)
  • /trunk/extensions/CodeReview/SpecialCode.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/CodeRevision.php
@@ -45,12 +45,12 @@
4646 return $this->mStatus;
4747 }
4848
49 - function getPossibleStates() {
 49+ static function getPossibleStates() {
5050 return array( 'new', 'fixme', 'resolved', 'ok' );
5151 }
5252
5353 function isValidStatus( $status ) {
54 - return in_array( $status, $this->getPossibleStates(), true );
 54+ return in_array( $status, self::getPossibleStates(), true );
5555 }
5656
5757 function setStatus( $status ) {
Index: trunk/extensions/CodeReview/CodeReview.php
@@ -50,6 +50,9 @@
5151 $wgAutoloadClasses['CodeRevisionTagger'] = $dir . 'CodeRevisionTagger.php';
5252 $wgAutoloadClasses['CodeRevisionTagView'] = $dir . 'CodeRevisionTagView.php';
5353 $wgAutoloadClasses['CodeRevisionView'] = $dir . 'CodeRevisionView.php';
 54+$wgAutoloadClasses['CodeRevisionAuthorListView'] = $dir . 'CodeRevisionAuthorListView.php';
 55+$wgAutoloadClasses['CodeRevisionStatusListView'] = $dir . 'CodeRevisionStatusListView.php';
 56+$wgAutoloadClasses['CodeRevisionTagListView'] = $dir . 'CodeRevisionTagListView.php';
5457 $wgAutoloadClasses['CodeComment'] = $dir . 'CodeComment.php';
5558 $wgAutoloadClasses['SpecialCode'] = $dir . 'SpecialCode.php';
5659 $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
123 + native
Index: trunk/extensions/CodeReview/CodeRepository.php
@@ -69,18 +69,64 @@
7070 return false;
7171 }
7272
73 - function getLastStoredRev(){
 73+ function getLastStoredRev() {
7474 $dbr = wfGetDB( DB_SLAVE );
7575 $row = $dbr->selectField(
7676 'code_rev',
7777 'MAX(cr_id)',
78 - array(
79 - 'cr_repo_id' => $this->getId(),
80 - ),
 78+ array( 'cr_repo_id' => $this->getId() ),
8179 __METHOD__
8280 );
8381 return intval( $row );
8482 }
 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+ }
85131
86132 /**
87133 * Load a particular revision out of the DB
Index: trunk/extensions/CodeReview/SpecialCode.php
@@ -23,17 +23,28 @@
2424 $view = new CodeRevisionListView( $params[0] );
2525 break;
2626 case 2:
27 - $view = new CodeRevisionView( $params[0], $params[1] );
28 - break;
2927 case 3:
 28+ if( is_numeric( $params[1] ) ) {
 29+ $view = new CodeRevisionView( $params[0], $params[1] );
 30+ break;
 31+ }
3032 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] );
3237 break;
3338 } 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] );
3543 break;
3644 } 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] );
3849 break;
3950 } else {
4051 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
123 + 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
123 + native
Index: trunk/extensions/CodeReview/CodeRevisionView.php
@@ -191,7 +191,7 @@
192192 }
193193
194194 function buildStatusList() {
195 - $states = $this->mRev->getPossibleStates();
 195+ $states = CodeRevision::getPossibleStates();
196196 $out = '';
197197 foreach( $states as $state ) {
198198 $list[$state] = $this->statusDesc( $state );

Comments

#Comment by Brion VIBBER (talk | contribs)   23:42, 2 October 2008

It might be worth making an abstract base class for these list-of-possible-values views, especially if we want to better handle a large data set.

Or we could do crazy shit like a tag cloud. ;)

Status & tagging log