r23375 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23374‎ | r23375 | r23376 >
Date:09:30, 25 June 2007
Author:robchurch
Status:old
Tags:
Comment:
Port Special:WantedCategories - I'm not splitting some of these reports up, where the semantics differ, for example
Modified paths:
  • /branches/robchurch/reports/includes/AutoLoader.php (modified) (history)
  • /branches/robchurch/reports/includes/QueryPage.php (modified) (history)
  • /branches/robchurch/reports/includes/SpecialPage.php (modified) (history)
  • /branches/robchurch/reports/includes/SpecialWantedcategories.php (deleted) (history)
  • /branches/robchurch/reports/includes/reports/Report.php (modified) (history)
  • /branches/robchurch/reports/includes/reports/WantedCategoriesReport.php (added) (history)
  • /branches/robchurch/reports/includes/reports/WantedPagesReport.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
@@ -965,7 +965,7 @@
966966 'popularpages',
967967 'popularpages-header',
968968 'wantedcategories',
969 - 'wantedcategories-summary',
 969+ 'wantedcategories-header',
970970 'wantedpages',
971971 'wantedpages-header',
972972 'mostlinked',
Index: branches/robchurch/reports/maintenance/language/messageTypes.inc
@@ -119,7 +119,6 @@
120120 'whatlinkshere-summary',
121121 'whatlinkshere-barrow',
122122 'imagelist-summary',
123 - 'wantedcategories-summary',
124123 'mostlinked-summary',
125124 'mostlinkedcategories-summary',
126125 'mostlinkedtemplates-summary',
Index: branches/robchurch/reports/includes/SpecialWantedcategories.php
@@ -1,79 +0,0 @@
2 -<?php
3 -/**
4 - * A querypage to list the most wanted categories - implements Special:Wantedcategories
5 - *
6 - * @addtogroup SpecialPage
7 - *
8 - * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
9 - * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
10 - * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
11 - */
12 -class WantedCategoriesPage extends QueryPage {
13 -
14 - function getName() { return 'Wantedcategories'; }
15 - function isExpensive() { return true; }
16 - function isSyndicated() { return false; }
17 -
18 - function getSQL() {
19 - $dbr = wfGetDB( DB_SLAVE );
20 - list( $categorylinks, $page ) = $dbr->tableNamesN( 'categorylinks', 'page' );
21 - $name = $dbr->addQuotes( $this->getName() );
22 - return
23 - "
24 - SELECT
25 - $name as type,
26 - " . NS_CATEGORY . " as namespace,
27 - cl_to as title,
28 - COUNT(*) as value
29 - FROM $categorylinks
30 - LEFT JOIN $page ON cl_to = page_title AND page_namespace = ". NS_CATEGORY ."
31 - WHERE page_title IS NULL
32 - GROUP BY 1,2,3
33 - ";
34 - }
35 -
36 - function sortDescending() { return true; }
37 -
38 - /**
39 - * Fetch user page links and cache their existence
40 - */
41 - function preprocessResults( &$db, &$res ) {
42 - $batch = new LinkBatch;
43 - while ( $row = $db->fetchObject( $res ) )
44 - $batch->addObj( Title::makeTitleSafe( $row->namespace, $row->title ) );
45 - $batch->execute();
46 -
47 - // Back to start for display
48 - if ( $db->numRows( $res ) > 0 )
49 - // If there are no rows we get an error seeking.
50 - $db->dataSeek( $res, 0 );
51 - }
52 -
53 - function formatResult( $skin, $result ) {
54 - global $wgLang, $wgContLang;
55 -
56 - $nt = Title::makeTitle( $result->namespace, $result->title );
57 - $text = $wgContLang->convert( $nt->getText() );
58 -
59 - $plink = $this->isCached() ?
60 - $skin->makeLinkObj( $nt, htmlspecialchars( $text ) ) :
61 - $skin->makeBrokenLinkObj( $nt, htmlspecialchars( $text ) );
62 -
63 - $nlinks = wfMsgExt( 'nmembers', array( 'parsemag', 'escape'),
64 - $wgLang->formatNum( $result->value ) );
65 - return wfSpecialList($plink, $nlinks);
66 - }
67 -}
68 -
69 -/**
70 - * constructor
71 - */
72 -function wfSpecialWantedCategories() {
73 - list( $limit, $offset ) = wfCheckLimits();
74 -
75 - $wpp = new WantedCategoriesPage();
76 -
77 - $wpp->doQuery( $offset, $limit );
78 -}
79 -
80 -?>
Index: branches/robchurch/reports/includes/reports/WantedPagesReport.php
@@ -46,15 +46,6 @@
4747 }
4848
4949 /**
50 - * Should redirects be filtered from results?
51 - *
52 - * @return bool
53 - */
54 - public function excludeRedirects() {
55 - return false;
56 - }
57 -
58 - /**
5950 * Is it appropriate to allow filtering namespaces?
6051 *
6152 * @return bool
Index: branches/robchurch/reports/includes/reports/Report.php
@@ -386,6 +386,7 @@
387387 'ShortPagesReport',
388388 'UncategorisedPagesReport',
389389 'UnwatchedPagesReport',
 390+ 'WantedCategoriesReport',
390391 'WantedPagesReport',
391392 'WithoutInterwikiReport',
392393 ) + $GLOBALS['wgCustomReports'];
Index: branches/robchurch/reports/includes/reports/WantedCategoriesReport.php
@@ -0,0 +1,166 @@
 2+<?php
 3+
 4+/**
 5+ * Report lists all pages which don't exist but have
 6+ * incoming links
 7+ *
 8+ * @addtogroup Reports
 9+ * @author Rob Church <robchur@gmail.com>
 10+ */
 11+class WantedCategoriesReport extends Report {
 12+
 13+ /**
 14+ * Constructor
 15+ */
 16+ public function __construct() {
 17+ parent::__construct();
 18+ }
 19+
 20+ /**
 21+ * Get the name of the report
 22+ *
 23+ * @return string
 24+ */
 25+ public function getName() {
 26+ return 'Wantedcategories';
 27+ }
 28+
 29+ /**
 30+ * Is it appropriate to allow filtering redirects?
 31+ *
 32+ * @return bool
 33+ */
 34+ public function allowRedirectFilter() {
 35+ return false;
 36+ }
 37+
 38+ /**
 39+ * Is it appropriate to allow filtering namespaces?
 40+ *
 41+ * @return bool
 42+ */
 43+ public function allowNamespaceFilter() {
 44+ return false;
 45+ }
 46+
 47+ /**
 48+ * Get a list of namespaces this report can be run
 49+ * against - false indicates *all* namespaces
 50+ *
 51+ * @return mixed
 52+ */
 53+ public function getApplicableNamespaces() {
 54+ return array(
 55+ NS_CATEGORY,
 56+ );
 57+ }
 58+
 59+ /**
 60+ * Return base SQL for the report
 61+ *
 62+ * @param Database $dbr Database object being queried
 63+ * @return string
 64+ */
 65+ public function getBaseSql( $dbr ) {
 66+ list( $page, $categorylinks ) = $dbr->tableNamesN( 'page', 'categorylinks' );
 67+ return
 68+ "SELECT
 69+ cl_to AS rp_id,
 70+ " . NS_CATEGORY . " AS rp_namespace,
 71+ cl_to AS rp_title,
 72+ 0 AS rp_redirect,
 73+ COUNT(*) AS count
 74+ FROM {$categorylinks}
 75+ LEFT JOIN {$page} ON cl_to = page_title AND page_namespace = " . NS_CATEGORY;
 76+ }
 77+
 78+ /**
 79+ * Return additional WHERE clauses and other conditions
 80+ * to which the paging clauses will be appened when
 81+ * the report runs live
 82+ *
 83+ * @param Database $dbr Database object being queried
 84+ * @return array
 85+ */
 86+ public function getExtraConditions( $dbr ) {
 87+ return array(
 88+ 'page_title IS NULL',
 89+ );
 90+ }
 91+
 92+ /**
 93+ * Get the column used for paging when the report is run live
 94+ *
 95+ * @return string
 96+ */
 97+ public function getPagingColumn() {
 98+ return 'cl_to';
 99+ }
 100+
 101+ /**
 102+ * Get a partial WHERE clause to filter on namespace when
 103+ * the report is run live
 104+ *
 105+ * @param int $namespace Namespace to limit to
 106+ * @return string
 107+ */
 108+ public function getNamespaceClause( $namespace ) {
 109+ // Not applicable to this report
 110+ return '1 = 1';
 111+ }
 112+
 113+ /**
 114+ * Get additional SQL to be inserted between the
 115+ * conditions and ORDER clauses when the report is run live
 116+ *
 117+ * @param Database $dbr Database object being queried
 118+ * @return string
 119+ */
 120+ public function getExtraSql( $dbr ) {
 121+ return ' GROUP BY 1, 2, 3';
 122+ }
 123+
 124+ /**
 125+ * Get ORDER BY clauses to be applied when the
 126+ * report is run live
 127+ *
 128+ * @return array
 129+ */
 130+ public function getOrderingClauses() {
 131+ return array(
 132+ 'count DESC',
 133+ );
 134+ }
 135+
 136+ /**
 137+ * Given a result object, extract additional parameters
 138+ * as a dictionary for later use
 139+ *
 140+ * @param object $row Result row
 141+ * @return array
 142+ */
 143+ public function extractParameters( $row ) {
 144+ return array(
 145+ 'count' => $row->count,
 146+ );
 147+ }
 148+
 149+ /**
 150+ * Format an individual result row
 151+ *
 152+ * @param Title $title Result title
 153+ * @param object $row Result row
 154+ * @param array $params Result parameters
 155+ * @param Skin $skin User skin
 156+ * @return string
 157+ */
 158+ public function formatRow( $title, $row, $params, $skin ) {
 159+ global $wgLang;
 160+ $members = wfMsgExt( 'nmembers', array( 'parsemag', 'escape' ), $params['count'] );
 161+ return "<li>" . $skin->makeLinkObj( $title, htmlspecialchars( $title->getText() ) )
 162+ . " ({$members})</li>\n";
 163+ }
 164+
 165+}
 166+
 167+?>
