r23288 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23287‎ | r23288 | r23289 >
Date:10:24, 23 June 2007
Author:robchurch
Status:old
Tags:
Comment:
* Introduce `UncategorisedPagesReport` which combines all the "uncategorised X" pages of old
* Started to butcher Special:Newpage so it's no longer a report, because that doesn't make sense -- more or less done, but needs cleanup and feeds need fixing ;)
Modified paths:
  • /branches/robchurch/reports/includes/AutoLoader.php (modified) (history)
  • /branches/robchurch/reports/includes/NewPagesPager.php (added) (history)
  • /branches/robchurch/reports/includes/QueryPage.php (modified) (history)
  • /branches/robchurch/reports/includes/SpecialNewpages.php (modified) (history)
  • /branches/robchurch/reports/includes/SpecialPage.php (modified) (history)
  • /branches/robchurch/reports/includes/reports/Report.php (modified) (history)
  • /branches/robchurch/reports/includes/reports/ReportCache.php (modified) (history)
  • /branches/robchurch/reports/includes/reports/ReportPager.php (modified) (history)
  • /branches/robchurch/reports/includes/reports/UncategorisedPagesReport.php (added) (history)

Diff [purge]

Index: branches/robchurch/reports/includes/reports/ReportPager.php
@@ -41,7 +41,7 @@
4242 wfProfileIn( $fname );
4343
4444 # Base conditions
45 - $conds = array();
 45+ $conds = $this->report->getExtraConditions( $this->mDb );
4646 if( ( $ns = $this->getNamespace() ) !== false )
4747 $conds[] = $this->report->getNamespaceClause( $ns );
4848 if( !$this->getRedirects() || $this->report->excludeRedirects() )
Index: branches/robchurch/reports/includes/reports/Report.php
@@ -88,6 +88,18 @@
8989 public abstract function getBaseSql( $dbr );
9090
9191 /**
 92+ * Return additional WHERE clauses and other conditions
 93+ * to which the paging clauses will be appened when
 94+ * the report runs live
 95+ *
 96+ * @param Database $dbr Database object being queried
 97+ * @return array
 98+ */
 99+ public function getExtraConditions( $dbr ) {
 100+ return array();
 101+ }
 102+
 103+ /**
92104 * Get the column used for paging when the report is run live
93105 *
94106 * @return string
@@ -283,6 +295,7 @@
284296 return array(
285297 'RedirectReport',
286298 'ShortPagesReport',
 299+ 'UncategorisedPagesReport',
287300 );
288301 }
289302
Index: branches/robchurch/reports/includes/reports/ReportCache.php
@@ -30,7 +30,9 @@
3131 # Obtain fresh entries for the report
3232 $dbr = wfGetDB( DB_SLAVE );
3333 $sql = $report->getBaseSql( $dbr );
34 - $sql .= ' WHERE ' . $report->getNamespaceClause( $namespace );
 34+ $conds = $report->getExtraConditions();
 35+ $conds[] = $report->getNamespaceClause( $namespace );
 36+ $sql .= ' WHERE ' . implode( ' AND ', $conds );
3537 $sql .= " LIMIT {$limit}";
3638 $res = $dbr->query( $sql, __METHOD__ );
3739 $rows = $dbr->numRows( $res );
Index: branches/robchurch/reports/includes/reports/UncategorisedPagesReport.php
@@ -0,0 +1,110 @@
 2+<?php
 3+
 4+/**
 5+ * Report generates a list of pages without categories
 6+ * in the main, image, template and category namespaces
 7+ *
 8+ * @addtogroup Reports
 9+ * @author Rob Church <robchur@gmail.com>
 10+ */
 11+class UncategorisedPagesReport 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 'Uncategorizedpages';
 27+ }
 28+
 29+ /**
 30+ * Is it appropriate to allow filtering redirects?
 31+ *
 32+ * @return bool
 33+ */
 34+ public function allowRedirectFilter() {
 35+ return true;
 36+ }
 37+
 38+ /**
 39+ * Get a list of namespaces this report can be run
 40+ * against - false indicates *all* namespaces
 41+ *
 42+ * @return mixed
 43+ */
 44+ public function getApplicableNamespaces() {
 45+ return array(
 46+ NS_MAIN,
 47+ NS_IMAGE,
 48+ NS_TEMPLATE,
 49+ NS_CATEGORY
 50+ );
 51+ }
 52+
 53+ /**
 54+ * Return base SQL for the report
 55+ *
 56+ * @param Database $dbr Database object being queried
 57+ * @return string
 58+ */
 59+ public function getBaseSql( $dbr ) {
 60+ list( $page, $categorylinks ) = $dbr->tableNamesN( 'page', 'categorylinks' );
 61+ return
 62+ "SELECT
 63+ page_id AS rp_id,
 64+ page_namespace AS rp_namespace,
 65+ page_title AS rp_title,
 66+ page_is_redirect AS rp_redirect
 67+ FROM {$page}
 68+ LEFT JOIN {$categorylinks} ON page_id = cl_from";
 69+ }
 70+
 71+ /**
 72+ * Return additional WHERE clauses and other conditions
 73+ * to which the paging clauses will be appened when
 74+ * the report runs live
 75+ *
 76+ * @param Database $dbr Database object being queried
 77+ * @return array
 78+ */
 79+ public function getExtraConditions( $dbr ) {
 80+ return array(
 81+ 'cl_from IS NULL',
 82+ );
 83+ }
 84+
 85+ /**
 86+ * Given a result object, extract additional parameters
 87+ * as a dictionary for later use
 88+ *
 89+ * @param object $row Result row
 90+ * @return array
 91+ */
 92+ public function extractParameters( $row ) {
 93+ return array();
 94+ }
 95+
 96+ /**
 97+ * Format an individual result row
 98+ *
 99+ * @param Title $title Result title
 100+ * @param object $row Result row
 101+ * @param array $params Result parameters
 102+ * @param Skin $skin User skin
 103+ * @return string
 104+ */
 105+ public function formatRow( $title, $row, $params, $skin ) {
 106+ return "<li>" . $skin->makeLinkObj( $title ) . "</li>\n";
 107+ }
 108+
 109+}
 110+
 111+?>
