r41641 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41640‎ | r41641 | r41642 >
Date:11:23, 4 October 2008
Author:nicdumz
Status:old (Comments)
Tags:
Comment:
Improving Linking system :
* Introducing a Special page to handle addlink/alterlink/unlink
* Only display on top of AuthorView a statusline + link to the page
Modified paths:
  • /trunk/extensions/CodeReview/CodeReview.i18n.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeReview.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeRevisionAuthorLink.php (added) (history)
  • /trunk/extensions/CodeReview/CodeRevisionAuthorView.php (modified) (history)
  • /trunk/extensions/CodeReview/SpecialCode.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/CodeRevisionAuthorLink.php
@@ -0,0 +1,135 @@
 2+<?php
 3+
 4+// Special:Code/MediaWiki/author/johndoe/link
 5+
 6+class CodeRevisionAuthorLink extends CodeRevisionAuthorView {
 7+ function getTitle() {
 8+ $repo = $this->mRepo->getName();
 9+ $auth = $this->mAuthor;
 10+ return SpecialPage::getTitleFor( 'Code', "$repo/author/$auth/link");
 11+ }
 12+
 13+ function execute() {
 14+ global $wgOut, $wgRequest, $wgUser;
 15+
 16+ if ( !$wgUser->isAllowed( 'codereview-link-user' ) ) {
 17+ $wgOut->permissionRequired( 'codereview-link-user' );
 18+ return;
 19+ }
 20+
 21+ $target = $wgRequest->getVal( 'linktouser' );
 22+
 23+ if ( $target && $wgRequest->getVal( 'newname' ) ) {
 24+ $this->linkTo( $target );
 25+ return;
 26+ } else if ( $wgRequest->getVal( 'unlink' ) ) {
 27+ $this->unlink();
 28+ return;
 29+ }
 30+
 31+
 32+ $form = Xml::openElement( 'form',
 33+ array( 'method' => 'get',
 34+ 'action' => $this->getTitle()->getLocalUrl(),
 35+ 'name' => 'uluser',
 36+ 'id' => 'mw-codeauthor-form1'
 37+ )
 38+ ) . Xml::openElement( 'fieldset' );
 39+
 40+ $additional = '';
 41+ if ( !$this->mUser )
 42+ $form .= Xml::element( 'legend', array(), wfMsg( 'code-author-dolink' ) );
 43+ else {
 44+ $form .= Xml::element( 'legend', array(), wfMsg( 'code-author-alterlink' ) );
 45+ $additional = Xml::openElement( 'fieldset' ) .
 46+ Xml::element( 'legend', array(), wfMsg( 'code-author-orunlink' ) ) .
 47+ Xml::submitButton( wfMsg( 'code-author-unlink' ), array( 'name' => 'unlink' ) ) .
 48+ Xml::closeElement( 'fieldset' );
 49+ }
 50+
 51+ $form .= Xml::inputLabel( wfMsg( 'code-author-name' ), 'linktouser', 'username', 30, '') . ' ' .
 52+ Xml::submitButton( wfMsg( 'ok' ), array( 'name' => 'newname') ) .
 53+ Xml::closeElement( 'fieldset' ) .
 54+ $additional .
 55+ Xml::closeElement( 'form' ) . "\n";
 56+
 57+ $wgOut->addHtml( $this->linkStatus() . $form );
 58+ }
 59+
 60+ /*
 61+ * Link the author to the wikiuser $name
 62+ */
 63+ function linkTo ( $name ) {
 64+ global $wgOut, $wgUser;
 65+
 66+ if( $name == '' ) {
 67+ $wgOut->addWikiMsg( 'nouserspecified' );
 68+ return;
 69+ }
 70+ $user = User::newFromName( $name );
 71+
 72+ if( !$user || $user->isAnon() ) {
 73+ $wgOut->addWikiMsg( 'nosuchusershort', $name );
 74+ return;
 75+ }
 76+ $dbw = wfGetDB( DB_MASTER );
 77+ if ( !$this->mUser )
 78+ $dbw->insert(
 79+ 'code_authors',
 80+ array(
 81+ 'ca_repo_id' => $this->mRepo->getId(),
 82+ 'ca_author' => $this->mAuthor,
 83+ 'ca_user_text' => $user->getName()
 84+ ),
 85+ __METHOD__
 86+ );
 87+ else
 88+ $dbw->update(
 89+ 'code_authors',
 90+ array( 'ca_user_text' => $user->getName()),
 91+ array(
 92+ 'ca_repo_id' => $this->mRepo->getId(),
 93+ 'ca_author' => $this->mAuthor,
 94+ ),
 95+ __METHOD__
 96+ );
 97+
 98+ $repo = $this->mRepo->getName();
 99+ $author = SpecialPage::getTitleFor( 'Code', "$repo/author/$auth");
 100+ $authorlink = $this->mSkin->link( $author, $this->mAuthor);
 101+ $userlink = $this->mSkin->userLink( $user->getId(), $user->getName() );
 102+
 103+ parent::$userLinks[$this->mAuthor] = $user;
 104+
 105+ $wgOut->addHtml(
 106+ '<div class="successbox">' .
 107+ wfMsgHtml( 'code-author-success', $authorlink, $userlink) .
 108+ '</div>'
 109+ );
 110+ }
 111+
 112+ function unlink() {
 113+ global $wgOut;
 114+ if ( !$this->mUser ) {
 115+ $wgOut->addHtml( wfMsg( 'code-author-orphan' ) );
 116+ return;
 117+ }
 118+ $dbw = wfGetDB( DB_MASTER );
 119+ $dbw->delete(
 120+ 'code_authors',
 121+ array(
 122+ 'ca_repo_id' => $this->mRepo->getId(),
 123+ 'ca_author' => $this->mAuthor,
 124+ ),
 125+ __METHOD__
 126+ );
 127+
 128+ parent::$userLinks[$this->mAuthor] = false;
 129+
 130+ $wgOut->addHtml(
 131+ '<div class="successbox">' .
 132+ wfMsgHtml( 'code-author-unlinksuccess' ) .
 133+ '</div>'
 134+ );
 135+ }
 136+}
