r49951 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49950‎ | r49951 | r49952 >
Date:13:29, 27 April 2009
Author:catrope
Status:deferred
Tags:
Comment:
querypage-work: (bug 8130) Query pages should limit to $wgContentNamespaces rather than just NS_MAIN. Patch by nephele
Modified paths:
  • /branches/querypage-work/phase3/includes/Namespace.php (modified) (history)
  • /branches/querypage-work/phase3/includes/PageQueryPage.php (modified) (history)
  • /branches/querypage-work/phase3/includes/specials/SpecialAncientpages.php (modified) (history)
  • /branches/querypage-work/phase3/includes/specials/SpecialDeadendpages.php (modified) (history)
  • /branches/querypage-work/phase3/includes/specials/SpecialDisambiguations.php (modified) (history)
  • /branches/querypage-work/phase3/includes/specials/SpecialFewestrevisions.php (modified) (history)
  • /branches/querypage-work/phase3/includes/specials/SpecialLonelypages.php (modified) (history)
  • /branches/querypage-work/phase3/includes/specials/SpecialMostcategories.php (modified) (history)
  • /branches/querypage-work/phase3/includes/specials/SpecialPopularpages.php (modified) (history)
  • /branches/querypage-work/phase3/includes/specials/SpecialShortpages.php (modified) (history)
  • /branches/querypage-work/phase3/includes/specials/SpecialUncategorizedpages.php (modified) (history)

Diff [purge]

Index: branches/querypage-work/phase3/includes/PageQueryPage.php
@@ -5,7 +5,7 @@
66 *
77 * @ingroup SpecialPage
88 */
9 -class PageQueryPage extends QueryPage {
 9+abstract class PageQueryPage extends QueryPage {
1010
1111 /**
1212 * Format the result as a simple link to the page
Index: branches/querypage-work/phase3/includes/Namespace.php
@@ -182,4 +182,23 @@
183183 return !empty( $wgNamespacesWithSubpages[$index] );
184184 }
185185
 186+ /**
 187+ * Get a list of all namespace indices which are considered to contain content
 188+ *
 189+ * If only one content namespace exists, returns that single index (Int)
 190+ * If multiple content namespaces exist, it returns an array of indices
 191+ *
 192+ * @return mixed
 193+ */
 194+ public static function getContentNamespaces() {
 195+ global $wgContentNamespaces;
 196+ if( empty( $wgContentNamespaces ) )
 197+ return NS_MAIN;
 198+ // always force NS_MAIN to be part of array (to match the algorithm used by isContent)
 199+ elseif ( !in_array( NS_MAIN, $wgContentNamespaces ) )
 200+ return array( NS_MAIN ) + $wgContentNamespaces;
 201+ else
 202+ return $wgContentNamespaces;
 203+
 204+ }
186205 }
Index: branches/querypage-work/phase3/includes/specials/SpecialFewestrevisions.php
@@ -32,7 +32,7 @@
3333 'page_title AS title',
3434 'COUNT(*) AS value',
3535 'page_is_redirect AS redirect' ),
36 - 'conds' => array ( 'page_namespace' => NS_MAIN,
 36+ 'conds' => array ( 'page_namespace' => MWNamespace::getContentNamespaces(),
3737 'page_id = rev_page' ),
3838 'options' => array ( 'HAVING' => 'COUNT(*) > 1',
3939 // ^^^ This was probably here to weed out redirects.
Index: branches/querypage-work/phase3/includes/specials/SpecialDisambiguations.php
@@ -129,7 +129,7 @@
130130 'pl_namespace = p1.page_namespace',
131131 'pl_title = p1.page_title',
132132 'p2.page_id = pl_from',
133 - 'p2.page_namespace' => NS_MAIN )
 133+ 'p2.page_namespace' => MWNamespace::getContentNamespaces() )
134134 );
135135 }
136136
Index: branches/querypage-work/phase3/includes/specials/SpecialMostcategories.php
@@ -25,7 +25,7 @@
2626 'page_namespace AS namespace',
2727 'page_title AS title',
2828 'COUNT(*) AS value' ),
29 - 'conds' => array ( 'page_namespace' => NS_MAIN ),
 29+ 'conds' => array ( 'page_namespace' => MWNamespace::getContentNamespaces() ),
