r49599 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49598‎ | r49599 | r49600 >
Date:14:47, 17 April 2009
Author:catrope
Status:deferred
Tags:
Comment:
querypage-work: Convert SpecialDisambiguations.php, tweak coding style, remove old getSQL() code
Modified paths:
  • /branches/querypage-work/phase3/includes/specials/SpecialBrokenRedirects.php (modified) (history)
  • /branches/querypage-work/phase3/includes/specials/SpecialDeadendpages.php (modified) (history)
  • /branches/querypage-work/phase3/includes/specials/SpecialDisambiguations.php (modified) (history)

Diff [purge]

Index: branches/querypage-work/phase3/includes/specials/SpecialDisambiguations.php
@@ -13,11 +13,11 @@
1414 return 'Disambiguations';
1515 }
1616
17 - function isExpensive( ) { return true; }
 17+ function isExpensive() { return true; }
1818 function isSyndicated() { return false; }
1919
2020
21 - function getPageHeader( ) {
 21+ function getPageHeader() {
2222 return wfMsgExt( 'disambiguations-text', array( 'parse' ) );
2323 }
2424
@@ -77,11 +77,70 @@
7878
7979 return $sql;
8080 }
 81+
 82+ function getQueryInfo() {
 83+ $dbr = wfGetDB( DB_SLAVE );
 84+ $dMsgText = wfMsgForContent('disambiguationspage');
 85+ $linkBatch = new LinkBatch;
8186
82 - function getOrder() {
83 - return '';
 87+ # If the text can be treated as a title, use it verbatim.
 88+ # Otherwise, pull the titles from the links table
 89+ $dp = Title::newFromText($dMsgText);
 90+ if( $dp ) {
 91+ if($dp->getNamespace() != NS_TEMPLATE) {
 92+ # FIXME we assume the disambiguation message is a template but
 93+ # the page can potentially be from another namespace :/
 94+ wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n");
 95+ }
 96+ $linkBatch->addObj( $dp );
 97+ } else {
 98+ # Get all the templates linked from the Mediawiki:Disambiguationspage
 99+ $disPageObj = Title::makeTitleSafe( NS_MEDIAWIKI, 'disambiguationspage' );
 100+ $res = $dbr->select(
 101+ array('pagelinks', 'page'),
 102+ 'pl_title',
 103+ array('page_id = pl_from', 'pl_namespace' => NS_TEMPLATE,
 104+ 'page_namespace' => $disPageObj->getNamespace(), 'page_title' => $disPageObj->getDBkey()),
 105+ __METHOD__ );
 106+
 107+ while ( $row = $dbr->fetchObject( $res ) ) {
 108+ $linkBatch->addObj( Title::makeTitle( NS_TEMPLATE, $row->pl_title ));
 109+ }
 110+
 111+ $dbr->freeResult( $res );
 112+ }
 113+ $set = $linkBatch->constructSet( 'tl', $dbr );
 114+ if( $set === false ) {
 115+ # We must always return a valid SQL query, but this way
 116+ # the DB will always quickly return an empty result
 117+ $set = 'FALSE';
 118+ wfDebug("Mediawiki:disambiguationspage message does not link to any templates!\n");
 119+ }
 120+
 121+ // FIXME: What are pagelinks and p2 doing here?
 122+ return array (
 123+ 'tables' => array( 'templatelinks', 'page AS p1', 'pagelinks', 'page AS p2' ),
 124+ 'fields' => array( "'{$this->getName()}' AS type",
 125+ 'p1.page_namespace AS namespace',
 126+ 'p1.page_title AS title',
 127+ 'pl_from AS value' ),
 128+ 'conds' => array( $set,
 129+ 'p1.page_id = tl_from',
 130+ 'pl_namespace = p1.page_namespace',
 131+ 'pl_title = p1.page_title',
 132+ 'p2.page_id = pl_from',
 133+ 'p2.page_namespace' => NS_MAIN )
 134+ );
84135 }
85136
 137+ function getOrderFields() {
 138+ return array('tl_namespace', 'tl_title', 'value');
 139+ }
 140+
 141+ function sortDescending() {
 142+ return false;
 143+ }
 144+
86145 function formatResult( $skin, $result ) {
87146 global $wgContLang;
88147 $title = Title::newFromID( $result->value );
Index: branches/querypage-work/phase3/includes/specials/SpecialBrokenRedirects.php
@@ -16,30 +16,13 @@
1717 return 'BrokenRedirects';
1818 }
1919
20 - function isExpensive( ) { return true; }
 20+ function isExpensive() { return true; }
2121 function isSyndicated() { return false; }
2222
23 - function getPageHeader( ) {
 23+ function getPageHeader() {
2424 return wfMsgExt( 'brokenredirectstext', array( 'parse' ) );
2525 }
2626
27 - function getSQL() {
28 - $dbr = wfGetDB( DB_SLAVE );
29 - list( $page, $redirect ) = $dbr->tableNamesN( 'page', 'redirect' );
30 -
31 - $sql = "SELECT 'BrokenRedirects' AS type,
32 - p1.page_namespace AS namespace,
33 - p1.page_title AS title,
34 - rd_namespace,
35 - rd_title
36 - FROM $redirect AS rd
37 - JOIN $page p1 ON (rd.rd_from=p1.page_id)
38 - LEFT JOIN $page AS p2 ON (rd_namespace=p2.page_namespace AND rd_title=p2.page_title )
39 - WHERE rd_namespace >= 0
40 - AND p2.page_namespace IS NULL";
41 - return $sql;
42 - }
43 -
4427 function getQueryInfo() {
4528 return array(
4629 'tables' => array( 'redirect', 'page AS p1', 'page AS p2' ),
@@ -64,7 +47,8 @@
6548 );
6649 }
6750
68 - function getOrder() {
 51+ function getOrderFields() {
 52+ // FIXME: really?
6953 return array ();
7054 }
7155
Index: branches/querypage-work/phase3/includes/specials/SpecialDeadendpages.php
@@ -9,7 +9,7 @@
1010 */
1111 class DeadendPagesPage extends PageQueryPage {
1212
13 - function getName( ) {
 13+ function getName() {
1414 return "Deadendpages";
1515 }
1616
@@ -22,7 +22,7 @@
2323 *
2424 * @return true
2525 */
26 - function isExpensive( ) {
 26+ function isExpensive() {
2727 return 1;
2828 }
2929
@@ -35,19 +35,6 @@
3636 return false;
3737 }
3838
39 - /**
40 - * @return string an sqlquery
41 - */
42 - function getSQL() {
43 - $dbr = wfGetDB( DB_SLAVE );
44 - list( $page, $pagelinks ) = $dbr->tableNamesN( 'page', 'pagelinks' );
45 - return "SELECT 'Deadendpages' as type, page_namespace AS namespace, page_title as title, page_title AS value " .
46 - "FROM $page LEFT JOIN $pagelinks ON page_id = pl_from " .
47 - "WHERE pl_from IS NULL " .
48 - "AND page_namespace = 0 " .
49 - "AND page_is_redirect = 0";
50 - }
51 -
5239 function getQueryInfo() {
5340 return array(
5441 'tables' => array( 'page', 'pagelinks' ),

Follow-up revisions

RevisionCommit summaryAuthorDate
r65315querypage-work2: merge r49599 from querypage-workreedy14:07, 20 April 2010

Status & tagging log