Index: trunk/extensions/PageTriage/SpecialPageTriage.php |
— | — | @@ -26,6 +26,9 @@ |
27 | 27 | public function execute( $sub ) { |
28 | 28 | $out = $this->getOutput(); |
29 | 29 | |
| 30 | +//$data = array( array( 'user_name' => 'Bsitu'), array( 'user_name' => 'Test1' ) ); |
| 31 | +//print_r( PageTriageUtil::pageStatusForUser( $data )); |
| 32 | +//die; |
30 | 33 | // TODO: check user permissions, make sure they're logged in and have the pagepatrol userright |
31 | 34 | |
32 | 35 | global $wgUser; |
— | — | @@ -124,9 +127,9 @@ |
125 | 128 | <div class="mwe-pt-author"> |
126 | 129 | <% if( typeof( user_name ) != 'undefined' ) { %> |
127 | 130 | <%= gM( 'pagetriage-byline' ) %> |
128 | | - <a href="<%= user_title.getUrl() %>"><%= user_name %></a> |
| 131 | + <a <%= userPageLinkClass %> href="<%= user_title.getUrl() %>"><%= user_name %></a> |
129 | 132 | <span class="mwe-pt-talk-contribs"> |
130 | | - (<a href="<%= user_talk_title.getUrl() %>">talk</a> |
| 133 | + (<a <%= talkPageLinkClass %> href="<%= user_talk_title.getUrl()+'&redlink=1' %>">talk</a> |
131 | 134 | · |
132 | 135 | <a href="<%= user_contribs_title.getUrl() %>">contribs</a>) |
133 | 136 | </span> |
— | — | @@ -245,7 +248,21 @@ |
246 | 249 | <!-- bottom nav template --> |
247 | 250 | <script type="text/template" id="listStatsNavTemplate"> |
248 | 251 | <div id="mwe-pt-top-triager"> |
249 | | - <%= ptrTopTriager %> |
| 252 | + <% |
| 253 | + if ( toptriager.total ) { |
| 254 | + %> |
| 255 | + <%= ptrTopTriagerStr %> |
| 256 | + <% |
| 257 | + for ( var m in ptrTopTriager ) { |
| 258 | + %> |
| 259 | + <!-- Todo: escape user name --> |
| 260 | + <a <%= ptrTopTriager[m].linkCSS %> href="<%= ptrTopTriager[m].title.getUrl() %>"><%= ptrTopTriager[m].userName %></a> |
| 261 | + <% |
| 262 | + } |
| 263 | + %> |
| 264 | + <% |
| 265 | + } |
| 266 | + %> |
250 | 267 | </div> |
251 | 268 | <div id="mwe-pt-article-age-stats"> |
252 | 269 | <% if ( ptrAverage ) { %> <%= gM( 'pagetriage-stats-untriaged-age', ptrAverage, ptrOldest ) %> <% } %> |
Index: trunk/extensions/PageTriage/includes/PageTriageUtil.php |
— | — | @@ -212,7 +212,77 @@ |
213 | 213 | return false; |
214 | 214 | } |
215 | 215 | } |
| 216 | + |
| 217 | + /** |
| 218 | + * Check the existance of user page and talk page for a list of users |
| 219 | + * @param $users array - contains user_name db keys |
| 220 | + * @return array |
| 221 | + */ |
| 222 | + public static function pageStatusForUser( $users ) { |
| 223 | + global $wgMemc; |
216 | 224 | |
| 225 | + $return = array(); |
| 226 | + $title = array(); |
| 227 | + $dataToCache = array(); |
| 228 | + |
| 229 | + foreach ( $users as $user ) { |
| 230 | + $user = (array) $user; |
| 231 | + $key = wfMemcKey( 'pagetriage', 'user-page-status', $user['user_name']); |
| 232 | + $data = $wgMemc->get( $key ); |
| 233 | + if ( $data !== false ) { |
| 234 | + foreach ( $data as $pageKey => $status ) { |
| 235 | + if ( $status === 1 ) { |
| 236 | + $return[$pageKey] = $status; |
| 237 | + } |
| 238 | + } |
| 239 | + } else { |
| 240 | + $u = Title::newFromText( $user['user_name'], NS_USER ); |
| 241 | + if ( $u ) { |
| 242 | + $t = Title::makeTitle( NS_USER_TALK, $u->getDBkey() ); |
| 243 | + $title[$u->getDBkey()] = array( 'user_name' => $user['user_name'], 'u' => $u, 't' => $t ); |
| 244 | + } |
| 245 | + } |
| 246 | + } |
| 247 | + |
| 248 | + if ( $title ) { |
| 249 | + $dbr = wfGetDB( DB_SLAVE ); |
| 250 | + $res = $dbr->select( |
| 251 | + array( 'page' ), |
| 252 | + array( 'page_namespace', 'page_title' ), |
| 253 | + array( 'page_title' => array_keys( $title ), 'page_namespace' => array( NS_USER, NS_USER_TALK ) ), |
| 254 | + __METHOD__ |
| 255 | + ); |
| 256 | + |
| 257 | + $dataToCache = array(); |
| 258 | + foreach ( $res as $row ) { |
| 259 | + $user = $title[$row->page_title]; |
| 260 | + if ( $row->page_namespace == NS_USER ) { |
| 261 | + $dataToCache[$user['user_name']][$user['u']->getPrefixedDBkey()] = 1; |
| 262 | + } else { |
| 263 | + $dataToCache[$user['user_name']][$user['t']->getPrefixedDBkey()] = 1; |
| 264 | + } |
| 265 | + } |
| 266 | + |
| 267 | + foreach ( $title as $key => $value ) { |
| 268 | + $data = array(); |
| 269 | + if ( !isset( $dataToCache[$value['user_name']][$value['u']->getPrefixedDBkey()] ) ) { |
| 270 | + $dataToCache[$value['user_name']][$value['u']->getPrefixedDBkey()] = 0; |
| 271 | + } else { |
| 272 | + $return[$value['u']->getPrefixedDBkey()] = 1; |
| 273 | + } |
| 274 | + if ( !isset( $dataToCache[$value['user_name']][$value['t']->getPrefixedDBkey()] ) ) { |
| 275 | + $dataToCache[$value['user_name']][$value['t']->getPrefixedDBkey()] = 0; |
| 276 | + } else { |
| 277 | + $return[$value['t']->getPrefixedDBkey()] = 1; |
| 278 | + } |
| 279 | + $memcKey = wfMemcKey( 'pagetriage', 'user-page-status', $value['user_name'] ); |
| 280 | + $wgMemc->set( $memcKey, $dataToCache[$value['user_name']], 3600 ); |
| 281 | + } |
| 282 | + } |
| 283 | + |
| 284 | + return $return; |
| 285 | + } |
| 286 | + |
217 | 287 | } |
218 | 288 | |
219 | 289 | class MWPageTriageUtilInvalidNumberException extends MWException {} |
Index: trunk/extensions/PageTriage/modules/ext.pageTriage.models/ext.pageTriage.stats.js |
— | — | @@ -15,7 +15,19 @@ |
16 | 16 | |
17 | 17 | formatMetadata: function ( stats ) { |
18 | 18 | stats.set( 'ptr_untriaged_article_count', stats.get( 'untriagedarticle' )['count'] ); |
19 | | - stats.set( 'ptrTopTriager', this.formatTopTriager( stats.get( 'toptriager' ) ) ); |
| 19 | + |
| 20 | + var topTriager = {}; |
| 21 | + for ( var i in stats.get( 'toptriager' )['data'] ) { |
| 22 | + var title = new mw.Title( stats.get( 'toptriager' )['data'][i]['user_name'], mw.config.get('wgNamespaceIds')['user'] ); |
| 23 | + topTriager[i] = { |
| 24 | + title: title, |
| 25 | + linkCSS: mw.Title.exists( title) ? '' : 'class="new"', |
| 26 | + userName: stats.get( 'toptriager' )['data'][i]['user_name'] |
| 27 | + }; |
| 28 | + } |
| 29 | + |
| 30 | + stats.set( 'ptrTopTriager', topTriager ); |
| 31 | + stats.set( 'ptrTopTriagerStr', gM( 'pagetriage-stats-top-triagers', Number( stats.get( 'toptriager' ).total ) ) ); |
20 | 32 | stats.set( 'ptrAverage', this.formatDaysFromNow( stats.get( 'untriagedarticle' )['age-50th-percentile'] ) ); |
21 | 33 | stats.set( 'ptrOldest', this.formatDaysFromNow( stats.get( 'untriagedarticle' )['age-100th-percentile'] ) ); |
22 | 34 | }, |
— | — | @@ -67,6 +79,9 @@ |
68 | 80 | url: mw.util.wikiScript( 'api' ) + '?action=pagetriagestats&format=json', |
69 | 81 | |
70 | 82 | parse: function( response ) { |
| 83 | + for ( var title in response.userpagestatus ) { |
| 84 | + mw.Title.exist.set( title ); |
| 85 | + } |
71 | 86 | // extract the useful bits of json. |
72 | 87 | return response.pagetriagestats.stats; |
73 | 88 | } |
Index: trunk/extensions/PageTriage/modules/ext.pageTriage.models/ext.pageTriage.article.js |
— | — | @@ -30,6 +30,9 @@ |
31 | 31 | article.set( 'user_title', new mw.Title( userName, mw.config.get('wgNamespaceIds')['user'] ) ); |
32 | 32 | article.set( 'user_talk_title', new mw.Title( userName, mw.config.get('wgNamespaceIds')['user_talk'] ) ); |
33 | 33 | article.set( 'user_contribs_title', new mw.Title( gM( 'pagetriage-special-contributions' ) + '/' + userName ) ); |
| 34 | + article.set( 'userPageLinkClass', article.get( 'user_title' ).exists() ? '' : 'class="new"' ); |
| 35 | + article.set( 'talkPageLinkClass', article.get( 'user_talk_title' ).exists() ? '' : 'class="new"' ); |
| 36 | + |
34 | 37 | } |
35 | 38 | article.set( 'title_url', mw.util.wikiUrlencode( article.get( 'title' ) ) ); |
36 | 39 | } |
— | — | @@ -75,6 +78,9 @@ |
76 | 79 | }, |
77 | 80 | |
78 | 81 | parse: function( response ) { |
| 82 | + for ( var title in response.pagetriagelist.userpagestatus ) { |
| 83 | + mw.Title.exist.set( title ); |
| 84 | + } |
79 | 85 | // extract the useful bits of json. |
80 | 86 | return response.pagetriagelist.pages; |
81 | 87 | }, |
Index: trunk/extensions/PageTriage/api/ApiPageTriageList.php |
— | — | @@ -28,7 +28,7 @@ |
29 | 29 | } |
30 | 30 | |
31 | 31 | // Output the results |
32 | | - $result = array( 'result' => 'success', 'pages' => $metaDataSend ); |
| 32 | + $result = array( 'result' => 'success', 'pages' => $metaDataSend, 'userpagestatus' => PageTriageUtil::pageStatusForUser( $metaDataSend ) ); |
33 | 33 | $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
34 | 34 | } |
35 | 35 | |
Index: trunk/extensions/PageTriage/api/ApiPageTriageStats.php |
— | — | @@ -14,7 +14,8 @@ |
15 | 15 | 'toptriager' => array( |
16 | 16 | 'total' => count( $topTriager ), |
17 | 17 | 'data' => $topTriager |
18 | | - ) |
| 18 | + ), |
| 19 | + 'userpagestatus' => PageTriageUtil::pageStatusForUser( $topTriager ) |
19 | 20 | ); |
20 | 21 | |
21 | 22 | $result = array( 'result' => 'success', 'stats' => $data ); |
Index: trunk/extensions/PageTriage/PageTriage.i18n.php |
— | — | @@ -52,7 +52,7 @@ |
53 | 53 | 'pagetriage-filter-set-button' => 'Set Filters', |
54 | 54 | 'pagetriage-stats-untriaged-age' => 'Article Ages: Average: $1, Oldest: $2', |
55 | 55 | 'pagetriage-stats-less-than-a-day' => 'less than one day', |
56 | | - 'pagetriage-stats-top-triagers' => 'Top {{PLURAL:$1|triager|$1 triagers}}: $2', |
| 56 | + 'pagetriage-stats-top-triagers' => 'Top {{PLURAL:$1|triager|$1 triagers}}: ', |
57 | 57 | 'pagetriage-filter-ns-article' => 'Article', |
58 | 58 | 'pagetriage-filter-ns-all' => 'All', |
59 | 59 | 'pagetriage-more' => 'More', |