r23359 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23358‎ | r23359 | r23360 >
Date:05:44, 25 June 2007
Author:robchurch
Status:old
Tags:
Comment:
Port Special:PopularPages
Modified paths:
  • /branches/robchurch/reports/includes/AutoLoader.php (modified) (history)
  • /branches/robchurch/reports/includes/SpecialPage.php (modified) (history)
  • /branches/robchurch/reports/includes/SpecialPopularpages.php (deleted) (history)
  • /branches/robchurch/reports/includes/reports/PopularPagesReport.php (added) (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
@@ -963,7 +963,7 @@
964964 'unusedcategories',
965965 'unusedimages',
966966 'popularpages',
967 - 'popularpages-summary',
 967+ 'popularpages-header',
968968 'wantedcategories',
969969 'wantedcategories-summary',
970970 'wantedpages',
Index: branches/robchurch/reports/maintenance/language/messageTypes.inc
@@ -120,7 +120,6 @@
121121 'whatlinkshere-summary',
122122 'whatlinkshere-barrow',
123123 'imagelist-summary',
124 - 'popularpages-summary',
125124 'wantedcategories-summary',
126125 'wantedpages-summary',
127126 'mostlinked-summary',
Index: branches/robchurch/reports/includes/SpecialPopularpages.php
@@ -1,69 +0,0 @@
2 -<?php
3 -/**
4 - *
5 - * @addtogroup SpecialPage
6 - */
7 -
8 -/**
9 - * implements Special:Popularpages
10 - * @addtogroup SpecialPage
11 - */
12 -class PopularPagesPage extends QueryPage {
13 -
14 - function getName() {
15 - return "Popularpages";
16 - }
17 -
18 - function isExpensive() {
19 - # page_counter is not indexed
20 - return true;
21 - }
22 - function isSyndicated() { return false; }
23 -
24 - function getSQL() {
25 - $dbr = wfGetDB( DB_SLAVE );
26 - $page = $dbr->tableName( 'page' );
27 -
28 - $query =
29 - "SELECT 'Popularpages' as type,
30 - page_namespace as namespace,
31 - page_title as title,
32 - page_counter as value
33 - FROM $page ";
34 - $where =
35 - "WHERE page_is_redirect=0 AND page_namespace";
36 -
37 - global $wgContentNamespaces;
38 - if( empty( $wgContentNamespaces ) ) {
39 - $where .= '='.NS_MAIN;
40 - } else if( count( $wgContentNamespaces ) > 1 ) {
41 - $where .= ' in (' . implode( ', ', $wgContentNamespaces ) . ')';
42 - } else {
43 - $where .= '='.$wgContentNamespaces[0];
44 - }
45 -
46 - return $query . $where;
47 - }
48 -
49 - function formatResult( $skin, $result ) {
50 - global $wgLang, $wgContLang;
51 - $title = Title::makeTitle( $result->namespace, $result->title );
52 - $link = $skin->makeKnownLinkObj( $title, htmlspecialchars( $wgContLang->convert( $title->getPrefixedText() ) ) );
53 - $nv = wfMsgExt( 'nviews', array( 'parsemag', 'escape'),
54 - $wgLang->formatNum( $result->value ) );
55 - return wfSpecialList($link, $nv);
56 - }
57 -}
58 -
59 -/**
60 - * Constructor
61 - */
62 -function wfSpecialPopularpages() {
63 - list( $limit, $offset ) = wfCheckLimits();
64 -
65 - $ppp = new PopularPagesPage();
66 -
67 - return $ppp->doQuery( $offset, $limit );
68 -}
69 -
70 -?>
Index: branches/robchurch/reports/includes/reports/PopularPagesReport.php
@@ -0,0 +1,152 @@
 2+<?php
 3+
 4+/**
 5+ * Report lists the most-viewed pages on the wiki
 6+ *
 7+ * @addtogroup Reports
 8+ * @author Rob Church <robchur@gmail.com>
 9+ */
 10+class PopularPagesReport 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 'Popularpages';
 26+ }
 27+
 28+ /**
 29+ * Are updates for this report disabled?
 30+ *
 31+ * @return bool
 32+ */
 33+ public function isDisabled() {
 34+ global $wgDisableCounters, $wgDisabledReports;
 35+ return $wgDisableCounters
 36+ || in_array( $this->getName(), $wgDisabledReports );
 37+ }
 38+
 39+ /**
 40+ * Is it appropriate to allow filtering redirects?
 41+ *
 42+ * @return bool
 43+ */
 44+ public function allowRedirectFilter() {
 45+ return false;
 46+ }
 47+
 48+ /**
 49+ * Should redirects be filtered from results?
 50+ *
 51+ * @return bool
 52+ */
 53+ public function excludeRedirects() {
 54+ return true;
 55+ }
 56+
 57+ /**
 58+ * Is it appropriate to allow filtering namespaces?
 59+ *
 60+ * @return bool
 61+ */
 62+ public function allowNamespaceFilter() {
 63+ return true;
 64+ }
 65+
 66+ /**
 67+ * Get a list of namespaces this report can be run
 68+ * against - false indicates *all* namespaces
 69+ *
 70+ * @return mixed
 71+ */
 72+ public function getApplicableNamespaces() {
 73+ return array(
 74+ NS_MAIN,
 75+ ) + $GLOBALS['wgContentNamespaces'];
 76+ }
 77+
 78+ /**
 79+ * Return base SQL for the report
 80+ *
 81+ * @param Database $dbr Database object being queried
 82+ * @return string
 83+ */
 84+ public function getBaseSql( $dbr ) {
 85+ $page = $dbr->tableName( 'page' );
 86+ return
 87+ "SELECT
 88+ page_id AS rp_id,
 89+ page_namespace AS rp_namespace,
 90+ page_title AS rp_title,
 91+ page_is_redirect AS rp_redirect,
 92+ page_counter
 93+ FROM {$page}";
 94+ }
 95+
 96+ /**
 97+ * Return additional WHERE clauses and other conditions
 98+ * to which the paging clauses will be appened when
 99+ * the report runs live
 100+ *
 101+ * @param Database $dbr Database object being queried
 102+ * @return array
 103+ */
 104+ public function getExtraConditions( $dbr ) {
 105+ return array(
 106+ 'page_counter > 0',
 107+ );
 108+ }
 109+
 110+ /**
 111+ * Get ORDER BY clauses to be applied when the
 112+ * report is run live
 113+ *
 114+ * @return array
 115+ */
 116+ public function getOrderingClauses() {
 117+ return array(
 118+ 'page_counter DESC',
 119+ );
 120+ }
 121+
 122+ /**
 123+ * Given a result object, extract additional parameters
 124+ * as a dictionary for later use
 125+ *
 126+ * @param object $row Result row
 127+ * @return array
 128+ */
 129+ public function extractParameters( $row ) {
 130+ return array(
 131+ 'page_counter' => $row->page_counter,
 132+ );
 133+ }
 134+
 135+ /**
 136+ * Format an individual result row
 137+ *
 138+ * @param Title $title Result title
 139+ * @param object $row Result row
 140+ * @param array $params Result parameters
 141+ * @param Skin $skin User skin
 142+ * @return string
 143+ */
 144+ public function formatRow( $title, $row, $params, $skin ) {
 145+ global $wgLang;
 146+ $views = wfMsgExt( 'nviews', array( 'parsemag', 'escape' ),
 147+ $wgLang->formatNum( $params['page_counter'] ) );
 148+ return "<li>" . $skin->makeLinkObj( $title ) . " ({$views})</li>\n";
 149+ }
 150+
 151+}
 152+
 153+?>
