r20386 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r20385‎ | r20386 | r20387 >
Date:12:19, 13 March 2007
Author:daniel
Status:old
Tags:
Comment:
UNTESTED: UsernameBlacklist robustness fixes by robchurch (see http://mediawiki.pastey.net/8204)
Modified paths:
  • /trunk/extensions/UsernameBlacklist/README (modified) (history)
  • /trunk/extensions/UsernameBlacklist/UsernameBlacklist.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UsernameBlacklist/README
@@ -1,7 +1,7 @@
22 USERNAME BLACKLIST EXTENSION
33
44 Version 1.6
5 - © 2006 Rob Church
 5+ © 2006-2007 Rob Church
66
77 This is free software licensed under the GNU General Public License. Please
88 see http://www.gnu.org/copyleft/gpl.html for further details, including the
@@ -58,8 +58,9 @@
5959 The example above would prevent creation of the user account "Foo", and any
6060 account where the username contains "Bar" or "bar".
6161
62 -You can comment out lines with #; this is useful for adding explanation as to
63 -what a complicated regular expression will block, or for providing reasons.
 62+Lines without the list token (*) will be ignored when constructing the
 63+regular expression, which allows for adding comments or other explanations
 64+to the message page.
6465
6566 == 5. Customising Warning Messages ==
6667
@@ -112,10 +113,13 @@
113114 1.6
114115 Support multiple language translations
115116
 117+1.7
 118+ Ignore all non-list lines when constructing the regular expression
 119+
116120 == 8. Thanks... ==
117121
118122 * Avar; whose other extensions provide better reference than the docs
119123 * To the poster on mediawiki-l who inspired it
120124 * Brion, for fixing a couple of bugs
121125
122 - All feedback welcome via <robchur@gmail.com>.
\ No newline at end of file
 126+ All feedback welcome via <robchur@gmail.com>.
Index: trunk/extensions/UsernameBlacklist/UsernameBlacklist.php
@@ -5,7 +5,7 @@
66 *
77 * @author Rob Church <robchur@gmail.com>
88 * @addtogroup Extensions
9 - * @copyright © 2006 Rob Church
 9+ * @copyright © 2006-2007 Rob Church
1010 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0
1111 */
1212
@@ -86,12 +86,13 @@
8787 }
8888
8989 /**
90 - * Is the supplied text a comment?
91 - * @param $text Text to check
 90+ * Is the supplied text an appropriate fragment to include?
 91+ *
 92+ * @param string $text Text to validate
9293 * @return bool
9394 */
94 - function isComment( $text ) {
95 - return substr( $this->transform( $text ), 0, 1 ) == '#';
 95+ function isUsable( $text ) {
 96+ return substr( $text, 0, 1 ) == '*';
9697 }
9798
9899 /**
@@ -122,8 +123,8 @@
123124 if( $blacklist != '&lt;usernameblacklist&gt;' ) {
124125 $lines = explode( "\n", $blacklist );
125126 foreach( $lines as $line ) {
126 - $line = rtrim( $line );
127 - if( !empty( $line ) && !$this->isComment( $line ) )
 127+ $line = trim( $line );
 128+ if( $this->isUsable( $line ) )
128129 $groups[] = $this->transform( $line );
129130 }
130131 return count( $groups ) ? '/(' . implode( '|', $groups ) . ')/u' : false;