This way the messages are generated in the correct language instead
of relying on the user language from global context.
This should ideally become a non-static method at some point,
but currently there currently many out-of-class callers.
Change-Id: Ifb1756c1a3bddc717387ed66a58dedd4c1a7dab9
$s .= $dirmark;
if ( $rev->isMinor() ) {
$s .= $dirmark;
if ( $rev->isMinor() ) {
- $s .= ' ' . ChangesList::flag( 'minor' );
+ $s .= ' ' . ChangesList::flag( 'minor', $this->getContext() );
}
# Sometimes rev_len isn't populated
}
# Sometimes rev_len isn't populated
$f = '';
foreach ( array_keys( $this->getConfig()->get( 'RecentChangesFlags' ) ) as $flag ) {
$f .= isset( $flags[$flag] ) && $flags[$flag]
$f = '';
foreach ( array_keys( $this->getConfig()->get( 'RecentChangesFlags' ) ) as $flag ) {
$f .= isset( $flags[$flag] ) && $flags[$flag]
+ ? self::flag( $flag, $this->getContext() )
- * Provide the "<abbr>" element appropriate to a given abbreviated flag,
- * namely the flag indicating a new page, a minor edit, a bot edit, or an
- * unpatrolled edit. By default in English it will contain "N", "m", "b",
- * "!" respectively, plus it will have an appropriate title and class.
+ * Make an "<abbr>" element for a given change flag. The flag indicating a new page, minor edit,
+ * bot edit, or unpatrolled edit. In English it typically contains "N", "m", "b", or "!".
*
* @param string $flag One key of $wgRecentChangesFlags
*
* @param string $flag One key of $wgRecentChangesFlags
- * @return string Raw HTML
+ * @param IContextSource $context
+ * @return string HTML
- public static function flag( $flag ) {
+ public static function flag( $flag, IContextSource $context = null ) {
+ static $map = [ 'minoredit' => 'minor', 'botedit' => 'bot' ];
static $flagInfos = null;
static $flagInfos = null;
if ( is_null( $flagInfos ) ) {
global $wgRecentChangesFlags;
$flagInfos = [];
foreach ( $wgRecentChangesFlags as $key => $value ) {
if ( is_null( $flagInfos ) ) {
global $wgRecentChangesFlags;
$flagInfos = [];
foreach ( $wgRecentChangesFlags as $key => $value ) {
- $flagInfos[$key]['letter'] = wfMessage( $value['letter'] )->escaped();
- $flagInfos[$key]['title'] = wfMessage( $value['title'] )->escaped();
+ $flagInfos[$key]['letter'] = $value['letter'];
+ $flagInfos[$key]['title'] = $value['title'];
// Allow customized class name, fall back to flag name
// Allow customized class name, fall back to flag name
- $flagInfos[$key]['class'] = Sanitizer::escapeClass(
- isset( $value['class'] ) ? $value['class'] : $key );
+ $flagInfos[$key]['class'] = isset( $value['class'] ) ? $value['class'] : $key;
- // Inconsistent naming, bleh, kepted for b/c
- $map = [
- 'minoredit' => 'minor',
- 'botedit' => 'bot',
- ];
+ $context = $context ?: RequestContext::getMain();
+
+ // Inconsistent naming, kepted for b/c
if ( isset( $map[$flag] ) ) {
$flag = $map[$flag];
}
if ( isset( $map[$flag] ) ) {
$flag = $map[$flag];
}
- return "<abbr class='" . $flagInfos[$flag]['class'] . "' title='" .
- $flagInfos[$flag]['title'] . "'>" . $flagInfos[$flag]['letter'] .
- '</abbr>';
+ $info = $flagInfos[$flag];
+ return Html::element( 'abbr', [
+ 'class' => $info['class'],
+ 'title' => wfMessage( $info['title'] )->setContext( $context )->text(),
+ ], wfMessage( $info['letter'] )->setContext( $context )->text() );
$line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
$this->assertContains(
$line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
$this->assertContains(
- "<abbr class='newpage' title='(recentchanges-label-newpage)'>(newpageletter)</abbr>",
+ '<abbr class="newpage" title="(recentchanges-label-newpage)">(newpageletter)</abbr>',
$line,
'new page flag'
);
$this->assertContains(
$line,
'new page flag'
);
$this->assertContains(
- "<abbr class='botedit' title='(recentchanges-label-bot)'>(boteditletter)</abbr>",
+ '<abbr class="botedit" title="(recentchanges-label-bot)">(boteditletter)</abbr>',