r53465 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53464‎ | r53465 | r53466 >
Date:23:54, 18 July 2009
Author:siebrand
Status:deferred
Tags:
Comment:
* Update messages for MostRevisors
* stylize.php, indentation fixes and triling whitespace removed for MostRevisors
* add support for MostRevisors to Translate
Modified paths:
  • /trunk/extensions/MostRevisors/MostRevisors.i18n.php (modified) (history)
  • /trunk/extensions/MostRevisors/MostRevisors.php (modified) (history)
  • /trunk/extensions/MostRevisors/MostRevisors_body.php (modified) (history)
  • /trunk/extensions/Translate/aliases.txt (modified) (history)
  • /trunk/extensions/Translate/groups/mediawiki-defines.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/groups/mediawiki-defines.txt
@@ -508,6 +508,9 @@
509509
510510 Mini Preview
511511
 512+Most Revisors
 513+ignored = mostrevisors-users, mostrevisors-limit-few-revisors
 514+
512515 Multi Boilerplate
513516 ignored = multiboilerplate, multiboilerplate-label
514517
Index: trunk/extensions/Translate/aliases.txt
@@ -178,6 +178,9 @@
179179 Mibbit
180180 file = Mibbit/Mibbit.alias.php
181181
 182+Most revisors
 183+file = MostRevisors/MostRevisors.alias.php
 184+
