Index: trunk/phase3/includes/Parser.php |
— | — | @@ -3207,54 +3207,59 @@ |
3208 | 3208 | * @access private |
3209 | 3209 | */ |
3210 | 3210 | function getUserSig( &$user ) { |
3211 | | - $name = $user->getName(); |
3212 | | - $nick = trim( $user->getOption( 'nickname' ) ); |
3213 | | - if ( '' == $nick ) { |
3214 | | - $nick = $name; |
3215 | | - } |
| 3211 | + global $wgContLang; |
3216 | 3212 | |
| 3213 | + $username = $user->getName(); |
| 3214 | + $nickname = trim( $user->getOption( 'nickname' ) ); |
| 3215 | + $nickname = ( $nickname == '' ? $username : $nickname ); |
| 3216 | + |
3217 | 3217 | if( $user->getOption( 'fancysig' ) ) { |
3218 | | - // A wikitext signature. |
3219 | | - $valid = $this->validateSig( $nick ); |
3220 | | - if( $valid === false ) { |
3221 | | - // Fall back to default sig |
3222 | | - $nick = $name; |
| 3218 | + # Sig. might contain markup; validate this |
| 3219 | + if( $this->validateSig( $nickname ) ) { |
| 3220 | + # Validated; clean up (if needed) and return it |
| 3221 | + return( $this->cleanSig( $nick ) ); |
| 3222 | + } else { |
| 3223 | + # Failed to validate; fall back to the default |
| 3224 | + $nickname = $username; |
3223 | 3225 | wfDebug( "Parser::getUserSig: $name has bad XML tags in signature.\n" ); |
3224 | | - } else { |
3225 | | - return $nick; |
3226 | 3226 | } |
3227 | 3227 | } |
3228 | 3228 | |
3229 | | - // Plain text linking to the user's homepage |
3230 | | - global $wgContLang; |
3231 | | - $page = $user->getUserPage(); |
3232 | | - return '[[' . |
3233 | | - $page->getPrefixedText() . |
3234 | | - "|" . |
3235 | | - wfEscapeWikIText( $nick ) . |
3236 | | - "]]"; |
| 3229 | + # If we're still here, make it a link to the user page |
| 3230 | + $userpage = $user->getUserPage(); |
| 3231 | + return( '[[' . $userpage->getPrefixedText() . '|' . wfEscapeWikiText( $nickname ) . ']]' ); |
3237 | 3232 | } |
3238 | 3233 | |
3239 | 3234 | /** |
3240 | | - * We want to enforce two rules on wikitext sigs here: |
3241 | | - * 1) Expand any templates at save time (forced subst:) |
3242 | | - * 2) Check for unbalanced XML tags, and reject if so. |
| 3235 | + * Check that the user's signature contains no bad XML |
3243 | 3236 | * |
3244 | 3237 | * @param string $text |
3245 | 3238 | * @return mixed An expanded string, or false if invalid. |
3246 | | - * |
3247 | | - * @todo Run brace substitutions |
3248 | | - * @todo ?? Check for unbalanced '' and ''' quotes, etc |
3249 | 3239 | */ |
3250 | 3240 | function validateSig( $text ) { |
3251 | | - if( wfIsWellFormedXmlFragment( $text ) ) { |
3252 | | - return $text; |
3253 | | - } else { |
3254 | | - return false; |
3255 | | - } |
| 3241 | + return( wfIsWellFormedXmlFragment( $text ) ? $text : false ); |
3256 | 3242 | } |
3257 | | - |
| 3243 | + |
3258 | 3244 | /** |
| 3245 | + * Clean up signature text |
| 3246 | + * |
| 3247 | + * 1) Force transclusions to be substituted |
| 3248 | + * 2) Strip ~~~, ~~~~ and ~~~~~ out of signatures |
| 3249 | + * |
| 3250 | + * @static |
| 3251 | + * @param string $text |
| 3252 | + * @return string Text |
| 3253 | + */ |
| 3254 | + function cleanSig( $text ) { |
| 3255 | + $text = str_replace( '{{', '{{subst:', $text ); |
| 3256 | + $text = str_replace( '{{subst:subst:', '{{subst:', $text ); |
| 3257 | + $text = str_replace( '~~~', '', $text ); |
| 3258 | + $text = str_replace( '~~~~', '', $text ); |
| 3259 | + $text = str_replace( '~~~~~', '', $text ); |
| 3260 | + return( $text ); |
| 3261 | + } |
| 3262 | + |
| 3263 | + /** |
3259 | 3264 | * Set up some variables which are usually set up in parse() |
3260 | 3265 | * so that an external function can call some class members with confidence |
3261 | 3266 | * @access public |