r53448 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53447‎ | r53448 | r53449 >
Date:16:24, 18 July 2009
Author:demon
Status:deferred
Tags:
Comment:
(bug 19632) Commit extension MostRevisors.
Modified paths:
  • /trunk/extensions/MostRevisors (added) (history)
  • /trunk/extensions/MostRevisors/MostRevisors.alias.php (added) (history)
  • /trunk/extensions/MostRevisors/MostRevisors.i18n.php (added) (history)
  • /trunk/extensions/MostRevisors/MostRevisors.php (added) (history)
  • /trunk/extensions/MostRevisors/MostRevisors_body.php (added) (history)

Diff [purge]

Index: trunk/extensions/MostRevisors/MostRevisors_body.php
@@ -0,0 +1,178 @@
 2+<?php
 3+class MostRevisors extends IncludableSpecialPage {
 4+
 5+ private $limit = NULL;
 6+ private $namespace = NULL;
 7+ private $redirects = NULL;
 8+
 9+ public function __construct() {
 10+ parent::__construct( 'MostRevisors' );
 11+ $this->mIncludable = true;
 12+ }
 13+
 14+ public function execute( $par ) {
 15+ global $wgOut, $wgRequest, $wgLang, $wgContLang, $wgUser, $wgArticle, $wgTitle;
 16+ wfLoadExtensionMessages( 'MostRevisors' );
 17+
 18+ # Decipher input passed to the page
 19+ $this->decipherParams( $par );
 20+ $this->setOptions( $wgRequest );
 21+
 22+ ###debug
 23+ #$wgOut->addWikiText( "DEBUG thisNS: $this->namespace" );
 24+
 25+ $dbr = wfGetDB( DB_SLAVE );
 26+
 27+ $conds = array();
 28+ if ( $this->namespace == 'all' ) {
 29+ $qns = NULL;
 30+ if ( !$this->redirects ) $qns = "WHERE page_is_redirect=0";
 31+ } else {
 32+ $qns = "WHERE page_namespace=" . $this->namespace;
 33+ if ( !$this->redirects ) $qns .= " AND page_is_redirect=0";
 34+ }
 35+ ###debug
 36+ #$wgOut->addWikiText( "DEBUG qns: $qns" );
 37+ $limitfewrevisors = wfMsg( 'mostrevisors-limit-few-revisors');
 38+ list( $revision, $page ) = $dbr->tableNamesN( 'revision', 'page' );
 39+ $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" );
 53+ $res = $dbr->query( $sql, __METHOD__ );
 54+ $count = $dbr->numRows( $res );
 55+
 56+ # Don't show the navigation if we're including the page
 57+ if( !$this->mIncluding ) {
 58+ $this->setHeaders();
 59+ $limit = $wgLang->formatNum( $this->limit );
 60+ if( $this->namespace > 0 ) {
 61+ $wgOut->addWikiMsg( 'mostrevisors-ns-header', $limit, $wgContLang->getFormattedNsText( $this->namespace ) );
 62+ } else {
 63+ $wgOut->addWikiMsg( 'mostrevisors-header', $limit );
 64+ }
 65+ $wgOut->addHTML( $this->makeNamespaceForm() );
 66+ $wgOut->addHTML( '<p>' . $this->makeLimitLinks() );
 67+ $wgOut->addHTML( '<br />' . $this->makeRedirectToggle() . '</p>' );
 68+ }
 69+
 70+ if( $count > 0 ) {
 71+ # Make list
 72+ if( !$this->mIncluding )
 73+ $wgOut->addWikiMsg( 'mostrevisors-showing', $wgLang->formatNum($count) );
 74+ $wgOut->addHTML( "<ol>" );
 75+ foreach ( $res as $row ) {
 76+ $wgOut->addHTML( $this->makeListItem( $row ) );
 77+ }
 78+ $wgOut->addHTML( "</ol>" );
 79+ } else {
 80+ $wgOut->addWikiMsg( 'mostrevisors-none' );
 81+ }
 82+ }
 83+
 84+ private function setOptions( &$req ) {
 85+ 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 );
 92+ }
 93+ private function sanitiseLimit( $limit ) {
 94+ return min( (int)$limit, 5000 );
 95+ }
 96+ private function decipherParams( $par ) {
 97+ if( $par ) {
 98+ $bits = explode( '/', $par );
 99+ foreach( $bits as $bit ) {
 100+ if( is_numeric( $bit ) ) {
 101+ $this->limit = $this->sanitiseLimit( $bit );
 102+ } else {
 103+ $this->namespace = $this->extractNamespace( $bit );
 104+ }
 105+ }
 106+ }
 107+ }
 108+ private function extractNamespace( $namespace ) {
 109+ global $wgContLang;
 110+ if( is_numeric( $namespace ) ) {
 111+ return $namespace;
 112+ } elseif( $wgContLang->getNsIndex( $namespace ) !== false ) {
 113+ return $wgContLang->getNsIndex( $namespace );
 114+ } elseif( $namespace == '-' ) {
 115+ return NS_MAIN;
 116+ } elseif( $namespace == 'all' ) {
 117+ return 'all';
 118+ } else {
 119+ return 'all';
 120+ }
 121+ }
 122+ private function makeListItem( $row ) {
 123+ global $wgUser, $wgMostRevisorsLinkContributors;
 124+ $title = Title::makeTitleSafe( $row->namespace, $row->title );
 125+ if( !is_null( $title ) ) {
 126+ $skin = $wgUser->getSkin();
 127+ $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') ).")";
 132+ return( "<li>{$link}</li>\n" );
 133+ } else {
 134+ return( "<!-- Invalid title " . htmlspecialchars( $row->title ) . " in namespace " . htmlspecialchars( $row->page_namespace ) . " -->\n" );
 135+ }
 136+ }
 137+ private function makeLimitLinks() {
 138+ global $wgLang;
 139+
 140+ $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 );
 144+ } else {
 145+ $links[] = (string)$limit;
 146+ }
 147+ }
 148+ return( wfMsgHtml( 'mostrevisors-limitlinks', $wgLang->pipeList( $links ) ) );
 149+ }
 150+
 151+ private function makeRedirectToggle() {
 152+ $label = wfMsgHtml( $this->redirects ? 'mostrevisors-hideredir' : 'mostrevisors-showredir' );
 153+ return $this->makeSelfLink( $label, 'redirects', (int)!$this->redirects );
 154+ }
 155+ private function makeSelfLink( $label, $oname = false, $oval = false ) {
 156+ global $wgUser;
 157+ $skin =& $wgUser->getSkin();
 158+ $self = $this->getTitle();
 159+ $attr['limit'] = $this->limit;
 160+ $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}";
 167+ return $skin->makeKnownLinkObj( $self, $label, implode( '&', $attribs ) );
 168+ }
 169+ private function makeNamespaceForm() {
 170+ $self = $this->getTitle();
 171+ $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
 172+ $form .= Xml::label( wfMsg( 'mostrevisors-namespace' ), 'namespace' ) . '&nbsp;';
 173+ $form .= Xml::namespaceSelector( $this->namespace, 'all' );
 174+ $form .= Xml::hidden( 'limit', $this->limit );
 175+ $form .= Xml::hidden( 'redirects', $this->redirects );
 176+ $form .= Xml::submitButton( wfMsg( 'mostrevisors-submit' ) ) . '</form>';
 177+ return $form;
 178+ }
 179+}
