r23387 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23386‎ | r23387 | r23388 >
Date:14:50, 25 June 2007
Author:robchurch
Status:old
Tags:
Comment:
* Port Special:MostCategories
* Port Special:MostImages, renaming to Special:MostUsedImages to reflect the actual purpose
Modified paths:
  • /branches/robchurch/reports/includes/AutoLoader.php (modified) (history)
  • /branches/robchurch/reports/includes/QueryPage.php (modified) (history)
  • /branches/robchurch/reports/includes/SpecialMostcategories.php (deleted) (history)
  • /branches/robchurch/reports/includes/SpecialMostimages.php (deleted) (history)
  • /branches/robchurch/reports/includes/SpecialPage.php (modified) (history)
  • /branches/robchurch/reports/includes/reports/MostCategoriesReport.php (added) (history)
  • /branches/robchurch/reports/includes/reports/MostUsedImagesReport.php (added) (history)
  • /branches/robchurch/reports/includes/reports/Report.php (modified) (history)
  • /branches/robchurch/reports/languages/messages/MessagesEn.php (modified) (history)
  • /branches/robchurch/reports/maintenance/language/messageTypes.inc (modified) (history)
  • /branches/robchurch/reports/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: branches/robchurch/reports/maintenance/language/messages.inc
@@ -974,7 +974,7 @@
975975 'mostlinkedtemplates',
976976 'mostlinkedtemplates-header',
977977 'mostcategories',
978 - 'mostcategories-summary',
 978+ 'mostcategories-header',
979979 'mostimages',
980980 'mostimages-summary',
981981 'mostrevisions',
Index: branches/robchurch/reports/maintenance/language/messageTypes.inc
@@ -119,7 +119,6 @@
120120 'whatlinkshere-summary',
121121 'whatlinkshere-barrow',
122122 'imagelist-summary',
123 - 'mostcategories-summary',
124123 'mostimages-summary',
125124 'mostrevisions-summary',
126125 'prefixindex-summary',
Index: branches/robchurch/reports/includes/SpecialMostcategories.php
@@ -1,59 +0,0 @@
2 -<?php
3 -/**
4 - * @addtogroup SpecialPage
5 - *
6 - * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
7 - * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
8 - * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
9 - */
10 -
11 -/**
12 - * implements Special:Mostcategories
13 - * @addtogroup SpecialPage
14 - */
15 -class MostcategoriesPage extends QueryPage {
16 -
17 - function getName() { return 'Mostcategories'; }
18 - function isExpensive() { return true; }
19 - function isSyndicated() { return false; }
20 -
21 - function getSQL() {
22 - $dbr = wfGetDB( DB_SLAVE );
23 - list( $categorylinks, $page) = $dbr->tableNamesN( 'categorylinks', 'page' );
24 - return
25 - "
26 - SELECT
27 - 'Mostcategories' as type,
28 - page_namespace as namespace,
29 - page_title as title,
30 - COUNT(*) as value
31 - FROM $categorylinks
32 - LEFT JOIN $page ON cl_from = page_id
33 - WHERE page_namespace = " . NS_MAIN . "
34 - GROUP BY 1,2,3
35 - HAVING COUNT(*) > 1
36 - ";
37 - }
38 -
39 - function formatResult( $skin, $result ) {
40 - global $wgLang;
41 - $title = Title::makeTitleSafe( $result->namespace, $result->title );
42 - if ( !$title instanceof Title ) { throw new MWException('Invalid title in database'); }
43 - $count = wfMsgExt( 'ncategories', array( 'parsemag', 'escape' ), $wgLang->formatNum( $result->value ) );
44 - $link = $skin->makeKnownLinkObj( $title, $title->getText() );
45 - return wfSpecialList( $link, $count );
46 - }
47 -}
48 -
49 -/**
50 - * constructor
51 - */
52 -function wfSpecialMostcategories() {
53 - list( $limit, $offset ) = wfCheckLimits();
54 -
55 - $wpp = new MostcategoriesPage();
56 -
57 - $wpp->doQuery( $offset, $limit );
58 -}
59 -
60 -?>
Index: branches/robchurch/reports/includes/SpecialMostimages.php
@@ -1,55 +0,0 @@
2 -<?php
3 -/**
4 - * @addtogroup SpecialPage
5 - *
6 - * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
7 - * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
8 - * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
9 - */
10 -
11 -/**
12 - * implements Special:Mostimages
13 - * @addtogroup SpecialPage
14 - */
15 -class MostimagesPage extends ImageQueryPage {
16 -
17 - function getName() { return 'Mostimages'; }
18 - function isExpensive() { return true; }
19 - function isSyndicated() { return false; }
20 -
21 - function getSQL() {
22 - $dbr = wfGetDB( DB_SLAVE );
23 - $imagelinks = $dbr->tableName( 'imagelinks' );
24 - return
25 - "
26 - SELECT
27 - 'Mostimages' as type,
28 - " . NS_IMAGE . " as namespace,
29 - il_to as title,
30 - COUNT(*) as value
31 - FROM $imagelinks
32 - GROUP BY 1,2,3
33 - HAVING COUNT(*) > 1
34 - ";
35 - }
36 -
37 - function getCellHtml( $row ) {
38 - global $wgLang;
39 - return wfMsgExt( 'nlinks', array( 'parsemag', 'escape' ),
40 - $wgLang->formatNum( $row->value ) ) . '<br />';
41 - }
42 -
43 -}
44 -
45 -/**
46 - * Constructor
47 - */
48 -function wfSpecialMostimages() {
49 - list( $limit, $offset ) = wfCheckLimits();
50 -
51 - $wpp = new MostimagesPage();
52 -
53 - $wpp->doQuery( $offset, $limit );
54 -}
55 -
56 -?>
Index: branches/robchurch/reports/includes/reports/Report.php
@@ -382,7 +382,9 @@
383383 'DoubleRedirectsReport',
384384 'LargestCategoriesReport',
385385 'LongPagesReport',
 386+ 'MostCategoriesReport',
