r84279 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84278‎ | r84279 | r84280 >
Date:22:28, 18 March 2011
Author:happy-melon
Status:ok (Comments)
Tags:
Comment:
Follow-ups to r84258
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Block.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/ProtectionForm.php (modified) (history)
  • /trunk/phase3/includes/api/ApiBlock.php (modified) (history)
  • /trunk/phase3/includes/api/ApiProtect.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialBlock.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialBlockList.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialProtectedpages.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ProtectionForm.php
@@ -158,7 +158,7 @@
159159 $value = $this->mExpirySelection[$action];
160160 }
161161 if ( $value == 'infinite' || $value == 'indefinite' || $value == 'infinity' ) {
162 - $time = Block::infinity();
 162+ $time = wfGetDB( DB_SLAVE )->getInfinity();
163163 } else {
164164 $unix = strtotime( $value );
165165
Index: trunk/phase3/includes/Article.php
@@ -2615,7 +2615,7 @@
26162616 $protect_description = '';
26172617 foreach ( $limit as $action => $restrictions ) {
26182618 if ( !isset( $expiry[$action] ) )
2619 - $expiry[$action] = Block::infinity();
 2619+ $expiry[$action] = $dbw->getInfinity();
26202620
26212621 $encodedExpiry[$action] = $dbw->encodeExpiry( $expiry[$action] );
26222622 if ( $restrictions != '' ) {
Index: trunk/phase3/includes/OutputPage.php
@@ -1909,15 +1909,7 @@
19101910
19111911 $blockid = $wgUser->mBlock->mId;
19121912
1913 - $blockExpiry = $wgUser->mBlock->mExpiry;
1914 - if ( $blockExpiry == Block::infinity() ) {
1915 - $blockExpiry = wfMessage( 'infiniteblock' );
1916 - } else {
1917 - $blockExpiry = $wgLang->timeanddate(
1918 - wfTimestamp( TS_MW, $blockExpiry ),
1919 - true
1920 - );
1921 - }
 1913+ $blockExpiry = $wgLang->formatExpiry( $wgUser->mBlock->mExpiry );
19221914
19231915 if ( $wgUser->mBlock->mAuto ) {
19241916 $msg = 'autoblockedtext';
Index: trunk/phase3/includes/api/ApiProtect.php
@@ -63,6 +63,7 @@
6464 }
6565
6666 $restrictionTypes = $titleObj->getRestrictionTypes();
 67+ $dbr = wfGetDB( DB_SLAVE );
6768
6869 $protections = array();
6970 $expiryarray = array();
@@ -86,7 +87,7 @@
8788 }
8889
8990 if ( in_array( $expiry[$i], array( 'infinite', 'indefinite', 'never' ) ) ) {
90 - $expiryarray[$p[0]] = Block::infinity();
 91+ $expiryarray[$p[0]] = $dbr->getInfinity();
9192 } else {
9293 $exp = strtotime( $expiry[$i] );
9394 if ( $exp < 0 || !$exp ) {
@@ -100,7 +101,7 @@
101102 $expiryarray[$p[0]] = $exp;
102103 }
103104 $resultProtections[] = array( $p[0] => $protections[$p[0]],
104 - 'expiry' => ( $expiryarray[$p[0]] == Block::infinity() ?
 105+ 'expiry' => ( $expiryarray[$p[0]] == $dbr->getInfinity() ?
105106 'infinite' :
106107 wfTimestamp( TS_ISO_8601, $expiryarray[$p[0]] ) ) );
107108 }
Index: trunk/phase3/includes/api/ApiBlock.php
@@ -104,7 +104,7 @@
105105
106106 $block = Block::newFromTargetAndType( $target, $type );
107107 if( $block instanceof Block ){
108 - $res['expiry'] = $block->mExpiry == Block::infinity()
 108+ $res['expiry'] = $block->mExpiry == wfGetDB( DB_SLAVE )->getInfinity()
109109 ? 'infinite'
110110 : wfTimestamp( TS_ISO_8601, $block->mExpiry );
111111 } else {
Index: trunk/phase3/includes/specials/SpecialBlockList.php
@@ -301,9 +301,7 @@
302302 break;
303303
304304 case 'ipb_expiry':
305 - $formatted = $value == Block::infinity()
306 - ? $msg['infiniteblock']
307 - : $wgLang->timeanddate( $value );
 305+ $formatted = $wgLang->formatExpiry( $value );
308306 if( $wgUser->isAllowed( 'block' ) ){
309307 if( $row->ipb_auto ){
310308 $links[] = $sk->linkKnown(
Index: trunk/phase3/includes/specials/SpecialBlock.php
@@ -120,7 +120,7 @@
121121 'validation-callback' => array( __CLASS__, 'validateTargetField' ),
122122 ),
123123 'Expiry' => array(
124 - 'type' => self::getSuggestedDurations() === array() ? 'text' : 'selectorother',
 124+ 'type' => !count( self::getSuggestedDurations() ) ? 'text' : 'selectorother',
125125 'label-message' => 'ipbexpiry',
126126 'required' => true,
127127 'tabindex' => '2',
@@ -668,8 +668,12 @@
669669 * @return String: timestamp or "infinity" string for the DB implementation
670670 */
671671 public static function parseExpiryInput( $expiry ) {
 672+ static $infinity;
 673+ if( $infinity == null ){
 674+ $infinity = wfGetDB( DB_READ )->getInfinity();
 675+ }
672676 if ( $expiry == 'infinite' || $expiry == 'indefinite' ) {
673 - $expiry = Block::infinity();
 677+ $expiry = $infinity;
674678 } else {
675679 $expiry = strtotime( $expiry );
676680 if ( $expiry < 0 || $expiry === false ) {
Index: trunk/phase3/includes/specials/SpecialProtectedpages.php
@@ -80,11 +80,11 @@
8181
8282 wfProfileIn( __METHOD__ );
8383
84 - static $skin = null, $dbr = null;
 84+ static $skin = null, $infinity = null;
8585
8686 if( is_null( $skin ) ){
8787 $skin = $wgUser->getSkin();
88 - $dbr = wfGetDB( DB_READ );
 88+ $infinity = wfGetDB( DB_READ )->getInfinity();
8989 }
9090
9191 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
@@ -103,7 +103,7 @@
104104 $stxt = '';
105105
106106 $expiry = $wgLang->formatExpiry( $row->pr_expiry, TS_MW );
107 - if( $expiry != $dbr->getInfinity() ) {
 107+ if( $expiry != $infinity ) {
108108
109109 $expiry_description = wfMsg(
110110 'protect-expiring',
Index: trunk/phase3/includes/Block.php
@@ -781,11 +781,7 @@
782782 * @deprecated since 1.18; use $dbw->encodeExpiry() instead
783783 */
784784 public static function encodeExpiry( $expiry, $db ) {
785 - if ( $expiry == '' || $expiry == Block::infinity() ) {
786 - return Block::infinity();
787 - } else {
788 - return $db->timestamp( $expiry );
789 - }
 785+ return $db->encodeExpiry( $expiry );
790786 }
791787
792788 /**
@@ -859,7 +855,7 @@
860856 /**
861857 * Get a value to insert into expiry field of the database when infinite expiry
862858 * is desired
863 - *
 859+ * @deprecated since 1.18, call $dbr->getInfinity() directly
864860 * @return String
865861 */
866862 public static function infinity() {
@@ -887,7 +883,7 @@
888884 }
889885
890886 $expiry = $wgContLang->formatExpiry( $encoded_expiry, TS_MW );
891 - if ( $expiry == self::infinity() ) {
 887+ if ( $expiry == wfGetDB( DB_SLAVE )->getInfinity() ) {
892888 $expirystr = $msg['infiniteblock'];
893889 } else {
894890 global $wgLang;

Sign-offs

UserFlagDate
Aaron Schulzinspected21:27, 17 June 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r84287Missed one instance of Block::infinity() from r84279.happy-melon23:29, 18 March 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r84258More cleanup in Block.php. Push Block::encodeExpiry() and Block::decodeExpir...happy-melon19:15, 18 March 2011

Comments

#Comment by Duplicatebug (talk | contribs)   14:25, 23 April 2011

DB_READ is obsolete

#Comment by Aaron Schulz (talk | contribs)   20:57, 17 June 2011

Why is Block::infinity() deprecated? The random DB handles seem worse too me.

#Comment by 😂 (talk | contribs)   18:25, 28 June 2011

+1

Status & tagging log