r12486 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r12485‎ | r12486 | r12487 >
Date:23:09, 7 January 2006
Author:robchurch
Status:old
Tags:
Comment:
Cleanup signature handling

* Introduce a function to cleanup signatures [currently strips out ~~~, ~~~~ and ~~~~~, and forces transclusions to be substituted]
* Cleanup Parser::getUserSig()
* Minor cleanup on Parser::validateSig()
Modified paths:
  • /trunk/phase3/includes/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Parser.php
@@ -3207,54 +3207,59 @@
32083208 * @access private
32093209 */
32103210 function getUserSig( &$user ) {
3211 - $name = $user->getName();
3212 - $nick = trim( $user->getOption( 'nickname' ) );
3213 - if ( '' == $nick ) {
3214 - $nick = $name;
3215 - }
 3211+ global $wgContLang;
32163212
 3213+ $username = $user->getName();
 3214+ $nickname = trim( $user->getOption( 'nickname' ) );
 3215+ $nickname = ( $nickname == '' ? $username : $nickname );
 3216+
32173217 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;
32233225 wfDebug( "Parser::getUserSig: $name has bad XML tags in signature.\n" );
3224 - } else {
3225 - return $nick;
32263226 }
32273227 }
32283228
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 ) . ']]' );
32373232 }
32383233
32393234 /**
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
32433236 *
32443237 * @param string $text
32453238 * @return mixed An expanded string, or false if invalid.
3246 - *
3247 - * @todo Run brace substitutions
3248 - * @todo ?? Check for unbalanced '' and ''' quotes, etc
32493239 */
32503240 function validateSig( $text ) {
3251 - if( wfIsWellFormedXmlFragment( $text ) ) {
3252 - return $text;
3253 - } else {
3254 - return false;
3255 - }
 3241+ return( wfIsWellFormedXmlFragment( $text ) ? $text : false );
32563242 }
3257 -
 3243+
32583244 /**
 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+ /**
32593264 * Set up some variables which are usually set up in parse()
32603265 * so that an external function can call some class members with confidence
32613266 * @access public

Status & tagging log