r23284 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23283‎ | r23284 | r23285 >
Date:06:01, 23 June 2007
Author:robchurch
Status:old
Tags:
Comment:
* Port Special:Shortpages to Report form
* Some fixes and workarounds for various reporting complexities; it *might* be smarter to ditch the Pager for "live" views
Modified paths:
  • /branches/robchurch/reports/includes/AutoLoader.php (modified) (history)
  • /branches/robchurch/reports/includes/SpecialPage.php (modified) (history)
  • /branches/robchurch/reports/includes/SpecialShortpages.php (deleted) (history)
  • /branches/robchurch/reports/includes/reports/CachedReportPager.php (modified) (history)
  • /branches/robchurch/reports/includes/reports/Report.php (modified) (history)
  • /branches/robchurch/reports/includes/reports/ReportPager.php (modified) (history)
  • /branches/robchurch/reports/includes/reports/ShortPagesReport.php (added) (history)

Diff [purge]

Index: branches/robchurch/reports/includes/SpecialShortpages.php
@@ -1,92 +0,0 @@
2 -<?php
3 -/**
4 - *
5 - * @addtogroup SpecialPage
6 - */
7 -
8 -/**
9 - * SpecialShortpages extends QueryPage. It is used to return the shortest
10 - * pages in the database.
11 - * @addtogroup SpecialPage
12 - */
13 -class ShortPagesPage extends QueryPage {
14 -
15 - function getName() {
16 - return "Shortpages";
17 - }
18 -
19 - /**
20 - * This query is indexed as of 1.5
21 - */
22 - function isExpensive() {
23 - return true;
24 - }
25 -
26 - function isSyndicated() {
27 - return false;
28 - }
29 -
30 - function getSQL() {
31 - $dbr = wfGetDB( DB_SLAVE );
32 - $page = $dbr->tableName( 'page' );
33 - $name = $dbr->addQuotes( $this->getName() );
34 -
35 - $forceindex = $dbr->useIndexClause("page_len");
36 - return
37 - "SELECT $name as type,
38 - page_namespace as namespace,
39 - page_title as title,
40 - page_len AS value
41 - FROM $page $forceindex
42 - WHERE page_namespace=".NS_MAIN." AND page_is_redirect=0";
43 - }
44 -
45 - function preprocessResults( &$db, &$res ) {
46 - # There's no point doing a batch check if we aren't caching results;
47 - # the page must exist for it to have been pulled out of the table
48 - if( $this->isCached() ) {
49 - $batch = new LinkBatch();
50 - while( $row = $db->fetchObject( $res ) )
51 - $batch->addObj( Title::makeTitleSafe( $row->namespace, $row->title ) );
52 - $batch->execute();
53 - if( $db->numRows( $res ) > 0 )
54 - $db->dataSeek( $res, 0 );
55 - }
56 - }
57 -
58 - function sortDescending() {
59 - return false;
60 - }
61 -
62 - function formatResult( $skin, $result ) {
63 - global $wgLang, $wgContLang;
64 - $dm = $wgContLang->getDirMark();
65 -
66 - $title = Title::makeTitleSafe( $result->namespace, $result->title );
67 - if ( !$title ) {
68 - return '<!-- Invalid title ' . htmlspecialchars( "{$result->namespace}:{$result->title}" ). '-->';
69 - }
70 - $hlink = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'hist' ), 'action=history' );
71 - $plink = $this->isCached()
72 - ? $skin->makeLinkObj( $title )
73 - : $skin->makeKnownLinkObj( $title );
74 - $size = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ), $wgLang->formatNum( htmlspecialchars( $result->value ) ) );
75 -
76 - return $title->exists()
77 - ? "({$hlink}) {$dm}{$plink} {$dm}[{$size}]"
78 - : "<s>({$hlink}) {$dm}{$plink} {$dm}[{$size}]</s>";
79 - }
80 -}
81 -
82 -/**
83 - * constructor
84 - */
85 -function wfSpecialShortpages() {
86 - list( $limit, $offset ) = wfCheckLimits();
87 -
88 - $spp = new ShortPagesPage();
89 -
90 - return $spp->doQuery( $offset, $limit );
91 -}
92 -
93 -?>
Index: branches/robchurch/reports/includes/reports/ReportPager.php
@@ -44,19 +44,20 @@
4545 $conds = array();
4646 if( ( $ns = $this->getNamespace() ) !== false )
4747 $conds[] = $this->report->getNamespaceClause( $ns );
48 - if( !$this->getRedirects() )
 48+ if( !$this->getRedirects() || $this->report->excludeRedirects() )