386387 'MostLinkedPagesReport',
 388+ 'MostUsedImagesReport',
387389 'MostUsedTemplatesReport',
388390 'OrphanedPagesReport',
389391 'PopularPagesReport',
Index: branches/robchurch/reports/includes/reports/MostCategoriesReport.php
@@ -0,0 +1,139 @@
 2+<?php
 3+
 4+/**
 5+ * Report lists pages with the most categories
 6+ *
 7+ * @addtogroup Reports
 8+ * @author Rob Church <robchur@gmail.com>
 9+ */
 10+class MostCategoriesReport extends Report {
 11+
 12+ /**
 13+ * Constructor
 14+ */
 15+ public function __construct() {
 16+ parent::__construct();
 17+ }
 18+
 19+ /**
 20+ * Get the name of the report
 21+ *
 22+ * @return string
 23+ */
 24+ public function getName() {
 25+ return 'Mostcategories';
 26+ }
 27+
 28+ /**
 29+ * Is it appropriate to allow filtering redirects?
 30+ *
 31+ * @return bool
 32+ */
 33+ public function allowRedirectFilter() {
 34+ return false;
 35+ }
 36+
 37+ /**
 38+ * Should redirects be filtered from results?
 39+ *
 40+ * @return bool
 41+ */
 42+ public function excludeRedirects() {
 43+ return true;
 44+ }
 45+
 46+ /**
 47+ * Is it appropriate to allow filtering namespaces?
 48+ *
 49+ * @return bool
 50+ */
 51+ public function allowNamespaceFilter() {
 52+ return true;
 53+ }
 54+
 55+ /**
 56+ * Get a list of namespaces this report can be run
 57+ * against - false indicates *all* namespaces
 58+ *
 59+ * @return mixed
 60+ */
 61+ public function getApplicableNamespaces() {
 62+ return array(
 63+ NS_MAIN,
 64+ ) + $GLOBALS['wgContentNamespaces'];
 65+ }
 66+
 67+ /**
 68+ * Return base SQL for the report
 69+ *
 70+ * @param Database $dbr Database object being queried
 71+ * @return string
 72+ */
 73+ public function getBaseSql( $dbr ) {
 74+ list( $page, $categorylinks ) = $dbr->tableNamesN( 'page', 'categorylinks' );
 75+ return
 76+ "SELECT
 77+ page_id AS rp_id,
 78+ page_namespace AS rp_namespace,
 79+ page_title AS rp_title,
 80+ page_is_redirect AS rp_redirect,
 81+ COUNT(*) AS count
 82+ FROM {$categorylinks}
 83+ LEFT JOIN {$page} ON cl_from = page_id";
 84+ }
 85+
 86+ /**
 87+ * Get additional SQL to be inserted between the
 88+ * conditions and ORDER clauses when the report is run live
 89+ *
 90+ * @param Database $dbr Database object being queried
 91+ * @return string
 92+ */
 93+ public function getExtraSql( $dbr ) {
 94+ return ' GROUP BY 2, 3 HAVING count > 1';
 95+ }
 96+
 97+ /**
 98+ * Get ORDER BY clauses to be applied when the
 99+ * report is run live
 100+ *
 101+ * @return array
 102+ */
 103+ public function getOrderingClauses() {
 104+ return array(
 105+ 'count DESC',
 106+ );
 107+ }
 108+
 109+ /**
 110+ * Given a result object, extract additional parameters
 111+ * as a dictionary for later use
 112+ *
 113+ * @param object $row Result row
 114+ * @return array
 115+ */
 116+ public function extractParameters( $row ) {
 117+ return array(
 118+ 'count' => $row->count,
 119+ );
 120+ }
 121+
 122+ /**
 123+ * Format an individual result row
 124+ *
 125+ * @param Title $title Result title
 126+ * @param object $row Result row
 127+ * @param array $params Result parameters
 128+ * @param Skin $skin User skin
 129+ * @return string
 130+ */
 131+ public function formatRow( $title, $row, $params, $skin ) {
 132+ global $wgLang;
 133+ $categories = wfMsgExt( 'ncategories', array( 'parsemag', 'escape' ),
 134+ $wgLang->formatNum( $params['count'] ) );
 135+ return "<li>" . $skin->makeLinkObj( $title ) . " ({$categories})</li>\n";
 136+ }
 137+
 138+}
 139+
 140+?>
