r84258 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84257‎ | r84258 | r84259 >
Date:19:15, 18 March 2011
Author:happy-melon
Status:resolved (Comments)
Tags:
Comment:
More cleanup in Block.php. Push Block::encodeExpiry() and Block::decodeExpiry() deeper into the callstack, to DatabaseBase for encode and Language for decode. The vast majority of callers of these functions are not handling block expiries, but expiries generally, particularly page protections.
Modified paths:
  • /trunk/extensions/GlobalBlocking/GlobalBlocking.class.php (modified) (history)
  • /trunk/extensions/GlobalBlocking/SpecialGlobalBlockList.php (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Block.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryBlocks.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryInfo.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryProtectedTitles.php (modified) (history)
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialProtectedpages.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialProtectedtitles.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryInfo.php
@@ -397,6 +397,7 @@
398398 * Get information about protections and put it in $protections
399399 */
400400 private function getProtectionInfo() {
 401+ global $wgContLang;
401402 $this->protections = array();
402403 $db = $this->getDB();
403404
@@ -415,7 +416,7 @@
416417 $a = array(
417418 'type' => $row->pr_type,
418419 'level' => $row->pr_level,
419 - 'expiry' => Block::decodeExpiry( $row->pr_expiry, TS_ISO_8601 )
 420+ 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry, TS_ISO_8601 )
420421 );
421422 if ( $row->pr_cascade ) {
422423 $a['cascade'] = '';
@@ -472,7 +473,7 @@
473474 $this->protections[$row->pt_namespace][$row->pt_title][] = array(
474475 'type' => 'create',
475476 'level' => $row->pt_create_perm,
476 - 'expiry' => Block::decodeExpiry( $row->pt_expiry, TS_ISO_8601 )
 477+ 'expiry' => $wgContLang->formatExpiry( $row->pt_expiry, TS_ISO_8601 )
477478 );
478479 }
479480 }
@@ -506,7 +507,7 @@
507508 $this->protections[$row->tl_namespace][$row->tl_title][] = array(
508509 'type' => $row->pr_type,
509510 'level' => $row->pr_level,
510 - 'expiry' => Block::decodeExpiry( $row->pr_expiry, TS_ISO_8601 ),
 511+ 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry, TS_ISO_8601 ),
511512 'source' => $source->getPrefixedText()
512513 );
513514 }
@@ -529,7 +530,7 @@
530531 $this->protections[NS_FILE][$row->il_to][] = array(
531532 'type' => $row->pr_type,
532533 'level' => $row->pr_level,
533 - 'expiry' => Block::decodeExpiry( $row->pr_expiry, TS_ISO_8601 ),
 534+ 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry, TS_ISO_8601 ),
534535 'source' => $source->getPrefixedText()
535536 );
536537 }
Index: trunk/phase3/includes/api/ApiQueryBlocks.php
@@ -46,7 +46,7 @@
4747 }
4848
4949 public function execute() {
50 - global $wgUser;
 50+ global $wgUser, $wgContLang;
5151
5252 $params = $this->extractRequestParams();
5353 if ( isset( $params['users'] ) && isset( $params['ip'] ) ) {
@@ -170,7 +170,7 @@
171171 $block['timestamp'] = wfTimestamp( TS_ISO_8601, $row->ipb_timestamp );
172172 }
173173 if ( $fld_expiry ) {
174 - $block['expiry'] = Block::decodeExpiry( $row->ipb_expiry, TS_ISO_8601 );
 174+ $block['expiry'] = $wgContLang->formatExpiry( $row->ipb_expiry, TS_ISO_8601 );
175175 }
176176 if ( $fld_reason ) {
177177 $block['reason'] = $row->ipb_reason;
Index: trunk/phase3/includes/api/ApiQueryProtectedTitles.php
@@ -117,7 +117,8 @@
118118 }
119119
120120 if ( isset( $prop['expiry'] ) ) {
121 - $vals['expiry'] = Block::decodeExpiry( $row->pt_expiry, TS_ISO_8601 );
 121+ global $wgContLang;
 122+ $vals['expiry'] = $wgContLang->formatExpiry( $row->pt_expiry, TS_ISO_8601 );
122123 }
123124
124125 if ( isset( $prop['level'] ) ) {
Index: trunk/phase3/includes/Title.php
@@ -1566,20 +1566,7 @@
15671567 $blockExpiry = $user->mBlock->mExpiry;
15681568 $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW, $user->mBlock->mTimestamp ), true );
15691569 if ( $blockExpiry == 'infinity' ) {
1570 - // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
1571 - $scBlockExpiryOptions = wfMsg( 'ipboptions' );
1572 -
1573 - foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
1574 - if ( !strpos( $option, ':' ) )
1575 - continue;
1576 -
1577 - list( $show, $value ) = explode( ':', $option );
1578 -
1579 - if ( $value == 'infinite' || $value == 'indefinite' ) {
1580 - $blockExpiry = $show;
1581 - break;
1582 - }
1583 - }
 1570+ $blockExpiry = wfMessage( 'infiniteblock' );
