diff --git a/documentation/database/patches/patch-13.sql b/documentation/database/patches/patch-13.sql new file mode 100644 index 0000000..68721f3 --- /dev/null +++ b/documentation/database/patches/patch-13.sql @@ -0,0 +1,2 @@ +ALTER TABLE `{$prefix}user` ADD COLUMN `user_metawiki` VARCHAR(64); +ALTER TABLE `{$prefix}user` ADD UNIQUE INDEX `user_metawiki`(`user_metawiki`); diff --git a/includes/class-QueryUser.php b/includes/class-QueryUser.php index ef05f49..b2cb9e0 100644 --- a/includes/class-QueryUser.php +++ b/includes/class-QueryUser.php @@ -1,67 +1,83 @@ . trait QueryUserTrait { /** * Where the user ID is... * * @param int $id * @return self */ public function whereUserID( $id ) { return $this->whereInt( $this->USER_ID, $id ); } /** * Where the user is... * * @param User $user User object * @return self */ public function whereUser( $user ) { $id = $user->getUserID(); return $this->whereUserID( $id ); } + /** + * Where the Meta-wiki username is... + * + * @param string $username Meta-wiki username as displayed after [[User:]] without underscores + * @return self + */ + public function whereMetaUsername( $username ) { + return $this->whereStr( User::META_WIKI, $username ); + } + + /** + * Join whatever table with the user table + */ + public function joinUser() { + return $this->joinOn( 'INNER', User::T, $this->USER_ID, User::ID_ ); + } } /** * Class useful to retrieve User(s) */ class QueryUser extends Query { use QueryUserTrait; /** * Univoque User ID column name */ protected $USER_ID = 'user.user_ID'; /** * Constructor */ public function __construct( $db = null ) { // choose database and default return class parent::__construct( $db, User::class ); // choose database table $this->from( User::T ); } } diff --git a/includes/class-User.php b/includes/class-User.php index 017719e..eec5580 100644 --- a/includes/class-User.php +++ b/includes/class-User.php @@ -1,455 +1,475 @@ . trait UserTrait { /** * Get the user ID * * @return int */ public function getUserID() { return $this->nonnull( User::ID ); } /** * Get the user UID * * @return string */ public function getUserUID() { return $this->get( User::UID ); } /** * Get the user e-mail * * @return string */ public function getUserEmail() { return $this->get( User::EMAIL ); } /** * Check if the user is public * * @return bool */ public function isUserPublic() { return $this->get( User::IS_PUBLIC ); } /** * Check if I can see this user * * @return bool */ public function isUserVisible() { return $this->isUserPublic() || $this->isUserMyself(); } /** * Get the user full name * * @return string */ public function getUserFullname() { return sprintf( __("%s %s"), $this->get( User::NAME ), $this->get( User::SURNAME ) ); } /** * Get the User URL * * The User URL is based on the CURRENT_CONFERENCE_UID. * * @param boolean $absolute Set to true to force an absolute URL * @return string */ public function getUserURL( $absolute = false ) { $url = sprintf( PERMALINK_USER, CURRENT_CONFERENCE_UID, $this->getUserUID() ); $url = site_page( $url, $absolute ); return keep_url_in_language( $url ); } function getUserLink( $base = null, $html_class = null) { $name = $this->getUserFullname(); return HTML::a( $this->getUserURL( $base ), esc_html( $name ), sprintf( __("Profilo utente di %s"), $name ), $html_class ); } /** * Check if the User has a Gravatar image * * @return int */ public function hasUserGravatar() { return $this->has( User::GRAVATAR ) || $this->has( User::EMAIL ); } /** * Get the md5 of the E-mail * * @return string|null */ public function getUserGravatarUID() { return $this->get( User::GRAVATAR ); } /** * Check if the User has an image * * @return boolean */ public function hasUserImage() { return $this->has( User::IMAGE ) || $this->has( User::GRAVATAR ); } /** * Get the URL of the user image * * @param int $size Suggested width * @param boolean $absolute Set true to force an absolute URL * @return string */ public function getUserImage( $size = 256, $absolute = false ) { $image = $this->get( User::IMAGE ); if( ! $image ) { $image = 'https://www.gravatar.com/avatar/' . $this->getUserGravatarUID() . '?s=' . $size; } return site_page( $image, $absolute ); } /** * It has an user bio? * * @return bool */ public function hasUserBio() { return null !== $this->get('user_bio'); } function getUserBio() { return $this->get('user_bio'); } function getUserBioHTML($args = []) { return Markdown::parse( __( $this->getUserBIO() ), $args); } /** * Check if the user is somehow social * * @return bool */ public function isUserSocial() { foreach( User::allSocialFields() as $field ) { if( $this->has( $field ) ) { return true; } } return false; } /** * Get the user Facebook profile URL * * @return string URL */ public function getUserFacebruck() { return 'https://facebook.com/' . $this->get( User::FACEBOOK ); } /** * Get the user Google+ profile URL * * @return string URL */ public function getUserGuggolpluz() { return 'https://plus.google.com/' . $this->get( User::GOOGLE_PLUS ); } /** * Get the user Twitter profile URL * * @return string URL */ public function getUserTuitt() { return 'https://twitter.com/' . $this->get( User::TWITTER ); } /** * Get the user Linkedin profile URL * * @return string URL */ public function getUserLinkeddon() { return 'https://www.linkedin.com/in/' . $this->get( User::LINKEDIN ); } /** * Get the user GitHub profile URL * * @return string URL */ public function getUserGithubbo() { return 'https://github.com/' . $this->get( User::GITHUB ); } + /** + * Get the user Wikimedia Meta-wiki URL + * + * @return string + */ + public function getUserMetaWikiURL() { + $username = $this->get( User::META_WIKI ); + $username = str_replace( ' ', '_', $username ); + return sprintf( + 'https://meta.wikimedia.org/wiki/User:%s', + $username + ); + } + /** * Get the edit URL to this user * * @return string */ public function getUserEditURL() { $url = http_build_get_query( '2016/user-edit.php', [ 'uid' => $this->getUserUID(), ] ); return site_page( $url ); } /** * Can you edit this user? * * @return bool */ public function hasPermissionToEditUser() { if( has_permission('edit-users') ) { return true; } if( has_permission('edit-account') && $this->isUserMyself() ) { return true; } return false; } /** * Is this user myself? * * @return bool */ public function isUserMyself() { return is_logged() && get_user()->getUserID() === $this->getUserID(); } /** * Check if the User has a loved license * * @return */ public function hasUserLovelicense() { return $this->has( User::LOVED_LICENSE ); } /** * Get the User loved license * * @return License */ public function getUserLovelicense() { return license( $this->get( User::LOVED_LICENSE ) ); } function factoryUserSkills() { return UserSkill::factorySkillByUser( $this->getUserID() ); } function factoryUserEvents() { return FullEvent::factoryByUser( $this->getUserID() ); } /** * Normalize a User object */ protected function normalizeUser() { $this->integers( User::ID ); $this->booleans( User::IS_PUBLIC, User::IS_ACTIVE ); } } class User extends Sessionuser { use UserTrait; /** * Name column */ const NAME = 'user_name'; /** * Aristocratic title column */ const ARISTOCRATIC_TITLE = 'user_title'; /** * ID column */ const SURNAME = 'user_surname'; /** * He/she public column */ const IS_PUBLIC = 'user_public'; /** * Image column */ const IMAGE = 'user_image'; /** * E-mail */ const EMAIL = 'user_email'; /** * Gravatar column */ const GRAVATAR = 'user_gravatar'; /** * RSS column */ const RSS = 'user_rss'; /** * Facebook username column */ const FACEBOOK = 'user_fb'; /** * Linkedin username column */ const LINKEDIN = 'user_lnkd'; /** * Google+ username column */ const GOOGLE_PLUS = 'user_googl'; /** * Twitter username */ const TWITTER = 'user_twtr'; /** * GitHub username */ const GITHUB = 'user_github'; /** * Personal website column */ const WEBSITE = 'user_site'; /** * Loved license column */ const LOVED_LICENSE = 'user_lovelicense'; /** * Biography column */ const BIO = 'user_bio'; + /** + * Username in Meta-wiki + */ + const META_WIKI = 'user_metawiki'; + /** * Complete ID column name */ const ID_ = self::T . DOT . self::ID; /** * Maximum UID length */ const MAXLEN_UID = 64; /** * Constructor */ public function __construct() { $this->normalizeUser(); } /** * Get all the user social fields * * @return array */ public static function allSocialFields() { return [ User::RSS, User::FACEBOOK, User::LINKEDIN, User::GOOGLE_PLUS, User::TWITTER, User::GITHUB, + User::META_WIKI, ]; } /** * Factory users by an event * * @param $event_ID int * @return Query */ public static function factoryByEvent( $event_ID ) { return self::factory() ->from('event_user') ->equals('event_user.user_ID', 'user.user_ID') ->whereInt('event_user.event_ID', $event_ID ); } /** * Generate the appropriate SELECT for the User Bio * * @return string */ public static function BIO_L10N() { return i18n_coalesce( 'user_bio', 'user_bio_%s' ); } /** * Get all the public User fields * * @return array */ public static function fields() { return [ self::ID, self::UID, self::GRAVATAR, self::NAME, self::SURNAME, self::IMAGE, self::WEBSITE, self::LOVED_LICENSE, self::BIO_L10N(), ]; } }