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 @@ |
45 | 45 | $conds = array(); |
46 | 46 | if( ( $ns = $this->getNamespace() ) !== false ) |
47 | 47 | $conds[] = $this->report->getNamespaceClause( $ns ); |
48 | | - if( !$this->getRedirects() ) |
| 48 | + if( !$this->getRedirects() || $this->report->excludeRedirects() ) |
49 | 49 | $conds[] = $this->report->getRedirectClause(); |
50 | 50 | |
51 | 51 | # Paging conditions |
52 | 52 | if( $this->mDefaultDirection ) { |
53 | 53 | # DESC |
54 | 54 | $op = ' < '; |
55 | | - $options[] = 'ORDER BY ' . $this->report->getPagingColumn() . ' DESC'; |
| 55 | + $order = $this->report->getPagingColumn() . ' DESC'; |
56 | 56 | } else { |
57 | 57 | # ASC |
58 | 58 | $op = ' > '; |
59 | | - $options[] = 'ORDER BY ' . $this->report->getPagingColumn(); |
| 59 | + $order = $this->report->getPagingColumn(); |
60 | 60 | } |
| 61 | + $options[] = 'ORDER BY ' . implode( ', ', $this->report->getOrderingClauses() + array( $order ) ); |
61 | 62 | $options[] = 'LIMIT ' . ( $this->mLimit + 1 ); |
62 | 63 | $conds[] = $this->report->getPagingColumn() . $op . $this->mDb->addQuotes( $this->mOffset ); |
63 | 64 | |
Index: branches/robchurch/reports/includes/reports/Report.php |
— | — | @@ -52,6 +52,15 @@ |
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
| 56 | + * Should redirects be filtered from results? |
| 57 | + * |
| 58 | + * @return bool |
| 59 | + */ |
| 60 | + public function excludeRedirects() { |
| 61 | + return false; |
| 62 | + } |
| 63 | + |
| 64 | + /** |
56 | 65 | * Is it appropriate to allow filtering namespaces? |
57 | 66 | * |
58 | 67 | * @return bool |
— | — | @@ -107,6 +116,16 @@ |
108 | 117 | public function getRedirectClause() { |
109 | 118 | return 'page_is_redirect = 0'; |
110 | 119 | } |
| 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 | + } |
111 | 130 | |
112 | 131 | /** |
113 | 132 | * Given a result object, extract additional parameters |
— | — | @@ -220,10 +239,11 @@ |
221 | 240 | public function buildNamespaceSelector( $select ) { |
222 | 241 | global $wgContLang; |
223 | 242 | $html = Xml::openElement( 'select', array( 'id' => 'namespace', 'name' => 'namespace' ) ); |
224 | | - $html .= Xml::option( wfMsg( 'report-filter-namespace-all' ), '' ); |
225 | 243 | $namespaces = $this->getApplicableNamespaces(); |
226 | | - if( $namespaces === false ) |
| 244 | + if( $namespaces === false ) { |
| 245 | + $html .= Xml::option( wfMsg( 'report-filter-namespace-all' ), '' ); |
227 | 246 | $namespaces = array_keys( $wgContLang->getNamespaces() ); |
| 247 | + } |
228 | 248 | foreach( $namespaces as $index ) { |
229 | 249 | if( $index >= 0 ) { |
230 | 250 | $label = $index != 0 |
— | — | @@ -262,6 +282,7 @@ |
263 | 283 | public static function getReports() { |
264 | 284 | return array( |
265 | 285 | 'RedirectReport', |
| 286 | + 'ShortPagesReport', |
266 | 287 | ); |
267 | 288 | } |
268 | 289 | |
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 |
1 | 114 | + native |
Index: branches/robchurch/reports/includes/reports/CachedReportPager.php |
— | — | @@ -29,7 +29,7 @@ |
30 | 30 | $conds['rp_report'] = $this->report->getName(); |
31 | 31 | if( ( $ns = $this->getNamespace() ) !== false ) |
32 | 32 | $conds['rp_namespace'] = $ns; |
33 | | - if( !$this->getRedirects() ) |
| 33 | + if( !$this->getRedirects() || $this->report->excludeRedirects() ) |
34 | 34 | $conds['rp_redirect'] = 0; |
35 | 35 | |
36 | 36 | # Paging conditions |
Index: branches/robchurch/reports/includes/AutoLoader.php |
— | — | @@ -209,7 +209,6 @@ |
210 | 210 | 'RevisionDeleteForm' => 'includes/SpecialRevisiondelete.php', |
211 | 211 | 'RevisionDeleter' => 'includes/SpecialRevisiondelete.php', |
212 | 212 | 'SpecialSearch' => 'includes/SpecialSearch.php', |
213 | | - 'ShortPagesPage' => 'includes/SpecialShortpages.php', |
214 | 213 | 'UncategorizedCategoriesPage' => 'includes/SpecialUncategorizedcategories.php', |
215 | 214 | 'UncategorizedPagesPage' => 'includes/SpecialUncategorizedpages.php', |
216 | 215 | 'UncategorizedTemplatesPage' => 'includes/SpecialUncategorizedtemplates.php', |
— | — | @@ -291,6 +290,7 @@ |
292 | 291 | 'ReportCache' => 'includes/reports/ReportCache.php', |
293 | 292 | 'ReportPager' => 'includes/reports/ReportPager.php', |
294 | 293 | 'CachedReportPager' => 'includes/reports/CachedReportPager.php', |
| 294 | + 'ShortPagesReport' => 'includes/reports/ShortPagesReport.php', |
295 | 295 | 'RedirectReport' => 'includes/reports/RedirectReport.php', |
296 | 296 | |
297 | 297 | # API |
Index: branches/robchurch/reports/includes/SpecialPage.php |
— | — | @@ -106,7 +106,7 @@ |
107 | 107 | 'Mostimages' => array( 'SpecialPage', 'Mostimages' ), |
108 | 108 | 'Mostrevisions' => array( 'SpecialPage', 'Mostrevisions' ), |
109 | 109 | 'Fewestrevisions' => array( 'SpecialPage', 'Fewestrevisions' ), |
110 | | - 'Shortpages' => array( 'SpecialPage', 'Shortpages' ), |
| 110 | + 'Shortpages' => 'ShortPagesReport', |
111 | 111 | 'Longpages' => array( 'SpecialPage', 'Longpages' ), |
112 | 112 | 'Newpages' => array( 'IncludableSpecialPage', 'Newpages' ), |
113 | 113 | 'Ancientpages' => array( 'SpecialPage', 'Ancientpages' ), |