r41594 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41593‎ | r41594 | r41595 >
Date:09:21, 3 October 2008
Author:nicdumz
Status:old (Comments)
Tags:
Comment:
Add the ability for users with the 'codereview-link-user' permission to link an author to a wiki user from Special:Code/mediawiki/author/xx
If the author is linked, a notice is printed at the top of the same page
Modified paths:
  • /trunk/extensions/CodeReview/CodeReview.i18n.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeReview.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeRevisionAuthorView.php (modified) (history)
  • /trunk/extensions/CodeReview/SpecialCode.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/CodeReview.php
@@ -72,11 +72,13 @@
7373 $wgAvailableRights[] = 'codereview-remove-tag';
7474 $wgAvailableRights[] = 'codereview-post-comment';
7575 $wgAvailableRights[] = 'codereview-set-status';
 76+$wgAvailableRights[] = 'codereview-link-user';
7677
7778 $wgGroupPermissions['*']['codereview-add-tag'] = true;
7879 $wgGroupPermissions['*']['codereview-remove-tag'] = true;
7980 $wgGroupPermissions['*']['codereview-post-comment'] = true;
8081 $wgGroupPermissions['*']['codereview-set-status'] = true;
 82+$wgGroupPermissions['*']['codereview-link-user'] = true;
8183
8284 $wgGroupPermissions['steward']['repoadmin'] = true; // temp
8385
Index: trunk/extensions/CodeReview/CodeRevisionAuthorView.php
@@ -9,6 +9,86 @@
1010 function getPager() {
1111 return new SvnRevAuthorTablePager( $this, $this->mAuthor );
1212 }
 13+
 14+ function execute() {
 15+ global $wgOut, $wgUser, $wgRequest;
 16+
 17+ $name = $wgRequest->getVal( 'user' );
 18+
 19+ if ( $name ) {
 20+ $this->linkTo( $name );
 21+ return;
 22+ }
 23+
 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+ }
 32+
 33+ 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+ }
 53+
 54+ /*
 55+ * Link the author to the wikiuser $name
 56+ */
 57+ function linkTo ( $name ) {
 58+ global $wgOut, $wgUser;
 59+
 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+ }
1393 }
1494
1595 class SvnRevAuthorTablePager extends SvnRevTablePager {
Index: trunk/extensions/CodeReview/CodeReview.i18n.php
@@ -13,6 +13,10 @@
1414 'code-comments' => 'Comments',
1515 'code-desc' => '[[Special:Code|Code review tool]] with [[Special:RepoAdmin|Subversion support]]',
1616 'code-no-repo' => 'No repository configured!',
 17+ 'code-author-haslink' => 'This author is linked to the wikiuser $1',
 18+ 'code-author-dolink' => 'Link this author to a wiki user :',
 19+ 'code-author-name' => 'Enter a username:',
 20+ 'code-author-success' => 'The author $1 has been successfully linked to the wiki user $2',
1721 'code-field-id' => 'Revision',
1822 'code-field-author' => 'Author',
1923 'code-field-message' => 'Comment',
@@ -253,6 +257,9 @@
254258 'code' => 'Vérification du code',
255259 'code-comments' => 'Commentaires',
256260 'code-desc' => '[[Special:Code|Outils pour revoir le code]] avec [[Special:RepoAdmin|support de Subversion]]',
 261+ 'code-author-haslink' => 'Cet auteur est lié au compte $1 de ce wiki',
 262+ 'code-author-dolink' => 'Associer cet auteur à un compte wiki local :',
 263+ 'code-author-name' => 'Entrez un nom d\'utilisateur :',
257264 'code-no-repo' => 'Pas de dépôt configuré !',
258265 'code-field-id' => 'Révision',
259266 'code-field-author' => 'Auteur',
Index: trunk/extensions/CodeReview/SpecialCode.php
@@ -90,9 +90,11 @@
9191
9292 abstract function execute();
9393
94 - function authorLink( $author ) {
95 - /*
96 - // Leave this for later for now...
 94+ /*
 95+ * returns a User object if $author has a wikiuser associated,
 96+ * of false
 97+ */
 98+ function authorWikiUser( $author ) {
9799 static $userLinks = array();
98100 if( isset( $userLinks[$author] ) )
99101 return $userLinks[$author];
@@ -111,12 +113,13 @@
112114 if( $wikiUser )
113115 $user = User::newFromName( $wikiUser );
114116 if( $user instanceof User )
115 - $link = $author . ' (' . $this->mSkin->userLink( $user->getId(), $user->getName() ) . ')';
 117+ $res = $user;
116118 else
117 - $link = htmlspecialchars( $author );
118 - return $userLinks[$author] = $link;
119 - */
120 -
 119+ $res = false;
 120+ return $userLinks[$author] = $res;
 121+ }
 122+
 123+ function authorLink( $author ) {
121124 $repo = $this->mRepo->getName();
122125 $special = SpecialPage::getTitleFor( 'Code', "$repo/author/$author" );
123126 return $this->mSkin->link( $special, htmlspecialchars( $author ) );

Comments

#Comment by Brion VIBBER (talk | contribs)   23:09, 3 October 2008

Hmmm, two problems:

1) The "link this author" mini-form is at the bottom of the revision list, where I'm never going to see it. :) It should be moved to the top.

2) There doesn't seem to be an interface to *un*-link them, say if I put in the wrong (but a valid) username, or need to swap to a person's newer account etc.

And as a nit, the author name should get htmlspecialchar()'d in the link() call; I'm not sure of the validation rules for SVN usernames, so who knows what it might contain. ;)

#Comment by NicDumZ (talk | contribs)   11:25, 4 October 2008

see Special:Code/MediaWiki/41641 improving the system.

Status & tagging log