\ No newline at end of file
Property changes on: branches/robchurch/reports/includes/reports/MostCategoriesReport.php
___________________________________________________________________
Added: svn:eol-style
1141 + native
Index: branches/robchurch/reports/includes/reports/MostUsedImagesReport.php
@@ -0,0 +1,157 @@
 2+<?php
 3+
 4+/**
 5+ * Report lists the most used images
 6+ *
 7+ * @addtogroup Reports
 8+ * @author Rob Church <robchur@gmail.com>
 9+ */
 10+class MostUsedImagesReport extends Report {
 11+
 12+ /**
 13+ * Constructor
 14+ */
 15+ public function __construct() {
 16+ parent::__construct();
 17+ }
 18+
 19+ /**
 20+ * Get the name of the report
 21+ *
 22+ * @return string
 23+ */
 24+ public function getName() {
 25+ return 'Mostusedimages';
 26+ }
 27+
 28+ /**
 29+ * Is it appropriate to allow filtering redirects?
 30+ *
 31+ * @return bool
 32+ */
 33+ public function allowRedirectFilter() {
 34+ return false;
 35+ }
 36+
 37+ /**
 38+ * Is it appropriate to allow filtering namespaces?
 39+ *
 40+ * @return bool
 41+ */
 42+ public function allowNamespaceFilter() {
 43+ return false;
 44+ }
 45+
 46+ /**
 47+ * Get a list of namespaces this report can be run
 48+ * against - false indicates *all* namespaces
 49+ *
 50+ * @return mixed
 51+ */
 52+ public function getApplicableNamespaces() {
 53+ return array(
 54+ NS_IMAGE,
 55+ );
 56+ }
 57+
 58+ /**
 59+ * Return base SQL for the report
 60+ *
 61+ * @param Database $dbr Database object being queried
 62+ * @return string
 63+ */
 64+ public function getBaseSql( $dbr ) {
 65+ $imagelinks = $dbr->tableName( 'imagelinks' );
 66+ return
 67+ "SELECT
 68+ il_to AS rp_id,
 69+ " . NS_IMAGE . " AS rp_namespace,
 70+ il_to AS rp_title,
 71+ 0 AS rp_redirect,
 72+ COUNT(*) AS count
 73+ FROM {$imagelinks}";
 74+ }
 75+
 76+ /**
 77+ * Get the column used for paging when the report is run live
 78+ *
 79+ * @return string
 80+ */
 81+ public function getPagingColumn() {
 82+ return 'il_to';
 83+ }
 84+
 85+ /**
 86+ * Get a partial WHERE clause to filter on namespace when
 87+ * the report is run live
 88+ *
 89+ * @param int $namespace Namespace to limit to
 90+ * @return string
 91+ */
 92+ public function getNamespaceClause( $namespace ) {
 93+ // Not applicable for this report
 94+ return '1 = 1';
 95+ }
 96+
 97+ /**
 98+ * Get additional SQL to be inserted between the
 99+ * conditions and ORDER clauses when the report is run live
 100+ *
 101+ * @param Database $dbr Database object being queried
 102+ * @return string
 103+ */
 104+ public function getExtraSql( $dbr ) {
 105+ return ' GROUP BY 2, 3';
 106+ }
 107+
 108+ /**
 109+ * Get ORDER BY clauses to be applied when the
 110+ * report is run live
 111+ *
 112+ * @return array
 113+ */
 114+ public function getOrderingClauses() {
 115+ return array(
 116+ 'count DESC',
 117+ );
 118+ }
 119+
 120+ /**
 121+ * Given a result object, extract additional parameters
 122+ * as a dictionary for later use
 123+ *
 124+ * @param object $row Result row
 125+ * @return array
 126+ */
 127+ public function extractParameters( $row ) {
 128+ return array(
 129+ 'count' => $row->count,
 130+ );
 131+ }
 132+
 133+ /**
 134+ * Format an individual result row
 135+ *
 136+ * @param Title $title Result title
 137+ * @param object $row Result row
 138+ * @param array $params Result parameters
 139+ * @param Skin $skin User skin
 140+ * @return string
 141+ */
 142+ public function formatRow( $title, $row, $params, $skin ) {
 143+ // Not needed; we forced the use of galleries
 144+ }
 145+
 146+ /**
 147+ * Get the namespace to filter results for, or false
 148+ * to omit filtering
 149+ *
 150+ * @return mixed
 151+ */
 152+ public function getNamespace() {
 153+ return NS_IMAGE;
 154+ }
 155+
 156+}
 157+
 158+?>
