Index: trunk/extensions/Interlanguage/InterlanguageCentralExtensionPurgeJob.php |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * MediaWiki InterlanguageCentral extension v1.1 |
| 4 | + * MediaWiki InterlanguageCentral extension v1.2 |
5 | 5 | * InterlanguageCentralExtensionPurgeJob class |
6 | 6 | * |
7 | 7 | * Copyright © 2010-2011 Nikola Smolenski <smolensk@eunet.rs> |
— | — | @@ -36,29 +36,23 @@ |
37 | 37 | * @return bool |
38 | 38 | */ |
39 | 39 | public function run() { |
40 | | - global $wgInterlanguageCentralExtensionIndexUrl; |
41 | | - |
42 | 40 | //sleep() could be added here to reduce unnecessary use |
43 | 41 | $ill = $this->params['ill']; |
44 | 42 | |
45 | 43 | foreach($ill as $lang => $pages) { |
| 44 | + $iw = Interwiki::fetch( $lang ); |
| 45 | + if( !$iw ) continue; |
| 46 | + $apiUrl = $iw->getAPI(); |
| 47 | + if( !$apiUrl ) continue; |
| 48 | + $apiUrl .= '?' . wfArrayToCGI( array( |
| 49 | + 'action' => 'purge', |
| 50 | + 'format' => 'json', //Smallest response |
| 51 | + 'titles' => implode( '|', array_keys( $pages ) ) |
| 52 | + ) ); |
| 53 | + Http::post( $apiUrl ); |
46 | 54 | //TODO: error handling |
47 | | - $baseURL = sprintf($wgInterlanguageCentralExtensionIndexUrl, $lang) . |
48 | | - "?action=purge&title="; |
49 | | - foreach($pages as $page => $dummy) { |
50 | | - $url = $baseURL . urlencode(strtr($page, ' ', '_')); |
51 | | - Http::post( $url ); |
52 | | - } |
53 | | - //TODO: activate when becomes possible |
54 | | - /* |
55 | | - global $wgInterlanguageCentralExtensionApiUrl; |
56 | | - $url = sprintf($wgInterlanguageCentralExtensionApiUrl, $lang) . |
57 | | - "?action=purge&title=" . |
58 | | - implode( "|", array_walk( array_keys( $pages ), 'urlencode' ) ); |
59 | | - Http::post( $url ); |
60 | | - */ |
61 | 55 | } |
62 | | - |
| 56 | + |
63 | 57 | return true; |
64 | 58 | } |
65 | 59 | |
Index: trunk/extensions/Interlanguage/InterlanguageCentralExtension.php |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * MediaWiki InterlanguageCentral extension v1.1 |
| 4 | + * MediaWiki InterlanguageCentral extension v1.2 |
5 | 5 | * InterlanguageCentralExtension class |
6 | 6 | * |
7 | 7 | * Copyright © 2010-2011 Nikola Smolenski <smolensk@eunet.rs> |
— | — | @@ -29,12 +29,12 @@ |
30 | 30 | var $oldILL = array(); |
31 | 31 | |
32 | 32 | function onArticleSave( $article ) { |
33 | | - $this->oldILL = $this->getILL($article->mTitle); |
| 33 | + $this->oldILL = $this->getILL( DB_SLAVE, $article->mTitle); |
34 | 34 | return true; |
35 | 35 | } |
36 | 36 | |
37 | 37 | function onArticleSaveComplete( $article ) { |
38 | | - $newILL = $this->getILL($article->mTitle); |
| 38 | + $newILL = $this->getILL( DB_MASTER, $article->mTitle); |
39 | 39 | |
40 | 40 | //Compare ILLs before and after the save; if nothing changed, there is no need to purge |
41 | 41 | if( |
— | — | @@ -57,8 +57,8 @@ |
58 | 58 | |
59 | 59 | } |
60 | 60 | |
61 | | - function getILL($title) { |
62 | | - $dbr = wfGetDB( DB_SLAVE ); |
| 61 | + function getILL( $db, $title ) { |
| 62 | + $dbr = wfGetDB( $db ); |
63 | 63 | $res = $dbr->select( 'langlinks', array( 'll_lang', 'll_title' ), array( 'll_from' => $title->mArticleID), __FUNCTION__); |
64 | 64 | $a = array(); |
65 | 65 | foreach( $res as $row ) { |
Index: trunk/extensions/Interlanguage/InterlanguageCentral.php |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * MediaWiki InterlanguageCentral extension v1.1 |
| 4 | + * MediaWiki InterlanguageCentral extension v1.2 |
5 | 5 | * |
6 | 6 | * Copyright © 2010-2011 Nikola Smolenski <smolensk@eunet.rs> |
7 | 7 | * @version 1.1 |
— | — | @@ -45,7 +45,9 @@ |
46 | 46 | $wgInterlanguageCentralExtension = new InterlanguageCentralExtension(); |
47 | 47 | $wgHooks['ArticleSave'][] = $wgInterlanguageCentralExtension; |
48 | 48 | $wgHooks['ArticleSaveComplete'][] = $wgInterlanguageCentralExtension; |
49 | | - //TODO: ArticleDelete etc. |
| 49 | + //TODO: ArticleDelete etc. OR |
| 50 | + //TODO: After https://bugzilla.wikimedia.org/show_bug.cgi?id=24502 |
| 51 | + //$wgHooks['LinksUpdate'][] = $wgInterlanguageCentralExtension; |
50 | 52 | } |
51 | 53 | return true; |
52 | 54 | } |
\ No newline at end of file |