r70930 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70929‎ | r70930 | r70931 >
Date:08:38, 12 August 2010
Author:mgrabovsky
Status:ok (Comments)
Tags:
Comment:
TitleBlacklist extension fixes:
* fixed user creation error when user name was invalid title in main namespace;
* fixed error message rendering when creating user with invalid name;
* employed the Html class;
* made code a little more consistent.
Modified paths:
  • /trunk/extensions/TitleBlacklist/TitleBlacklist.hooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TitleBlacklist/TitleBlacklist.hooks.php
@@ -61,32 +61,28 @@
6262 *
6363 * @return bool Acceptable
6464 */
65 - private static function acceptNewUserName( $userName, &$message ) {
 65+ private static function acceptNewUserName( $userName, &$err ) {
6666 global $wgTitleBlacklist;
6767 efInitTitleBlacklist();
68 - $title = Title::newFromText( $userName );
 68+ $title = Title::newFromText( $userName, NS_USER );
6969 $blacklisted = $wgTitleBlacklist->isBlacklisted( $title, 'new-account' );
7070 if( !( $blacklisted instanceof TitleBlacklistEntry ) )
7171 $blacklisted = $wgTitleBlacklist->isBlacklisted( $title, 'create' );
7272 if( $blacklisted instanceof TitleBlacklistEntry ) {
7373 wfLoadExtensionMessages( 'TitleBlacklist' );
7474 $message = $blacklisted->getCustomMessage();
75 - if( is_null( $message ) )
76 - $message = wfMsgWikiHtml( 'titleblacklist-forbidden-new-account',
77 - $blacklisted->getRaw(),
78 - $userName );
79 - $result = array( $message,
80 - htmlspecialchars( $blacklisted->getRaw() ),
81 - $title->getFullText() );
 75+ if ( is_null( $message ) )
 76+ $message = 'titleblacklist-forbidden-new-account';
 77+ $err = wfMsgWikiHtml( $message, $blacklisted->getRaw(), $userName );
8278 return false;
8379 }
8480 return true;
8581 }
8682
8783 /** AbortNewAccount hook */
88 - public static function abortNewAccount($user, &$message) {
 84+ public static function abortNewAccount( $user, &$message ) {
8985 global $wgUser;
90 - if ( $wgUser->isAllowed( 'tboverride' ) )
 86+ if( $wgUser->isAllowed( 'tboverride' ) )
9187 return true;
9288 return self::acceptNewUserName( $user->getName(), $message );
9389 }
@@ -96,7 +92,7 @@
9793 $message = ''; # Will be ignored
9894 return self::acceptNewUserName( $userName, $message );
9995 }
100 -
 96+
10197 /** EditFilter hook */
10298 public static function validateBlacklist( $editor, $text, $section, $error ) {
10399 global $wgTitleBlacklist;
@@ -113,28 +109,28 @@
114110 wfLoadExtensionMessages( 'TitleBlacklist' );
115111 $errmsg = wfMsgExt( 'titleblacklist-invalid', array( 'parsemag' ), count( $ok ) );
116112 $errlines = '* <tt>' . implode( "</tt>\n* <tt>", array_map( 'wfEscapeWikiText', $ok ) ) . '</tt>';
117 - $error = '<div class="errorbox">' .
 113+ $error = Html::openElement( 'div', array( 'class' => 'errorbox' ) ) .
118114 $errmsg .
119115 "\n" .
120116 $errlines .
121 - "</div>\n" .
122 - "<br clear='all' />\n";
123 -
 117+ Html::closeElement( 'div' ) . "\n" .
 118+ Html::element( 'br', array( 'clear' => 'all' ) ) . "\n";
 119+
124120 // $error will be displayed by the edit class
125121 return true;
126 - } else if (!$section) {
 122+ } elseif( !$section ) {
127123 # Block redirects to nonexistent blacklisted titles
128124 $retitle = Title::newFromRedirect( $text );
129 - if ( $retitle !== null && !$retitle->exists() ) {
 125+ if( $retitle !== null && !$retitle->exists() ) {
130126 $blacklisted = $wgTitleBlacklist->isBlacklisted( $retitle, 'create' );
131 - if ( $blacklisted instanceof TitleBlacklistEntry ) {
 127+ if( $blacklisted instanceof TitleBlacklistEntry ) {
132128 wfLoadExtensionMessages( 'TitleBlacklist' );
133 - $error = ( '<div class="errorbox">' .
134 - wfMsg( 'titleblacklist-forbidden-edit',
135 - htmlspecialchars( $blacklisted->getRaw() ),
136 - $retitle->getFullText() ) .
137 - "</div>\n" .
138 - "<br clear='all' />\n" );
 129+ $error = Html::openElement( 'div', array( 'class' => 'errorbox' ) ) .
 130+ wfMsg( 'titleblacklist-forbidden-edit',
 131+ htmlspecialchars( $blacklisted->getRaw() ),
 132+ $retitle->getFullText() ) .
 133+ Html::closeElement( 'div' ) . "\n" .
 134+ Html::element( 'br', array( 'clear' => 'all' ) ) . "\n";
139135 }
140136 }
141137
@@ -142,10 +138,11 @@
143139 }
144140 return true;
145141 }
146 -
 142+
147143 /** ArticleSaveComplete hook */
148144 public static function clearBlacklist( &$article, &$user,
149 - $text, $summary, $isminor, $iswatch, $section ) {
 145+ $text, $summary, $isminor, $iswatch, $section )
 146+ {
150147 $title = $article->getTitle();
151148 if( $title->getNamespace() == NS_MEDIAWIKI && $title->getDBkey() == 'Titleblacklist' ) {
152149 global $wgTitleBlacklist;

Follow-up revisions

RevisionCommit summaryAuthorDate
r70932Followup r70930: drop wfLoadExtensionMessages(), use makeTitleSafe() instead ...catrope09:28, 12 August 2010
r709331.16wmf4: Functional merge of r70390, r70392 (real merge causes a mess becaus...catrope09:33, 12 August 2010

Comments

#Comment by Nikerabbit (talk | contribs)   09:25, 12 August 2010
wfLoadExtensionMessages( 'TitleBlacklist' );

You can remove these too.

+$title = Title::newFromText( $userName, NS_USER );

Use Title::makeTitleSafe if you want to force User-namespace. Otherwise it's just the default which can be overridden by the $userName itself.

#Comment by The Evil IP address (talk | contribs)   17:24, 13 August 2010

Not yet a big thing, but Html::element( 'br', array( 'clear' => 'all' ) ) . "\n"; should be Html::element( 'br', array( 'style' => 'clear: both;' ) ) . "\n";, since the clear attribute will be removed in HTML 5.

#Comment by Simetrical (talk | contribs)   17:26, 13 August 2010

Presentational usage of <br> is illegal per HTML5 to begin with. It should be done with CSS, like maybe in the rule for div.errorbox.

Status & tagging log