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 |
1 | 137 | + native |
Index: trunk/extensions/CodeReview/CodeReview.php |
— | — | @@ -44,6 +44,7 @@ |
45 | 45 | $wgAutoloadClasses['CodeRepoListView'] = $dir . 'CodeRepoListView.php'; |
46 | 46 | $wgAutoloadClasses['CodeRevision'] = $dir . 'CodeRevision.php'; |
47 | 47 | $wgAutoloadClasses['CodeRevisionAuthorView'] = $dir . 'CodeRevisionAuthorView.php'; |
| 48 | +$wgAutoloadClasses['CodeRevisionAuthorLink'] = $dir . 'CodeRevisionAuthorLink.php'; |
48 | 49 | $wgAutoloadClasses['CodeRevisionListView'] = $dir . 'CodeRevisionListView.php'; |
49 | 50 | $wgAutoloadClasses['CodeRevisionStatusSetter'] = $dir . 'CodeRevisionStatusSetter.php'; |
50 | 51 | $wgAutoloadClasses['CodeRevisionStatusView'] = $dir . 'CodeRevisionStatusView.php'; |
Index: trunk/extensions/CodeReview/CodeRevisionAuthorView.php |
— | — | @@ -4,91 +4,38 @@ |
5 | 5 | function __construct( $repoName, $author ) { |
6 | 6 | parent::__construct( $repoName ); |
7 | 7 | $this->mAuthor = $author; |
| 8 | + $this->mUser = $this->authorWikiUser( $author ); |
8 | 9 | } |
9 | 10 | |
10 | 11 | function getPager() { |
11 | 12 | return new SvnRevAuthorTablePager( $this, $this->mAuthor ); |
12 | 13 | } |
13 | 14 | |
| 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 | + |
14 | 24 | function execute() { |
15 | | - global $wgOut, $wgUser, $wgRequest; |
| 25 | + global $wgOut, $wgUser; |
16 | 26 | |
17 | | - $name = $wgRequest->getVal( 'user' ); |
| 27 | + $linkInfo = $this->linkStatus(); |
18 | 28 | |
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') ) . ')' ; |
22 | 33 | } |
23 | 34 | |
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); |
32 | 36 | |
33 | 37 | 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 | | - } |
52 | 38 | } |
53 | | - |
54 | | - /* |
55 | | - * Link the author to the wikiuser $name |
56 | | - */ |
57 | | - function linkTo ( $name ) { |
58 | | - global $wgOut, $wgUser; |
59 | 39 | |
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 | | - } |
93 | 40 | } |
94 | 41 | |
95 | 42 | class SvnRevAuthorTablePager extends SvnRevTablePager { |
Index: trunk/extensions/CodeReview/CodeReview.i18n.php |
— | — | @@ -14,9 +14,15 @@ |
15 | 15 | 'code-desc' => '[[Special:Code|Code review tool]] with [[Special:RepoAdmin|Subversion support]]', |
16 | 16 | 'code-no-repo' => 'No repository configured!', |
17 | 17 | 'code-author-haslink' => 'This author is linked to the wikiuser $1', |
| 18 | + 'code-author-orphan' => 'This author has no wiki account linked to him', |
18 | 19 | '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 :', |
19 | 22 | 'code-author-name' => 'Enter a username:', |
20 | 23 | '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', |
21 | 27 | 'code-field-id' => 'Revision', |
22 | 28 | 'code-field-author' => 'Author', |
23 | 29 | 'code-field-message' => 'Comment', |
Index: trunk/extensions/CodeReview/SpecialCode.php |
— | — | @@ -62,6 +62,10 @@ |
63 | 63 | break; |
64 | 64 | } |
65 | 65 | case 4: |
| 66 | + if ( $params[1] == 'author' && $params[3] == 'link') { |
| 67 | + $view = new CodeRevisionAuthorLink( $params[0], $params[2] ); |
| 68 | + break; |
| 69 | + } |
66 | 70 | default: |
67 | 71 | if( $params[2] == 'reply' ) { |
68 | 72 | $view = new CodeRevisionView( $params[0], $params[1], $params[3] ); |
— | — | @@ -85,6 +89,7 @@ |
86 | 90 | */ |
87 | 91 | abstract class CodeView { |
88 | 92 | var $mRepo; |
| 93 | + static $userLinks = array(); |
89 | 94 | |
90 | 95 | function __construct() { |
91 | 96 | global $wgUser; |
— | — | @@ -105,9 +110,8 @@ |
106 | 111 | * of false |
107 | 112 | */ |
108 | 113 | 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]; |
112 | 116 | |
113 | 117 | $dbr = wfGetDB( DB_SLAVE ); |
114 | 118 | $wikiUser = $dbr->selectField( |
— | — | @@ -126,7 +130,7 @@ |
127 | 131 | $res = $user; |
128 | 132 | else |
129 | 133 | $res = false; |
130 | | - return $userLinks[$author] = $res; |
| 134 | + return self::$userLinks[$author] = $res; |
131 | 135 | } |
132 | 136 | |
133 | 137 | function authorLink( $author ) { |