Index: trunk/phase3/includes/api/ApiQueryLogEvents.php |
— | — | @@ -239,7 +239,7 @@ |
240 | 240 | list( $vals2['duration'], $vals2['flags'] ) = $params; |
241 | 241 | |
242 | 242 | // Indefinite blocks have no expiry time |
243 | | - if ( Block::parseExpiryInput( $params[0] ) !== Block::infinity() ) { |
| 243 | + if ( SpecialBlock::parseExpiryInput( $params[0] ) !== Block::infinity() ) { |
244 | 244 | $vals2['expiry'] = wfTimestamp( TS_ISO_8601, |
245 | 245 | strtotime( $params[0], wfTimestamp( TS_UNIX, $ts ) ) ); |
246 | 246 | } |
Index: trunk/phase3/includes/specials/SpecialBlock.php |
— | — | @@ -120,7 +120,7 @@ |
121 | 121 | 'validation-callback' => array( __CLASS__, 'validateTargetField' ), |
122 | 122 | ), |
123 | 123 | 'Expiry' => array( |
124 | | - 'type' => 'selectorother', |
| 124 | + 'type' => self::getSuggestedDurations() === array() ? 'text' : 'selectorother', |
125 | 125 | 'label-message' => 'ipbexpiry', |
126 | 126 | 'required' => true, |
127 | 127 | 'tabindex' => '2', |
— | — | @@ -139,10 +139,6 @@ |
140 | 140 | ), |
141 | 141 | ); |
142 | 142 | |
143 | | - if( wfMsgForContent( 'ipboptions' ) == '-' ){ |
144 | | - $a['Expiry']['type'] = 'text'; |
145 | | - } |
146 | | - |
147 | 143 | if( self::canBlockEmail( $wgUser ) ) { |
148 | 144 | $a['DisableEmail'] = array( |
149 | 145 | 'type' => 'check', |
— | — | @@ -501,7 +497,7 @@ |
502 | 498 | } |
503 | 499 | |
504 | 500 | if( ( strlen( $data['Expiry'] ) == 0) || ( strlen( $data['Expiry'] ) > 50 ) |
505 | | - || !Block::parseExpiryInput( $data['Expiry'] ) ) |
| 501 | + || !self::parseExpiryInput( $data['Expiry'] ) ) |
506 | 502 | { |
507 | 503 | return array( 'ipb_expiry_invalid' ); |
508 | 504 | } |
— | — | @@ -548,7 +544,7 @@ |
549 | 545 | $data['Reason'][0], # Reason string |
550 | 546 | wfTimestampNow(), # Block Timestamp |
551 | 547 | 0, # Is this an autoblock (no) |
552 | | - Block::parseExpiryInput( $data['Expiry'] ), # Expiry time |
| 548 | + self::parseExpiryInput( $data['Expiry'] ), # Expiry time |
553 | 549 | !$data['HardBlock'], # Block anon only |
554 | 550 | $data['CreateAccount'], |
555 | 551 | $data['AutoBlock'], |
— | — | @@ -645,10 +641,20 @@ |
646 | 642 | * to the standard "**<duration>|<displayname>" format? |
647 | 643 | * @return Array |
648 | 644 | */ |
649 | | - protected static function getSuggestedDurations(){ |
| 645 | + public static function getSuggestedDurations( $lang = null ){ |
650 | 646 | $a = array(); |
651 | | - foreach( explode( ',', wfMsgForContent( 'ipboptions' ) ) as $option ) { |
652 | | - if( strpos( $option, ':' ) === false ) $option = "$option:$option"; |
| 647 | + $msg = $lang === null |
| 648 | + ? wfMessage( 'ipboptions' )->inContentLanguage() |
| 649 | + : wfMessage( 'ipboptions' )->inLanguage( $lang ); |
| 650 | + |
| 651 | + if( $msg == '-' ){ |
| 652 | + return array(); |
| 653 | + } |
| 654 | + |
| 655 | + foreach( explode( ',', $msg ) as $option ) { |
| 656 | + if( strpos( $option, ':' ) === false ){ |
| 657 | + $option = "$option:$option"; |
| 658 | + } |
653 | 659 | list( $show, $value ) = explode( ':', $option ); |
654 | 660 | $a[htmlspecialchars( $show )] = htmlspecialchars( $value ); |
655 | 661 | } |
— | — | @@ -656,6 +662,25 @@ |
657 | 663 | } |
658 | 664 | |
659 | 665 | /** |
| 666 | + * Convert a submitted expiry time, which may be relative ("2 weeks", etc) or absolute |
| 667 | + * ("24 May 2034", etc), into an absolute timestamp we can put into the database. |
| 668 | + * @param $expiry String: whatever was typed into the form |
| 669 | + * @return String: timestamp or "infinity" string for the DB implementation |
| 670 | + */ |
| 671 | + public static function parseExpiryInput( $expiry ) { |
| 672 | + if ( $expiry == 'infinite' || $expiry == 'indefinite' ) { |
| 673 | + $expiry = Block::infinity(); |
| 674 | + } else { |
| 675 | + $expiry = strtotime( $expiry ); |
| 676 | + if ( $expiry < 0 || $expiry === false ) { |
| 677 | + return false; |
| 678 | + } |
| 679 | + $expiry = wfTimestamp( TS_MW, $expiry ); |
| 680 | + } |
| 681 | + return $expiry; |
| 682 | + } |
| 683 | + |
| 684 | + /** |
660 | 685 | * Can we do an email block? |
661 | 686 | * @param $user User: the sysop wanting to make a block |
662 | 687 | * @return Boolean |
Index: trunk/phase3/includes/Block.php |
— | — | @@ -885,8 +885,8 @@ |
886 | 886 | } |
887 | 887 | } |
888 | 888 | |
889 | | - $expiry = Block::decodeExpiry( $encoded_expiry ); |
890 | | - if ( $expiry == 'infinity' ) { |
| 889 | + $expiry = self::decodeExpiry( $encoded_expiry ); |
| 890 | + if ( $expiry == self::infinity() ) { |
891 | 891 | $expirystr = $msg['infiniteblock']; |
892 | 892 | } else { |
893 | 893 | global $wgLang; |
— | — | @@ -898,27 +898,20 @@ |
899 | 899 | return $expirystr; |
900 | 900 | } |
901 | 901 | |
| 902 | + # FIXME: everything above here is a mess, needs much cleaning up |
| 903 | + |
902 | 904 | /** |
903 | | - * Convert a typed-in expiry time into something we can put into the database. |
904 | | - * @param $expiry_input String: whatever was typed into the form |
905 | | - * @return String: more database friendly |
| 905 | + * Convert a submitted expiry time, which may be relative ("2 weeks", etc) or absolute |
| 906 | + * ("24 May 2034"), into an absolute timestamp we can put into the database. |
| 907 | + * @param $expiry String: whatever was typed into the form |
| 908 | + * @return String: timestamp or "infinity" string for th DB implementation |
| 909 | + * @deprecated since 1.18 moved to SpecialBlock::parseExpiryInput() |
906 | 910 | */ |
907 | | - public static function parseExpiryInput( $expiry_input ) { |
908 | | - if ( $expiry_input == 'infinite' || $expiry_input == 'indefinite' ) { |
909 | | - $expiry = 'infinity'; |
910 | | - } else { |
911 | | - $expiry = strtotime( $expiry_input ); |
912 | | - |
913 | | - if ( $expiry < 0 || $expiry === false ) { |
914 | | - return false; |
915 | | - } |
916 | | - } |
917 | | - |
918 | | - return $expiry; |
| 911 | + public static function parseExpiryInput( $expiry ) { |
| 912 | + wfDeprecated( __METHOD__ ); |
| 913 | + return SpecialBlock::parseExpiryInput( $expiry ); |
919 | 914 | } |
920 | 915 | |
921 | | - # FIXME: everything above here is a mess, needs much cleaning up |
922 | | - |
923 | 916 | /** |
924 | 917 | * Given a target and the target's type, get an existing Block object if possible. |
925 | 918 | * Note that passing an IP address will get an applicable rangeblock if the IP is |
— | — | @@ -1015,12 +1008,12 @@ |
1016 | 1009 | } |
1017 | 1010 | |
1018 | 1011 | public function getType(){ |
1019 | | - list( $target, $type ) = $this->getTargetAndType(); |
| 1012 | + list( /*...*/, $type ) = $this->getTargetAndType(); |
1020 | 1013 | return $type; |
1021 | 1014 | } |
1022 | 1015 | |
1023 | 1016 | public function getTarget(){ |
1024 | | - list( $target, $type ) = $this->getTargetAndType(); |
| 1017 | + list( $target, /*...*/ ) = $this->getTargetAndType(); |
1025 | 1018 | return $target; |
1026 | 1019 | } |
1027 | 1020 | } |
Index: trunk/phase3/languages/Language.php |
— | — | @@ -2675,28 +2675,19 @@ |
2676 | 2676 | } |
2677 | 2677 | |
2678 | 2678 | /** |
2679 | | - * For translating of expiry times |
2680 | | - * @param $str String: the validated block time in English |
2681 | | - * @return Somehow translated block time |
| 2679 | + * Maybe translate block durations. Note that this function is somewhat misnamed: it |
| 2680 | + * deals with translating the *duration* ("1 week", "4 days", etc), not the expiry time |
| 2681 | + * (which is an absolute timestamp). |
| 2682 | + * @param $str String: the validated block duration in English |
| 2683 | + * @return Somehow translated block duration |
2682 | 2684 | * @see LanguageFi.php for example implementation |
2683 | 2685 | */ |
2684 | 2686 | function translateBlockExpiry( $str ) { |
2685 | | - $scBlockExpiryOptions = $this->getMessageFromDB( 'ipboptions' ); |
2686 | | - |
2687 | | - if ( $scBlockExpiryOptions == '-' ) { |
2688 | | - return $str; |
2689 | | - } |
2690 | | - |
2691 | | - foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) { |
2692 | | - if ( strpos( $option, ':' ) === false ) { |
2693 | | - continue; |
2694 | | - } |
2695 | | - list( $show, $value ) = explode( ':', $option ); |
| 2687 | + foreach( SpecialBlock::getSuggestedDurations( $this ) as $show => $value ){ |
2696 | 2688 | if ( strcmp( $str, $value ) == 0 ) { |
2697 | 2689 | return htmlspecialchars( trim( $show ) ); |
2698 | 2690 | } |
2699 | 2691 | } |
2700 | | - |
2701 | 2692 | return $str; |
2702 | 2693 | } |
2703 | 2694 | |
Index: trunk/extensions/GlobalBlocking/GlobalBlocking.class.php |
— | — | @@ -38,8 +38,7 @@ |
39 | 39 | return $result = array(); |
40 | 40 | } |
41 | 41 | |
42 | | - if ( $user->isAllowed( 'ipblock-exempt' ) || |
43 | | - $user->isAllowed( 'globalblock-exempt' ) ) { |
| 42 | + if ( $user->isAllowed( 'ipblock-exempt', 'globalblock-exempt' ) ) { |
44 | 43 | // User is exempt from IP blocks. |
45 | 44 | return $result = array(); |
46 | 45 | } |
— | — | @@ -243,7 +242,7 @@ |
244 | 243 | static function block( $address, $reason, $expiry, $options = array() ) { |
245 | 244 | global $wgContLang; |
246 | 245 | |
247 | | - $expiry = Block::parseExpiryInput( $expiry ); |
| 246 | + $expiry = SpecialBlock::parseExpiryInput( $expiry ); |
248 | 247 | $errors = self::insertBlock( $address, $reason, $expiry, $options ); |
249 | 248 | |
250 | 249 | if ( count($errors) > 0 ) |
Index: trunk/extensions/CheckUser/CheckUser_body.php |
— | — | @@ -296,7 +296,7 @@ |
297 | 297 | $usertalk = new Article( $userTalkTitle ); |
298 | 298 | $safeUsers[] = '[[' . $userTitle->getPrefixedText() . '|' . $userTitle->getText() . ']]'; |
299 | 299 | $expirestr = $u->getId() ? 'indefinite' : '1 week'; |
300 | | - $expiry = Block::parseExpiryInput( $expirestr ); |
| 300 | + $expiry = SpecialBlock::parseExpiryInput( $expirestr ); |
301 | 301 | $anonOnly = IP::isIPAddress( $u->getName() ) ? 1 : 0; |
302 | 302 | // Create the block |
303 | 303 | $block = new Block( $u->getName(), // victim |
Index: trunk/extensions/AbuseFilter/AbuseFilter.class.php |
— | — | @@ -1015,7 +1015,7 @@ |
1016 | 1016 | $block->mTimestamp = wfTimestampNow(); |
1017 | 1017 | $block->mAnonOnly = 1; |
1018 | 1018 | $block->mCreateAccount = 1; |
1019 | | - $block->mExpiry = Block::parseExpiryInput( $wgAbuseFilterBlockDuration ); |
| 1019 | + $block->mExpiry = SpecialBlock::parseExpiryInput( $wgAbuseFilterBlockDuration ); |
1020 | 1020 | |
1021 | 1021 | $block->insert(); |
1022 | 1022 | |
— | — | @@ -1058,7 +1058,7 @@ |
1059 | 1059 | $block->mTimestamp = wfTimestampNow(); |
1060 | 1060 | $block->mAnonOnly = 0; |
1061 | 1061 | $block->mCreateAccount = 1; |
1062 | | - $block->mExpiry = Block::parseExpiryInput( '1 week' ); |
| 1062 | + $block->mExpiry = SpecialBlock::parseExpiryInput( '1 week' ); |
1063 | 1063 | |
1064 | 1064 | $block->insert(); |
1065 | 1065 | |