r66921 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66920‎ | r66921 | r66922 >
Date:14:36, 26 May 2010
Author:werdna
Status:deferred
Tags:
Comment:
ActiveStrategy: Implement task force member counting with an absolutely awful regex algorithm.
Modified paths:
  • /trunk/extensions/StrategyWiki/ActiveStrategy/ActiveStrategy_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/StrategyWiki/ActiveStrategy/ActiveStrategy_body.php
@@ -33,8 +33,8 @@
3434 $title = Title::makeTitle( $result->namespace, $result->title );
3535 $text = $wgContLang->convert( $title->getPrefixedText() );
3636 $pageLink = $skin->linkKnown( $title, $text );
37 - $members = 0;
38 - $details = '';
 37+ $members = self::getMemberCount( $title->getPrefixedText() );
 38+ $details = array();
3939
4040 $numberLink = $skin->linkKnown(
4141 $title,
@@ -44,10 +44,14 @@
4545 array( 'action' => 'history' )
4646 );
4747
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+ }
5054
51 - $details = $wgLang->commaList( array( $numberLink, $members ) );
 55+ $details = $wgLang->commaList( $details );
5256
5357 return wfSpecialList( $pageLink, $details );
5458 }
@@ -70,5 +74,43 @@
7175
7276 return $html;
7377 }
 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+ }
74116 }
75117

Status & tagging log