\ No newline at end of file
Property changes on: branches/robchurch/reports/includes/reports/UncategorisedPagesReport.php
___________________________________________________________________
Added: svn:eol-style
1112 + native
Index: branches/robchurch/reports/includes/NewPagesPager.php
@@ -0,0 +1,136 @@
 2+<?php
 3+
 4+/**
 5+ * Pager for Special:Newpages
 6+ *
 7+ * @addtogroup SpecialPage
 8+ * @author Rob Church <robchur@gmail.com>
 9+ */
 10+class NewPagesPager extends IndexPager {
 11+
 12+ private $namespace = 0;
 13+ private $username = '';
 14+
 15+ /**
 16+ * Constructor
 17+ *
 18+ * @param mixed $namespace
 19+ * @param mixed $username
 20+ */
 21+ public function __construct( $namespace, $username ) {
 22+ parent::__construct();
 23+ $this->namespace = $namespace;
 24+ $this->username = $username;
 25+ }
 26+
 27+ /**
 28+ * Column to use for paging
 29+ *
 30+ * @return string
 31+ */
 32+ public function getIndexField() {
 33+ return 'rc_id';
 34+ }
 35+
 36+ /**
 37+ * Information about the SELECT operation
 38+ *
 39+ * @return array
 40+ */
 41+ public function getQueryInfo() {
 42+ $base = array(
 43+ 'tables' => array(
 44+ 'recentchanges',
 45+ 'page',
 46+ ),
 47+ 'fields' => array(
 48+ 'rc_id',
 49+ 'rc_namespace',
 50+ 'rc_title',
 51+ 'rc_user',
 52+ 'rc_user_text',
 53+ 'rc_comment',
 54+ 'rc_timestamp',
 55+ 'rc_patrolled',
 56+ 'page_len',
 57+ 'page_latest',
 58+ ),
 59+ 'conds' => array(
 60+ 'rc_cur_id = page_id',
 61+ 'rc_new = 1',
 62+ 'page_is_redirect = 0',
 63+ ),
 64+ );
 65+ $base['conds'] += $this->getNamespaceConditions();
 66+ $base['conds'] += $this->getUserConditions();
 67+ return $base;
 68+ }
 69+
 70+ /**
 71+ * Get conditions for filtering per namespace
 72+ *
 73+ * @return array
 74+ */
 75+ private function getNamespaceConditions() {
 76+ return $this->namespace != 'all'
 77+ ? array( 'rc_namespace' => $this->namespace )
 78+ : array();
 79+ }
 80+
 81+ /**
 82+ * Get conditions for filtering per user
 83+ *
 84+ * @return array
 85+ */
 86+ private function getUserConditions() {
 87+ $username = trim( $this->username );
 88+ return strlen( $username ) > 0
 89+ ? array( 'rc_user_text' => $username )
 90+ : array();
 91+ }
 92+
 93+ /**
 94+ * Format a result row
 95+ *
 96+ * @param object $row
 97+ * @return string
 98+ */
 99+ public function formatRow( $row ) {
 100+ # FIXME: Full repertoire required
 101+ $title = Title::makeTitleSafe( $row->rc_namespace, $row->rc_title );
 102+ return "<li>" . $this->getSkin()->makeKnownLinkObj( $title ) . "</li>\n";
 103+ }
 104+
 105+ /**
 106+ * Get paging and limit links
 107+ *
 108+ * @return
 109+ */
 110+ public function getNavigationBar() {
 111+ foreach( array( 'first', 'last', 'prev', 'next' ) as $link )
 112+ $labels[$link] = wfMsgHtml( 'paging-' . $link );
 113+ return '( ' . implode( ' | ', $this->getPagingLinks( $labels ) ) . ' ) ( '
 114+ . implode( ' | ', $this->getLimitLinks() ) . ' )';
 115+ }
 116+
 117+ /**
 118+ * Inject start-of-list-tag
 119+ *
 120+ * @return string
 121+ */
 122+ public function getStartBody() {
 123+ return '<ul>';
 124+ }
 125+
 126+ /**
 127+ * Inject end-of-list-tag
 128+ *
 129+ * @return string
 130+ */
 131+ public function getEndBody() {
 132+ return '</ul>';
 133+ }
 134+
 135+}
 136+
 137+?>