\ No newline at end of file
Property changes on: trunk/extensions/MostRevisors/MostRevisors_body.php
___________________________________________________________________
Name: svn:eol-style
1180 + native
Index: trunk/extensions/MostRevisors/MostRevisors.i18n.php
@@ -0,0 +1,31 @@
 2+<?php
 3+/**
 4+ * Internationalisation file for extension mostrevisors.
 5+ *
 6+ * @addtogroup Extensions
 7+*/
 8+
 9+$messages = array();
 10+
 11+$messages['en'] = array(
 12+ 'mostrevisors-header' => "'''This page lists the {{PLURAL:$1|page|$1 pages}} with most revisors on the wiki.'''",
 13+ '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]]',
 23+ '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',
 26+ 'mostrevisors-limit-few-revisors' => '1',
 27+);
 28+
 29+$messages['qqq'] = array(
 30+ 'mostrevisors' => '{{Identical|Most Revisors}}',
 31+ 'mostrevisors-desc' => 'Short description of the extension, shown on [[Special:Version]].',
 32+);
Property changes on: trunk/extensions/MostRevisors/MostRevisors.i18n.php
___________________________________________________________________
Name: svn:eol-style
133 + native
Index: trunk/extensions/MostRevisors/MostRevisors.php
@@ -0,0 +1,30 @@
 2+<?php
 3+/**
 4+ * A special page to show pages with most revisors.
 5+ *
 6+ */
 7+
 8+// 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.' );
 10+
 11+// Extension credits.
 12+$wgExtensionCredits['specialpage'][] = array(
 13+ 'path' => __FILE__,
 14+ 'name' => 'MostRevisors',
 15+ 'version' => '2.0',
 16+ 'author' => 'Al Maghi',
 17+ 'email' => 'alfred.maghi@gmail.com',
 18+ 'url' => 'http://www.mediawiki.org/wiki/Extension:MostRevisors',
 19+ 'description' => '',
 20+ 'descriptionmsg' => 'mostrevisors-desc',
 21+);
 22+
 23+$wgMostRevisorsPagesLimit = 25;
 24+$wgMostRevisorsLinkContributors = True;
 25+// Set extension files.
 26+$dir = dirname( __FILE__ ) . '/';
 27+$wgExtensionMessagesFiles['MostRevisors'] = $dir . 'MostRevisors.i18n.php';
 28+$wgExtensionAliasesFiles['MostRevisors'] = $dir . 'MostRevisors.alias.php';
 29+$wgAutoloadClasses['MostRevisors'] = $dir . 'MostRevisors_body.php';
 30+$wgSpecialPages['MostRevisors'] = 'MostRevisors';
 31+$wgSpecialPageGroups['MostRevisors'] = 'wiki';
Property changes on: trunk/extensions/MostRevisors/MostRevisors.php
___________________________________________________________________
Name: svn:eol-style
132 + native
Index: trunk/extensions/MostRevisors/MostRevisors.alias.php
@@ -0,0 +1,14 @@
 2+<?php
 3+/**
 4+ * Aliases for special pages
 5+ *
 6+ */
 7+
 8+$aliases = array();
 9+
 10+/** English
 11+ *
 12+ */
 13+$aliases['en'] = array(
 14+ 'MostRevisors' => array( 'MostRevisors' ),
 15+);
Property changes on: trunk/extensions/MostRevisors/MostRevisors.alias.php
___________________________________________________________________
Name: svn:eol-style
116 + native

Status & tagging log