r23364 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23363‎ | r23364 | r23365 >
Date:06:40, 25 June 2007
Author:robchurch
Status:old
Tags:
Comment:
Port Special:AncientPages, introducing $wgAncientPagesThreshold which is a significant boost
Modified paths:
  • /branches/robchurch/reports/includes/AutoLoader.php (modified) (history)
  • /branches/robchurch/reports/includes/DefaultSettings.php (modified) (history)
  • /branches/robchurch/reports/includes/QueryPage.php (modified) (history)
  • /branches/robchurch/reports/includes/SpecialAncientpages.php (deleted) (history)
  • /branches/robchurch/reports/includes/SpecialPage.php (modified) (history)
  • /branches/robchurch/reports/includes/reports/AncientPagesReport.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
@@ -1008,7 +1008,7 @@
10091009 'newpages-summary',
10101010 'newpages-username',
10111011 'ancientpages',
1012 - 'ancientpages-summary',
 1012+ 'ancientpages-header',
10131013 'intl',
10141014 'move',
10151015 'movethispage',
Index: branches/robchurch/reports/maintenance/language/messageTypes.inc
@@ -129,7 +129,6 @@
130130 'mostrevisions-summary',
131131 'prefixindex-summary',
132132 'newpages-summary',
133 - 'ancientpages-summary',
134133 'newimages-summary',
135134 'userrights-summary',
136135 'protectedpages-summary',
Index: branches/robchurch/reports/includes/SpecialAncientpages.php
@@ -1,63 +0,0 @@
2 -<?php
3 -/**
4 - *
5 - * @addtogroup SpecialPage
6 - */
7 -
8 -/**
9 - * Implements Special:Ancientpages
10 - * @addtogroup SpecialPage
11 - */
12 -class AncientPagesPage extends QueryPage {
13 -
14 - function getName() {
15 - return "Ancientpages";
16 - }
17 -
18 - function isExpensive() {
19 - return true;
20 - }
21 -
22 - function isSyndicated() { return false; }
23 -
24 - function getSQL() {
25 - global $wgDBtype;
26 - $db = wfGetDB( DB_SLAVE );
27 - $page = $db->tableName( 'page' );
28 - $revision = $db->tableName( 'revision' );
29 - #$use_index = $db->useIndexClause( 'cur_timestamp' ); # FIXME! this is gone
30 - $epoch = $wgDBtype == 'mysql' ? 'UNIX_TIMESTAMP(rev_timestamp)' :
31 - 'EXTRACT(epoch FROM rev_timestamp)';
32 - return
33 - "SELECT 'Ancientpages' as type,
34 - page_namespace as namespace,
35 - page_title as title,
36 - $epoch as value
37 - FROM $page, $revision
38 - WHERE page_namespace=".NS_MAIN." AND page_is_redirect=0
39 - AND page_latest=rev_id";
40 - }
41 -
42 - function sortDescending() {
43 - return false;
44 - }
45 -
46 - function formatResult( $skin, $result ) {
47 - global $wgLang, $wgContLang;
48 -
49 - $d = $wgLang->timeanddate( wfTimestamp( TS_MW, $result->value ), true );
50 - $title = Title::makeTitle( $result->namespace, $result->title );
51 - $link = $skin->makeKnownLinkObj( $title, htmlspecialchars( $wgContLang->convert( $title->getPrefixedText() ) ) );
52 - return wfSpecialList($link, $d);
53 - }
54 -}
55 -
56 -function wfSpecialAncientpages() {
57 - list( $limit, $offset ) = wfCheckLimits();
58 -
59 - $app = new AncientPagesPage();
60 -
61 - $app->doQuery( $offset, $limit );
62 -}
63 -
64 -?>
Index: branches/robchurch/reports/includes/reports/Report.php
@@ -361,6 +361,7 @@
362362 */
363363 public static function getReports() {
364364 return array(
 365+ 'AncientPagesReport',
365366 'BrokenRedirectsReport',
366367 'DeadEndPagesReport',
367368 'DoubleRedirectsReport',
Index: branches/robchurch/reports/includes/reports/AncientPagesReport.php
@@ -0,0 +1,142 @@
 2+<?php
 3+
 4+/**
 5+ * Report lists pages on the wiki which haven't been
 6+ * updated in a while
 7+ *
 8+ * @addtogroup Reports
 9+ * @author Rob Church <robchur@gmail.com>
 10+ */
 11+class AncientPagesReport 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 'Ancientpages';
 27+ }
 28+
 29+ /**
 30+ * Get a HTML header for the top of the page
 31+ *
 32+ * @return string
 33+ */
 34+ public function getHeader() {
 35+ global $wgLang, $wgAncientPagesThreshold;
 36+ return wfMsgExt( 'ancientpages-header', 'parse',
 37+ $wgLang->formatNum( $wgAncientPagesThreshold ) );
 38+ }
 39+
 40+ /**
 41+ * Is it appropriate to allow filtering redirects?
 42+ *
 43+ * @return bool
 44+ */
 45+ public function allowRedirectFilter() {
 46+ return false;
 47+ }
 48+
 49+ /**
 50+ * Should redirects be filtered from results?
 51+ *
 52+ * @return bool
 53+ */
 54+ public function excludeRedirects() {
 55+ return true;
 56+ }
 57+
 58+ /**
 59+ * Is it appropriate to allow filtering namespaces?
 60+ *
 61+ * @return bool
 62+ */
 63+ public function allowNamespaceFilter() {
 64+ return true;
 65+ }
 66+
 67+ /**
 68+ * Get a list of namespaces this report can be run
 69+ * against - false indicates *all* namespaces
 70+ *
 71+ * @return mixed
 72+ */
 73+ public function getApplicableNamespaces() {
 74+ return array(
 75+ NS_MAIN,
 76+ ) + $GLOBALS['wgContentNamespaces'];
 77+ }
 78+
 79+ /**
 80+ * Return base SQL for the report
 81+ *
 82+ * @param Database $dbr Database object being queried
 83+ * @return string
 84+ */
 85+ public function getBaseSql( $dbr ) {
 86+ list( $page, $revision ) = $dbr->tableNamesN( 'page', 'revision' );
 87+ return
 88+ "SELECT
 89+ page_id AS rp_id,
 90+ page_namespace AS rp_namespace,
 91+ page_title AS rp_title,
 92+ page_is_redirect AS rp_redirect,
 93+ rev_timestamp
 94+ FROM {$page}
 95+ LEFT JOIN {$revision} ON page_id = rev_page";
 96+ }
 97+
 98+ /**
 99+ * Return additional WHERE clauses and other conditions
 100+ * to which the paging clauses will be appened when
 101+ * the report runs live
 102+ *
 103+ * @param Database $dbr Database object being queried
 104+ * @return array
 105+ */
 106+ public function getExtraConditions( $dbr ) {
 107+ return array(
 108+ 'rev_id = page_latest',
 109+ 'rev_timestamp < ' . $dbr->timestamp( time() - ( $GLOBALS['wgAncientPagesThreshold'] * 86400 ) ),
 110+ );
 111+ }
 112+
 113+ /**
 114+ * Given a result object, extract additional parameters
 115+ * as a dictionary for later use
 116+ *
 117+ * @param object $row Result row
 118+ * @return array
 119+ */
 120+ public function extractParameters( $row ) {
 121+ return array(
 122+ 'rev_timestamp' => $row->rev_timestamp,
 123+ );
 124+ }
 125+
 126+ /**
 127+ * Format an individual result row
 128+ *
 129+ * @param Title $title Result title
 130+ * @param object $row Result row
 131+ * @param array $params Result parameters
 132+ * @param Skin $skin User skin
 133+ * @return string
 134+ */
 135+ public function formatRow( $title, $row, $params, $skin ) {
 136+ global $wgLang;
 137+ $time = $wgLang->timeAndDate( $params['rev_timestamp'], true );
 138+ return "<li>" . $skin->makeLinkObj( $title ) . " [{$time}]</li>\n";
 139+ }
 140+
 141+}
 142+
 143+?>