\ No newline at end of file
Property changes on: branches/robchurch/reports/includes/reports/MostUsedImagesReport.php
___________________________________________________________________
Added: svn:eol-style
1159 + native
Index: branches/robchurch/reports/includes/AutoLoader.php
@@ -182,8 +182,6 @@
183183 'LogReader' => 'includes/SpecialLog.php',
184184 'LogViewer' => 'includes/SpecialLog.php',
185185 'MIMEsearchPage' => 'includes/SpecialMIMEsearch.php',
186 - 'MostcategoriesPage' => 'includes/SpecialMostcategories.php',
187 - 'MostimagesPage' => 'includes/SpecialMostimages.php',
188186 'MostrevisionsPage' => 'includes/SpecialMostrevisions.php',
189187 'FewestrevisionsPage' => 'includes/SpecialFewestrevisions.php',
190188 'MovePageForm' => 'includes/SpecialMovepage.php',
@@ -282,7 +280,9 @@
283281 'DoubleRedirectsReport' => 'includes/reports/DoubleRedirectsReport.php',
284282 'LargestCategoriesReport' => 'includes/reports/LargestCategoriesReport.php',
285283 'LongPagesReport' => 'includes/reports/LongPagesReport.php',
 284+ 'MostCategoriesReport' => 'includes/reports/MostCategoriesReport.php',
