Index: trunk/extensions/LiquidThreads/classes/View.php |
— | — | @@ -27,6 +27,8 @@ |
28 | 28 | protected $sort_order = LQT_NEWEST_CHANGES; |
29 | 29 | |
30 | 30 | static $stylesAndScriptsDone = false; |
| 31 | + |
| 32 | + static $userSignatureCache = array(); |
31 | 33 | |
32 | 34 | function __construct( &$output, &$article, &$title, &$user, &$request ) { |
33 | 35 | $this->article = $article; |
— | — | @@ -826,11 +828,8 @@ |
827 | 829 | $sk = $wgUser->getSkin(); |
828 | 830 | |
829 | 831 | $author = $thread->author(); |
830 | | - $signature = $sk->userLink( $author->getId(), $author->getName() ); |
831 | | - $signature = '— '. Xml::tags( 'span', array( 'class' => 'lqt-thread-author' ), |
832 | | - $signature ); |
833 | | - $signature .= $sk->userToolLinks( $author->getId(), $author->getName() ); |
834 | 832 | |
| 833 | + $signature = $this->getSignature( $author ); |
835 | 834 | $signature = Xml::tags( 'div', array( 'class' => 'lqt-thread-signature' ), |
836 | 835 | $signature ); |
837 | 836 | |
— | — | @@ -1194,4 +1193,33 @@ |
1195 | 1194 | function showSummary( $t ) { |
1196 | 1195 | $this->output->addHTML( $this->getSummary( $t ) ); |
1197 | 1196 | } |
| 1197 | + |
| 1198 | + function getSignature( $user ) { |
| 1199 | + if ( is_object($user) ) { |
| 1200 | + $uid = $user->getId(); |
| 1201 | + } elseif ( is_integer($user) ) { |
| 1202 | + $uid = $user; |
| 1203 | + $user = null; |
| 1204 | + } else { |
| 1205 | + $user = User::newFromName( $user ); |
| 1206 | + $uid = $user->getId(); |
| 1207 | + } |
| 1208 | + |
| 1209 | + if ( isset( self::$userSignatureCache[$uid] ) ) { |
| 1210 | + return self::$userSignatureCache[$uid]; |
| 1211 | + } |
| 1212 | + |
| 1213 | + if (!$user) { |
| 1214 | + $user = User::newFromId( $uid ); |
| 1215 | + } |
| 1216 | + |
| 1217 | + global $wgParser, $wgOut; |
| 1218 | + |
| 1219 | + $sig = $wgParser->getUserSig( $user ); |
| 1220 | + $sig = $wgOut->parseInline( $sig ); |
| 1221 | + |
| 1222 | + self::$userSignatureCache[$uid] = $sig; |
| 1223 | + |
| 1224 | + return $sig; |
| 1225 | + } |
1198 | 1226 | } |
Index: trunk/extensions/LiquidThreads/classes/Thread.php |
— | — | @@ -364,6 +364,7 @@ |
365 | 365 | $all_thread_rows = $rows; |
366 | 366 | $pageIds = array(); |
367 | 367 | $linkBatch = new LinkBatch(); |
| 368 | + $userIds = array(); |
368 | 369 | |
369 | 370 | if (!is_array(self::$replyCacheById)) { |
370 | 371 | self::$replyCacheById = array(); |
— | — | @@ -460,12 +461,52 @@ |
461 | 462 | $linkBatch->addObj( $t ); |
462 | 463 | |
463 | 464 | User::$idCacheByName[$row->thread_author_name] = $row->thread_author_id; |
| 465 | + $userIds[$row->thread_author_id] = true; |
464 | 466 | |
465 | 467 | if ( $row->thread_parent ) { |
466 | 468 | self::$replyCacheById[$row->thread_parent][$row->thread_id] = $thread; |
467 | 469 | } |
468 | 470 | } |
469 | 471 | |
| 472 | + $userIds = array_keys($userIds); |
| 473 | + |
| 474 | + // Pull signature data and pre-cache in View object. |
| 475 | + if ( count($userIds) ) { |
| 476 | + $signatureDataCache = array_fill_keys( $userIds, array() ); |
| 477 | + $res = $dbr->select( 'user_properties', |
| 478 | + array( 'up_user', 'up_property', 'up_value' ), |
| 479 | + array( 'up_property' => array('nickname', 'fancysig'), |
| 480 | + 'up_user' => $userIds ), |
| 481 | + __METHOD__ ); |
| 482 | + |
| 483 | + foreach( $res as $row ) { |
| 484 | + $signatureDataCache[$row->up_user][$row->up_property] = $row->up_value; |
| 485 | + } |
| 486 | + |
| 487 | + global $wgParser, $wgOut; |
| 488 | + |
| 489 | + foreach( $userIds as $uid ) { |
| 490 | + $user = User::newFromId($uid); // Should pull from UID cache. |
| 491 | + |
| 492 | + // Grab sig data |
| 493 | + $nickname = null; |
| 494 | + $fancysig = (bool)User::getDefaultOption( 'fancysig' ); |
| 495 | + |
| 496 | + if ( isset($signatureDataCache[$uid]['nickname']) ) |
| 497 | + $nickname = $signatureDataCache[$uid]['nickname']; |
| 498 | + if( isset($signatureDataCache[$uid]['fancysig']) ) |
| 499 | + $fancysig = $signatureDataCache[$uid]['fancysig']; |
| 500 | + |
| 501 | + // Generate signature from Parser |
| 502 | + |
| 503 | + $sig = $wgParser->getUserSig( $user, $nickname, $fancysig ); |
| 504 | + $sig = $wgOut->parseInline( $sig ); |
| 505 | + |
| 506 | + // Save into LqtView for later use. |
| 507 | + LqtView::$userSignatureCache[$uid] = $sig; |
| 508 | + } |
| 509 | + } |
| 510 | + |
470 | 511 | // Pull link batch data. |
471 | 512 | $linkBatch->execute(); |
472 | 513 | |