182185 Multi upload
183186 file = MultiUpload/SpecialMultipleUpload.alias.php
184187
Index: trunk/extensions/MostRevisors/MostRevisors_body.php
@@ -1,26 +1,25 @@
22 <?php
33 class MostRevisors extends IncludableSpecialPage {
4 -
54 private $limit = NULL;
65 private $namespace = NULL;
76 private $redirects = NULL;
87
9 - public function __construct() {
10 - parent::__construct( 'MostRevisors' );
 8+ public function __construct() {
 9+ parent::__construct( 'MostRevisors' );
1110 $this->mIncludable = true;
12 - }
 11+ }
1312
14 - public function execute( $par ) {
15 - global $wgOut, $wgRequest, $wgLang, $wgContLang, $wgUser, $wgArticle, $wgTitle;
16 - wfLoadExtensionMessages( 'MostRevisors' );
17 -
 13+ public function execute( $par ) {
 14+ global $wgOut, $wgRequest, $wgLang, $wgContLang, $wgUser, $wgArticle, $wgTitle;
 15+ wfLoadExtensionMessages( 'MostRevisors' );
 16+
1817 # Decipher input passed to the page
1918 $this->decipherParams( $par );
2019 $this->setOptions( $wgRequest );
21 -
22 - ###debug
23 - #$wgOut->addWikiText( "DEBUG thisNS: $this->namespace" );
24 -
 20+
 21+ # ##debug
 22+ # $wgOut->addWikiText( "DEBUG thisNS: $this->namespace" );
 23+
2524 $dbr = wfGetDB( DB_SLAVE );
2625
2726 $conds = array();
@@ -31,32 +30,34 @@
3231 $qns = "WHERE page_namespace=" . $this->namespace;
3332 if ( !$this->redirects ) $qns .= " AND page_is_redirect=0";
3433 }
35 - ###debug
36 - #$wgOut->addWikiText( "DEBUG qns: $qns" );
37 - $limitfewrevisors = wfMsg( 'mostrevisors-limit-few-revisors');
 34+ # ##debug
 35+ # $wgOut->addWikiText( "DEBUG qns: $qns" );
 36+ $limitfewrevisors = wfMsg( 'mostrevisors-limit-few-revisors' );
3837 list( $revision, $page ) = $dbr->tableNamesN( 'revision', 'page' );
3938 $sql = "
40 - SELECT
41 - page_title as title, page_is_redirect, page_namespace as namespace,
42 - COUNT(distinct rev_user) as value
43 - FROM $revision
44 - JOIN $page ON page_id = rev_page
45 - " . $dbr->strencode($qns) . "
46 - GROUP BY page_namespace, page_title
47 - HAVING COUNT(distinct rev_user) >=$limitfewrevisors
48 - ORDER BY value DESC
49 - LIMIT "."{$this->limit}
50 - ";
51 - ###debug
52 - #$wgOut->addWikiText( "DEBUG sql: $sql" );
 39+ SELECT
 40+ page_title as title,
 41+ page_is_redirect,
 42+ page_namespace as namespace,
 43+ COUNT(distinct rev_user) as value
 44+ FROM $revision
 45+ JOIN $page ON page_id = rev_page
 46+ " . $dbr->strencode( $qns ) . "
 47+ GROUP BY page_namespace, page_title
 48+ HAVING COUNT(distinct rev_user) >=$limitfewrevisors
 49+ ORDER BY value DESC
 50+ LIMIT " . "{$this->limit}
 51+ ";
 52+ # ##debug
 53+ # $wgOut->addWikiText( "DEBUG sql: $sql" );
5354 $res = $dbr->query( $sql, __METHOD__ );
5455 $count = $dbr->numRows( $res );
5556
5657 # Don't show the navigation if we're including the page
57 - if( !$this->mIncluding ) {
 58+ if ( !$this->mIncluding ) {
5859 $this->setHeaders();
5960 $limit = $wgLang->formatNum( $this->limit );
60 - if( $this->namespace > 0 ) {
 61+ if ( $this->namespace > 0 ) {
6162 $wgOut->addWikiMsg( 'mostrevisors-ns-header', $limit, $wgContLang->getFormattedNsText( $this->namespace ) );
6263 } else {
6364 $wgOut->addWikiMsg( 'mostrevisors-header', $limit );
@@ -66,10 +67,10 @@
6768 $wgOut->addHTML( '<br />' . $this->makeRedirectToggle() . '</p>' );
6869 }
6970
70 - if( $count > 0 ) {
 71+ if ( $count > 0 ) {
7172 # Make list
72 - if( !$this->mIncluding )
73 - $wgOut->addWikiMsg( 'mostrevisors-showing', $wgLang->formatNum($count) );
 73+ if ( !$this->mIncluding )
 74+ $wgOut->addWikiMsg( 'mostrevisors-showing', $wgLang->formatNum( $count ) );
7475 $wgOut->addHTML( "<ol>" );
7576 foreach ( $res as $row ) {
7677 $wgOut->addHTML( $this->makeListItem( $row ) );
@@ -78,25 +79,27 @@
7980 } else {
8081 $wgOut->addWikiMsg( 'mostrevisors-none' );
8182 }
82 - }
83 -
 83+ }
 84+
8485 private function setOptions( &$req ) {
8586 global $wgMostRevisorsPagesLimit;
86 - if( !isset( $this->limit ) )
87 - $this->limit = $this->sanitiseLimit( $req->getInt( 'limit', $wgMostRevisorsPagesLimit ) );
88 - if( !isset( $this->namespace ) )
89 - $this->namespace = $this->extractNamespace( $req->getVal( 'namespace', 0 ) );
90 - if( !isset( $this->redirects ) )
91 - $this->redirects = (bool)$req->getInt( 'redirects', 1 );
 87+ if ( !isset( $this->limit ) )
 88+ $this->limit = $this->sanitiseLimit( $req->getInt( 'limit', $wgMostRevisorsPagesLimit ) );
 89+ if ( !isset( $this->namespace ) )
 90+ $this->namespace = $this->extractNamespace( $req->getVal( 'namespace', 0 ) );
 91+ if ( !isset( $this->redirects ) )
 92+ $this->redirects = (bool)$req->getInt( 'redirects', 1 );
9293 }
 94+
9395 private function sanitiseLimit( $limit ) {
9496 return min( (int)$limit, 5000 );
9597 }
 98+
9699 private function decipherParams( $par ) {
97 - if( $par ) {
 100+ if ( $par ) {
98101 $bits = explode( '/', $par );
99 - foreach( $bits as $bit ) {
100 - if( is_numeric( $bit ) ) {
 102+ foreach ( $bits as $bit ) {
 103+ if ( is_numeric( $bit ) ) {
101104 $this->limit = $this->sanitiseLimit( $bit );
102105 } else {
103106 $this->namespace = $this->extractNamespace( $bit );
@@ -104,42 +107,45 @@
105108 }
106109 }
107110 }
 111+
108112 private function extractNamespace( $namespace ) {
109113 global $wgContLang;
110 - if( is_numeric( $namespace ) ) {
 114+ if ( is_numeric( $namespace ) ) {
111115 return $namespace;
112 - } elseif( $wgContLang->getNsIndex( $namespace ) !== false ) {
 116+ } elseif ( $wgContLang->getNsIndex( $namespace ) !== false ) {
113117 return $wgContLang->getNsIndex( $namespace );
114 - } elseif( $namespace == '-' ) {
 118+ } elseif ( $namespace == '-' ) {
115119 return NS_MAIN;
116 - } elseif( $namespace == 'all' ) {
 120+ } elseif ( $namespace == 'all' ) {
117121 return 'all';
118122 } else {
119123 return 'all';
120124 }
121125 }
 126+
122127 private function makeListItem( $row ) {
123128 global $wgUser, $wgMostRevisorsLinkContributors;
124129 $title = Title::makeTitleSafe( $row->namespace, $row->title );
125 - if( !is_null( $title ) ) {
 130+ if ( !is_null( $title ) ) {
126131 $skin = $wgUser->getSkin();
127132 $link = $row->page_is_redirect
128 - ? '<span class="allpagesredirect">' . $skin->makeKnownLinkObj( $title ) . '</span>'
129 - : $skin->makeKnownLinkObj( $title );
130 - $link .= " - $row->value ". wfMsg('mostrevisors-users');
131 - if ( $wgMostRevisorsLinkContributors == True ) $link .= " (".$skin->makeKnownLinkObj( Title::makeTitleSafe( -1, 'Contributors/'.$title ), wfMsg('mostrevisors-viewcontributors') ).")";
 133+ ? '<span class="allpagesredirect">' . $skin->makeKnownLinkObj( $title ) . '</span>'
 134+ : $skin->makeKnownLinkObj( $title );
 135+ $link .= " - $row->value " . wfMsg( 'mostrevisors-users' );
 136+ if ( $wgMostRevisorsLinkContributors == True ) $link .= " (" . $skin->makeKnownLinkObj( Title::makeTitleSafe( - 1, 'Contributors/' . $title ), wfMsg( 'mostrevisors-viewcontributors' ) ) . ")";
132137 return( "<li>{$link}</li>\n" );
133138 } else {
134139 return( "<!-- Invalid title " . htmlspecialchars( $row->title ) . " in namespace " . htmlspecialchars( $row->page_namespace ) . " -->\n" );
135140 }
136141 }
 142+
137143 private function makeLimitLinks() {
138144 global $wgLang;
139145
140146 $limits = array( 10, 20, 30, 50, 100, 150 );
141 - foreach( $limits as $limit ) {
142 - if( $limit != $this->limit ) {
143 - $links[] = $this->makeSelfLink( $wgLang->formatNum($limit), 'limit', $limit );
 147+ foreach ( $limits as $limit ) {
 148+ if ( $limit != $this->limit ) {
 149+ $links[] = $this->makeSelfLink( $wgLang->formatNum( $limit ), 'limit', $limit );
144150 } else {
145151 $links[] = (string)$limit;
146152 }
@@ -151,20 +157,22 @@
152158 $label = wfMsgHtml( $this->redirects ? 'mostrevisors-hideredir' : 'mostrevisors-showredir' );
153159 return $this->makeSelfLink( $label, 'redirects', (int)!$this->redirects );
154160 }
 161+
155162 private function makeSelfLink( $label, $oname = false, $oval = false ) {
156163 global $wgUser;
157164 $skin =& $wgUser->getSkin();
158165 $self = $this->getTitle();
159166 $attr['limit'] = $this->limit;
160167 $attr['namespace'] = $this->namespace;
161 - if( !$this->redirects )
162 - $attr['redirects'] = 0;
163 - if( $oname )
164 - $attr[$oname] = $oval;
165 - foreach( $attr as $aname => $aval )
166 - $attribs[] = "{$aname}={$aval}";
 168+ if ( !$this->redirects )
 169+ $attr['redirects'] = 0;
 170+ if ( $oname )
 171+ $attr[$oname] = $oval;
 172+ foreach ( $attr as $aname => $aval )
 173+ $attribs[] = "{$aname}={$aval}";
167174 return $skin->makeKnownLinkObj( $self, $label, implode( '&', $attribs ) );
168175 }
 176+
169177 private function makeNamespaceForm() {
170178 $self = $this->getTitle();
171179 $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
@@ -175,4 +183,4 @@
176184 $form .= Xml::submitButton( wfMsg( 'mostrevisors-submit' ) ) . '</form>';
177185 return $form;
178186 }
179 -}
\ No newline at end of file
 187+}
Index: trunk/extensions/MostRevisors/MostRevisors.i18n.php
@@ -8,20 +8,22 @@
99 $messages = array();
1010
1111 $messages['en'] = array(
12 - 'mostrevisors-header' => "'''This page lists the {{PLURAL:$1|page|$1 pages}} with most revisors on the wiki.'''",
 12+ 'mostrevisors' => 'Pages with the most revisors',
 13+ 'mostrevisors-desc' => 'List [[Special:MostRevisors|pages with the most revisors]]',
 14+ 'mostrevisors-header' => "'''This page lists the {{PLURAL:$1|page|$1 pages}} with most revisors on the wiki.'''",
1315 'mostrevisors-limitlinks' => 'Show up to $1 pages',
14 - 'mostrevisors-namespace' => 'Namespace:',
15 - 'mostrevisors-none' => 'No entries were found.',
16 - 'mostrevisors-ns-header' => "'''This page lists the {{PLURAL:$1|page|$1 pages}} with most revisors in the $2 namespace.'''",
17 - 'mostrevisors-showing' => 'Listing {{PLURAL:$1|page|$1 pages}}:',
18 - 'mostrevisors-submit' => 'Go',
19 - 'mostrevisors-showredir' => 'Show redirect pages',
20 - 'mostrevisors-hideredir' => 'Hide redirect pages',
21 - 'mostrevisors' => 'Pages with the most revisors',
22 - 'mostrevisors-desc' => 'List [[Special:MostRevisors|pages with the most revisors]]',
 16+ 'mostrevisors-namespace' => 'Namespace:',
 17+ 'mostrevisors-none' => 'No entries were found.',
 18+ 'mostrevisors-ns-header' => "'''This page lists the {{PLURAL:$1|page|$1 pages}} with most revisors in the $2 namespace.'''",
 19+ 'mostrevisors-showing' => 'Listing {{PLURAL:$1|page|$1 pages}}:',
 20+ 'mostrevisors-submit' => 'Go',
 21+ 'mostrevisors-showredir' => 'Show redirect pages',
 22+ 'mostrevisors-hideredir' => 'Hide redirect pages',
2323 'mostrevisors-viewcontributors' => 'View main contributors',
24 - 'mostrevisors-text' => 'Show Pages with the most revisors, starting from [[MediaWiki:mostrevisors-limit-few-revisors|{{MediaWiki:mostrevisors-limit-few-revisors}} revisors]]. See also [[Special:MostRevisions]].',
25 - 'mostrevisors-users' => 'editors',
 24+ 'mostrevisors-text' => 'Show [[Special:MostRevisions|pages with the most revisors]], starting from [[MediaWiki:mostrevisors-limit-few-revisors|{{MediaWiki:Mostrevisors-limit-few-revisors}} revisors]].',
 25+
 26+ // Settings. Do not translate these messages.
 27+ 'mostrevisors-users' => 'editors',
2628 'mostrevisors-limit-few-revisors' => '1',
2729 );
2830
Index: trunk/extensions/MostRevisors/MostRevisors.php
@@ -5,7 +5,7 @@
66 */
77
88 // If this is run directly from the web die as this is not a valid entry point.
9 -if( !defined( 'MEDIAWIKI' ) ) die( 'Invalid entry point.' );
 9+if ( !defined( 'MEDIAWIKI' ) ) die( 'Invalid entry point.' );
1010
1111 // Extension credits.
1212 $wgExtensionCredits['specialpage'][] = array(

Status & tagging log