286285 'MostLinkedPagesReport' => 'includes/reports/MostLinkedPagesReport.php',
 286+ 'MostUsedImagesReport' => 'includes/reports/MostUsedImagesReport.php',
287287 'MostUsedTemplatesReport' => 'includes/reports/MostUsedTemplatesReport.php',
288288 'OrphanedPagesReport' => 'includes/reports/OrphanedPagesReport.php',
289289 'PopularPagesReport' => 'includes/reports/PopularPagesReport.php',
Index: branches/robchurch/reports/includes/QueryPage.php
@@ -15,7 +15,6 @@
1616 // QueryPage subclass Special page name Limit (false for none, none for the default)
1717 //----------------------------------------------------------------------------
1818 array( 'DisambiguationsPage', 'Disambiguations' ),
19 - array( 'MostcategoriesPage', 'Mostcategories' ),
2019 array( 'MostimagesPage', 'Mostimages' ),
2120 array( 'MostrevisionsPage', 'Mostrevisions' ),
2221 array( 'FewestrevisionsPage', 'Fewestrevisions' ),
Index: branches/robchurch/reports/includes/SpecialPage.php
@@ -102,8 +102,8 @@
103103 'Mostlinked' => 'MostLinkedPagesReport',
104104 'Largestcategories' => 'LargestCategoriesReport',
105105 'Mostlinkedtemplates' => 'MostUsedTemplatesReport',
106 - 'Mostcategories' => array( 'SpecialPage', 'Mostcategories' ),
107 - 'Mostimages' => array( 'SpecialPage', 'Mostimages' ),
 106+ 'Mostcategories' => 'MostCategoriesReport',
 107+ 'Mostusedimages' => 'MostUsedImagesReport',
108108 'Mostrevisions' => array( 'SpecialPage', 'Mostrevisions' ),
109109 'Fewestrevisions' => array( 'SpecialPage', 'Fewestrevisions' ),
110110 'Shortpages' => 'ShortPagesReport',
Index: branches/robchurch/reports/languages/messages/MessagesEn.php
@@ -1582,10 +1582,10 @@
15831583 'largestcategories-header' => 'This report lists categories with the most members.',
15841584 'mostlinkedtemplates' => 'Most used templates',
15851585 'mostlinkedtemplates-header' => 'This report lists the most-used templates on the wiki.',
1586 -'mostcategories' => 'Articles with the most categories',
1587 -'mostcategories-summary' => '', # only translate this message to other languages if you have to change it
1588 -'mostimages' => 'Most linked to images',
1589 -'mostimages-summary' => '', # only translate this message to other languages if you have to change it
 1586+'mostcategories' => 'Pages with the most categories',
 1587+'mostcategories-header' => 'This report lists pages belonging to the largest number of categories.',
 1588+'mostusedimages' => 'Most used images',
 1589+'mostusedimages-header' => 'This report lists the most-used images on the wiki.',
15901590 'mostrevisions' => 'Articles with the most revisions',
15911591 'mostrevisions-summary' => '', # only translate this message to other languages if you have to change it
15921592 'allpages' => 'All pages',

Status & tagging log