\ No newline at end of file
Property changes on: branches/robchurch/reports/includes/NewPagesPager.php
___________________________________________________________________
Added: svn:eol-style
1138 + native
Index: branches/robchurch/reports/includes/AutoLoader.php
@@ -197,7 +197,8 @@
198198 'FewestrevisionsPage' => 'includes/SpecialFewestrevisions.php',
199199 'MovePageForm' => 'includes/SpecialMovepage.php',
200200 'NewbieContributionsPage' => 'includes/SpecialNewbieContributions.php',
201 - 'NewPagesPage' => 'includes/SpecialNewpages.php',
 201+ 'SpecialNewPages' => 'includes/SpecialNewpages.php',
 202+ 'NewPagesPager' => 'includes/NewPagesPager.php',
202203 'SpecialPage' => 'includes/SpecialPage.php',
203204 'UnlistedSpecialPage' => 'includes/SpecialPage.php',
204205 'IncludableSpecialPage' => 'includes/SpecialPage.php',
@@ -292,6 +293,7 @@
293294 'CachedReportPager' => 'includes/reports/CachedReportPager.php',
294295 'ShortPagesReport' => 'includes/reports/ShortPagesReport.php',
295296 'RedirectReport' => 'includes/reports/RedirectReport.php',
 297+ 'UncategorisedPagesReport' => 'includes/reports/UncategorisedPagesReport.php',
296298
297299 # API
298300 'ApiBase' => 'includes/api/ApiBase.php',
Index: branches/robchurch/reports/includes/SpecialNewpages.php
@@ -1,14 +1,79 @@
22 <?php
 3+