15841571 } else {
15851572 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW, $blockExpiry ), true );
15861573 }
@@ -1680,10 +1667,10 @@
16811668
16821669 $dbw = wfGetDB( DB_MASTER );
16831670
1684 - $encodedExpiry = Block::encodeExpiry( $expiry, $dbw );
 1671+ $encodedExpiry = $dbw->encodeExpiry( $expiry );
16851672
16861673 $expiry_description = '';
1687 - if ( $encodedExpiry != 'infinity' ) {
 1674+ if ( $encodedExpiry != $dbw->getInfinity() ) {
16881675 $expiry_description = ' (' . wfMsgForContent( 'protect-expiring', $wgContLang->timeanddate( $expiry ),
16891676 $wgContLang->date( $expiry ) , $wgContLang->time( $expiry ) ) . ')';
16901677 } else {
@@ -1696,7 +1683,7 @@
16971684 'pt_namespace' => $namespace,
16981685 'pt_title' => $title,
16991686 'pt_create_perm' => $create_perm,
1700 - 'pt_timestamp' => Block::encodeExpiry( wfTimestampNow(), $dbw ),
 1687+ 'pt_timestamp' => $dbw->encodeExpiry( wfTimestampNow() ),
17011688 'pt_expiry' => $encodedExpiry,
17021689 'pt_user' => $wgUser->getId(),
17031690 'pt_reason' => $reason,
@@ -2037,6 +2024,7 @@
20382025 * contains a array of unique groups.
20392026 */
20402027 public function getCascadeProtectionSources( $getPages = true ) {
 2028+ global $wgContLang;
20412029 $pagerestrictions = array();
20422030
20432031 if ( isset( $this->mCascadeSources ) && $getPages ) {
@@ -2082,7 +2070,7 @@
20832071 $purgeExpired = false;
20842072
20852073 foreach ( $res as $row ) {
2086 - $expiry = Block::decodeExpiry( $row->pr_expiry );
 2074+ $expiry = $wgContLang->formatExpiry( $row->pr_expiry, TS_MW );
20872075 if ( $expiry > $now ) {
20882076 if ( $getPages ) {
20892077 $page_id = $row->pr_page;
@@ -2163,13 +2151,14 @@
21642152 * restrictions from page table (pre 1.10)
21652153 */
21662154 public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) {
 2155+ global $wgContLang;
21672156 $dbr = wfGetDB( DB_SLAVE );
21682157
21692158 $restrictionTypes = $this->getRestrictionTypes();
21702159
21712160 foreach ( $restrictionTypes as $type ) {
21722161 $this->mRestrictions[$type] = array();
2173 - $this->mRestrictionsExpiry[$type] = Block::decodeExpiry( '' );
 2162+ $this->mRestrictionsExpiry[$type] = $wgContLang->formatExpiry( '', TS_MW );
21742163 }
21752164
21762165 $this->mCascadeRestriction = false;
@@ -2212,7 +2201,7 @@
22132202
22142203 // This code should be refactored, now that it's being used more generally,
22152204 // But I don't really see any harm in leaving it in Block for now -werdna
2216 - $expiry = Block::decodeExpiry( $row->pr_expiry );
 2205+ $expiry = $wgContLang->formatExpiry( $row->pr_expiry, TS_MW );
22172206
22182207 // Only apply the restrictions if they haven't expired!
22192208 if ( !$expiry || $expiry > $now ) {
@@ -2241,12 +2230,17 @@
22422231 * restrictions from page table (pre 1.10)
22432232 */
22442233 public function loadRestrictions( $oldFashionedRestrictions = null ) {
 2234+ global $wgContLang;
22452235 if ( !$this->mRestrictionsLoaded ) {
22462236 if ( $this->exists() ) {
22472237 $dbr = wfGetDB( DB_SLAVE );
22482238
2249 - $res = $dbr->select( 'page_restrictions', '*',
2250 - array( 'pr_page' => $this->getArticleId() ), __METHOD__ );
 2239+ $res = $dbr->select(
 2240+ 'page_restrictions',
 2241+ '*',
 2242+ array( 'pr_page' => $this->getArticleId() ),
 2243+ __METHOD__
 2244+ );
22512245
22522246 $this->loadRestrictionsFromResultWrapper( $res, $oldFashionedRestrictions );
22532247 } else {
@@ -2254,7 +2248,7 @@
22552249
22562250 if ( $title_protection ) {
22572251 $now = wfTimestampNow();
2258 - $expiry = Block::decodeExpiry( $title_protection['pt_expiry'] );
 2252+ $expiry = $wgContLang->formatExpiry( $title_protection['pt_expiry'], TS_MW );
22592253
22602254 if ( !$expiry || $expiry > $now ) {
22612255 // Apply the restrictions
@@ -2265,7 +2259,7 @@
22662260 $this->mTitleProtection = false;
22672261 }
22682262 } else {
2269 - $this->mRestrictionsExpiry['create'] = Block::decodeExpiry( '' );
 2263+ $this->mRestrictionsExpiry['create'] = $wgContLang->formatExpiry( '', TS_MW );
22702264 }
22712265 $this->mRestrictionsLoaded = true;
22722266 }
Index: trunk/phase3/includes/Block.php
@@ -45,7 +45,7 @@
4646 $this->mAuto = $auto;
4747 $this->mAnonOnly = $anonOnly;
4848 $this->mCreateAccount = $createAccount;
49 - $this->mExpiry = self::decodeExpiry( $expiry );
 49+ $this->mExpiry = $expiry;
5050 $this->mEnableAutoblock = $enableAutoblock;
5151 $this->mHideName = $hideName;
5252 $this->mBlockEmail = $blockEmail;
@@ -342,7 +342,7 @@
343343 $this->mAllowUsertalk = $row->ipb_allow_usertalk;
344344 $this->mHideName = $row->ipb_deleted;
345345 $this->mId = $row->ipb_id;
346 - $this->mExpiry = self::decodeExpiry( $row->ipb_expiry );
 346+ $this->mExpiry = $row->ipb_expiry;
347347
348348 if ( isset( $row->user_name ) ) {
349349 $this->mByName = $row->user_name;
@@ -420,7 +420,7 @@
421421 'ipb_anon_only' => $this->mAnonOnly,
422422 'ipb_create_account' => $this->mCreateAccount,
423423 'ipb_enable_autoblock' => $this->mEnableAutoblock,
424 - 'ipb_expiry' => self::encodeExpiry( $this->mExpiry, $dbw ),
 424+ 'ipb_expiry' => $dbw->encodeExpiry( $this->mExpiry ),
425425 'ipb_range_start' => $this->mRangeStart,
426426 'ipb_range_end' => $this->mRangeEnd,
427427 'ipb_deleted' => intval( $this->mHideName ), // typecast required for SQLite
@@ -460,7 +460,7 @@
461461 'ipb_anon_only' => $this->mAnonOnly,
462462 'ipb_create_account' => $this->mCreateAccount,
463463 'ipb_enable_autoblock' => $this->mEnableAutoblock,
464 - 'ipb_expiry' => self::encodeExpiry( $this->mExpiry, $dbw ),
 464+ 'ipb_expiry' => $dbw->encodeExpiry( $this->mExpiry ),
465465 'ipb_range_start' => $this->mRangeStart,
466466 'ipb_range_end' => $this->mRangeEnd,
467467 'ipb_deleted' => $this->mHideName,
@@ -778,6 +778,7 @@
779779 * @param $expiry String: timestamp for expiry, or
780780 * @param $db Database object
781781 * @return String
 782+ * @deprecated since 1.18; use $dbw->encodeExpiry() instead
782783 */
783784 public static function encodeExpiry( $expiry, $db ) {
784785 if ( $expiry == '' || $expiry == Block::infinity() ) {
@@ -793,13 +794,11 @@
794795 * @param $expiry String: Database expiry format
795796 * @param $timestampType Requested timestamp format
796797 * @return String
 798+ * @deprecated since 1.18; use $wgLang->decodeExpiry() instead
797799 */
798800 public static function decodeExpiry( $expiry, $timestampType = TS_MW ) {
799 - if ( $expiry == '' || $expiry == Block::infinity() ) {
800 - return Block::infinity();
801 - } else {
802 - return wfTimestamp( $timestampType, $expiry );
803 - }
 801+ global $wgContLang;
 802+ return $wgContLang->formatExpiry( $expiry, $timestampType );
804803 }
805804
806805 /**
@@ -872,8 +871,10 @@
873872 *
874873 * @param $encoded_expiry String: Database encoded expiry time
875874 * @return Html-escaped String
 875+ * @deprecated since 1.18; use $wgLang->formatExpiry() instead
876876 */
877877 public static function formatExpiry( $encoded_expiry ) {
 878+ global $wgContLang;
878879 static $msg = null;
879880
880881 if ( is_null( $msg ) ) {
@@ -885,7 +886,7 @@
886887 }
887888 }
888889
889 - $expiry = self::decodeExpiry( $encoded_expiry );
 890+ $expiry = $wgContLang->formatExpiry( $encoded_expiry, TS_MW );
890891 if ( $expiry == self::infinity() ) {
891892 $expirystr = $msg['infiniteblock'];
892893 } else {
Index: trunk/phase3/includes/db/Database.php
@@ -2748,6 +2748,20 @@
27492749 }
27502750
27512751 /**
 2752+ * Encode an expiry time
 2753+ *
 2754+ * @param $expiry String: timestamp for expiry, or the 'infinity' string
 2755+ * @return String
 2756+ */
 2757+ public function encodeExpiry( $expiry ) {
 2758+ if ( $expiry == '' || $expiry == $this->getInfinity() ) {
 2759+ return $this->getInfinity();
 2760+ } else {
 2761+ return $this->timestamp( $expiry );
 2762+ }
 2763+ }
 2764+
 2765+ /**
27522766 * Allow or deny "big selects" for this session only. This is done by setting
27532767 * the sql_big_selects session variable.
27542768 *
Index: trunk/phase3/includes/OutputPage.php
@@ -1910,20 +1910,8 @@
19111911 $blockid = $wgUser->mBlock->mId;
19121912
19131913 $blockExpiry = $wgUser->mBlock->mExpiry;
1914 - if ( $blockExpiry == 'infinity' ) {
1915 - // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
1916 - // Search for localization in 'ipboptions'
1917 - $scBlockExpiryOptions = wfMsg( 'ipboptions' );
1918 - foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
1919 - if ( strpos( $option, ':' ) === false ) {
1920 - continue;
1921 - }
1922 - list( $show, $value ) = explode( ':', $option );
1923 - if ( $value == 'infinite' || $value == 'indefinite' ) {
1924 - $blockExpiry = $show;
1925 - break;
1926 - }
1927 - }
 1914+ if ( $blockExpiry == Block::infinity() ) {
 1915+ $blockExpiry = wfMessage( 'infiniteblock' );
19281916 } else {
19291917 $blockExpiry = $wgLang->timeanddate(
19301918 wfTimestamp( TS_MW, $blockExpiry ),
Index: trunk/phase3/includes/Article.php
@@ -2617,7 +2617,7 @@
26182618 if ( !isset( $expiry[$action] ) )
26192619 $expiry[$action] = Block::infinity();
26202620
2621 - $encodedExpiry[$action] = Block::encodeExpiry( $expiry[$action], $dbw );
 2621+ $encodedExpiry[$action] = $dbw->encodeExpiry( $expiry[$action] );
26222622 if ( $restrictions != '' ) {
26232623 $protect_description .= "[$action=$restrictions] (";
26242624 if ( $encodedExpiry[$action] != 'infinity' ) {
Index: trunk/phase3/includes/specials/SpecialProtectedtitles.php
@@ -93,7 +93,7 @@
9494 $stxt = '';
9595
9696 if ( $row->pt_expiry != 'infinity' && strlen($row->pt_expiry) ) {
97 - $expiry = Block::decodeExpiry( $row->pt_expiry );
 97+ $expiry = $wgLang->formatExpiry( $row->pt_expiry );
9898
9999 $expiry_description = wfMsg( 'protect-expiring', $wgLang->timeanddate( $expiry ) , $wgLang->date( $expiry ) , $wgLang->time( $expiry ) );
100100
Index: trunk/phase3/includes/specials/SpecialProtectedpages.php
@@ -80,10 +80,12 @@
8181
8282 wfProfileIn( __METHOD__ );
8383
84 - static $skin=null;
 84+ static $skin = null, $dbr = null;
8585
86 - if( is_null( $skin ) )
 86+ if( is_null( $skin ) ){
8787 $skin = $wgUser->getSkin();
 88+ $dbr = wfGetDB( DB_READ );
 89+ }
8890
8991 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
9092 $link = $skin->link( $title );
@@ -100,11 +102,15 @@
101103
102104 $stxt = '';
103105
104 - if( $row->pr_expiry != 'infinity' && strlen($row->pr_expiry) ) {
105 - $expiry = Block::decodeExpiry( $row->pr_expiry );
 106+ $expiry = $wgLang->formatExpiry( $row->pr_expiry, TS_MW );
 107+ if( $expiry != $dbr->getInfinity() ) {
106108
107 - $expiry_description = wfMsg( 'protect-expiring' , $wgLang->timeanddate( $expiry ) ,
108 - $wgLang->date( $expiry ) , $wgLang->time( $expiry ) );
 109+ $expiry_description = wfMsg(
 110+ 'protect-expiring',
 111+ $wgLang->timeanddate( $expiry ),
 112+ $wgLang->date( $expiry ),
 113+ $wgLang->time( $expiry )
 114+ );
109115
110116 $description_items[] = htmlspecialchars($expiry_description);
111117 }
Index: trunk/phase3/languages/Language.php
@@ -2970,6 +2970,37 @@
29712971 return array( $wikiUpperChars, $wikiLowerChars );
29722972 }
29732973
 2974+ /**
 2975+ * Decode an expiry (block, protection, etc) which has come from the DB
 2976+ *
 2977+ * @param $expiry String: Database expiry String
 2978+ * @param $format Bool|Int true to process using language functions, or TS_ constant
 2979+ * to return the expiry in a given timestamp
 2980+ * @return String
 2981+ */
 2982+ public function formatExpiry( $expiry, $format = true ) {
 2983+ static $dbr, $msg;
 2984+ if( !$dbr ){
 2985+ $dbr = wfGetDB( DB_SLAVE );
 2986+ $msg = wfMessage( 'infiniteblock' );
 2987+ }
 2988+
 2989+ if ( $expiry == '' || $expiry == $dbr->getInfinity() ) {
 2990+ return $format === true
 2991+ ? $msg
 2992+ : $dbr->getInfinity();
 2993+ } else {
 2994+ return $format === true
 2995+ ? $this->timeanddate( $expiry )
 2996+ : wfTimestamp( $format, $expiry );
 2997+ }
 2998+ }
 2999+
 3000+ /**
 3001+ * @todo Document
 3002+ * @param $seconds String
 3003+ * @return string
 3004+ */
29743005 function formatTimePeriod( $seconds ) {
29753006 if ( round( $seconds * 10 ) < 100 ) {
29763007 return $this->formatNum( sprintf( "%.1f", round( $seconds * 10 ) / 10 ) ) . $this->getMessageFromDB( 'seconds-abbrev' );
Index: trunk/extensions/GlobalBlocking/GlobalBlocking.class.php
@@ -25,6 +25,7 @@
2626 }
2727
2828 static function getUserBlockErrors( $user, $ip ) {
 29+ global $wgLang;
2930 static $result = null;
3031
3132 // Instance cache
@@ -43,7 +44,17 @@
4445 return $result = array();
4546 }
4647
47 - $expiry = Block::formatExpiry( $block->gb_expiry );
 48+ # Messy B/C until $wgLang->formatExpiry() is well embedded
 49+ if( Block::decodeExpiry( $block->gb_expiry ) == 'infinity' ){
 50+ $expiry = wfMsgExt( 'infiniteblock', 'parseinline' );
 51+ } else {
 52+ $expiry = Block::decodeExpiry( $block->gb_expiry );
 53+ $expiry = wfMsgExt(
 54+ 'expiringblock',
 55+ $wgLang->date( $expiry ),
 56+ $wgLang->time( $expiry )
 57+ );
 58+ }
4859
4960 $display_wiki = self::getWikiName( $block->gb_by_wiki );
5061 $user_display = self::maybeLinkUserpage( $block->gb_by_wiki, $block->gb_by );
Index: trunk/extensions/GlobalBlocking/SpecialGlobalBlockList.php
@@ -135,8 +135,17 @@
136136 $expiry = $row->gb_expiry;
137137 $options = array();
138138
139 - ## Options to display
140 - $options[] = Block::formatExpiry( $expiry );
 139+ # Messy B/C until $wgLang->formatExpiry() is well embedded
 140+ if( Block::decodeExpiry( $expiry ) == 'infinity' ){
 141+ $options[] = wfMsgExt( 'infiniteblock', 'parseinline' );
 142+ } else {
 143+ $expiry = Block::decodeExpiry( $expiry );
 144+ $options[] = wfMsgExt(
 145+ 'expiringblock',
 146+ $wgLang->date( $expiry ),
 147+ $wgLang->time( $expiry )
 148+ );
 149+ }
141150
142151 # Check for whitelisting.
143152 $wlinfo = GlobalBlocking::getWhitelistInfo( $row->gb_id );

Follow-up revisions

RevisionCommit summaryAuthorDate
r84273Follow-ups to r84258.happy-melon22:03, 18 March 2011
r84279Follow-ups to r84258happy-melon22:28, 18 March 2011
r93726Fixing Special:Protectedtitles to match Special:Protectedpages. This prevents...rotem11:43, 2 August 2011
r99082Fix a regression from 1.17: Show date/times in user preference timezone....raymond09:52, 6 October 2011

Comments

#Comment by Aaron Schulz (talk | contribs)   20:24, 18 March 2011

Don't forget extensions too.

#Comment by Happy-melon (talk | contribs)   20:50, 18 March 2011

Extensions were deliberately not done, because it breaks compatibility between later versions of extensions and older versions of MediaWiki (same principle behind keeping wfLoadExtensionMessages()). Extensions should be updated in a version or so's time.

#Comment by Aaron Schulz (talk | contribs)   21:22, 18 March 2011

Only for extensions that encourage mismatching extension/core versions, which I really don't like. I don't think any WMF extensions do that, so they can be done at least. Since the old block functions are still there, it doesn't really matter for now I guess.

#Comment by Nikerabbit (talk | contribs)   20:29, 18 March 2011

If you just toss the return value of wfMessage( 'foo' ); around, it will default to full parsing... I'd rather use ->text() in this case. Maybe the default should be changed?

+			$options[] = wfMsgExt(
+				'expiringblock',
+				$wgLang->date( $expiry ),
+				$wgLang->time( $expiry )
+			);

Second value missing.

Just grabbing random database handle in Language::formatExpiry feels ugly.

And lastly, I think $foo == (and equivalents) is just bullshit and should be avoided in new code. One should decide what is intended and write either !$foo or $foo === or strval($foo) === . In this case it's already in use, but something to keep in mind for future.

#Comment by Happy-melon (talk | contribs)   22:14, 18 March 2011

->text() is the equivalent of the old parsemag, which I never really liked. What's wrong with people linking "indefinite block" to a relevant policy or somesuch?

I've had a go at building a static method at the Database level for this, but it just seems more ugly still. The only other options would be a global function or a global define, both of which are equally unpleasant. Or continue to call $protectionFormExpiry = Block::infinite() and such incorrectnesses.

I agree on the $foo == ''; although as you say, the code was copied verbatim and I'd have to look carefully at what edgecase it's testing against there.

#Comment by Nikerabbit (talk | contribs)   08:57, 19 March 2011

What if it appears, say in a drop down?

#Comment by Happy-melon (talk | contribs)   11:03, 19 March 2011

Does it?

#Comment by 😂 (talk | contribs)   18:31, 28 June 2011
I've had a go at building a static method at the Database level for this, but it just seems more ugly still.

I really don't see what the problem was here. The implementations are identical for all subclasses except DatabaseMssql anyway.

#Comment by Happy-melon (talk | contribs)   16:28, 28 August 2011

It's basically impossible to do without Late Static Binding, for which we'd require PHP5.3.

#Comment by Duplicatebug (talk | contribs)   20:32, 18 March 2011

+ static $dbr, $msg; + if( !$dbr ){ + $dbr = wfGetDB( DB_SLAVE ); + $msg = wfMessage( 'infiniteblock' ); + }

It is better to cache the value of $dbr->getInfinity() instead of a db connection.

#Comment by Aaron Schulz (talk | contribs)   21:12, 17 June 2011
-		$this->mExpiry = self::decodeExpiry( $expiry );
+		$this->mExpiry = $expiry;
-		$this->mExpiry = self::decodeExpiry( $row->ipb_expiry );
+		$this->mExpiry = $row->ipb_expiry;

What about equals(), initFromRow(), doAutoblock(), isExpired()? The assume that it is either a MW timestamp or DB::getInfinity(). However, initFromRow() has the line:

$this->mExpiry = $row->ipb_expiry;

...and it never makes sure it is TS_MW as needed. That would break on non-MySQL.

It looks like *new* blocks come in with the expiry filtered via parseExpiryInput(), which is OK.

At any rate, I'm not sure I like mExpiry being DBMS dependent; ideally it would be independent and convert on save/load on the fly like most timestamp stuff already does.

#Comment by Aaron Schulz (talk | contribs)   21:14, 17 June 2011

To be clear, in that last sentence, I was talking not liking 'infinity' in mExpiry being DBMS dependent. Definitely non-infinite mExpiry timestamps should all be TS_MW.

#Comment by Aaron Schulz (talk | contribs)   22:05, 18 July 2011

Fixed in r92480.

Status & tagging log