r58963 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58962‎ | r58963 | r58964 >
Date:20:14, 12 November 2009
Author:btongminh
Status:ok
Tags:
Comment:
* Honor $wgUseDumpLinkUpdate by using incremental updates (used by default)
* Fixed SQL table creation syntax
* Other misc fixes
Modified paths:
  • /trunk/extensions/GlobalUsage/GlobalUsage.sql (modified) (history)
  • /trunk/extensions/GlobalUsage/GlobalUsageHooks.php (modified) (history)
  • /trunk/extensions/GlobalUsage/GlobalUsageQuery.php (modified) (history)
  • /trunk/extensions/GlobalUsage/GlobalUsage_body.php (modified) (history)
  • /trunk/extensions/GlobalUsage/SpecialGlobalUsage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GlobalUsage/GlobalUsageHooks.php
@@ -12,10 +12,28 @@
1313 // Create a list of locally existing images
1414 $images = array_keys( $linksUpdater->getImages() );
1515 $localFiles = array_keys( RepoGroup::singleton()->getLocalRepo()->findFiles( $images ) );
 16+ $missingFiles = array_diff( $images, $localFiles );
1617
 18+ global $wgUseDumbLinkUpdate;
1719 $gu = self::getGlobalUsage();
18 - $gu->deleteFrom( $title->getArticleId( GAID_FOR_UPDATE ) );
19 - $gu->setUsage( $title, array_diff( $images, $localFiles ) );
 20+ if ( $wgUseDumbLinkUpdate ) {
 21+ // Delete all entries to the page
 22+ $gu->deleteFrom( $title->getArticleId( GAID_FOR_UPDATE ) );
 23+ // Re-insert new usage for the page
 24+ $gu->setUsage( $title, $missingFiles );
 25+ } else {
 26+ $articleId = $title->getArticleId( GAID_FOR_UPDATE );
 27+ $existing = $gu->getAllFrom( $articleId );
 28+
 29+ // Calculate changes
 30+ $added = array_diff( $missingFiles, $existing );
 31+ $removed = array_diff( $existing, $missingFiles );
 32+
 33+ // Add new usages and delete removed
 34+ $gu->setUsage( $title, $added );
 35+ if ( $removed )
 36+ $gu->deleteFrom( $articleId, $removed );
 37+ }
2038
2139 return true;
2240 }
Index: trunk/extensions/GlobalUsage/GlobalUsageQuery.php
@@ -136,6 +136,12 @@
137137 public function getResult() {
138138 return $this->result;
139139 }
 140+ public function getSingleImageResult() {
 141+ if ( $this->result )
 142+ return current( $this->result );
 143+ else
 144+ return array();
 145+ }
140146
141147 /**
142148 * Returns whether there are more results
Index: trunk/extensions/GlobalUsage/GlobalUsage.sql
@@ -10,7 +10,7 @@
1111 -- Image name
1212 gil_to varchar(255) binary not null,
1313
14 - PRIMARY KEY (gil_to, gil_wiki, gil_page),
 14+ PRIMARY KEY (gil_to, gil_wiki, gil_page)
1515 ) /*$wgDBTableOptions*/;
1616
1717 CREATE INDEX globalimagelinks_wiki ON globalimagelinks(gil_wiki, gil_page);
Index: trunk/extensions/GlobalUsage/GlobalUsage_body.php
@@ -35,21 +35,41 @@
3636 $this->db->insert( 'globalimagelinks', $insert, __METHOD__ );
3737 }
3838 /**
39 - * Deletes all entries from a certain page
40 - *
41 - * @param $id int Page id of the page
 39+ * Get all global images from a certain page
4240 */
43 - public function deleteFrom( $id ) {
44 - $this->db->delete(
45 - 'globalimagelinks',
 41+ public function getAllFrom( $id ) {
 42+ $res = $this->db->select(
 43+ 'globalimagelinks',
 44+ 'gil_to',
4645 array(
4746 'gil_wiki' => $this->interwiki,
48 - 'gil_page' => $id
 47+ 'gil_page' => $id,
4948 ),
50 - __METHOD__
 49+ __METHOD__
5150 );
 51+
 52+ $images = array();
 53+ foreach ( $res as $row )
 54+ $images[] = $row->gil_to;
 55+ return $images;
5256 }
5357 /**
 58+ * Deletes all entries from a certain page to certain files
 59+ *
 60+ * @param $id int Page id of the page
 61+ * @param $to mixed File name(s)
 62+ */
 63+ public function deleteFrom( $id, $to = null ) {
 64+ $where = array(
 65+ 'gil_wiki' => $this->interwiki,
 66+ 'gil_page' => $id
 67+ );
 68+ if ( $to ) {
 69+ $where['gil_to'] = $to;
 70+ }
 71+ $this->db->delete( 'globalimagelinks', $where, __METHOD__ );
 72+ }
 73+ /**
5474 * Deletes all entries to a certain image
5575 *
5676 * @param $title Title Title of the file
Index: trunk/extensions/GlobalUsage/SpecialGlobalUsage.php
@@ -99,7 +99,7 @@
100100 $wgOut->addHtml( $navbar );
101101
102102 $wgOut->addHtml( '<div id="mw-globalusage-result">' );
103 - foreach ( reset( $query->getResult() ) as $wiki => $result ) {
 103+ foreach ( $query->getSingleImageResult() as $wiki => $result ) {
104104 $wgOut->addHtml(
105105 '<h2>' . wfMsgExt(
106106 'globalusage-on-wiki', 'parseinline',
@@ -136,7 +136,7 @@
137137 $query->execute();
138138
139139 $guHtml = '';
140 - foreach ( $query->getResult() as $wiki => $result ) {
 140+ foreach ( $query->getSingleImageResult() as $wiki => $result ) {
141141 $guHtml .= '<li>' . wfMsgExt(
142142 'globalusage-on-wiki', 'parseinline',
143143 $targetName, WikiMap::getWikiName( $wiki ) ) . "\n<ul>";

Status & tagging log