34 /**
 5+ * Special page lists new pages on the wiki
46 *
57 * @addtogroup SpecialPage
68 */
 9+class SpecialNewPages extends SpecialPage {
710
 11+ /**
 12+ * Constructor
 13+ */
 14+ public function __construct() {
 15+ parent::__construct( 'Newpages' );
 16+ }
 17+
 18+ /**
 19+ * Main execution function
 20+ *
 21+ * @param mixed $par Parameter passed to the page
 22+ */
 23+ public function execute( $par = false ) {
 24+ global $wgOut, $wgRequest;
 25+ $this->setHeaders();
 26+
 27+ $namespace = $wgRequest->getVal( 'namespace', NS_MAIN );
 28+ $username = $wgRequest->getText( 'username' );
 29+
 30+ $wgOut->addHtml( $this->buildFilterUI( $namespace, $username ) );
 31+
 32+ $pager = new NewPagesPager( $namespace, $username );
 33+ if( $pager->getNumRows() > 0 ) {
 34+ $wgOut->addHtml(
 35+ $pager->getNavigationBar()
 36+ . $pager->getBody()
 37+ . $pager->getNavigationBar()
 38+ );
 39+ } else {
 40+ # ???
 41+ }
 42+ }
 43+
 44+ /**
 45+ * Build the namespace/username filtering from
 46+ *
 47+ * @param mixed $namespace
 48+ * @param mixed $username
 49+ * @return string
 50+ */
 51+ private function buildFilterUI( $namespace, $username ) {
 52+ $self = SpecialPage::getTitleFor( 'Newpages' );
 53+ $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
 54+ # Namespace selector
 55+ $form .= '<table><tr><td align="right">' . Xml::label( wfMsg( 'namespace' ), 'namespace' ) . '</td>';
 56+ $form .= '<td>' . Xml::namespaceSelector( $namespace, 'all' ) . '</td></tr>';
 57+ # Username filter
 58+ $form .= '<tr><td align="right">' . Xml::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) . '</td>';
 59+ $form .= '<td>' . Xml::input( 'username', 30, $username, array( 'id' => 'mw-np-username' ) ) . '</td></tr>';
 60+ $form .= '<tr><td></td><td>' . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . '</td></tr></table>';
 61+ $form .= '</form>';
 62+ return $form;
 63+ }
 64+
 65+}
 66+
 67+
868 /**
 69+ *
 70+ * @addtogroup SpecialPage
 71+ */
 72+
 73+/**
974 * implements Special:Newpages
1075 * @addtogroup SpecialPage
1176 */
12 -class NewPagesPage extends QueryPage {
 77+/*class NewPagesPage extends QueryPage {
1378
1479 var $namespace;
1580 var $username = '';
@@ -42,38 +107,6 @@
43108 : '';
44109 }
45110
46 - function getSQL() {
47 - global $wgUser, $wgUseRCPatrol;
48 - $usepatrol = ( $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) ) ? 1 : 0;
49 - $dbr = wfGetDB( DB_SLAVE );
50 - list( $recentchanges, $page ) = $dbr->tableNamesN( 'recentchanges', 'page' );
51 -
52 - $nsfilter = $this->makeNamespaceWhere();
53 - $uwhere = $this->makeUserWhere( $dbr );
54 -
55 - # FIXME: text will break with compression
56 - return
57 - "SELECT 'Newpages' as type,
58 - rc_namespace AS namespace,
59 - rc_title AS title,
60 - rc_cur_id AS cur_id,
61 - rc_user AS \"user\",
62 - rc_user_text AS user_text,
63 - rc_comment as \"comment\",
64 - rc_timestamp AS timestamp,
65 - rc_timestamp AS value,
66 - '{$usepatrol}' as usepatrol,
67 - rc_patrolled AS patrolled,
68 - rc_id AS rcid,
69 - page_len as length,
70 - page_latest as rev_id
71 - FROM $recentchanges,$page
72 - WHERE rc_cur_id=page_id AND rc_new=1
73 - {$nsfilter}
74 - AND page_is_redirect = 0
75 - {$uwhere}";
76 - }
77 -
78111 function preprocessResults( &$dbo, &$res ) {
79112 # Do a batch existence check on the user and talk pages
80113 $linkBatch = new LinkBatch();
@@ -87,13 +120,6 @@
88121 $dbo->dataSeek( $res, 0 );
89122 }
90123
91 - /**
92 - * Format a row, providing the timestamp, links to the page/history, size, user links, and a comment
93 - *
94 - * @param $skin Skin to use
95 - * @param $result Result row
96 - * @return string
97 - */
98124 function formatResult( $skin, $result ) {
99125 global $wgLang, $wgContLang;
100126 $dm = $wgContLang->getDirMark();
@@ -109,12 +135,6 @@
110136 return "{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment}";
111137 }
112138
113 - /**
114 - * Should a specific result row provide "patrollable" links?
115 - *
116 - * @param $result Result row
117 - * @return bool
118 - */
119139 function patrollable( $result ) {
120140 global $wgUser, $wgUseRCPatrol;
121141 return $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) && !$result->patrolled;
@@ -132,11 +152,6 @@
133153 return parent::feedItemDesc( $row );
134154 }
135155
136 - /**
137 - * Show a form for filtering namespace and username
138 - *
139 - * @return string
140 - */
141156 function getPageHeader() {
142157 $self = SpecialPage::getTitleFor( $this->getName() );
143158 $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
@@ -152,21 +167,16 @@
153168 return $form;
154169 }
155170
156 - /**
157 - * Link parameters
158 - *
159 - * @return array
160 - */
161171 function linkParameters() {
162172 return( array( 'namespace' => $this->namespace, 'username' => $this->username ) );
163173 }
164174
165 -}
 175+}*/
