r80242 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80241‎ | r80242 | r80243 >
Date:09:40, 14 January 2011
Author:btongminh
Status:resolved (Comments)
Tags:
Comment:
Add backend infrastructure to start querying by category
Modified paths:
  • /trunk/extensions/GlobalUsage/GlobalUsageQuery.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GlobalUsage/GlobalUsageQuery.php
@@ -12,15 +12,17 @@
1313 private $reversed = false;
1414
1515 /**
16 - * @param $target mixed Title or db key, or array of db keys of target(s)
 16+ * @param $target mixed Title or db key, or array of db keys of target(s).
 17+ * If a title, can be a category or a file
1718 */
1819 public function __construct( $target ) {
1920 global $wgGlobalUsageDatabase;
2021 $this->db = wfGetDB( DB_SLAVE, array(), $wgGlobalUsageDatabase );
21 - if ( $target instanceof Title )
22 - $this->target = $target->getDBKey();
23 - else
 22+ if ( $target instanceof Title ) {
2423 $this->target = $target;
 24+ } else {
 25+ $this->target = Title::makeTitleSafe( NS_FILE, $target );
 26+ }
2527 $this->offset = array();
2628
2729 }
@@ -101,10 +103,29 @@
102104 * Executes the query
103105 */
104106 public function execute() {
105 - /* Construct a where clause */
 107+ /* Construct the SQL query */
 108+ $tables = array( 'globalimagelinks' );
 109+
106110 // Add target image(s)
107 - $where = array( 'gil_to' => $this->target );
 111+ switch ( $this->target->getNamespace() ) {
 112+ case NS_FILE:
 113+ $where = array( 'gil_to' => $this->target );
 114+ break;
 115+ case NS_CATEGORY:
 116+ $tables[] = 'categorylinks';
 117+ $tables[] = 'page';
 118+ $where = array(
 119+ 'cl_to' => $this->target->getDbKey(),
 120+ 'cl_from = page_id',
 121+ 'page_namespace = ' . NS_FILE,
 122+ 'gil_to = page_title',
 123+ );
 124+ break;
 125+ default:
 126+ return array();
 127+ }
108128
 129+
109130 if ( $this->filterLocal )
110131 // Don't show local file usage
111132 $where[] = 'gil_wiki != ' . $this->db->addQuotes( wfWikiId() );
@@ -135,7 +156,7 @@
136157 }
137158
138159 /* Perform select (Duh.) */
139 - $res = $this->db->select( 'globalimagelinks',
 160+ $res = $this->db->select( $tables,
140161 array(
141162 'gil_to',
142163 'gil_wiki',

Follow-up revisions

RevisionCommit summaryAuthorDate
r92374Fix regression from r80242 that broke ApiQueryGlobalUsage totally. Array valu...btongminh18:37, 16 July 2011

Comments

#Comment by Bryan (talk | contribs)   10:03, 14 January 2011

This filesorts, so is not yet suitable for Wikimedia use.

#Comment by Reedy (talk | contribs)   11:50, 15 June 2011

I'm guessing this needs backing out of 1.18 then? Or more likely, out of 1.18wmf1

#Comment by Bryan (talk | contribs)   21:36, 15 June 2011

Currently $this->target is guaranteed to be NS_FILE, so nothing needs to be changed atm.

Status & tagging log