r114692 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114691‎ | r114692 | r114693 >
Date:01:03, 4 April 2012
Author:bsitu
Status:deferred (Comments)
Tags:
Comment:
add redlink status to user page and user talk page
Modified paths:
  • /trunk/extensions/PageTriage/PageTriage.i18n.php (modified) (history)
  • /trunk/extensions/PageTriage/SpecialPageTriage.php (modified) (history)
  • /trunk/extensions/PageTriage/api/ApiPageTriageList.php (modified) (history)
  • /trunk/extensions/PageTriage/api/ApiPageTriageStats.php (modified) (history)
  • /trunk/extensions/PageTriage/includes/PageTriageUtil.php (modified) (history)
  • /trunk/extensions/PageTriage/modules/ext.pageTriage.models/ext.pageTriage.article.js (modified) (history)
  • /trunk/extensions/PageTriage/modules/ext.pageTriage.models/ext.pageTriage.stats.js (modified) (history)

Diff [purge]

Index: trunk/extensions/PageTriage/SpecialPageTriage.php
@@ -26,6 +26,9 @@
2727 public function execute( $sub ) {
2828 $out = $this->getOutput();
2929
 30+//$data = array( array( 'user_name' => 'Bsitu'), array( 'user_name' => 'Test1' ) );
 31+//print_r( PageTriageUtil::pageStatusForUser( $data ));
 32+//die;
3033 // TODO: check user permissions, make sure they're logged in and have the pagepatrol userright
3134
3235 global $wgUser;
@@ -124,9 +127,9 @@
125128 <div class="mwe-pt-author">
126129 <% if( typeof( user_name ) != 'undefined' ) { %>
127130 <%= gM( 'pagetriage-byline' ) %>
128 - <a href="<%= user_title.getUrl() %>"><%= user_name %></a>
 131+ <a <%= userPageLinkClass %> href="<%= user_title.getUrl() %>"><%= user_name %></a>
129132 <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>
131134 &#xb7;
132135 <a href="<%= user_contribs_title.getUrl() %>">contribs</a>)
133136 </span>
@@ -245,7 +248,21 @@
246249 <!-- bottom nav template -->
247250 <script type="text/template" id="listStatsNavTemplate">
248251 <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+ %>
250267 </div>
251268 <div id="mwe-pt-article-age-stats">
252269 <% if ( ptrAverage ) { %> <%= gM( 'pagetriage-stats-untriaged-age', ptrAverage, ptrOldest ) %> <% } %>
Index: trunk/extensions/PageTriage/includes/PageTriageUtil.php
@@ -212,7 +212,77 @@
213213 return false;
214214 }
215215 }
 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;
216224
 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+
217287 }
218288
219289 class MWPageTriageUtilInvalidNumberException extends MWException {}
Index: trunk/extensions/PageTriage/modules/ext.pageTriage.models/ext.pageTriage.stats.js
@@ -15,7 +15,19 @@
1616
1717 formatMetadata: function ( stats ) {
1818 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 ) ) );
2032 stats.set( 'ptrAverage', this.formatDaysFromNow( stats.get( 'untriagedarticle' )['age-50th-percentile'] ) );
2133 stats.set( 'ptrOldest', this.formatDaysFromNow( stats.get( 'untriagedarticle' )['age-100th-percentile'] ) );
2234 },
@@ -67,6 +79,9 @@
6880 url: mw.util.wikiScript( 'api' ) + '?action=pagetriagestats&format=json',
6981
7082 parse: function( response ) {
 83+ for ( var title in response.userpagestatus ) {
 84+ mw.Title.exist.set( title );
 85+ }
7186 // extract the useful bits of json.
7287 return response.pagetriagestats.stats;
7388 }
Index: trunk/extensions/PageTriage/modules/ext.pageTriage.models/ext.pageTriage.article.js
@@ -30,6 +30,9 @@
3131 article.set( 'user_title', new mw.Title( userName, mw.config.get('wgNamespaceIds')['user'] ) );
3232 article.set( 'user_talk_title', new mw.Title( userName, mw.config.get('wgNamespaceIds')['user_talk'] ) );
3333 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+
3437 }
3538 article.set( 'title_url', mw.util.wikiUrlencode( article.get( 'title' ) ) );
3639 }
@@ -75,6 +78,9 @@
7679 },
7780
7881 parse: function( response ) {
 82+ for ( var title in response.pagetriagelist.userpagestatus ) {
 83+ mw.Title.exist.set( title );
 84+ }
7985 // extract the useful bits of json.
8086 return response.pagetriagelist.pages;
8187 },
Index: trunk/extensions/PageTriage/api/ApiPageTriageList.php
@@ -28,7 +28,7 @@
2929 }
3030
3131 // Output the results
32 - $result = array( 'result' => 'success', 'pages' => $metaDataSend );
 32+ $result = array( 'result' => 'success', 'pages' => $metaDataSend, 'userpagestatus' => PageTriageUtil::pageStatusForUser( $metaDataSend ) );
3333 $this->getResult()->addValue( null, $this->getModuleName(), $result );
3434 }
3535
Index: trunk/extensions/PageTriage/api/ApiPageTriageStats.php
@@ -14,7 +14,8 @@
1515 'toptriager' => array(
1616 'total' => count( $topTriager ),
1717 'data' => $topTriager
18 - )
 18+ ),
 19+ 'userpagestatus' => PageTriageUtil::pageStatusForUser( $topTriager )
1920 );
2021
2122 $result = array( 'result' => 'success', 'stats' => $data );
Index: trunk/extensions/PageTriage/PageTriage.i18n.php
@@ -52,7 +52,7 @@
5353 'pagetriage-filter-set-button' => 'Set Filters',
5454 'pagetriage-stats-untriaged-age' => 'Article Ages: Average: $1, Oldest: $2',
5555 '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}}: ',
5757 'pagetriage-filter-ns-article' => 'Article',
5858 'pagetriage-filter-ns-all' => 'All',
5959 'pagetriage-more' => 'More',

Follow-up revisions

RevisionCommit summaryAuthorDate
r114693followup to -r114692 - remove debugging codebsitu01:05, 4 April 2012
r114707followup to -r114692 - remove trailing space from messagebsitu17:19, 4 April 2012

Comments

#Comment by Nikerabbit (talk | contribs)   07:17, 4 April 2012

Trailing whitespace is not allowed in messages.

Status & tagging log