r92141 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92140‎ | r92141 | r92142 >
Date:06:27, 14 July 2011
Author:robin
Status:ok (Comments)
Tags:
Comment:
Babel: (bug 29663) Babel doesn't validate babel-autocreate-user message -> do nothing if the username is invalid. Also, do not create categories if the user is blocked.
NewUserMessage: Fix fatal error when username is invalid. Instead, do nothing.
Modified paths:
  • /trunk/extensions/Babel/Babel.php (modified) (history)
  • /trunk/extensions/Babel/BabelAutoCreate.class.php (modified) (history)
  • /trunk/extensions/NewUserMessage/NewUserMessage.class.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Babel/Babel.php
@@ -21,7 +21,7 @@
2222 $wgExtensionCredits['parserhook'][] = array(
2323 'path' => __FILE__,
2424 'name' => 'Babel',
25 - 'version' => '1.7.0',
 25+ 'version' => '1.7.1',
2626 'author' => 'Robert Leverington',
2727 'url' => 'http://www.mediawiki.org/wiki/Extension:Babel',
2828 'descriptionmsg' => 'babel-desc',
Index: trunk/extensions/Babel/BabelAutoCreate.class.php
@@ -38,12 +38,19 @@
3939 $text = wfMsgForContent( 'babel-autocreate-text-levels', $level, $language );
4040 }
4141 $article = new Article( $title );
 42+
 43+ $user = self::user();
 44+ # Do not add a message if the username is invalid or if the account that adds it, is blocked
 45+ if( !$user || $user->isBlocked() ) {
 46+ return;
 47+ }
 48+
4249 $article->doEdit(
4350 $text,
4451 wfMsgForContent( 'babel-autocreate-reason', wfMsgForContent( 'babel-url' ) ),
4552 EDIT_FORCE_BOT,
4653 false,
47 - self::user()
 54+ $user
4855 );
4956 }
5057
@@ -54,8 +61,8 @@
5562 */
5663 public static function user() {
5764 if ( !self::$user ) {
58 - self::$user = User::newFromName( wfMsgForContent( 'babel-autocreate-user' ), false );
59 - if ( !self::$user->isLoggedIn() ) {
 65+ self::$user = User::newFromName( wfMsgForContent( 'babel-autocreate-user' ) );
 66+ if ( self::$user && !self::$user->isLoggedIn() ) {
6067 self::$user->addToDatabase();
6168 }
6269 }
Index: trunk/extensions/NewUserMessage/NewUserMessage.class.php
@@ -23,6 +23,11 @@
2424 // Create a user object for the editing user and add it to the
2525 // database if it is not there already
2626 $editor = User::newFromName( wfMsgForContent( 'newusermessage-editor' ) );
 27+
 28+ if( !$editor ) {
 29+ return false; # Invalid user name
 30+ }
 31+
2732 if ( !$editor->isLoggedIn() ) {
2833 $editor->addToDatabase();
2934 }
@@ -157,8 +162,8 @@
158163 $editor = self::fetchEditor();
159164 $flags = self::fetchFlags();
160165
161 - # Do not add a message if the account that adds it, is blocked
162 - if( $editor->isBlocked() ) {
 166+ # Do not add a message if the username is invalid or if the account that adds it, is blocked
 167+ if( !$editor || $editor->isBlocked() ) {
163168 return true;
164169 }
165170

Follow-up revisions

RevisionCommit summaryAuthorDate
r94210Add 0 to new Article() per r92141 comment and [[User:Catrope/Extension review...robin22:50, 10 August 2011

Comments

#Comment by Nikerabbit (talk | contribs)   07:58, 14 July 2011

If this code has any chance of being executed during web requests, it needs zero as second parameter to Article constructor.

$article = new Article( $title );
#Comment by Bawolff (talk | contribs)   19:43, 17 August 2011

I thnk this is using the wrong level of username validation. - Since category creation is a batch process, you should probably be doing valid User::newFromName( wfMsgForContent( 'babel-autocreate-user' ), 'valid' ) . See the docs for User::GetCanonicalName.


Not an issue with this commit, but since its touching this area of code I thought I'd mention, I don't think calling $article->doEdit while in the middle of parsing something is ok (I think it calls the parser recursively, which causes weird stuff to happen, like UNIQ everywhere)

#Comment by SPQRobin (talk | contribs)   22:14, 4 September 2011

Re validation: "true is accepted as an alias for 'valid', for BC." if ( $validate === true ) { $validate = 'valid'; } So 'valid' would've be better but it doesn't make any difference.

Re doEdit: That's bug 29245, which you explained there indeed.

#Comment by Bawolff (talk | contribs)   12:12, 5 September 2011

Oh whoops. For some reason I thought the default level was usable. Please ignore my comment then :)

Status & tagging log