r51594 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51593‎ | r51594 | r51595 >
Date:16:53, 8 June 2009
Author:skizzerz
Status:ok
Tags:
Comment:
* DISPLAYTITLE fixes:
** DISPLAYTITLE now parses the single-quote items of wiki markup (bold and italic).
** Remove UNIQ markers from the output due to people putting tags in there (nowiki, ref, etc.).
** Forbid hr and br elements from being in DISPLAYTITLE as well.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/parser/CoreParserFunctions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/CoreParserFunctions.php
@@ -88,19 +88,19 @@
8989 return array( 'found' => false );
9090 }
9191 }
92 -
 92+
9393 static function formatDate( $parser, $date, $defaultPref = null ) {
9494 $df = DateFormatter::getInstance();
95 -
 95+
9696 $date = trim($date);
97 -
 97+
9898 $pref = $parser->mOptions->getDateFormat();
99 -
 99+
100100 // Specify a different default date format other than the the normal default
101 - // iff the user has 'default' for their setting
 101+ // iff the user has 'default' for their setting
102102 if ($pref == 'default' && $defaultPref)
103103 $pref = $defaultPref;
104 -
 104+
105105 $date = $df->reformat( $pref, $date, array('match-whole') );
106106 return $date;
107107 }
@@ -198,10 +198,10 @@
199199
200200 // default
201201 $gender = User::getDefaultOption( 'gender' );
202 -
 202+
203203 // allow prefix.
204204 $title = Title::newFromText( $user );
205 -
 205+
206206 if (is_object( $title ) && $title->getNamespace() == NS_USER)
207207 $user = $title->getText();
208208
@@ -233,13 +233,21 @@
234234 */
235235 static function displaytitle( $parser, $text = '' ) {
236236 global $wgRestrictDisplayTitle;
237 -
 237+
 238+ #parse a limited subset of wiki markup (just the single quote items)
 239+ $text = $parser->doQuotes( $text );
 240+
 241+ #remove stripped text (e.g. the UNIQ-QINU stuff) that was generated by tag extensions/whatever
 242+ $text = preg_replace( '/' . preg_quote( $parser->uniqPrefix(), '/' ) . '.*?'
 243+ . preg_quote( Parser::MARKER_SUFFIX, '/' ) . '/', '', $text );
 244+
238245 #list of disallowed tags for DISPLAYTITLE
239246 #these will be escaped even though they are allowed in normal wiki text
240 - $bad = array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'div', 'blockquote', 'ol', 'ul', 'li',
241 - 'table', 'tr', 'th', 'td', 'dl', 'dd', 'caption', 'p', 'ruby', 'rb', 'rt', 'rp' );
242 -
 247+ $bad = array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'div', 'blockquote', 'ol', 'ul', 'li', 'hr',
 248+ 'table', 'tr', 'th', 'td', 'dl', 'dd', 'caption', 'p', 'ruby', 'rb', 'rt', 'rp', 'br' );
 249+
243250 #only requested titles that normalize to the actual title are allowed through
 251+ #if $wgRestrictDisplayTitle is true (it is by default)
244252 #mimic the escaping process that occurs in OutputPage::setPageTitle
245253 $text = Sanitizer::normalizeCharReferences( Sanitizer::removeHTMLtags( $text, null, array(), array(), $bad ) );
246254 $title = Title::newFromText( Sanitizer::stripAllTags( $text ) );
@@ -304,9 +312,9 @@
305313 }
306314 static function numberingroup( $parser, $name = '', $raw = null) {
307315 return self::formatRaw( SiteStats::numberingroup( strtolower( $name ) ), $raw );
308 - }
 316+ }
309317
310 -
 318+
311319 /**
312320 * Given a title, return the namespace name that would be given by the
313321 * corresponding magic word
@@ -400,7 +408,7 @@
401409 if ( is_null($t) )
402410 return '';
403411 return wfUrlEncode( str_replace( ' ', '_', $t->getBaseText() ) );
404 - }
 412+ }
405413 static function talkpagename( $parser, $title = null ) {
406414 $t = Title::newFromText( $title );
407415 if ( is_null($t) || !$t->canTalk() )
@@ -425,7 +433,7 @@
426434 return '';
427435 return $t->getSubjectPage()->getPrefixedUrl();
428436 }
429 -
 437+
430438 /**
431439 * Return the number of pages in the given category, or 0 if it's nonexis-
432440 * tent. This is an expensive parser function and can't be called too many
@@ -482,13 +490,13 @@
483491 $rev = Revision::newFromTitle($title);
484492 $id = $rev ? $rev->getPage() : 0;
485493 $length = $cache[$page] = $rev ? $rev->getSize() : 0;
486 -
 494+
487495 // Register dependency in templatelinks
488496 $parser->mOutput->addTemplate( $title, $id, $rev ? $rev->getId() : 0 );
489 - }
 497+ }
490498 return self::formatRaw( $length, $raw );
491499 }
492 -
 500+
493501 /**
494502 * Returns the requested protection level for the current page
495503 */
@@ -509,12 +517,12 @@
510518 * Unicode-safe str_pad with the restriction that $length is forced to be <= 500
511519 */
512520 static function pad( $string, $length, $padding = '0', $direction = STR_PAD_RIGHT ) {
513 - $lengthOfPadding = mb_strlen( $padding );
 521+ $lengthOfPadding = mb_strlen( $padding );
514522 if ( $lengthOfPadding == 0 ) return $string;
515 -
 523+
516524 # The remaining length to add counts down to 0 as padding is added
517525 $length = min( $length, 500 ) - mb_strlen( $string );
518 - # $finalPadding is just $padding repeated enough times so that
 526+ # $finalPadding is just $padding repeated enough times so that
519527 # mb_strlen( $string ) + mb_strlen( $finalPadding ) == $length
520528 $finalPadding = '';
521529 while ( $length > 0 ) {
@@ -523,7 +531,7 @@
524532 $finalPadding .= mb_substr( $padding, 0, $length );
525533 $length -= $lengthOfPadding;
526534 }
527 -
 535+
528536 if ( $direction == STR_PAD_LEFT ) {
529537 return $finalPadding . $string;
530538 } else {
Index: trunk/phase3/RELEASE-NOTES
@@ -79,6 +79,7 @@
8080 * (bug 14866) Messages 'recentchangeslinked-toolbox' and
8181 'recentchangeslinked-toolbox' were added to allow more fine grained
8282 customisation of the user interface
 83+* DISPLAYTITLE now accepts a limited amount of wiki markup (the single-quote items)
8384
8485 === Bug fixes in 1.16 ===
8586

Status & tagging log