r78724 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78723‎ | r78724 | r78725 >
Date:19:47, 21 December 2010
Author:catrope
Status:deferred
Tags:
Comment:
QueryPage-ify SpecialPagesWithoutScans. Move everything into the QueryPage subclass, redo getSQL() as getQueryInfo() and remove useless regex escaping for $page_namespace
Modified paths:
  • /branches/querypage-work2/extensions/ProofreadPage/SpecialPagesWithoutScans.php (modified) (history)

Diff [purge]

Index: branches/querypage-work2/extensions/ProofreadPage/SpecialPagesWithoutScans.php
@@ -23,30 +23,13 @@
2424 * Special page that lists the texts that have no transclusions
2525 * Pages in MediaWiki:Proofreadpage_notnaked_category are excluded.
2626 */
27 -class PagesWithoutScans extends SpecialPage {
 27+class PagesWithoutScans extends QueryPage {
2828
29 - public function __construct() {
30 - parent::__construct( 'PagesWithoutScans' );
 29+ function __construct( $name = 'PagesWithoutScans' ) {
 30+ parent::__construct( $name );
 31+ $this->page_namespace = wfMsgForContent( 'proofreadpage_namespace' );
3132 }
3233
33 - public function execute( $parameters ) {
34 - $this->setHeaders();
35 - list( $limit, $offset ) = wfCheckLimits();
36 - $cnl = new PagesWithoutScansQuery();
37 - $cnl->doQuery( $offset, $limit );
38 - }
39 -}
40 -
41 -class PagesWithoutScansQuery extends QueryPage {
42 -
43 - function __construct() {
44 - $this->page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' );
45 - }
46 -
47 - function getName() {
48 - return 'PagesWithoutScans';
49 - }
50 -
5134 function isExpensive() {
5235 return true;
5336 }
@@ -55,9 +38,9 @@
5639 return false;
5740 }
5841
59 - /*
60 - * return a clause with the list of disambiguation templates.
61 - * this function was copied verbatim from specials/SpecialDisambiguations.php
 42+ /**
 43+ * Return a clause with the list of disambiguation templates.
 44+ * This function was copied verbatim from specials/SpecialDisambiguations.php
6245 */
6346 function disambiguation_templates( $dbr ) {
6447 $dMsgText = wfMsgForContent('disambiguationspage');
@@ -92,30 +75,47 @@
9376 }
9477 return $linkBatch->constructSet( 'tl', $dbr );
9578 }
96 -
97 - function getSQL() {
 79+
 80+ function getQueryInfo() {
9881 $dbr = wfGetDB( DB_SLAVE );
99 - $page = $dbr->tableName( 'page' );
100 - $templatelinks = $dbr->tableName( 'templatelinks' );
101 - $forceindex = $dbr->useIndexClause( 'page_len' );
10282 $page_ns_index = MWNamespace::getCanonicalIndex( strtolower( $this->page_namespace ) );
103 -
104 - /* SQL clause to exclude pages with scans */
105 - $pages_with_scans = "( SELECT DISTINCT tl_from FROM $templatelinks LEFT JOIN $page ON page_id=tl_from WHERE tl_namespace=$page_ns_index AND page_namespace=" . NS_MAIN . " ) ";
106 -
107 - /* Exclude disambiguation pages too */
 83+
 84+ // Construct subqueries
 85+ $pagesWithScansSubquery = $dbr->selectSQLText(
 86+ array( 'templatelinks', 'page' ),
 87+ 'DISTINCT tl_from',
 88+ array(
 89+ 'page_id=tl_from',
 90+ 'tl_namespace' => $page_ns_index,
 91+ 'page_namespace' => NS_MAIN
 92+ )
 93+ );
 94+
 95+ // Exclude disambiguation pages too
10896 $dt = $this->disambiguation_templates( $dbr );
109 - $disambiguation_pages = "( SELECT page_id FROM $page LEFT JOIN $templatelinks ON page_id=tl_from WHERE page_namespace=" . NS_MAIN . " AND " . $dt . " )";
110 -
111 - $sql = "SELECT page_namespace as namespace,
112 - page_title as title,
113 - page_len AS value
114 - FROM $page $forceindex
115 - WHERE page_namespace=" . NS_MAIN . " AND page_is_redirect=0
116 - AND page_id NOT IN $pages_with_scans
117 - AND page_id NOT IN $disambiguation_pages";
118 -
119 - return $sql;
 97+ $disambigPagesSubquery = $dbr->selectSQLText(
 98+ array( 'page', 'templatelinks' ),
 99+ 'page_id',
 100+ array(
 101+ 'page_id=tl_from',
 102+ 'page_namespace' => NS_MAIN,
 103+ $dt
 104+ )
 105+ );
 106+
 107+ return array(
 108+ 'tables' => 'page',
 109+ 'fields' => array(
 110+ 'page_namespace AS namespace',
 111+ 'page_title AS title',
 112+ 'page_len AS value' ),
 113+ 'conds' => array(
 114+ 'page_namespace' => NS_MAIN,
 115+ 'page_is_redirect' => 0,
 116+ "page_id NOT IN ($pagesWithScansSubquery)",
 117+ "page_id NOT IN ($disambigPagesSubquery)" ),
 118+ 'options' => array( 'USE INDEX' => 'page_len' )
 119+ );
120120 }
121121
122122 function sortDescending() {

Status & tagging log