4949 $conds[] = $this->report->getRedirectClause();
5050
5151 # Paging conditions
5252 if( $this->mDefaultDirection ) {
5353 # DESC
5454 $op = ' < ';
55 - $options[] = 'ORDER BY ' . $this->report->getPagingColumn() . ' DESC';
 55+ $order = $this->report->getPagingColumn() . ' DESC';
5656 } else {
5757 # ASC
5858 $op = ' > ';
59 - $options[] = 'ORDER BY ' . $this->report->getPagingColumn();
 59+ $order = $this->report->getPagingColumn();
6060 }
 61+ $options[] = 'ORDER BY ' . implode( ', ', $this->report->getOrderingClauses() + array( $order ) );
6162 $options[] = 'LIMIT ' . ( $this->mLimit + 1 );
6263 $conds[] = $this->report->getPagingColumn() . $op . $this->mDb->addQuotes( $this->mOffset );
6364
Index: branches/robchurch/reports/includes/reports/Report.php
@@ -52,6 +52,15 @@
5353 }
5454
5555 /**
 56+ * Should redirects be filtered from results?
 57+ *
 58+ * @return bool
 59+ */
 60+ public function excludeRedirects() {
 61+ return false;
 62+ }
 63+
 64+ /**
5665 * Is it appropriate to allow filtering namespaces?
5766 *
5867 * @return bool
@@ -107,6 +116,16 @@
108117 public function getRedirectClause() {
109118 return 'page_is_redirect = 0';
110119 }
 120+
 121+ /**
 122+ * Get ORDER BY clauses to be applied when the
 123+ * report is run live
 124+ *
 125+ * @return array
 126+ */
 127+ public function getOrderingClauses() {
 128+ return array();
 129+ }
111130
112131 /**
113132 * Given a result object, extract additional parameters
@@ -220,10 +239,11 @@
221240 public function buildNamespaceSelector( $select ) {
222241 global $wgContLang;
223242 $html = Xml::openElement( 'select', array( 'id' => 'namespace', 'name' => 'namespace' ) );
224 - $html .= Xml::option( wfMsg( 'report-filter-namespace-all' ), '' );
225243 $namespaces = $this->getApplicableNamespaces();
226 - if( $namespaces === false )
 244+ if( $namespaces === false ) {
 245+ $html .= Xml::option( wfMsg( 'report-filter-namespace-all' ), '' );
227246 $namespaces = array_keys( $wgContLang->getNamespaces() );
 247+ }
228248 foreach( $namespaces as $index ) {
229249 if( $index >= 0 ) {
230250 $label = $index != 0
@@ -262,6 +282,7 @@
263283 public static function getReports() {
264284 return array(
265285 'RedirectReport',
 286+ 'ShortPagesReport',
266287 );
267288 }
268289
Index: branches/robchurch/reports/includes/reports/ShortPagesReport.php
@@ -0,0 +1,112 @@
 2+<?php
 3+
 4+/**
 5+ * Report generates a list of short pages in the main namespace
 6+ *
 7+ * @addtogroup Reports
 8+ * @author Rob Church <robchur@gmail.com>
 9+ */
 10+class ShortPagesReport 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 'Shortpages';
 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 false;
 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( NS_MAIN );
 63+ }
 64+
 65+ /**
 66+ * Return base SQL for the report
 67+ *
 68+ * @param Database $dbr Database object being queried
 69+ * @return string
 70+ */
 71+ public function getBaseSql( $dbr ) {
 72+ $page = $dbr->tableName( 'page' );
 73+ $index = $dbr->useIndexClause( 'page_len' );
 74+ return
 75+ "SELECT
 76+ page_id AS rp_id,
 77+ page_namespace AS rp_namespace,
 78+ page_title AS rp_title,
 79+ page_is_redirect AS rp_redirect,
 80+ page_len
 81+ FROM {$page} {$index}";
 82+ }
 83+
 84+ /**
 85+ * Given a result object, extract additional parameters
 86+ * as a dictionary for later use
 87+ *
 88+ * @param object $row Result row
 89+ * @return array
 90+ */
 91+ public function extractParameters( $row ) {
 92+ return array(
 93+ 'page_len' => $row->page_len,
 94+ );
 95+ }
 96+
 97+ /**
 98+ * Format an individual result row
 99+ *
 100+ * @param Title $title Result title
 101+ * @param object $row Result row
 102+ * @param array $params Result parameters
 103+ * @param Skin $skin User skin
 104+ * @return string
 105+ */
 106+ public function formatRow( $title, $row, $params, $skin ) {
 107+ return '<li>' . $skin->makeLinkObj( $title ) . ' [' . $skin->formatSize( $params['page_len'] )
 108+ . "]</li>\n";
 109+ }
 110+
 111+}
 112+
 113+?>
