r65496 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65495‎ | r65496 | r65497 >
Date:22:00, 23 April 2010
Author:catrope
Status:deferred
Tags:
Comment:
querypage-work2: Rewrite Special:IndexPages in extensions/ProofreadPage as a proper QueryPage
Modified paths:
  • /branches/querypage-work2/extensions/ProofreadPage/ProofreadPage.php (modified) (history)
  • /branches/querypage-work2/extensions/ProofreadPage/SpecialProofreadPages.php (modified) (history)

Diff [purge]

Index: branches/querypage-work2/extensions/ProofreadPage/ProofreadPage.php
@@ -28,9 +28,10 @@
2929
3030
3131 # special page
32 -$wgAutoloadClasses['ProofreadPages'] = $dir . 'SpecialProofreadPages.php';
33 -$wgSpecialPages['IndexPages'] = 'ProofreadPages';
 32+$wgAutoloadClasses['IndexPagesPage'] = $dir . 'SpecialProofreadPages.php';
 33+$wgSpecialPages['IndexPages'] = 'IndexPagesPage';
3434 $wgSpecialPageGroups['IndexPages'] = 'pages';
 35+$wgQueryPages['IndexPagesPage'] = 'IndexPages';
3536
3637 # Bump the version number every time you change proofread.js
3738 $wgProofreadPageVersion = 26;
Index: branches/querypage-work2/extensions/ProofreadPage/SpecialProofreadPages.php
@@ -4,21 +4,15 @@
55 * @ingroup SpecialPage
66 */
77
8 -
9 -if ( !defined( 'MEDIAWIKI' ) ) die( 1 );
10 -global $wgHooks, $IP;
11 -require_once "$IP/includes/QueryPage.php";
12 -
13 -
14 -class ProofreadPages extends SpecialPage {
15 -
16 - function ProofreadPages() {
17 - SpecialPage::SpecialPage( 'IndexPages' );
 8+class IndexPagesPage extends QueryPage {
 9+ public function __construct() {
 10+ SpecialPage::__construct( 'IndexPages' );
1811 }
1912
20 - function execute( $parameters ) {
 13+ public function execute( $parameters ) {
2114 global $wgOut, $wgRequest, $wgDisableTextSearch;
2215
 16+ wfLoadExtensionMessages( 'ProofreadPage' );
2317 $this->setHeaders();
2418 list( $limit, $offset ) = wfCheckLimits();
2519 $wgOut->addWikiText( wfMsgForContentNoTrans( 'proofreadpage_specialpage_text' ) );
@@ -49,22 +43,40 @@
5044 }
5145 }
5246 }
53 - $cnl = new ProofreadPagesQuery( $searchList, $searchTerm );
54 - $cnl->doQuery( $offset, $limit );
 47+ parent::execute( $parameters );
5548 }
56 -}
5749
58 -class ProofreadPagesQuery extends QueryPage {
59 - function ProofreadPagesQuery( $searchList, $searchTerm ) {
60 - $this->searchList = $searchList;
61 - $this->searchTerm = $searchTerm;
 50+ public function getQueryInfo() {
 51+ $conds = array();
 52+ if ( $this->searchTerm ) {
 53+ if ( $this->searchList ) {
 54+ $index_namespace = pr_index_ns();
 55+ $index_ns_index = MWNamespace::getCanonicalIndex( strtolower( $index_namespace ) );
 56+ $conds = array( 'page_namespace' => $index_ns_index, 'page_title' => $this->searchList );
 57+ } else {
 58+ $conds = array( 'false' ); // FIXME: This is ugly
 59+ }
 60+ }
 61+ return array(
 62+ 'tables' => array( 'pr_index', 'page' ),
 63+ 'fields' => array( 'page_title AS title', 'pr_count',
 64+ 'pr_q0', 'pr_q1', 'pr_q2' ,'pr_q3', 'pr_q4' ),
 65+ 'conds' => $conds,
 66+ 'options' => array(),
 67+ 'join_conds' => array( 'page' => array( 'LEFT JOIN', 'page_id=pr_page_id' ) )
 68+ );
6269 }
6370
64 - function getName() {
65 - return 'IndexPages';
 71+ public function getOrderFields() {
 72+ return array( '2*pr_q4+pr_q3' ); // FIXME: This causes a filesort
6673 }
6774
 75+ public function sortDescending() {
 76+ return true;
 77+ }
 78+
6879 function isExpensive() {
 80+ // FIXME: the query does filesort, so we're kinda lying here right now
6981 return false;
7082 }
7183
@@ -72,45 +84,6 @@
7385 return false;
7486 }
7587
76 - function linkParameters() {
77 - return array( 'key'=> $this->searchTerm );
78 - }
79 -
80 - function getSQL() {
81 - $dbr = wfGetDB( DB_SLAVE );
82 - $page = $dbr->tableName( 'page' );
83 - $pr_index = $dbr->tableName( 'pr_index' );
84 -
85 - $query = "SELECT page_title as title,
86 - pr_count,pr_q0,pr_q1,pr_q2,pr_q3,pr_q4
87 - FROM $pr_index LEFT JOIN $page ON page_id = pr_page_id";
88 -
89 - if( $this->searchTerm ) {
90 - if( $this->searchList ) {
91 - $index_namespace = pr_index_ns() ;
92 - $index_ns_index = MWNamespace::getCanonicalIndex( strtolower( $index_namespace ) );
93 - $querylist = '';
94 - foreach( $this->searchList as $item ) {
95 - if( $querylist ) $querylist .= ', ';
96 - $querylist .= "'" . $dbr->strencode( $item ). "'";
97 - }
98 - $query .= " WHERE page_namespace=$index_ns_index AND page_title IN ($querylist)";
99 - } else {
100 - $query .= " WHERE false";
101 - }
102 - }
103 - return $query;
104 - }
105 -
106 - function getOrder() {
107 - return ' ORDER BY 2*pr_q4+pr_q3 ' .
108 - ($this->sortDescending() ? 'DESC' : '');
109 - }
110 -
111 - function sortDescending() {
112 - return true;
113 - }
114 -
11588 function formatResult( $skin, $result ) {
11689 global $wgLang;
11790

Follow-up revisions

RevisionCommit summaryAuthorDate
r74567Reapply r65496reedy20:33, 9 October 2010
r78072Reapply r65496/t74567 againreedy16:10, 8 December 2010

Status & tagging log