http://www.mediawiki.org/wiki/Special:Code/MediaWiki/100269
Revision: 100269 Author: ashley Date: 2011-10-19 20:16:39 +0000 (Wed, 19 Oct 2011) Log Message: ----------- SocialProfile: allow specifying and showing the user's year of birth on social profile pages. Patch by Rinat Silnov. To use this feature, go to Special:UpdateProfile/preferences, toggle the new "Show year of birth" option, save preferences, then add your birthday on Special:UpdateProfile, save again and now your birthday will be shown on your profile. Do note that because of the mw.loader.using() call in UserProfile/UpdateProfile.js, this breaks backwards compatibility with pre-ResourceLoader MediaWikis (that is, 1.16 and older). I don't know if this works with 1.17, but I tested this against the current 1.18 branch. Modified Paths: -------------- trunk/extensions/SocialProfile/UserProfile/SpecialEditProfile.php trunk/extensions/SocialProfile/UserProfile/SpecialUpdateProfile.php trunk/extensions/SocialProfile/UserProfile/UpdateProfile.js trunk/extensions/SocialProfile/UserProfile/UserProfile.i18n.php trunk/extensions/SocialProfile/UserProfile/UserProfileClass.php Modified: trunk/extensions/SocialProfile/UserProfile/SpecialEditProfile.php =================================================================== --- trunk/extensions/SocialProfile/UserProfile/SpecialEditProfile.php 2011-10-19 20:15:34 UTC (rev 100268) +++ trunk/extensions/SocialProfile/UserProfile/SpecialEditProfile.php 2011-10-19 20:16:39 UTC (rev 100269) @@ -179,7 +179,7 @@ $hometown_city = $s->up_hometown_city; $hometown_state = $s->up_hometown_state; $hometown_country = $s->up_hometown_country; - $birthday = $this->formatBirthday( $s->up_birthday ); + $birthday = $this->formatBirthday( $s->up_birthday, true ); $schools = $s->up_schools; $places = $s->up_places_lived; $websites = $s->up_websites; @@ -286,8 +286,8 @@ $form .= '<div class="profile-update"> <p class="profile-update-title">' . wfMsg( 'user-profile-personal-birthday' ) . '</p> - <p class="profile-update-unit-left">' . wfMsg( 'user-profile-personal-birthdate' ) . '</p> - <p class="profile-update-unit"><input type="text" size="25" name="birthday" id="birthday" value="' . ( isset( $birthday ) ? $birthday : '' ) . '" /></p> + <p class="profile-update-unit-left">' . wfMsg( 'user-profile-personal-birthdate-with-year' ) . '</p> + <p class="profile-update-unit"><input type="text" class="long-birthday" size="25" name="birthday" id="birthday" value="' . ( isset( $birthday ) ? $birthday : '' ) . '" /></p> <div class="cleared"></div> </div><div class="cleared"></div>'; Modified: trunk/extensions/SocialProfile/UserProfile/SpecialUpdateProfile.php =================================================================== --- trunk/extensions/SocialProfile/UserProfile/SpecialUpdateProfile.php 2011-10-19 20:15:34 UTC (rev 100268) +++ trunk/extensions/SocialProfile/UserProfile/SpecialUpdateProfile.php 2011-10-19 20:16:39 UTC (rev 100269) @@ -86,7 +86,7 @@ $wgOut->addScriptFile( $wgUserProfileScripts . '/UpdateProfile.js' ); } - if ( $wgRequest->wasPosted() ) { + if ( $wgRequest->wasPosted() ) { if ( !$section ) { $section = 'basic'; } @@ -194,6 +194,7 @@ $notify_challenge = $wgRequest->getVal( 'notify_challenge' ); $notify_honorifics = $wgRequest->getVal( 'notify_honorifics' ); $notify_message = $wgRequest->getVal( 'notify_message' ); + $show_year_of_birth = $wgRequest->getVal( 'show_year_of_birth', 0 ); if ( $notify_friend == '' ) { $notify_friend = 0; } @@ -214,6 +215,7 @@ $wgUser->setOption( 'notifychallenge', $notify_challenge ); $wgUser->setOption( 'notifyhonorifics', $notify_honorifics ); $wgUser->setOption( 'notifymessage', $notify_message ); + $wgUser->setOption( 'showyearofbirth', $show_year_of_birth ); $wgUser->saveSettings(); // Allow extensions like UserMailingList do their magic here @@ -222,8 +224,8 @@ function formatBirthdayDB( $birthday ) { $dob = explode( '/', $birthday ); - if ( count( $dob ) == 2 ) { - $year = 2007; + if ( count( $dob ) == 2 || count( $dob ) == 3 ) { + $year = isset( $dob[2] ) ? $dob[2] : 2007; $month = $dob[0]; $day = $dob[1]; $birthday_date = $year . '-' . $month . '-' . $day; @@ -233,13 +235,16 @@ return ( $birthday_date ); } - function formatBirthday( $birthday ) { + function formatBirthday( $birthday, $showYOB = false ) { $dob = explode( '-', $birthday ); if ( count( $dob ) == 3 ) { - $year = 0000; $month = $dob[1]; $day = $dob[2]; - $birthday_date = $month . '/' . $day; // . '/' . $year; + $birthday_date = $month . '/' . $day; + if ( $showYOB ) { + $year = $dob[0]; + $birthday_date .= '/' . $year; + } } else { $birthday_date = ''; } @@ -382,6 +387,7 @@ __METHOD__ ); + $showYOB = true; if ( $s !== false ) { $location_city = $s->up_location_city; $location_state = $s->up_location_state; @@ -391,7 +397,8 @@ $hometown_city = $s->up_hometown_city; $hometown_state = $s->up_hometown_state; $hometown_country = $s->up_hometown_country; - $birthday = $this->formatBirthday( $s->up_birthday ); + $showYOB = $wgUser->getIntOption( 'showyearofbirth', !isset( $s->up_birthday ) ) == 1; + $birthday = $this->formatBirthday( $s->up_birthday, $showYOB ); $schools = $s->up_schools; $places = $s->up_places_lived; $websites = $s->up_websites; @@ -498,8 +505,13 @@ $form .= '<div class="profile-update"> <p class="profile-update-title">' . wfMsg( 'user-profile-personal-birthday' ) . '</p> - <p class="profile-update-unit-left">' . wfMsg( 'user-profile-personal-birthdate' ) . '</p> - <p class="profile-update-unit"><input type="text" size="25" name="birthday" id="birthday" value="' . ( isset( $birthday ) ? $birthday : '' ) . '" /></p> + <p class="profile-update-unit-left" id="birthday-format">' . + wfMsg( $showYOB ? 'user-profile-personal-birthdate-with-year' : 'user-profile-personal-birthdate' ) . + '</p> + <p class="profile-update-unit"><input type="text"' . + ( $showYOB ? ' class="long-birthday"' : null ) . + ' size="25" name="birthday" id="birthday" value="' . + ( isset( $birthday ) ? $birthday : '' ) . '" /></p> <div class="cleared"></div> </div><div class="cleared"></div>'; @@ -662,8 +674,18 @@ * @return HTML */ function displayPreferencesForm() { - global $wgUser, $wgOut; + global $wgRequest, $wgUser, $wgOut; + $dbr = wfGetDB( DB_MASTER ); + $s = $dbr->selectRow( + 'user_profile', + array( 'up_birthday' ), + array( 'up_user_id' => $wgUser->getID() ), + __METHOD__ + ); + + $showYOB = isset( $s, $s->up_birthday ) ? false : true; + // @todo If the checkboxes are in front of the option, this would look more like Special:Preferences $wgOut->setPageTitle( wfMsg( 'user-profile-section-preferences' ) ); $form = UserProfile::getEditProfileNav( wfMsg( 'user-profile-section-preferences' ) ); @@ -689,6 +711,14 @@ ' <input type="checkbox" size="25" name="notify_honorifics" id="notify_honorifics" value="1"' . ( ( $wgUser->getIntOption( 'notifyhonorifics', 1 ) == 1 ) ? 'checked' : '' ) . '/> </p>'; + $form .= '<p class="profile-update-title">' . + wfMsg( 'user-profile-preferences-miscellaneous' ) . + '</p> + <p class="profile-update-row">' . + wfMsg( 'user-profile-preferences-miscellaneous-show-year-of-birth' ) . + ' <input type="checkbox" size="25" name="show_year_of_birth" id="show_year_of_birth" value="1"' . ( ( $wgUser->getIntOption( 'showyearofbirth', $showYOB ) == 1 ) ? 'checked' : '' ) . '/> + </p>'; + // Allow extensions (like UserMailingList) to add new checkboxes wfRunHooks( 'SpecialUpdateProfile::displayPreferencesForm', array( $this, &$form ) ); @@ -735,7 +765,7 @@ $form = '<h1>' . wfMsg( 'user-profile-tidbits-title' ) . '</h1>'; $form .= UserProfile::getEditProfileNav( wfMsg( 'user-profile-section-custom' ) ); $form .= '<form action="" method="post" enctype="multipart/form-data" name="profile"> - <div class="profile-info clearfix"> + <div class="profile-info clearfix"> <div class="profile-update"> <p class="profile-update-title">' . wfMsgForContent( 'user-profile-tidbits-title' ) . '</p> <div id="profile-update-custom1"> Modified: trunk/extensions/SocialProfile/UserProfile/UpdateProfile.js =================================================================== --- trunk/extensions/SocialProfile/UserProfile/UpdateProfile.js 2011-10-19 20:15:34 UTC (rev 100268) +++ trunk/extensions/SocialProfile/UserProfile/UpdateProfile.js 2011-10-19 20:16:39 UTC (rev 100269) @@ -40,4 +40,14 @@ } document.getElementById( id + '_form' ).innerHTML = section_select; -} \ No newline at end of file +} + +mw.loader.using( 'jquery.ui.datepicker', function() { + jQuery( function( jQuery ) { + jQuery( '#birthday' ).datepicker({ + changeYear: true, + yearRange: '1930:c', + dateFormat: jQuery( '#birthday' ).hasClass( 'long-birthday' ) ? 'mm/dd/yy' : 'mm/dd' + }); + }); +}); \ No newline at end of file Modified: trunk/extensions/SocialProfile/UserProfile/UserProfile.i18n.php =================================================================== --- trunk/extensions/SocialProfile/UserProfile/UserProfile.i18n.php 2011-10-19 20:15:34 UTC (rev 100268) +++ trunk/extensions/SocialProfile/UserProfile/UserProfile.i18n.php 2011-10-19 20:16:39 UTC (rev 100269) @@ -117,6 +117,7 @@ 'user-profile-personal-hometown' => 'Hometown', 'user-profile-personal-birthday' => 'Birthday', 'user-profile-personal-birthdate' => 'Date (MM/DD)', + 'user-profile-personal-birthdate-with-year' => 'Date (MM/DD/YYYY)', 'user-profile-personal-aboutme' => 'About me', 'user-profile-personal-work' => 'Work', 'user-profile-personal-occupation' => 'Occupation', @@ -142,6 +143,8 @@ 'user-profile-preferences-emails-gift' => 'When you receive a gift', 'user-profile-preferences-emails-level' => 'When advancing a level', 'user-profile-preferences-emails-weekly' => 'Receive weekly email updates', + 'user-profile-preferences-miscellaneous' => 'Miscellaneous', + 'user-profile-preferences-miscellaneous-show-year-of-birth' => 'Show year of birth', 'user-profile-update-button' => 'Update', 'user-profile-tidbits-title' => 'Tidbits', 'user-profile-tidbits-favmoment' => 'Favorite sports moment', @@ -9284,6 +9287,7 @@ 'user-profile-personal-hometown' => 'Родной город', 'user-profile-personal-birthday' => 'День рождения', 'user-profile-personal-birthdate' => 'Дата (ММ/ДД)', + 'user-profile-personal-birthdate-with-year' => 'Дата (ММ/ДД/ГГГГ)', 'user-profile-personal-aboutme' => 'Обо мне', 'user-profile-personal-work' => 'Работа', 'user-profile-personal-occupation' => 'Занятие', @@ -9309,6 +9313,8 @@ 'user-profile-preferences-emails-gift' => 'Когда вы получаете подарок', 'user-profile-preferences-emails-level' => 'Когда повышается уровень', 'user-profile-preferences-emails-weekly' => 'Получать еженедельные обновления по почте', + 'user-profile-preferences-miscellaneous' => 'Разное', + 'user-profile-preferences-miscellaneous-show-year-of-birth' => 'Показывать год рождения', 'user-profile-update-button' => 'Обновить', 'user-profile-tidbits-title' => 'Интересные подробности', 'user-profile-tidbits-favmoment' => 'Любимые спортивный момент', Modified: trunk/extensions/SocialProfile/UserProfile/UserProfileClass.php =================================================================== --- trunk/extensions/SocialProfile/UserProfile/UserProfileClass.php 2011-10-19 20:15:34 UTC (rev 100268) +++ trunk/extensions/SocialProfile/UserProfile/UserProfileClass.php 2011-10-19 20:16:39 UTC (rev 100269) @@ -84,6 +84,9 @@ public function getProfile() { global $wgMemc; + $user = User::newFromId( $this->user_id ); + $user->loadFromId(); + // Try cache first $key = wfMemcKey( 'user', 'profile', 'info', $this->user_id ); $data = $wgMemc->get( $key ); @@ -107,13 +110,15 @@ $profile['user_page_type'] = 1; $profile['user_id'] = 0; } + $showYOB = $user->getIntOption( 'showyearofbirth', !isset( $row->up_birthday ) ) == 1; + $issetUpBirthday = isset( $row->up_birthday ) ? $row->up_birthday : ''; $profile['location_city'] = isset( $row->up_location_city ) ? $row->up_location_city : ''; $profile['location_state'] = isset( $row->up_location_state ) ? $row->up_location_state : ''; $profile['location_country'] = isset( $row->up_location_country ) ? $row->up_location_country : ''; $profile['hometown_city'] = isset( $row->up_hometown_city ) ? $row->up_hometown_city : ''; $profile['hometown_state'] = isset( $row->up_hometown_state ) ? $row->up_hometown_state : ''; $profile['hometown_country'] = isset( $row->up_hometown_country ) ? $row->up_hometown_country : ''; - $profile['birthday'] = $this->formatBirthday( isset( $row->up_birthday ) ? $row->up_birthday : '' ); + $profile['birthday'] = $this->formatBirthday( $issetUpBirthday, $showYOB); $profile['about'] = isset( $row->up_about ) ? $row->up_about : ''; $profile['places_lived'] = isset( $row->up_places_lived ) ? $row->up_places_lived : ''; @@ -138,8 +143,6 @@ $wgMemc->set( $key, $profile ); } - $user = User::newFromId( $this->user_id ); - $user->loadFromId(); $profile['real_name'] = $user->getRealName(); $profile['email'] = $user->getEmail(); @@ -152,12 +155,16 @@ * @param $birthday String: birthday in YYYY-MM-DD format * @return String: formatted birthday */ - function formatBirthday( $birthday ) { + function formatBirthday( $birthday, $showYear = true ) { $dob = explode( '-', $birthday ); if ( count( $dob ) == 3 ) { $month = $dob[1]; $day = $dob[2]; - return date( 'F jS', mktime( 0, 0, 0, $month, $day ) ); + if ( !$showYear ) { + return date( 'F jS', mktime( 0, 0, 0, $month, $day ) ); + } + $year = $dob[0]; + return date( 'F jS, Y', mktime( 0, 0, 0, $month, $day, $year ) ); //return $day . ' ' . $wgLang->getMonthNameGen( $month ); } return $birthday; _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs