r99899 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99898‎ | r99899 | r99900 >
Date:19:02, 15 October 2011
Author:demon
Status:reverted
Tags:
Comment:
Temporarily reverting r99863 to see if I can pin down test failures
Modified paths:
  • /trunk/phase3/includes/Preferences.php (modified) (history)
  • /trunk/phase3/includes/UserMailer.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/UserMailer.php
@@ -158,7 +158,7 @@
159159 global $wgEnotifMaxRecips, $wgAdditionalMailParams;
160160
161161 $emails = '';
162 - wfDebug( __METHOD__ . ': sending mail to ' . is_array( $to ) ? implode( ', ', $to ) : $to . "\n" );
 162+ wfDebug( __METHOD__ . ': sending mail to ' . implode( ',', array( $to->toString() ) ) . "\n" );
163163
164164 $headers['From'] = $from->toString();
165165 $headers['Return-Path'] = $from->toString();
@@ -571,14 +571,8 @@
572572 $keys = array();
573573
574574 if ( $this->oldid ) {
575 - if ( $wgEnotifImpersonal ) {
576 - // For impersonal mail, show a diff link to the last revision.
577 - $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_lastdiff',
578 - $this->title->getCanonicalUrl( 'diff=next&oldid=' . $this->oldid ) );
579 - } else {
580 - $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_lastvisited',
581 - $this->title->getCanonicalUrl( 'diff=0&oldid=' . $this->oldid ) );
582 - }
 575+ $difflink = $this->title->getCanonicalUrl( 'diff=0&oldid=' . $this->oldid );
 576+ $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_lastvisited', $difflink );
583577 $keys['$OLDID'] = $this->oldid;
584578 $keys['$CHANGEDORCREATED'] = wfMsgForContent( 'changed' );
585579 } else {
@@ -588,6 +582,15 @@
589583 $keys['$CHANGEDORCREATED'] = wfMsgForContent( 'created' );
590584 }
591585
 586+ if ( $wgEnotifImpersonal && $this->oldid ) {
 587+ /**
 588+ * For impersonal mail, show a diff link to the last
 589+ * revision.
 590+ */
 591+ $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_lastdiff',
 592+ $this->title->getCanonicalUrl( "oldid={$this->oldid}&diff=next" ) );
 593+ }
 594+
592595 $body = strtr( $body, $keys );
593596 $pagetitle = $this->title->getPrefixedText();
594597 $keys['$PAGETITLE'] = $pagetitle;
@@ -688,18 +691,22 @@
689692 // Note: The to parameter cannot be an address in the form of "Something <someone@example.com>".
690693 // The mail command will not parse this properly while talking with the MTA.
691694 $to = new MailAddress( $watchingUser );
 695+ $name = $wgEnotifUseRealName ? $watchingUser->getRealName() : $watchingUser->getName();
 696+ $body = str_replace( '$WATCHINGUSERNAME', $name, $this->body );
692697
 698+ $timecorrection = $watchingUser->getOption( 'timecorrection' );
 699+
693700 # $PAGEEDITDATE is the time and date of the page change
694701 # expressed in terms of individual local time of the notification
695702 # recipient, i.e. watching user
696703 $body = str_replace(
697 - array( '$WATCHINGUSERNAME',
 704+ array( '$PAGEEDITDATEANDTIME',
698705 '$PAGEEDITDATE',
699706 '$PAGEEDITTIME' ),
700 - array( $wgEnotifUseRealName ? $watchingUser->getRealName() : $watchingUser->getName(),
701 - $wgContLang->userDate( $this->timestamp, $watchingUser ),
702 - $wgContLang->userTime( $this->timestamp, $watchingUser ) ),
703 - $this->body );
 707+ array( $wgContLang->timeanddate( $this->timestamp, true, false, $timecorrection ),
 708+ $wgContLang->date( $this->timestamp, true, false, $timecorrection ),
 709+ $wgContLang->time( $this->timestamp, true, false, $timecorrection ) ),
 710+ $body );
704711
705712 return UserMailer::send( $to, $this->from, $this->subject, $body, $this->replyto );
706713 }
@@ -719,8 +726,8 @@
720727 '$PAGEEDITDATE',
721728 '$PAGEEDITTIME' ),
722729 array( wfMsgForContent( 'enotif_impersonal_salutation' ),
723 - $wgContLang->date( $this->timestamp, false, false ),
724 - $wgContLang->time( $this->timestamp, false, false ) ),
 730+ $wgContLang->date( $this->timestamp, true, false, false ),
 731+ $wgContLang->time( $this->timestamp, true, false, false ) ),
725732 $this->body );
726733
727734 return UserMailer::send( $addresses, $this->from, $this->subject, $body, $this->replyto );
Index: trunk/phase3/includes/Preferences.php
@@ -494,7 +494,6 @@
495495 $selectedSkin = $user->getOption( 'skin' );
496496 if ( in_array( $selectedSkin, array( 'cologneblue', 'standard' ) ) ) {
497497 $settings = array_flip( $context->getLang()->getQuickbarSettings() );
498 -
499498 $defaultPreferences['quickbar'] = array(
500499 'type' => 'radio',
501500 'options' => $settings,
Index: trunk/phase3/languages/Language.php
@@ -806,6 +806,82 @@
807807 }
808808
809809 /**
 810+ * Used by date() and time() to adjust the time output.
 811+ *
 812+ * @param $ts Int the time in date('YmdHis') format
 813+ * @param $tz Mixed: adjust the time by this amount (default false, mean we
 814+ * get user timecorrection setting)
 815+ * @return int
 816+ */
 817+ function userAdjust( $ts, $tz = false ) {
 818+ global $wgUser, $wgLocalTZoffset;
 819+
 820+ if ( $tz === false ) {
 821+ $tz = $wgUser->getOption( 'timecorrection' );
 822+ }
 823+
 824+ $data = explode( '|', $tz, 3 );
 825+
 826+ if ( $data[0] == 'ZoneInfo' ) {
 827+ wfSuppressWarnings();
 828+ $userTZ = timezone_open( $data[2] );
 829+ wfRestoreWarnings();
 830+ if ( $userTZ !== false ) {
 831+ $date = date_create( $ts, timezone_open( 'UTC' ) );
 832+ date_timezone_set( $date, $userTZ );
 833+ $date = date_format( $date, 'YmdHis' );
 834+ return $date;
 835+ }
 836+ # Unrecognized timezone, default to 'Offset' with the stored offset.
 837+ $data[0] = 'Offset';
 838+ }
 839+
 840+ $minDiff = 0;
 841+ if ( $data[0] == 'System' || $tz == '' ) {
 842+ #  Global offset in minutes.
 843+ if ( isset( $wgLocalTZoffset ) ) {
 844+ $minDiff = $wgLocalTZoffset;
 845+ }
 846+ } elseif ( $data[0] == 'Offset' ) {
 847+ $minDiff = intval( $data[1] );
 848+ } else {
 849+ $data = explode( ':', $tz );
 850+ if ( count( $data ) == 2 ) {
 851+ $data[0] = intval( $data[0] );
 852+ $data[1] = intval( $data[1] );
 853+ $minDiff = abs( $data[0] ) * 60 + $data[1];
 854+ if ( $data[0] < 0 ) {
 855+ $minDiff = -$minDiff;
 856+ }
 857+ } else {
 858+ $minDiff = intval( $data[0] ) * 60;
 859+ }
 860+ }
 861+
 862+ # No difference ? Return time unchanged
 863+ if ( 0 == $minDiff ) {
 864+ return $ts;
 865+ }
 866+
 867+ wfSuppressWarnings(); // E_STRICT system time bitching
 868+ # Generate an adjusted date; take advantage of the fact that mktime
 869+ # will normalize out-of-range values so we don't have to split $minDiff
 870+ # into hours and minutes.
 871+ $t = mktime( (
 872+ (int)substr( $ts, 8, 2 ) ), # Hours
 873+ (int)substr( $ts, 10, 2 ) + $minDiff, # Minutes
 874+ (int)substr( $ts, 12, 2 ), # Seconds
 875+ (int)substr( $ts, 4, 2 ), # Month
 876+ (int)substr( $ts, 6, 2 ), # Day
 877+ (int)substr( $ts, 0, 4 ) ); # Year
 878+
 879+ $date = date( 'YmdHis', $t );
 880+ wfRestoreWarnings();
 881+
 882+ return $date;
 883+ }
 884+
 885+ /**
810886 * This is a workalike of PHP's date() function, but with better
811887 * internationalisation, a reduced set of format characters, and a better
812888 * escaping format.
@@ -1644,82 +1720,6 @@
16451721 }
16461722
16471723 /**
1648 - * Used by date() and time() to adjust the time output.
1649 - *
1650 - * @param $ts Int the time in date('YmdHis') format
1651 - * @param $tz Mixed: adjust the time by this amount (default false, mean we
1652 - * get user timecorrection setting)
1653 - * @return int
1654 - */
1655 - function userAdjust( $ts, $tz = false ) {
1656 - global $wgUser, $wgLocalTZoffset;
1657 -
1658 - if ( $tz === false ) {
1659 - $tz = $wgUser->getOption( 'timecorrection' );
1660 - }
1661 -
1662 - $data = explode( '|', $tz, 3 );
1663 -
1664 - if ( $data[0] == 'ZoneInfo' ) {
1665 - wfSuppressWarnings();
1666 - $userTZ = timezone_open( $data[2] );
1667 - wfRestoreWarnings();
1668 - if ( $userTZ !== false ) {
1669 - $date = date_create( $ts, timezone_open( 'UTC' ) );
1670 - date_timezone_set( $date, $userTZ );
1671 - $date = date_format( $date, 'YmdHis' );
1672 - return $date;
1673 - }
1674 - # Unrecognized timezone, default to 'Offset' with the stored offset.
1675 - $data[0] = 'Offset';
1676 - }
1677 -
1678 - $minDiff = 0;
1679 - if ( $data[0] == 'System' || $tz == '' ) {
1680 - #  Global offset in minutes.
1681 - if ( isset( $wgLocalTZoffset ) ) {
1682 - $minDiff = $wgLocalTZoffset;
1683 - }
1684 - } elseif ( $data[0] == 'Offset' ) {
1685 - $minDiff = intval( $data[1] );
1686 - } else {
1687 - $data = explode( ':', $tz );
1688 - if ( count( $data ) == 2 ) {
1689 - $data[0] = intval( $data[0] );
1690 - $data[1] = intval( $data[1] );
1691 - $minDiff = abs( $data[0] ) * 60 + $data[1];
1692 - if ( $data[0] < 0 ) {
1693 - $minDiff = -$minDiff;
1694 - }
1695 - } else {
1696 - $minDiff = intval( $data[0] ) * 60;
1697 - }
1698 - }
1699 -
1700 - # No difference ? Return time unchanged
1701 - if ( 0 == $minDiff ) {
1702 - return $ts;
1703 - }
1704 -
1705 - wfSuppressWarnings(); // E_STRICT system time bitching
1706 - # Generate an adjusted date; take advantage of the fact that mktime
1707 - # will normalize out-of-range values so we don't have to split $minDiff
1708 - # into hours and minutes.
1709 - $t = mktime( (
1710 - (int)substr( $ts, 8, 2 ) ), # Hours
1711 - (int)substr( $ts, 10, 2 ) + $minDiff, # Minutes
1712 - (int)substr( $ts, 12, 2 ), # Seconds
1713 - (int)substr( $ts, 4, 2 ), # Month
1714 - (int)substr( $ts, 6, 2 ), # Day
1715 - (int)substr( $ts, 0, 4 ) ); # Year
1716 -
1717 - $date = date( 'YmdHis', $t );
1718 - wfRestoreWarnings();
1719 -
1720 - return $date;
1721 - }
1722 -
1723 - /**
17241724 * This is meant to be used by time(), date(), and timeanddate() to get
17251725 * the date preference they're supposed to use, it should be used in
17261726 * all children.
@@ -1840,113 +1840,6 @@
18411841 }
18421842
18431843 /**
1844 - * Internal helper function for userDate(), userTime() and userTimeAndDate()
1845 - *
1846 - * @param $type String: can be 'date', 'time' or 'both'
1847 - * @param $ts Mixed: the time format which needs to be turned into a
1848 - * date('YmdHis') format with wfTimestamp(TS_MW,$ts)
1849 - * @param $user User object used to get preferences for timezone and format
1850 - * @param $options Array, can contain the following keys:
1851 - * - 'timecorrection': time correction, can have the following values:
1852 - * - true: use user's preference
1853 - * - false: don't use time correction
1854 - * - integer: value of time correction in minutes
1855 - * - 'format': format to use, can have the following values:
1856 - * - true: use user's preference
1857 - * - false: use default preference
1858 - * - string: format to use
1859 - * @return String
1860 - */
1861 - private function internalUserTimeAndDate( $type, $ts, User $user, array $options ) {
1862 - $ts = wfTimestamp( TS_MW, $ts );
1863 - $options += array( 'timecorrection' => true, 'format' => true );
1864 - if ( $options['timecorrection'] !== false ) {
1865 - if ( $options['timecorrection'] === true ) {
1866 - $offset = $user->getOption( 'timecorrection' );
1867 - } else {
1868 - $offset = $options['timecorrection'];
1869 - }
1870 - $ts = $this->userAdjust( $ts, $offset );
1871 - }
1872 - if ( $options['format'] === true ) {
1873 - $format = $user->getDatePreference();
1874 - } else {
1875 - $format = $options['format'];
1876 - }
1877 - $df = $this->getDateFormatString( $type, $this->dateFormat( $format ) );
1878 - return $this->sprintfDate( $df, $ts );
1879 - }
1880 -
1881 - /**
1882 - * Get the formatted date for the given timestamp and formatted for
1883 - * the given user.
1884 - *
1885 - * @param $type String: can be 'date', 'time' or 'both'
1886 - * @param $ts Mixed: the time format which needs to be turned into a
1887 - * date('YmdHis') format with wfTimestamp(TS_MW,$ts)
1888 - * @param $user User object used to get preferences for timezone and format
1889 - * @param $options Array, can contain the following keys:
1890 - * - 'timecorrection': time correction, can have the following values:
1891 - * - true: use user's preference
1892 - * - false: don't use time correction
1893 - * - integer: value of time correction in minutes
1894 - * - 'format': format to use, can have the following values:
1895 - * - true: use user's preference
1896 - * - false: use default preference
1897 - * - string: format to use
1898 - * @return String
1899 - */
1900 - public function userDate( $ts, User $user, array $options = array() ) {
1901 - return $this->internalUserTimeAndDate( 'date', $ts, $user, $options );
1902 - }
1903 -
1904 - /**
1905 - * Get the formatted time for the given timestamp and formatted for
1906 - * the given user.
1907 - *
1908 - * @param $type String: can be 'date', 'time' or 'both'
1909 - * @param $ts Mixed: the time format which needs to be turned into a
1910 - * date('YmdHis') format with wfTimestamp(TS_MW,$ts)
1911 - * @param $user User object used to get preferences for timezone and format
1912 - * @param $options Array, can contain the following keys:
1913 - * - 'timecorrection': time correction, can have the following values:
1914 - * - true: use user's preference
1915 - * - false: don't use time correction
1916 - * - integer: value of time correction in minutes
1917 - * - 'format': format to use, can have the following values:
1918 - * - true: use user's preference
1919 - * - false: use default preference
1920 - * - string: format to use
1921 - * @return String
1922 - */
1923 - public function userTime( $ts, User $user, array $options = array() ) {
1924 - return $this->internalUserTimeAndDate( 'time', $ts, $user, $options );
1925 - }
1926 -
1927 - /**
1928 - * Get the formatted date and time for the given timestamp and formatted for
1929 - * the given user.
1930 - *
1931 - * @param $type String: can be 'date', 'time' or 'both'
1932 - * @param $ts Mixed: the time format which needs to be turned into a
1933 - * date('YmdHis') format with wfTimestamp(TS_MW,$ts)
1934 - * @param $user User object used to get preferences for timezone and format
1935 - * @param $options Array, can contain the following keys:
1936 - * - 'timecorrection': time correction, can have the following values:
1937 - * - true: use user's preference
1938 - * - false: don't use time correction
1939 - * - integer: value of time correction in minutes
1940 - * - 'format': format to use, can have the following values:
1941 - * - true: use user's preference
1942 - * - false: use default preference
1943 - * - string: format to use
1944 - * @return String
1945 - */
1946 - public function userTimeAndDate( $ts, User $user, array $options = array() ) {
1947 - return $this->internalUserTimeAndDate( 'both', $ts, $user, $options );
1948 - }
1949 -
1950 - /**
19511844 * @param $key string
19521845 * @return array|null
19531846 */

Follow-up revisions

RevisionCommit summaryAuthorDate
r99900Self revert r99899....I HATE YOU PHPUNIT YOU @#Q**#(#@(#@@#(!!!demon19:06, 15 October 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99863* Added Language::userDate(), Language::userTime() and Language::userTimeAndD...ialex09:32, 15 October 2011

Status & tagging log