Index: trunk/extensions/GlobalUsage/GlobalUsageHooks.php |
— | — | @@ -12,10 +12,28 @@ |
13 | 13 | // Create a list of locally existing images |
14 | 14 | $images = array_keys( $linksUpdater->getImages() ); |
15 | 15 | $localFiles = array_keys( RepoGroup::singleton()->getLocalRepo()->findFiles( $images ) ); |
| 16 | + $missingFiles = array_diff( $images, $localFiles ); |
16 | 17 | |
| 18 | + global $wgUseDumbLinkUpdate; |
17 | 19 | $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 | + } |
20 | 38 | |
21 | 39 | return true; |
22 | 40 | } |
Index: trunk/extensions/GlobalUsage/GlobalUsageQuery.php |
— | — | @@ -136,6 +136,12 @@ |
137 | 137 | public function getResult() { |
138 | 138 | return $this->result; |
139 | 139 | } |
| 140 | + public function getSingleImageResult() { |
| 141 | + if ( $this->result ) |
| 142 | + return current( $this->result ); |
| 143 | + else |
| 144 | + return array(); |
| 145 | + } |
140 | 146 | |
141 | 147 | /** |
142 | 148 | * Returns whether there are more results |
Index: trunk/extensions/GlobalUsage/GlobalUsage.sql |
— | — | @@ -10,7 +10,7 @@ |
11 | 11 | -- Image name |
12 | 12 | gil_to varchar(255) binary not null, |
13 | 13 | |
14 | | - PRIMARY KEY (gil_to, gil_wiki, gil_page), |
| 14 | + PRIMARY KEY (gil_to, gil_wiki, gil_page) |
15 | 15 | ) /*$wgDBTableOptions*/; |
16 | 16 | |
17 | 17 | CREATE INDEX globalimagelinks_wiki ON globalimagelinks(gil_wiki, gil_page); |
Index: trunk/extensions/GlobalUsage/GlobalUsage_body.php |
— | — | @@ -35,21 +35,41 @@ |
36 | 36 | $this->db->insert( 'globalimagelinks', $insert, __METHOD__ ); |
37 | 37 | } |
38 | 38 | /** |
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 |
42 | 40 | */ |
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', |
46 | 45 | array( |
47 | 46 | 'gil_wiki' => $this->interwiki, |
48 | | - 'gil_page' => $id |
| 47 | + 'gil_page' => $id, |
49 | 48 | ), |
50 | | - __METHOD__ |
| 49 | + __METHOD__ |
51 | 50 | ); |
| 51 | + |
| 52 | + $images = array(); |
| 53 | + foreach ( $res as $row ) |
| 54 | + $images[] = $row->gil_to; |
| 55 | + return $images; |
52 | 56 | } |
53 | 57 | /** |
| 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 | + /** |
54 | 74 | * Deletes all entries to a certain image |
55 | 75 | * |
56 | 76 | * @param $title Title Title of the file |
Index: trunk/extensions/GlobalUsage/SpecialGlobalUsage.php |
— | — | @@ -99,7 +99,7 @@ |
100 | 100 | $wgOut->addHtml( $navbar ); |
101 | 101 | |
102 | 102 | $wgOut->addHtml( '<div id="mw-globalusage-result">' ); |
103 | | - foreach ( reset( $query->getResult() ) as $wiki => $result ) { |
| 103 | + foreach ( $query->getSingleImageResult() as $wiki => $result ) { |
104 | 104 | $wgOut->addHtml( |
105 | 105 | '<h2>' . wfMsgExt( |
106 | 106 | 'globalusage-on-wiki', 'parseinline', |
— | — | @@ -136,7 +136,7 @@ |
137 | 137 | $query->execute(); |
138 | 138 | |
139 | 139 | $guHtml = ''; |
140 | | - foreach ( $query->getResult() as $wiki => $result ) { |
| 140 | + foreach ( $query->getSingleImageResult() as $wiki => $result ) { |
141 | 141 | $guHtml .= '<li>' . wfMsgExt( |
142 | 142 | 'globalusage-on-wiki', 'parseinline', |
143 | 143 | $targetName, WikiMap::getWikiName( $wiki ) ) . "\n<ul>"; |