r58740 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58739‎ | r58740 | r58741 >
Date:09:23, 8 November 2009
Author:werdna
Status:ok
Tags:
Comment:
Update GlobalUsage extension to trunk state
Modified paths:
  • /branches/wmf-deployment/extensions/GlobalUsage (modified) (history)
  • /branches/wmf-deployment/extensions/GlobalUsage/GlobalUsage.i18n.php (modified) (history)
  • /branches/wmf-deployment/extensions/GlobalUsage/GlobalUsage.php (modified) (history)
  • /branches/wmf-deployment/extensions/GlobalUsage/GlobalUsageHooks.php (modified) (history)
  • /branches/wmf-deployment/extensions/GlobalUsage/GlobalUsage_body.php (modified) (history)
  • /branches/wmf-deployment/extensions/GlobalUsage/SpecialGlobalUsage.php (modified) (history)
  • /branches/wmf-deployment/extensions/GlobalUsage/refreshGlobalimagelinks.php (added) (history)

Diff [purge]

Index: branches/wmf-deployment/extensions/GlobalUsage/GlobalUsageHooks.php
@@ -75,4 +75,6 @@
7676
7777 return self::$gu;
7878 }
 79+
 80+
7981 }
\ No newline at end of file
Index: branches/wmf-deployment/extensions/GlobalUsage/GlobalUsage_body.php
@@ -21,12 +21,12 @@
2222 * @param $title Title Title of the page
2323 * @param $images array Array of db keys of images used
2424 */
25 - public function setUsage( $title, $images ) {
 25+ public function setUsage( $title, $images, $pageIdFlags = GAID_FOR_UPDATE ) {
2626 $insert = array();
2727 foreach ( $images as $name ) {
2828 $insert[] = array(
2929 'gil_wiki' => $this->interwiki,
30 - 'gil_page' => $title->getArticleID( GAID_FOR_UPDATE ),
 30+ 'gil_page' => $title->getArticleID( $pageIdFlags ),
3131 'gil_page_namespace' => $title->getNsText(),
3232 'gil_page_title' => $title->getText(),
3333 'gil_to' => $name
Index: branches/wmf-deployment/extensions/GlobalUsage/GlobalUsage.i18n.php
@@ -17,6 +17,9 @@
1818 'globalusage-ok' => 'Search',
1919 'globalusage-text' => 'Search global file usage',
2020 'globalusage-on-wiki' => 'Usage of [[:File:$1|$1]] on $2',
 21+ 'globalusage-of-file' => 'The following other wikis use this file:',
 22+ 'globalusage-more' => 'View [[{{#Special:GlobalUsage}}/$1|more global usage]] of this file.',
 23+ 'globalusage-filterlocal' => 'Do not show local usage',
2124 );
2225
2326 /** Message documentation (Message documentation)
@@ -201,8 +204,11 @@
202205 'globalusage-for' => 'Globale Dateinutzung für „$1“',
203206 'globalusage-desc' => '[[Special:GlobalUsage|Spezialseite]] zur Anzeige, in welchen Projekten die Dateien eines gemeinsam genutzten Repositoriums verwendet werden',
204207 'globalusage-ok' => 'Suchen',
205 - 'globalusage-text' => 'Globale Suche nach Dateinutzungen.',
 208+ 'globalusage-text' => 'Globale Suche nach Dateinutzungen',
206209 'globalusage-on-wiki' => 'Nutzung von [[:File:$1|$1]] auf $2',
 210+ 'globalusage-of-file' => 'Die nachfolgenden anderen Wikis nutzen diese Datei:',
 211+ 'globalusage-more' => '[[{{#Special:GlobalUsage}}/$1|Weitere globale Dateinutzung]] für dieser Datei anschauen.',
 212+ 'globalusage-filterlocal' => 'Zeige keine lokale Dateinutzung',
207213 );
208214
209215 /** Lower Sorbian (Dolnoserbski)
@@ -215,6 +221,9 @@
216222 'globalusage-ok' => 'Pytaś',
217223 'globalusage-text' => 'Za globalnym wužywanim datajow pytaś',
218224 'globalusage-on-wiki' => 'Wužywanje dataje [[:File:$1|$1]] na $2',
 225+ 'globalusage-of-file' => 'Slědujuce druge wikije wužywaju toś ten wobraz:',
 226+ 'globalusage-more' => '[[{{#Special:GlobalUsage}}/$1|Dalšne globalne wužywanje]] toś teje dataje pokazaś',
 227+ 'globalusage-filterlocal' => 'Lokalne wužywanje njepokazaś',
219228 );
220229
221230 /** Greek (Ελληνικά)
@@ -287,6 +296,9 @@
288297 'globalusage-ok' => 'Rechercher',
289298 'globalusage-text' => "Rechercher l'usage global du fichier",
290299 'globalusage-on-wiki' => 'Utilisation de [[:File:$1|$1]] sur $2',
 300+ 'globalusage-of-file' => 'Les autres wikis suivants utilisent cette image :',
 301+ 'globalusage-more' => "Voir [[{{#Special:GlobalUsage}}/$1|d'autres utilisations globales]] de ce fichier.",
 302+ 'globalusage-filterlocal' => "Ne pas montrer l'utilisation locale",
291303 );
292304
293305 /** Western Frisian (Frysk)
@@ -306,7 +318,10 @@
307319 'globalusage-desc' => '[[Special:GlobalUsage|Páxina especial]] para ver o uso global do ficheiro',
308320 'globalusage-ok' => 'Procurar',
309321 'globalusage-text' => 'Procurar o uso global do ficheiro.',
310 - 'globalusage-on-wiki' => 'Uso de [[:File:$1|$1]] en $2',
 322+ 'globalusage-on-wiki' => 'Uso de "[[:File:$1|$1]]" en $2',
 323+ 'globalusage-of-file' => 'Os seguintes wikis empregan esta imaxe:',
 324+ 'globalusage-more' => 'Ver [[{{#Special:GlobalUsage}}/$1|máis usos globais]] deste ficheiro.',
 325+ 'globalusage-filterlocal' => 'Non mostrar o uso local',
311326 );
312327
313328 /** Ancient Greek (Ἀρχαία ἑλληνικὴ)
@@ -396,6 +411,9 @@
397412 'globalusage-ok' => 'Podać',
398413 'globalusage-text' => 'Globalne wužiwanje dataje pytać.',
399414 'globalusage-on-wiki' => 'Wužiwanje dataje [[:File:$1|$1]] na $2',
 415+ 'globalusage-of-file' => 'Slědowace druhe wikije wužiwaja tutón wobraz:',
 416+ 'globalusage-more' => '[[{{#Special:GlobalUsage}}/$1|Dalše globalne wužiwanje]] tuteje dataje pokazać',
 417+ 'globalusage-filterlocal' => 'Lokalne wužiwanje njepokazać',
400418 );
401419
402420 /** Hungarian (Magyar)
@@ -428,10 +446,14 @@
429447 'globalusage-ok' => 'Cercar',
430448 'globalusage-text' => 'Cercar uso global de files.',
431449 'globalusage-on-wiki' => 'Uso de [[:File:$1|$1]] in $2',
 450+ 'globalusage-of-file' => 'Le altere wikis sequente usa iste imagine:',
 451+ 'globalusage-more' => 'Vider [[{{#Special:GlobalUsage}}/$1|ulterior uso global]] de iste file.',
 452+ 'globalusage-filterlocal' => 'Non monstrar uso local',
432453 );
433454
434455 /** Indonesian (Bahasa Indonesia)
435456 * @author Bennylin
 457+ * @author IvanLanin
436458 * @author Rex
437459 */
438460 $messages['id'] = array(
@@ -441,6 +463,9 @@
442464 'globalusage-ok' => 'Cari',
443465 'globalusage-text' => 'Cari penggunaan berkas secara global.',
444466 'globalusage-on-wiki' => 'Penggunaan [[:File:$1|$1]] pada $2',
 467+ 'globalusage-of-file' => 'Wiki lain berikut menggunakan berkas ini:',
 468+ 'globalusage-more' => 'Lihat [[{{#Special:GlobalUsage}}/$1|penggunaan global lain]] dari berkas ini.',
 469+ 'globalusage-filterlocal' => 'Jangan tunjukkan penggunaan lokal',
445470 );
446471
447472 /** Icelandic (Íslenska)
@@ -470,6 +495,9 @@
471496 'globalusage-ok' => '検索',
472497 'globalusage-text' => 'グローバルなファイル使用状況を検索する',
473498 'globalusage-on-wiki' => '$2での[[:File:$1|$1]]の利用状況',
 499+ 'globalusage-of-file' => '以下に挙げる他のウィキがこの画像を使っています:',
 500+ 'globalusage-more' => 'このファイルの[[{{#Special:GlobalUsage}}/$1|グローバル使用状況]]をさらに表示する。',
 501+ 'globalusage-filterlocal' => 'ローカル使用状況を表示しない',
474502 );
475503
476504 /** Javanese (Basa Jawa)
@@ -905,6 +933,14 @@
906934 'globalusage-text' => 'Küresel dosya kullanımını ara.',
907935 );
908936
 937+/** Vèneto (Vèneto)
 938+ * @author Candalua
 939+ */
 940+$messages['vec'] = array(
 941+ 'globalusage-ok' => 'Serca',
 942+ 'globalusage-text' => 'Serca utilizo globale file',
 943+);
 944+
909945 /** Veps (Vepsan kel')
910946 * @author Игорь Бродский
911947 */
Index: branches/wmf-deployment/extensions/GlobalUsage/refreshGlobalimagelinks.php
@@ -0,0 +1,93 @@
 2+<?php
 3+require_once( '../../maintenance/Maintenance.php' );
 4+
 5+class RefreshGlobalImageLinks extends Maintenance {
 6+ public function __construct() {
 7+ parent::__construct();
 8+ $this->addOption( 'start-page', 'page_id of the page to start with' );
 9+ $this->addOption( 'start-image', 'il_to of the image to start with' );
 10+ $this->addOption( 'maxlag', 'Maximum replication lag', false, true );
 11+ }
 12+
 13+ public function execute() {
 14+ global $wgGlobalUsageDatabase;
 15+
 16+ $dbr = wfGetDB( DB_SLAVE );
 17+ $gu = new GlobalUsage( wfWikiId(),
 18+ wfGetDB( DB_MASTER, array(), $wgGlobalUsageDatabase ) );
 19+
 20+ $lastPageId = intval( $this->getOption( 'start-page', 0 ) );
 21+ $lastIlTo = $this->getOption( 'start-image' );
 22+ $limit = 500;
 23+ $maxlag = intval( $this->getOption( 'maxlag', 0 ) );
 24+
 25+ do
 26+ {
 27+ $this->output( "Querying links after (page_id, il_to) = ($lastPageId, $lastIlTo)\n" );
 28+
 29+ # Query all pages and any imagelinks associated with that
 30+ $quotedLastIlTo = $dbr->addQuotes( $lastIlTo );
 31+ $res = $dbr->select(
 32+ array( 'page', 'imagelinks', 'image' ),
 33+ array(
 34+ 'page_id', 'page_namespace', 'page_title',
 35+ 'il_to', 'img_name'
 36+ ),
 37+ "(page_id = $lastPageId AND il_to > {$quotedLastIlTo})" .
 38+ " OR page_id > $lastPageId",
 39+ __METHOD__,
 40+ array(
 41+ 'ORDER BY' => $dbr->implicitOrderBy() ? 'page_id' : 'page_id, il_to',
 42+ 'LIMIT' => $limit
 43+ ),
 44+ array(
 45+ # LEFT JOIN imagelinks since we need to delete usage
 46+ # from all images, even if they don't have images anymore
 47+ 'imagelinks' => array( 'LEFT JOIN', 'page_id = il_from' ),
 48+ # Check to see if images exist locally
 49+ 'image' => array( 'LEFT JOIN', 'il_to = img_name' )
 50+ )
 51+ );
 52+
 53+ # Build up a tree per pages
 54+ $pages = array();
 55+ $lastRow = null;
 56+ foreach ( $res as $row ) {
 57+ if ( !isset( $pages[$row->page_id] ) )
 58+ $pages[$row->page_id] = array();
 59+ # Add the imagelinks entry to the pages array if the image
 60+ # does not exist locally
 61+ if ( !is_null( $row->il_to ) && is_null( $row->img_name ) ) {
 62+ $pages[$row->page_id][$row->il_to] = $row;
 63+ }
 64+ $lastRow = $row;
 65+ }
 66+
 67+ # Insert the imagelinks data to the global table
 68+ foreach ( $pages as $pageId => $rows ) {
 69+ # Delete all original links if this page is not a continuation
 70+ # of last iteration.
 71+ if ( $pageId != $lastPageId )
 72+ $gu->deleteFrom( $pageId );
 73+ if ( $rows ) {
 74+ $title = Title::newFromRow( reset( $rows ) );
 75+ $images = array_keys( $rows );
 76+ # Since we have a pretty accurate page_id, don't specify
 77+ # GAID_FOR_UPDATE
 78+ $gu->setUsage( $title, $images, /* $flags */ 0 );
 79+ }
 80+ }
 81+
 82+ if ( $lastRow ) {
 83+ # We've processed some rows in this iteration, so save
 84+ # continuation variables
 85+ $lastPageId = $lastRow->page_id;
 86+ $lastIlTo = $lastRow->il_to;
 87+ wfWaitForSlaves( $maxlag );
 88+ }
 89+ } while ( !is_null( $lastRow ) );
 90+ }
 91+}
 92+
 93+$maintClass = 'RefreshGlobalImageLinks';
 94+require_once( DO_MAINTENANCE );
Property changes on: branches/wmf-deployment/extensions/GlobalUsage/refreshGlobalimagelinks.php
___________________________________________________________________
Name: svn:eol-style
195 + native
Index: branches/wmf-deployment/extensions/GlobalUsage/GlobalUsage.php
@@ -65,6 +65,7 @@
6666 $wgHooks['FileUndeleteComplete'][] = 'GlobalUsageHooks::onFileUndeleteComplete';
6767 $wgHooks['UploadComplete'][] = 'GlobalUsageHooks::onUploadComplete';
6868 $wgHooks['TitleMoveComplete'][] = 'GlobalUsageHooks::onTitleMoveComplete';
 69+$wgHooks['ImagePageAfterImageLinks'][] = 'SpecialGlobalUsage::onImagePageAfterImageLinks';
6970
7071
7172 // If set to false, the local database contains the globalimagelinks table
Index: branches/wmf-deployment/extensions/GlobalUsage/SpecialGlobalUsage.php
@@ -17,36 +17,41 @@
1818 global $wgOut, $wgRequest;
1919
2020 $target = $par ? $par : $wgRequest->getVal( 'target' );
21 - $title = Title::newFromText( $target, NS_FILE );
 21+ $this->target = Title::newFromText( $target, NS_FILE );
2222
 23+ $this->filterLocal = $wgRequest->getCheck( 'filterlocal' );
 24+
2325 $this->setHeaders();
2426
25 - $this->showForm( $title );
 27+ $this->showForm();
2628
27 - if ( is_null( $title ) )
 29+ if ( is_null( $this->target ) )
2830 {
2931 $wgOut->setPageTitle( wfMsg( 'globalusage' ) );
3032 return;
3133 }
3234
33 - $wgOut->setPageTitle( wfMsg( 'globalusage-for', $title->getPrefixedText() ) );
 35+ $wgOut->setPageTitle( wfMsg( 'globalusage-for', $this->target->getPrefixedText() ) );
3436
35 - $this->showResult( $title );
 37+ $this->showResult();
3638 }
3739
3840 /**
3941 * Shows the search form
4042 */
41 - private function showForm( $title ) {
 43+ private function showForm() {
4244 global $wgScript, $wgOut;
4345
4446 $html = Xml::openElement( 'form', array( 'action' => $wgScript ) ) . "\n";
4547 $html .= Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
46 - $formContent = "\t" . Xml::input( 'target', 40, is_null( $title ) ? '' : $title->getPrefixedText() )
 48+ $formContent = "\t" . Xml::input( 'target', 40, is_null( $this->target ) ? ''
 49+ : $this->target->getPrefixedText() )
4750 . "\n\t" . Xml::element( 'input', array(
4851 'type' => 'submit',
4952 'value' => wfMsg( 'globalusage-ok' )
50 - ) );
 53+ ) )
 54+ . "\n\t<p>" . Xml::checkLabel( wfMsg( 'globalusage-filterlocal' ),
 55+ 'filterlocal', 'mw-filterlocal', $this->filterLocal ) . '</p>';
5156 $html .= Xml::fieldSet( wfMsg( 'globalusage-text' ), $formContent ) . "\n</form>";
5257
5358 $wgOut->addHtml( $html );
@@ -55,14 +60,15 @@
5661 /**
5762 * Creates as queryer and executes it based on $wgRequest
5863 */
59 - private function showResult( $target ) {
 64+ private function showResult() {
6065 global $wgRequest;
6166
62 - $query = new GlobalUsageQuery( $target );
 67+ $query = new GlobalUsageQuery( $this->target );
6368
6469 // Extract params from $wgRequest
6570 $query->setContinue( $wgRequest->getInt( 'offset', 0 ) );
6671 $query->setLimit( $wgRequest->getInt( 'limit', 50 ) );
 72+ $query->filterLocal( $this->filterLocal );
6773
6874 // Perform query
6975 $query->execute();
@@ -71,11 +77,12 @@
7278 global $wgOut;
7379
7480 $navbar = wfViewPrevNext( $query->getOffset(), $query->getLimit(), $this->getTitle(),
75 - 'target=' . $target->getPrefixedText(), !$query->hasMore() );
76 - $targetName = $target->getText();
 81+ 'target=' . $this->target->getPrefixedText(), !$query->hasMore() );
 82+ $targetName = $this->target->getText();
7783
7884 $wgOut->addHtml( $navbar );
7985
 86+ $wgOut->addHtml( '<div id="mw-globalusage-result">' );
8087 foreach ( $query->getResult() as $wiki => $result ) {
8188 $wgOut->addHtml(
8289 '<h2>' . wfMsgExt(
@@ -83,9 +90,10 @@
8491 $targetName, $wiki )
8592 . "</h2><ul>\n" );
8693 foreach ( $result as $item )
87 - $wgOut->addHtml( "\t<li>" . $this->formatItem( $item ) . "</li>\n" );
 94+ $wgOut->addHtml( "\t<li>" . self::formatItem( $item ) . "</li>\n" );
8895 $wgOut->addHtml( "</ul>\n" );
8996 }
 97+ $wgOut->addHtml( '</div>' );
9098
9199 $wgOut->addHtml( $navbar );
92100 }
@@ -93,7 +101,7 @@
94102 * Helper to format a specific item
95103 * TODO: Make links
96104 */
97 - private function formatItem( $item ) {
 105+ private static function formatItem( $item ) {
98106 if ( !$item['namespace'] )
99107 $page = $item['title'];
100108 else
@@ -103,7 +111,36 @@
104112
105113 return WikiMap::makeForeignLink( $item['wiki'], $page );
106114 }
 115+
 116+ public static function onImagePageAfterImageLinks( $imagePage, &$html ) {
 117+ $title = $imagePage->getFile()->getTitle();
 118+ $targetName = $title->getText();
 119+
 120+ $query = new GlobalUsageQuery( $title );
 121+ $query->filterLocal();
 122+ $query->execute();
 123+
 124+ $guHtml = '';
 125+ foreach ( $query->getResult() as $wiki => $result ) {
 126+ $guHtml .= '<li>' . wfMsgExt(
 127+ 'globalusage-on-wiki', 'parseinline',
 128+ $targetName, $wiki ) . "\n<ul>";
 129+ foreach ( $result as $item )
 130+ $guHtml .= "\t<li>" . self::formatItem( $item ) . "</li>\n";
 131+ $guHtml .= "</ul></li>\n";
 132+ }
 133+
 134+ if ( $guHtml ) {
 135+ $html .= "<h2>" . wfMsgHtml( 'globalusage' ) . "</h2>\n"
 136+ . wfMsgExt( 'globalusage-of-file', 'parse' )
 137+ . "<ul>\n" . $guHtml . "</ul>\n";
 138+ if ( $query->hasMore() )
 139+ $html .= wfMsgExt( 'globalusage-more', 'parse', $targetName );
 140+ }
107141
 142+
 143+ return true;
 144+ }
108145 }
109146
110147
@@ -117,6 +154,7 @@
118155 private $limit = 50;
119156 private $offset = 0;
120157 private $hasMore = false;
 158+ private $filterLocal = false;
121159 private $result;
122160
123161
@@ -155,11 +193,22 @@
156194 return $this->limit;
157195 }
158196
 197+ /**
 198+ * Set whether to filter out the local usage
 199+ */
 200+ public function filterLocal( $value = true ) {
 201+ $this->filterLocal = $value;
 202+ }
159203
 204+
160205 /**
161206 * Executes the query
162207 */
163208 public function execute() {
 209+ $where = array( 'gil_to' => $this->target->getDBkey() );
 210+ if ( $this->filterLocal )
 211+ $where[] = 'gil_wiki != ' . $this->db->addQuotes( wfWikiId() );
 212+
164213 $res = $this->db->select( 'globalimagelinks',
165214 array(
166215 'gil_wiki',
@@ -167,9 +216,7 @@
168217 'gil_page_namespace',
169218 'gil_page_title'
170219 ),
171 - array(
172 - 'gil_to' => $this->target->getDBkey()
173 - ),
 220+ $where,
174221 __METHOD__,
175222 array(
176223 'ORDER BY' => 'gil_wiki, gil_page',
Property changes on: branches/wmf-deployment/extensions/GlobalUsage
___________________________________________________________________
Name: svn:mergeinfo
177224 + /branches/REL1_15/phase3/extensions/GlobalUsage:51646
/trunk/extensions/GlobalUsage:56207,56209,56296,56333,56355,58660-58739
/trunk/phase3/extensions/GlobalUsage:56213,56215-56216,56218,56325,56334-56336,56338,56340,56343,56345,56347,56350,57154-57447

Status & tagging log