\ No newline at end of file
Property changes on: branches/robchurch/reports/includes/reports/ShortPagesReport.php
___________________________________________________________________
Added: svn:eol-style
1114 + native
Index: branches/robchurch/reports/includes/reports/CachedReportPager.php
@@ -29,7 +29,7 @@
3030 $conds['rp_report'] = $this->report->getName();
3131 if( ( $ns = $this->getNamespace() ) !== false )
3232 $conds['rp_namespace'] = $ns;
33 - if( !$this->getRedirects() )
 33+ if( !$this->getRedirects() || $this->report->excludeRedirects() )
3434 $conds['rp_redirect'] = 0;
3535
3636 # Paging conditions
Index: branches/robchurch/reports/includes/AutoLoader.php
@@ -209,7 +209,6 @@
210210 'RevisionDeleteForm' => 'includes/SpecialRevisiondelete.php',
211211 'RevisionDeleter' => 'includes/SpecialRevisiondelete.php',
212212 'SpecialSearch' => 'includes/SpecialSearch.php',
213 - 'ShortPagesPage' => 'includes/SpecialShortpages.php',
214213 'UncategorizedCategoriesPage' => 'includes/SpecialUncategorizedcategories.php',
215214 'UncategorizedPagesPage' => 'includes/SpecialUncategorizedpages.php',
216215 'UncategorizedTemplatesPage' => 'includes/SpecialUncategorizedtemplates.php',
@@ -291,6 +290,7 @@
292291 'ReportCache' => 'includes/reports/ReportCache.php',
293292 'ReportPager' => 'includes/reports/ReportPager.php',
294293 'CachedReportPager' => 'includes/reports/CachedReportPager.php',
 294+ 'ShortPagesReport' => 'includes/reports/ShortPagesReport.php',
295295 'RedirectReport' => 'includes/reports/RedirectReport.php',
296296
297297 # API
Index: branches/robchurch/reports/includes/SpecialPage.php
@@ -106,7 +106,7 @@
107107 'Mostimages' => array( 'SpecialPage', 'Mostimages' ),
108108 'Mostrevisions' => array( 'SpecialPage', 'Mostrevisions' ),
109109 'Fewestrevisions' => array( 'SpecialPage', 'Fewestrevisions' ),
110 - 'Shortpages' => array( 'SpecialPage', 'Shortpages' ),
 110+ 'Shortpages' => 'ShortPagesReport',
111111 'Longpages' => array( 'SpecialPage', 'Longpages' ),
112112 'Newpages' => array( 'IncludableSpecialPage', 'Newpages' ),
113113 'Ancientpages' => array( 'SpecialPage', 'Ancientpages' ),

Status & tagging log