Index: trunk/extensions/StrategyWiki/ActiveStrategy/ActiveStrategy_body.php |
— | — | @@ -33,8 +33,8 @@ |
34 | 34 | $title = Title::makeTitle( $result->namespace, $result->title ); |
35 | 35 | $text = $wgContLang->convert( $title->getPrefixedText() ); |
36 | 36 | $pageLink = $skin->linkKnown( $title, $text ); |
37 | | - $members = 0; |
38 | | - $details = ''; |
| 37 | + $members = self::getMemberCount( $title->getPrefixedText() ); |
| 38 | + $details = array(); |
39 | 39 | |
40 | 40 | $numberLink = $skin->linkKnown( |
41 | 41 | $title, |
— | — | @@ -44,10 +44,14 @@ |
45 | 45 | array( 'action' => 'history' ) |
46 | 46 | ); |
47 | 47 | |
48 | | - $members = wfMsgExt( 'nmembers', array( 'parsemag', 'escape' ), |
49 | | - $wgLang->formatNum( $members ) ); |
| 48 | + $details = array( $numberLink ); |
| 49 | + |
| 50 | + if ($members >= 0) { |
| 51 | + $details[] = wfMsgExt( 'nmembers', array( 'parsemag', 'escape' ), |
| 52 | + $wgLang->formatNum( $members ) ); |
| 53 | + } |
50 | 54 | |
51 | | - $details = $wgLang->commaList( array( $numberLink, $members ) ); |
| 55 | + $details = $wgLang->commaList( $details ); |
52 | 56 | |
53 | 57 | return wfSpecialList( $pageLink, $details ); |
54 | 58 | } |
— | — | @@ -70,5 +74,43 @@ |
71 | 75 | |
72 | 76 | return $html; |
73 | 77 | } |
| 78 | + |
| 79 | + static function getMemberCount( $taskForce ) { |
| 80 | + global $wgMemc; |
| 81 | + |
| 82 | + $key = wfMemcKey( 'taskforce-member-count', $taskForce ); |
| 83 | + $cacheVal = $wgMemc->get( $key ); |
| 84 | + |
| 85 | + if ( $cacheVal !== false ) { |
| 86 | + return $cacheVal; |
| 87 | + } |
| 88 | + |
| 89 | + $article = new Article( Title::newFromText( $taskForce ) ); |
| 90 | + $content = $article->getContent(); |
| 91 | + |
| 92 | + $count = self::parseMemberList( $content ); |
| 93 | + |
| 94 | + $wgMemc->set( $key, $count, 86400 ); |
| 95 | + |
| 96 | + return $count; |
| 97 | + } |
| 98 | + |
| 99 | + // FIXME THIS IS TOTALLY AWFUL |
| 100 | + static function parseMemberList( $text ) { |
| 101 | + $regex = "/'''Members'''.*<!--- begin --->(.*)?<!--- end --->/s"; |
| 102 | + $matches = array(); |
| 103 | + |
| 104 | + if ( !preg_match( $regex, $text, $matches ) ) { |
| 105 | + return -1; |
| 106 | + } else { |
| 107 | + $regex = "/^\* .*/m"; |
| 108 | + $text = $matches[1]; |
| 109 | + $matches = array(); |
| 110 | + |
| 111 | + preg_match_all( $regex, $text, $matches ); |
| 112 | + |
| 113 | + return count( $matches[0] ); |
| 114 | + } |
| 115 | + } |
74 | 116 | } |
75 | 117 | |