* @since 1.16.3. $altUserName was added in 1.19.
*/
public static function userLink( $userId, $userName, $altUserName = false ) {
+ if ( $userName === '' ) {
+ wfLogWarning( __METHOD__ . ' received an empty username. Are there database errors ' .
+ 'that need to be fixed?' );
+ return wfMessage( 'empty-username' )->parse();
+ }
+
$classes = 'mw-userlink';
$page = null;
if ( $userId == 0 ) {
$userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits = null,
$useParentheses = true
) {
+ if ( $userText === '' ) {
+ wfLogWarning( __METHOD__ . ' received an empty username. Are there database errors ' .
+ 'that need to be fixed?' );
+ return ' ' . wfMessage( 'empty-username' )->parse();
+ }
+
global $wgUser, $wgDisableAnonTalk, $wgLang;
$talkable = !( $wgDisableAnonTalk && $userId == 0 );
$blockable = !( $flags & self::TOOL_LINKS_NOBLOCK );
* @return string HTML fragment with user talk link
*/
public static function userTalkLink( $userId, $userText ) {
+ if ( $userText === '' ) {
+ wfLogWarning( __METHOD__ . ' received an empty username. Are there database errors ' .
+ 'that need to be fixed?' );
+ return wfMessage( 'empty-username' )->parse();
+ }
+
$userTalkPage = new TitleValue( NS_USER_TALK, strtr( $userText, ' ', '_' ) );
$moreLinkAttribs['class'] = 'mw-usertoollinks-talk';
* @return string HTML fragment with block link
*/
public static function blockLink( $userId, $userText ) {
+ if ( $userText === '' ) {
+ wfLogWarning( __METHOD__ . ' received an empty username. Are there database errors ' .
+ 'that need to be fixed?' );
+ return wfMessage( 'empty-username' )->parse();
+ }
+
$blockPage = SpecialPage::getTitleFor( 'Block', $userText );
$moreLinkAttribs['class'] = 'mw-usertoollinks-block';
* @return string HTML fragment with e-mail user link
*/
public static function emailLink( $userId, $userText ) {
+ if ( $userText === '' ) {
+ wfLogWarning( __METHOD__ . ' received an empty username. Are there database errors ' .
+ 'that need to be fixed?' );
+ return wfMessage( 'empty-username' )->parse();
+ }
+
$emailPage = SpecialPage::getTitleFor( 'Emailuser', $userText );
$moreLinkAttribs['class'] = 'mw-usertoollinks-mail';
return self::link( $emailPage,
'wgArticlePath' => '/wiki/$1',
] );
- $this->assertEquals(
- $expected,
- Linker::userLink( $userId, $userName, $altUserName ),
- $msg
- );
+ // We'd also test the warning, but injecting a mock logger into a static method is tricky.
+ if ( $userName === '' ) {
+ Wikimedia\suppressWarnings();
+ }
+ $actual = Linker::userLink( $userId, $userName, $altUserName );
+ if ( $userName === '' ) {
+ Wikimedia\restoreWarnings();
+ }
+
+ $this->assertEquals( $expected, $actual, $msg );
}
public static function provideCasesForUserLink() {
# - optional altUserName
# - optional message
return [
+ # Empty name (T222529)
+ 'Empty username, userid 0' => [ '(no username available)', 0, '' ],
+ 'Empty username, userid > 0' => [ '(no username available)', 73, '' ],
# ## ANONYMOUS USER ########################################
[
];
}
+ /**
+ * @dataProvider provideUserToolLinks
+ * @covers Linker::userToolLinks
+ * @param string $expected
+ * @param int $userId
+ * @param string $userText
+ */
+ public function testUserToolLinks( $expected, $userId, $userText ) {
+ // We'd also test the warning, but injecting a mock logger into a static method is tricky.
+ if ( $userText === '' ) {
+ Wikimedia\suppressWarnings();
+ }
+ $actual = Linker::userToolLinks( $userId, $userText );
+ if ( $userText === '' ) {
+ Wikimedia\restoreWarnings();
+ }
+
+ $this->assertSame( $expected, $actual );
+ }
+
+ public static function provideUserToolLinks() {
+ return [
+ // Empty name (T222529)
+ 'Empty username, userid 0' => [ ' (no username available)', 0, '' ],
+ 'Empty username, userid > 0' => [ ' (no username available)', 73, '' ],
+ ];
+ }
+
+ /**
+ * @dataProvider provideUserTalkLink
+ * @covers Linker::userTalkLink
+ * @param string $expected
+ * @param int $userId
+ * @param string $userText
+ */
+ public function testUserTalkLink( $expected, $userId, $userText ) {
+ // We'd also test the warning, but injecting a mock logger into a static method is tricky.
+ if ( $userText === '' ) {
+ Wikimedia\suppressWarnings();
+ }
+ $actual = Linker::userTalkLink( $userId, $userText );
+ if ( $userText === '' ) {
+ Wikimedia\restoreWarnings();
+ }
+
+ $this->assertSame( $expected, $actual );
+ }
+
+ public static function provideUserTalkLink() {
+ return [
+ // Empty name (T222529)
+ 'Empty username, userid 0' => [ '(no username available)', 0, '' ],
+ 'Empty username, userid > 0' => [ '(no username available)', 73, '' ],
+ ];
+ }
+
+ /**
+ * @dataProvider provideBlockLink
+ * @covers Linker::blockLink
+ * @param string $expected
+ * @param int $userId
+ * @param string $userText
+ */
+ public function testBlockLink( $expected, $userId, $userText ) {
+ // We'd also test the warning, but injecting a mock logger into a static method is tricky.
+ if ( $userText === '' ) {
+ Wikimedia\suppressWarnings();
+ }
+ $actual = Linker::blockLink( $userId, $userText );
+ if ( $userText === '' ) {
+ Wikimedia\restoreWarnings();
+ }
+
+ $this->assertSame( $expected, $actual );
+ }
+
+ public static function provideBlockLink() {
+ return [
+ // Empty name (T222529)
+ 'Empty username, userid 0' => [ '(no username available)', 0, '' ],
+ 'Empty username, userid > 0' => [ '(no username available)', 73, '' ],
+ ];
+ }
+
+ /**
+ * @dataProvider provideEmailLink
+ * @covers Linker::emailLink
+ * @param string $expected
+ * @param int $userId
+ * @param string $userText
+ */
+ public function testEmailLink( $expected, $userId, $userText ) {
+ // We'd also test the warning, but injecting a mock logger into a static method is tricky.
+ if ( $userText === '' ) {
+ Wikimedia\suppressWarnings();
+ }
+ $actual = Linker::emailLink( $userId, $userText );
+ if ( $userText === '' ) {
+ Wikimedia\restoreWarnings();
+ }
+
+ $this->assertSame( $expected, $actual );
+ }
+
+ public static function provideEmailLink() {
+ return [
+ // Empty name (T222529)
+ 'Empty username, userid 0' => [ '(no username available)', 0, '' ],
+ 'Empty username, userid > 0' => [ '(no username available)', 73, '' ],
+ ];
+ }
+
/**
* @dataProvider provideCasesForFormatComment
* @covers Linker::formatComment