166176
167177 /**
168178 * constructor
169179 */
170 -function wfSpecialNewpages($par, $specialPage) {
 180+/*function wfSpecialNewpages($par, $specialPage) {
171181 global $wgRequest, $wgContLang;
172182
173183 list( $limit, $offset ) = wfCheckLimits();
@@ -174,7 +184,7 @@
175185 $username = '';
176186
177187 if ( $par ) {
178 - $bits = preg_split( '/\s*,\s*/', trim( $par ) );
 188+ $bits = preg_split( '/\s*,\s*'/', trim( $par ) );
179189 foreach ( $bits as $bit ) {
180190 if ( 'shownav' == $bit )
181191 $shownavigation = true;
@@ -207,6 +217,6 @@
208218
209219 if ( ! $npp->doFeed( $wgRequest->getVal( 'feed' ), $limit ) )
210220 $npp->doQuery( $offset, $limit, $shownavigation );
211 -}
 221+}*/
212222
213223 ?>
Index: branches/robchurch/reports/includes/QueryPage.php
@@ -29,10 +29,12 @@
3030 array( 'MostrevisionsPage', 'Mostrevisions' ),
3131 array( 'FewestrevisionsPage', 'Fewestrevisions' ),
3232 array( 'NewPagesPage', 'Newpages' ),
 33+ #
3334 array( 'UncategorizedCategoriesPage', 'Uncategorizedcategories' ),
3435 array( 'UncategorizedPagesPage', 'Uncategorizedpages' ),
3536 array( 'UncategorizedImagesPage', 'Uncategorizedimages' ),
3637 array( 'UncategorizedTemplatesPage', 'Uncategorizedtemplates' ),
 38+ #
3739 array( 'UnusedCategoriesPage', 'Unusedcategories' ),
3840 array( 'UnusedimagesPage', 'Unusedimages' ),
3941 array( 'WantedCategoriesPage', 'Wantedcategories' ),
Index: branches/robchurch/reports/includes/SpecialPage.php
@@ -91,7 +91,7 @@
9292 'Statistics' => array( 'SpecialPage', 'Statistics' ),
9393 'Randompage' => array( 'SpecialPage', 'Randompage' ),
9494 'Lonelypages' => array( 'SpecialPage', 'Lonelypages' ),
95 - 'Uncategorizedpages' => array( 'SpecialPage', 'Uncategorizedpages' ),
 95+ 'Uncategorizedpages' => 'UncategorisedPagesReport',
9696 'Uncategorizedcategories' => array( 'SpecialPage', 'Uncategorizedcategories' ),
9797 'Uncategorizedimages' => array( 'SpecialPage', 'Uncategorizedimages' ),
9898 'Uncategorizedtemplates' => array( 'SpecialPage', 'Uncategorizedtemplates' ),
@@ -108,7 +108,7 @@
109109 'Fewestrevisions' => array( 'SpecialPage', 'Fewestrevisions' ),
110110 'Shortpages' => 'ShortPagesReport',
111111 'Longpages' => array( 'SpecialPage', 'Longpages' ),
112 - 'Newpages' => array( 'IncludableSpecialPage', 'Newpages' ),
 112+ 'Newpages' => 'SpecialNewPages',//array( 'IncludableSpecialPage', 'Newpages' ),
113113 'Ancientpages' => array( 'SpecialPage', 'Ancientpages' ),
114114 'Deadendpages' => array( 'SpecialPage', 'Deadendpages' ),
115115 'Protectedpages' => array( 'SpecialPage', 'Protectedpages' ),

Status & tagging log