\ No newline at end of file
Property changes on: branches/robchurch/reports/includes/reports/AncientPagesReport.php
___________________________________________________________________
Added: svn:eol-style
1144 + native
Index: branches/robchurch/reports/includes/AutoLoader.php
@@ -167,7 +167,6 @@
168168 'SkinTemplate' => 'includes/SkinTemplate.php',
169169 'QuickTemplate' => 'includes/SkinTemplate.php',
170170 'SpecialAllpages' => 'includes/SpecialAllpages.php',
171 - 'AncientPagesPage' => 'includes/SpecialAncientpages.php',
172171 'IPBlockForm' => 'includes/SpecialBlockip.php',
173172 'SpecialBookSources' => 'includes/SpecialBooksources.php',
174173 'EmailConfirmation' => 'includes/SpecialConfirmemail.php',
@@ -283,6 +282,7 @@
284283 'ReportPager' => 'includes/reports/ReportPager.php',
285284 'CachedReportPager' => 'includes/reports/CachedReportPager.php',
286285
 286+ 'AncientPagesReport' => 'includes/reports/AncientPagesReport.php',
287287 'BrokenRedirectsReport' => 'includes/reports/BrokenRedirectsReport.php',
288288 'DeadEndPagesReport' => 'includes/reports/DeadEndPagesReport.php',
289289 'DoubleRedirectsReport' => 'includes/reports/DoubleRedirectsReport.php',
Index: branches/robchurch/reports/includes/DefaultSettings.php
@@ -1389,6 +1389,13 @@
13901390 $wgLongPagesThreshold = 80 * 1024;
13911391
13921392 /**
 1393+ * Pages which haven't been edited for at least this
 1394+ * number of days will be considered "ancient"
 1395+ * for the purposes of Special:Ancientpages
 1396+ */
 1397+$wgAncientPagesThreshold = 100;
 1398+
 1399+/**
13931400 * Maps jobs to their handling classes; extensions
13941401 * can add to this to provide custom jobs
13951402 */
Index: branches/robchurch/reports/includes/QueryPage.php
@@ -14,7 +14,6 @@
1515 $wgQueryPages = array(
1616 // QueryPage subclass Special page name Limit (false for none, none for the default)
1717 //----------------------------------------------------------------------------
18 - array( 'AncientPagesPage', 'Ancientpages' ),
1918 array( 'DisambiguationsPage', 'Disambiguations' ),
2019 array( 'LonelyPagesPage', 'Lonelypages' ),
2120 array( 'MostcategoriesPage', 'Mostcategories' ),
Index: branches/robchurch/reports/includes/SpecialPage.php
@@ -109,7 +109,7 @@
110110 'Shortpages' => 'ShortPagesReport',
111111 'Longpages' => 'LongPagesReport',
112112 'Newpages' => 'SpecialNewPages',//array( 'IncludableSpecialPage', 'Newpages' ),
113 - 'Ancientpages' => array( 'SpecialPage', 'Ancientpages' ),
 113+ 'Ancientpages' => 'AncientPagesReport',
114114 'Deadendpages' => 'DeadEndPagesReport',
115115 'Protectedpages' => array( 'SpecialPage', 'Protectedpages' ),
116116 'Allpages' => array( 'IncludableSpecialPage', 'Allpages' ),
Index: branches/robchurch/reports/languages/messages/MessagesEn.php
@@ -1617,7 +1617,7 @@
16181618 'newpages-summary' => '', # only translate this message to other languages if you have to change it
16191619 'newpages-username' => 'Username:',
16201620 'ancientpages' => 'Oldest pages',
1621 -'ancientpages-summary' => '', # only translate this message to other languages if you have to change it
 1621+'ancientpages-header' => 'This report lists pages which haven\'t been edited in at least $1 days.',
16221622 'intl' => 'Interlanguage links',
16231623 'move' => 'Move',
16241624 'movethispage' => 'Move this page',

Status & tagging log