3030 'options' => array ( 'HAVING' => 'COUNT(*) > 1',
3131 'GROUP BY' => 'page_namespace, page_title' ),
3232 // TODO: test this JOIN
Index: branches/querypage-work/phase3/includes/specials/SpecialPopularpages.php
@@ -20,29 +20,15 @@
2121 }
2222 function isSyndicated() { return false; }
2323
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;
 24+ function getQueryInfo() {
 25+ return array (
 26+ 'tables' => array( 'page' ),
 27+ 'fields' => array( "'{$this->getName()}' AS type",
 28+ 'page_namespace AS namespace',
 29+ 'page_title AS title',
 30+ 'page_counter AS value'),
 31+ 'conds' => array( 'page_is_redirect' => 0,
 32+ 'page_namespace' => MWNamespace::getContentNamespaces() ) );
4733 }
4834
4935 function formatResult( $skin, $result ) {
Index: branches/querypage-work/phase3/includes/specials/SpecialLonelypages.php
@@ -36,7 +36,7 @@
3737 'page_title AS title',
3838 'page_title AS value' ),
3939 'conds' => array ( 'pl_namespace IS NULL',
40 - 'page_namespace' => NS_MAIN,
 40+ 'page_namespace' => MWNamespace::getContentNamespaces(),
4141 'page_is_redirect' => 0,
4242 'tl_namespace IS NULL' ),
4343 // TODO: test this JOIN
Index: branches/querypage-work/phase3/includes/specials/SpecialUncategorizedpages.php
@@ -10,7 +10,7 @@
1111 */
1212 // FIXME: Make $requestedNamespace selectable, unify all subclasses into one
1313 class UncategorizedPagesPage extends PageQueryPage {
14 - var $requestedNamespace = NS_MAIN;
 14+ var $requestedNamespace = false;
1515
1616 function getName() {
1717 return "Uncategorizedpages";
@@ -32,8 +32,10 @@
3333 'page_namespace AS namespace',
3434 'page_title AS title',
3535 'page_title AS value' ),
 36+ // default for page_namespace is all content namespaces (if requestedNamespace is false)
 37+ // otherwise, page_namespace is requestedNamespace
3638 'conds' => array ( 'cl_from IS NULL',
37 - 'page_namespace' => $this->requestedNamespace,
 39+ 'page_namespace' => ( $this->requestedNamespace!==false ? $this->requestedNamespace : MWNamespace::getContentNamespaces() ),
3840 'page_is_redirect' => 0 ),
3941 'join_conds' => array ( 'categorylinks' => array (
4042 'LEFT JOIN', 'cl_from = page_id' ) )
Index: branches/querypage-work/phase3/includes/specials/SpecialShortpages.php
@@ -28,15 +28,13 @@
2929 }
3030
3131 function getQueryInfo() {
32 - global $wgContentNamespaces;
33 - $ns = ( $wgContentNamespaces ? $wgContentNamespaces : NS_MAIN );
3432 return array (
3533 'tables' => array ( 'page' ),
3634 'fields' => array ( "'{$this->getName()}' AS type",
3735 'page_namespace AS namespace',
3836 'page_title AS title',
3937 'page_len AS value' ),
40 - 'conds' => array ( 'page_namespace' => $ns,
 38+ 'conds' => array ( 'page_namespace' => MWNamespace::getContentNamespaces(),
4139 'page_is_redirect' => 0 ),
4240 'options' => array ( 'USE INDEX' => 'page_len' )
4341 );
Index: branches/querypage-work/phase3/includes/specials/SpecialAncientpages.php
@@ -28,7 +28,7 @@
2929 'page_namespace AS namespace',
3030 'page_title AS title',
3131 'rev_timestamp AS value' ),
32 - 'conds' => array( 'page_namespace' => NS_MAIN,
 32+ 'conds' => array( 'page_namespace' => MWNamespace::getContentNamespaces(),
3333 'page_is_redirect' => 0,
3434 'page_latest=rev_id' )
3535 );
Index: branches/querypage-work/phase3/includes/specials/SpecialDeadendpages.php
@@ -38,13 +38,13 @@
3939 function getQueryInfo() {
4040 return array(
4141 'tables' => array( 'page', 'pagelinks' ),
42 - 'fields' => array( "'{$this->getName()} AS type",
 42+ 'fields' => array( "'{$this->getName()}' AS type",
4343 'page_namespace AS namespace',
4444 'page_title AS title',
4545 'page_title AS value'
4646 ),
4747 'conds' => array( 'pl_from IS NULL',
48 - 'page_namespace' => NS_MAIN,
 48+ 'page_namespace' => MWNamespace::getContentNamespaces(),
4949 'page_is_redirect' => 0
5050 ),
5151 'join_conds' => array( 'pagelinks' => array( 'LEFT JOIN', array(

Follow-up revisions

RevisionCommit summaryAuthorDate
r65318querypage-work2: Merge r49951reedy14:19, 20 April 2010
r78780Various fixes for r49951: use array_merge() instead of + so as to not overwri...catrope11:59, 22 December 2010

Status & tagging log