summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Renameuser/includes/RenameuserHooks.php
blob: 9fdc29ed370896bf4835b40ee779e475d4ea7f28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php

class RenameuserHooks {
	/**
	 * Show a log if the user has been renamed and point to the new username.
	 * Don't show the log if the $oldUserName exists as a user.
	 *
	 * @param Article $article
	 * @return bool
	 */
	public static function onShowMissingArticle( $article ) {
		$title = $article->getTitle();
		$oldUser = User::newFromName( $title->getBaseText() );
		if ( ( $title->getNamespace() === NS_USER || $title->getNamespace() === NS_USER_TALK ) &&
			( $oldUser && $oldUser->isAnon() )
		) {
			// Get the title for the base userpage
			$page = Title::makeTitle( NS_USER, str_replace( ' ', '_', $title->getBaseText() ) )
				->getPrefixedDBkey();
			$out = $article->getContext()->getOutput();
			LogEventsList::showLogExtract(
				$out,
				'renameuser',
				$page,
				'',
				[
					'lim' => 10,
					'showIfEmpty' => false,
					'msgKey' => [ 'renameuser-renamed-notice', $title->getBaseText() ]
				]
			);
		}

		return true;
	}

	/**
	 * Shows link to Special:Renameuser on Special:Contributions/foo
	 *
	 * @param int $id
	 * @param Title $nt
	 * @param array &$tools
	 * @param SpecialPage $sp
	 */
	public static function onContributionsToolLinks( $id, $nt, array &$tools, SpecialPage $sp ) {
		if ( $id && $sp->getUser()->isAllowed( 'renameuser' ) ) {
			$tools['renameuser'] = $sp->getLinkRenderer()->makeKnownLink(
				SpecialPage::getTitleFor( 'Renameuser' ),
				$sp->msg( 'renameuser-linkoncontribs' )->text(),
				[ 'title' => $sp->msg( 'renameuser-linkoncontribs-text' )->parse() ],
				[ 'oldusername' => $nt->getText() ]
			);
		}
	}

	/**
	 * So users can just type in a username for target and it'll work
	 * @param array &$types
	 * @return bool
	 */
	public static function onGetLogTypesOnUser( array &$types ) {
		$types[] = 'renameuser';

		return true;
	}
}