Property changes on: trunk/extensions/CodeReview/CodeRevisionAuthorLink.php
___________________________________________________________________
Added: svn:eol-style
1137 + native
Index: trunk/extensions/CodeReview/CodeReview.php
@@ -44,6 +44,7 @@
4545 $wgAutoloadClasses['CodeRepoListView'] = $dir . 'CodeRepoListView.php';
4646 $wgAutoloadClasses['CodeRevision'] = $dir . 'CodeRevision.php';
4747 $wgAutoloadClasses['CodeRevisionAuthorView'] = $dir . 'CodeRevisionAuthorView.php';
 48+$wgAutoloadClasses['CodeRevisionAuthorLink'] = $dir . 'CodeRevisionAuthorLink.php';
4849 $wgAutoloadClasses['CodeRevisionListView'] = $dir . 'CodeRevisionListView.php';
4950 $wgAutoloadClasses['CodeRevisionStatusSetter'] = $dir . 'CodeRevisionStatusSetter.php';
5051 $wgAutoloadClasses['CodeRevisionStatusView'] = $dir . 'CodeRevisionStatusView.php';
Index: trunk/extensions/CodeReview/CodeRevisionAuthorView.php
@@ -4,91 +4,38 @@
55 function __construct( $repoName, $author ) {
66 parent::__construct( $repoName );
77 $this->mAuthor = $author;
 8+ $this->mUser = $this->authorWikiUser( $author );
89 }
910
1011 function getPager() {
1112 return new SvnRevAuthorTablePager( $this, $this->mAuthor );
1213 }
1314
 15+ function linkStatus() {
 16+ if ( !$this->mUser )
 17+ return wfMsg( 'code-author-orphan' );
 18+
 19+ return wfMsgHtml( 'code-author-haslink',
 20+ $this->mSkin->userLink( $this->mUser->getId(), $this->mUser->getName() ) .
 21+ $this->mSkin->userToolLinks( $this->mUser->getId(), $this->mUser->getName() ) );
 22+ }
 23+