\ No newline at end of file
Property changes on: branches/robchurch/reports/includes/reports/WantedCategoriesReport.php
___________________________________________________________________
Added: svn:eol-style
1168 + native
Index: branches/robchurch/reports/includes/AutoLoader.php
@@ -216,7 +216,6 @@
217217 'LoginForm' => 'includes/SpecialUserlogin.php',
218218 'UserrightsForm' => 'includes/SpecialUserrights.php',
219219 'SpecialVersion' => 'includes/SpecialVersion.php',
220 - 'WantedCategoriesPage' => 'includes/SpecialWantedcategories.php',
221220 'WhatLinksHerePage' => 'includes/SpecialWhatlinkshere.php',
222221 'SquidUpdate' => 'includes/SquidUpdate.php',
223222 'ReplacementArray' => 'includes/StringUtils.php',
@@ -291,6 +290,7 @@
292291 'ShortPagesReport' => 'includes/reports/ShortPagesReport.php',
293292 'UncategorisedPagesReport' => 'includes/reports/UncategorisedPagesReport.php',
294293 'UnwatchedPagesReport' => 'includes/reports/UnwatchedPagesReport.php',
 294+ 'WantedCategoriesReport' => 'includes/reports/WantedCategoriesReport.php',
295295 'WantedPagesReport' => 'includes/reports/WantedPagesReport.php',
296296 'WithoutInterwikiReport' => 'includes/reports/WithoutInterwikiReport.php',
297297
Index: branches/robchurch/reports/includes/QueryPage.php
@@ -25,9 +25,6 @@
2626 array( 'FewestrevisionsPage', 'Fewestrevisions' ),
2727 array( 'UnusedCategoriesPage', 'Unusedcategories' ),
2828 array( 'UnusedimagesPage', 'Unusedimages' ),
29 -
30 - array( 'WantedCategoriesPage', 'Wantedcategories' ),
31 -
3229 array( 'UnusedtemplatesPage', 'Unusedtemplates' ),
3330 );
3431 wfRunHooks( 'wgQueryPages', array( &$wgQueryPages ) );
Index: branches/robchurch/reports/includes/SpecialPage.php
@@ -98,7 +98,7 @@
9999 'Unusedcategories' => array( 'SpecialPage', 'Unusedcategories' ),
100100 'Unusedimages' => array( 'SpecialPage', 'Unusedimages' ),
101101 'Wantedpages' => 'WantedPagesReport',
102 - 'Wantedcategories' => array( 'SpecialPage', 'Wantedcategories' ),
 102+ 'Wantedcategories' => 'WantedCategoriesReport',
103103 'Mostlinked' => array( 'SpecialPage', 'Mostlinked' ),
104104 'Mostlinkedcategories' => array( 'SpecialPage', 'Mostlinkedcategories' ),
105105 'Mostlinkedtemplates' => array( 'SpecialPage', 'Mostlinkedtemplates' ),
Index: branches/robchurch/reports/languages/messages/MessagesEn.php
@@ -1574,7 +1574,7 @@
15751575 'popularpages' => 'Popular pages',
15761576 'popularpages-header' => 'This report lists the most-viewed pages on the wiki.',
15771577 'wantedcategories' => 'Wanted categories',
1578 -'wantedcategories-summary' => '', # only translate this message to other languages if you have to change it
 1578+'wantedcategories-header' => 'This report lists categories which contain pages, but which don\'t have an associated description page.',
15791579 'wantedpages' => 'Wanted pages',
15801580 'wantedpages-header' => 'This report lists pages which don\'t exist, but have $1 or more incoming links.',
15811581 'mostlinked' => 'Most linked to pages',

Status & tagging log