r59160 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59159‎ | r59160 | r59161 >
Date:00:19, 17 November 2009
Author:dantman
Status:deferred
Tags:
Comment:
Turn the Contributors' extension's getMainContributors and getContributors methods into static methods that work inside the extension and can be re-used outside of it.
Fixes my last commit, the methods weren't actually generic enough.
Modified paths:
  • /trunk/extensions/Contributors/Contributors.page.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contributors/Contributors.page.php
@@ -44,7 +44,7 @@
4545 if( is_object( $this->target ) ) {
4646 if( $this->target->exists() ) {
4747 $names = array();
48 - list( $contributors, $others ) = $this->getMainContributors();
 48+ list( $contributors, $others ) = self::getMainContributors($this->target);
4949 foreach( $contributors as $username => $info )
5050 $names[] = $username;
5151 $output = $wgContentLang->listToText( $names );
@@ -88,7 +88,7 @@
8989 $skin =& $wgUser->getSkin();
9090 $link = $skin->makeKnownLinkObj( $this->target );
9191 $wgOut->addHTML( '<h2>' . wfMsgHtml( 'contributors-subtitle', $link ) . '</h2>' );
92 - list( $contributors, $others ) = $this->getMainContributors();
 92+ list( $contributors, $others ) = self::getMainContributors($this->target);
9393 $wgOut->addHTML( '<ul>' );
9494 foreach( $contributors as $username => $info ) {
9595 list( $id, $count ) = $info;
@@ -116,12 +116,12 @@
117117 *
118118 * @return array
119119 */
120 - public function getMainContributors() {
 120+ public static function getMainContributors($title) {
121121 wfProfileIn( __METHOD__ );
122122 global $wgContributorsLimit, $wgContributorsThreshold;
123123 $total = 0;
124124 $ret = array();
125 - $all = $this->getContributors();
 125+ $all = self::getContributors($title);
126126 foreach( $all as $username => $info ) {
127127 list( $id, $count ) = $info;
128128 if( $total >= $wgContributorsLimit && $count < $wgContributorsThreshold )
@@ -139,10 +139,10 @@
140140 *
141141 * @return array
142142 */
143 - public function getContributors() {
 143+ public static function getContributors($title) {
144144 wfProfileIn( __METHOD__ );
145145 global $wgMemc;
146 - $k = wfMemcKey( 'contributors', $this->target->getArticleId() );
 146+ $k = wfMemcKey( 'contributors', $title->getArticleId() );
147147 $contributors = $wgMemc->get( $k );
148148 if( !$contributors ) {
149149 $contributors = array();
@@ -154,7 +154,7 @@
155155 'rev_user',
156156 'rev_user_text',
157157 ),
158 - $this->getConditions(),
 158+ self::getConditions($title),
159159 __METHOD__,
160160 array(
161161 'GROUP BY' => 'rev_user_text',
@@ -176,9 +176,9 @@
177177 *
178178 * @return array
179179 */
180 - protected function getConditions() {
 180+ protected static function getConditions($title) {
181181 global $wgVersion;
182 - $conds['rev_page'] = $this->target->getArticleId();
 182+ $conds['rev_page'] = $title->getArticleId();
183183 if( version_compare( $wgVersion, '1.11alpha', '>=' ) )
184184 $conds[] = 'rev_deleted & ' . Revision::DELETED_USER . ' = 0';
185185 return $conds;

Status & tagging log