1424 function execute() {
15 - global $wgOut, $wgUser, $wgRequest;
 25+ global $wgOut, $wgUser;
1626
17 - $name = $wgRequest->getVal( 'user' );
 27+ $linkInfo = $this->linkStatus();
1828
19 - if ( $name ) {
20 - $this->linkTo( $name );
21 - return;
 29+ if ( $wgUser->isAllowed( 'codereview-link-user' ) ) {
 30+ $repo = $this->mRepo->getName();
 31+ $page = SpecialPage::getTitleFor( 'Code', "$repo/author/$this->mAuthor/link");
 32+ $linkInfo .= ' (' . $this->mSkin->link( $page, wfMsg( 'code-author-' . ($this->mUser?'un':'') . 'link') ) . ')' ;
2233 }
2334
24 - $user = $this->authorWikiUser( $this->mAuthor );
25 - if ( $user ) {
26 - $auth = wfMsgHtml( 'code-author-haslink',
27 - $this->mSkin->userLink( $user->getId(), $user->getName() ) .
28 - $this->mSkin->userToolLinks( $user->getId(), $user->getName() )
29 - );
30 - $wgOut->addHtml($auth);
31 - }
 35+ $wgOut->addHtml($linkInfo);
3236
3337 parent::execute();
34 -
35 - if ( $wgUser->isAllowed( 'codereview-link-user' ) && !$user ) {
36 - $wgOut->addHtml(
37 - Xml::openElement( 'form',
38 - array( 'method' => 'get',
39 - 'action' => $this->getPager()->getTitle()->getLocalUrl(),
40 - 'name' => 'uluser',
41 - 'id' => 'mw-codeauthor-form1'
42 - )
43 - ) .
44 - Xml::openElement( 'fieldset' ) .
45 - Xml::element( 'legend', array(), wfMsg( 'code-author-dolink' ) ) .
46 - Xml::inputLabel( wfMsg( 'code-author-name' ), 'user', 'username', 30, '') . ' ' .
47 - Xml::submitButton( wfMsg( 'ok' ) ) .
48 - Xml::closeElement( 'fieldset' ) .
49 - Xml::closeElement( 'form' ) . "\n"
50 - );
51 - }
5238 }
53 -
54 - /*
55 - * Link the author to the wikiuser $name
56 - */
57 - function linkTo ( $name ) {
58 - global $wgOut, $wgUser;
5939
60 - if ( !$wgUser->isAllowed( 'codereview-link-user' ) ) {
61 - $wgOut->permissionRequired( 'codereview-link-user' );
62 - return;
63 - }
64 -
65 - if( $name == '' ) {
66 - $wgOut->addWikiMsg( 'nouserspecified' );
67 - return;
68 - }
69 - $user = User::newFromName( $name );
70 -
71 - if( !$user || $user->isAnon() ) {
72 - $wgOut->addWikiMsg( 'nosuchusershort', $name );
73 - return;
74 - }
75 - $dbw = wfGetDB( DB_MASTER );
76 - $dbw->insert(
77 - 'code_authors',
78 - array(
79 - 'ca_repo_id' => $this->mRepo->getId(),
80 - 'ca_author' => $this->mAuthor,
81 - 'ca_user_text' => $user->getName()
82 - ),
83 - __METHOD__
84 - );
85 - $authorlink = $this->mSkin->link( $this->getPager()->getTitle(), $this->mAuthor);
86 - $userlink = $this->mSkin->userLink( $user->getId(), $user->getName() );
87 - $wgOut->addHtml(
88 - '<div class="successbox">' .
89 - wfMsgHtml( 'code-author-success', $authorlink, $userlink) .
90 - '</div>'
91 - );
92 - }
9340 }
9441
9542 class SvnRevAuthorTablePager extends SvnRevTablePager {
Index: trunk/extensions/CodeReview/CodeReview.i18n.php
@@ -14,9 +14,15 @@
1515 'code-desc' => '[[Special:Code|Code review tool]] with [[Special:RepoAdmin|Subversion support]]',
1616 'code-no-repo' => 'No repository configured!',
1717 'code-author-haslink' => 'This author is linked to the wikiuser $1',
 18+ 'code-author-orphan' => 'This author has no wiki account linked to him',
1819 'code-author-dolink' => 'Link this author to a wiki user :',
 20+ 'code-author-alterlink' => 'Change the wiki user linked to this author:',
 21+ 'code-author-orunlink' => 'Or unlink this wiki user :',
1922 'code-author-name' => 'Enter a username:',
2023 'code-author-success' => 'The author $1 has been successfully linked to the wiki user $2',
 24+ 'code-author-link' => 'link ?',
 25+ 'code-author-unlink' => 'unlink ?',
 26+ 'code-author-unlinksuccess' => 'Author has been successfully orphaned',
2127 'code-field-id' => 'Revision',
2228 'code-field-author' => 'Author',
2329 'code-field-message' => 'Comment',
Index: trunk/extensions/CodeReview/SpecialCode.php
@@ -62,6 +62,10 @@
6363 break;
6464 }
6565 case 4:
 66+ if ( $params[1] == 'author' && $params[3] == 'link') {
 67+ $view = new CodeRevisionAuthorLink( $params[0], $params[2] );
 68+ break;
 69+ }
6670 default:
6771 if( $params[2] == 'reply' ) {
6872 $view = new CodeRevisionView( $params[0], $params[1], $params[3] );
@@ -85,6 +89,7 @@
8690 */
8791 abstract class CodeView {
8892 var $mRepo;
 93+ static $userLinks = array();
8994
9095 function __construct() {
9196 global $wgUser;
@@ -105,9 +110,8 @@
106111 * of false
107112 */
108113 function authorWikiUser( $author ) {
109 - static $userLinks = array();
110 - if( isset( $userLinks[$author] ) )
111 - return $userLinks[$author];
 114+ if( isset( self::$userLinks[$author] ) )
 115+ return self::$userLinks[$author];
112116
113117 $dbr = wfGetDB( DB_SLAVE );
114118 $wikiUser = $dbr->selectField(
@@ -126,7 +130,7 @@
127131 $res = $user;
128132 else
129133 $res = false;
130 - return $userLinks[$author] = $res;
 134+ return self::$userLinks[$author] = $res;
131135 }
132136
133137 function authorLink( $author ) {

Comments

#Comment by Brion VIBBER (talk | contribs)   21:57, 15 October 2008

This still violates the model/view separation by performing direct database manipulation in the view class; I'd prefer to pull that out to CodeRepository.

#Comment by Brion VIBBER (talk | contribs)   01:25, 24 October 2008

i believe that got fixed up

Status & tagging log