\ No newline at end of file
Property changes on: branches/robchurch/reports/includes/reports/PopularPagesReport.php
___________________________________________________________________
Added: svn:eol-style
1154 + native
Index: branches/robchurch/reports/includes/AutoLoader.php
@@ -202,7 +202,6 @@
203203 'IncludableSpecialPage' => 'includes/SpecialPage.php',
204204 'SpecialRedirect' => 'includes/SpecialRedirect.php',
205205 'SpecialSpecialPages' => 'includes/SpecialSpecialpages.php',
206 - 'PopularPagesPage' => 'includes/SpecialPopularpages.php',
207206 'PreferencesForm' => 'includes/SpecialPreferences.php',
208207 'SpecialPrefixindex' => 'includes/SpecialPrefixindex.php',
209208 'PasswordResetForm' => 'includes/SpecialResetpass.php',
@@ -285,8 +284,10 @@
286285 'ReportCache' => 'includes/reports/ReportCache.php',
287286 'ReportPager' => 'includes/reports/ReportPager.php',
288287 'CachedReportPager' => 'includes/reports/CachedReportPager.php',
 288+
289289 'BrokenRedirectsReport' => 'includes/reports/BrokenRedirectsReport.php',
290290 'DoubleRedirectsReport' => 'includes/reports/DoubleRedirectsReport.php',
 291+ 'PopularPagesReport' => 'includes/reports/PopularPagesReport.php',
291292 'RedirectReport' => 'includes/reports/RedirectReport.php',
292293 'ShortPagesReport' => 'includes/reports/ShortPagesReport.php',
293294 'UncategorisedPagesReport' => 'includes/reports/UncategorisedPagesReport.php',
Index: branches/robchurch/reports/includes/SpecialPage.php
@@ -171,7 +171,7 @@
172172 self::$mListInitialised = true;
173173
174174 if( !$wgDisableCounters ) {
175 - self::$mList['Popularpages'] = array( 'SpecialPage', 'Popularpages' );
 175+ self::$mList['Popularpages'] = 'PopularPagesReport';
176176 }
177177
178178 if( !$wgDisableInternalSearch ) {
Index: branches/robchurch/reports/languages/messages/MessagesEn.php
@@ -1572,7 +1572,7 @@
15731573 'unusedcategories' => 'Unused categories',
15741574 'unusedimages' => 'Unused files',
15751575 'popularpages' => 'Popular pages',
1576 -'popularpages-summary' => '', # only translate this message to other languages if you have to change it
 1576+'popularpages-header' => 'This report lists the most-viewed pages on the wiki.',
15771577 'wantedcategories' => 'Wanted categories',
15781578 'wantedcategories-summary' => '', # only translate this message to other languages if you have to change it
15791579 'wantedpages' => 'Wanted pages',

Status & tagging log