r62241 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62240‎ | r62241 | r62242 >
Date:13:08, 10 February 2010
Author:churchofemacs
Status:resolved (Comments)
Tags:
Comment:
showLogExtract of block log on user (talk) pages of blocked users
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -1208,7 +1208,7 @@
12091209 public function showMissingArticle() {
12101210 global $wgOut, $wgRequest, $wgUser;
12111211
1212 - # Show info in user (talk) namespace. Does the user exist?
 1212+ # Show info in user (talk) namespace. Does the user exist? Is he blocked?
12131213 if ( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
12141214 $parts = explode( '/', $this->mTitle->getText() );
12151215 $rootPart = $parts[0];
@@ -1217,6 +1217,21 @@
12181218 if ( $id == 0 && !$ip ) { # User does not exist
12191219 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1</div>",
12201220 array( 'userpage-userdoesnotexist-view', $rootPart ) );
 1221+ } else if (User::newFromId($id)->isBlocked()) { # Show log extract if the user is currently blocked
 1222+ LogEventsList::showLogExtract(
 1223+ $wgOut,
 1224+ 'block',
 1225+ $this->mTitle->getSubjectPage()->getPrefixedText(),
 1226+ '',
 1227+ array(
 1228+ 'lim' => 1,
 1229+ 'showIfEmpty' => false,
 1230+ 'msgKey' => array(
 1231+ 'sp-contributions-blocked-notice',
 1232+ $this->mTitle->getSubjectPage()->getPrefixedText() # Support GENDER in notice
 1233+ )
 1234+ )
 1235+ );
12211236 }
12221237 }
12231238 wfRunHooks( 'ShowMissingArticle', array( $this ) );
Index: trunk/phase3/includes/EditPage.php
@@ -765,15 +765,31 @@
766766 $wgOut->wrapWikiMsg( "<div class='mw-editinginterface'>\n$1</div>", 'editinginterface' );
767767 }
768768
769 - # Show a warning message when someone creates/edits a user (talk) page but the user does not exists
 769+ # Show a warning message when someone creates/edits a user (talk) page but the user does not exist
 770+ # Show log extract when the user is currently blocked
770771 if ( $namespace == NS_USER || $namespace == NS_USER_TALK ) {
771772 $parts = explode( '/', $this->mTitle->getText(), 2 );
772773 $username = $parts[0];
773774 $id = User::idFromName( $username );
774775 $ip = User::isIP( $username );
775 - if ( $id == 0 && !$ip ) {
 776+ if ( $id == 0 && !$ip ) { # User does not exist
776777 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n$1</div>",
777778 array( 'userpage-userdoesnotexist', $username ) );
 779+ } else if (User::newFromId($id)->isBlocked()) { # Show log extract if the user is currently blocked
 780+ LogEventsList::showLogExtract(
 781+ $wgOut,
 782+ 'block',
 783+ $this->mTitle->getSubjectPage()->getPrefixedText(),
 784+ '',
 785+ array(
 786+ 'lim' => 1,
 787+ 'showIfEmpty' => false,
 788+ 'msgKey' => array(
 789+ 'sp-contributions-blocked-notice',
 790+ $this->mTitle->getSubjectPage()->getPrefixedText() # Support GENDER in notice
 791+ )
 792+ )
 793+ );
778794 }
779795 }
780796 # Try to add a custom edit intro, or use the standard one if this is not possible.

Follow-up revisions

RevisionCommit summaryAuthorDate
r62697LogExtract on blocked user's pages: fixing r62241 (see comments by Tim)churchofemacs10:37, 19 February 2010
r62714Adding references to r62241 and r62358 to release noteschurchofemacs18:36, 19 February 2010

Comments

#Comment by Tim Starling (talk | contribs)   06:41, 19 February 2010

Please read Manual:Coding conventions and follow the site style. This means putting spaces inside brackets, among other things.

To improve performance, especially on page views, please minimise the number of DB queries you make. User objects have a cache of relevant data and should be reused if possible. The query from User::idFromName() and the one from User::newFromId( $id ) can be combined into a single query:

$user = User::newFromName( $rootPart );
$exists = $user->isLoggedIn();
$isBlocked = $user->isBlocked();
'msgKey' => array(
	'sp-contributions-blocked-notice',

Reusing messages makes it difficult for translators when different text is required in different places. See i18n#Avoid_message_reuse. Please copy it instead.

$this->mTitle->getSubjectPage()->getPrefixedText()

I think you want $user->getUserPage->getPrefixedText() for the first one and $user->getName() for the second one. Same in both files.

#Comment by Church of emacs (talk | contribs)   10:39, 19 February 2010

Hi Tim, thanks for your comment. I fixed theses issues in r62697, I hope it's okay now :)

Status & tagging log