r84841 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84840‎ | r84841 | r84842 >
Date:09:30, 27 March 2011
Author:nikola
Status:deferred
Tags:
Comment:
- Rewrote InterlanguageCentralExtensionPurgeJob to work with Interwiki
class and use the API per Tim's suggestions.
- InterlanguageCentralExtension::getILL() can now read from master or
slave DB depending on the need.
Modified paths:
  • /trunk/extensions/Interlanguage/InterlanguageCentral.php (modified) (history)
  • /trunk/extensions/Interlanguage/InterlanguageCentralExtension.php (modified) (history)
  • /trunk/extensions/Interlanguage/InterlanguageCentralExtensionPurgeJob.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Interlanguage/InterlanguageCentralExtensionPurgeJob.php
@@ -1,6 +1,6 @@
22 <?php
33 /**
4 - * MediaWiki InterlanguageCentral extension v1.1
 4+ * MediaWiki InterlanguageCentral extension v1.2
55 * InterlanguageCentralExtensionPurgeJob class
66 *
77 * Copyright © 2010-2011 Nikola Smolenski <smolensk@eunet.rs>
@@ -36,29 +36,23 @@
3737 * @return bool
3838 */
3939 public function run() {
40 - global $wgInterlanguageCentralExtensionIndexUrl;
41 -
4240 //sleep() could be added here to reduce unnecessary use
4341 $ill = $this->params['ill'];
4442
4543 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 );
4654 //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 - */
6155 }
62 -
 56+
6357 return true;
6458 }
6559
Index: trunk/extensions/Interlanguage/InterlanguageCentralExtension.php
@@ -1,6 +1,6 @@
22 <?php
33 /**
4 - * MediaWiki InterlanguageCentral extension v1.1
 4+ * MediaWiki InterlanguageCentral extension v1.2
55 * InterlanguageCentralExtension class
66 *
77 * Copyright © 2010-2011 Nikola Smolenski <smolensk@eunet.rs>
@@ -29,12 +29,12 @@
3030 var $oldILL = array();
3131
3232 function onArticleSave( $article ) {
33 - $this->oldILL = $this->getILL($article->mTitle);
 33+ $this->oldILL = $this->getILL( DB_SLAVE, $article->mTitle);
3434 return true;
3535 }
3636
3737 function onArticleSaveComplete( $article ) {
38 - $newILL = $this->getILL($article->mTitle);
 38+ $newILL = $this->getILL( DB_MASTER, $article->mTitle);
3939
4040 //Compare ILLs before and after the save; if nothing changed, there is no need to purge
4141 if(
@@ -57,8 +57,8 @@
5858
5959 }
6060
61 - function getILL($title) {
62 - $dbr = wfGetDB( DB_SLAVE );
 61+ function getILL( $db, $title ) {
 62+ $dbr = wfGetDB( $db );
6363 $res = $dbr->select( 'langlinks', array( 'll_lang', 'll_title' ), array( 'll_from' => $title->mArticleID), __FUNCTION__);
6464 $a = array();
6565 foreach( $res as $row ) {
Index: trunk/extensions/Interlanguage/InterlanguageCentral.php
@@ -1,6 +1,6 @@
22 <?php
33 /**
4 - * MediaWiki InterlanguageCentral extension v1.1
 4+ * MediaWiki InterlanguageCentral extension v1.2
55 *
66 * Copyright © 2010-2011 Nikola Smolenski <smolensk@eunet.rs>
77 * @version 1.1
@@ -45,7 +45,9 @@
4646 $wgInterlanguageCentralExtension = new InterlanguageCentralExtension();
4747 $wgHooks['ArticleSave'][] = $wgInterlanguageCentralExtension;
4848 $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;
5052 }
5153 return true;
5254 }
\ No newline at end of file

Status & tagging log