r94118 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94117‎ | r94118 | r94119 >
Date:16:13, 9 August 2011
Author:kbrown
Status:ok (Comments)
Tags:
Comment:
*add function for update.php schema updates
Modified paths:
  • /trunk/extensions/ArchiveLinks/ArchiveLinks.class.php (modified) (history)
  • /trunk/extensions/ArchiveLinks/ArchiveLinks.php (modified) (history)
  • /trunk/extensions/ArchiveLinks/setuptables.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/ArchiveLinks/ArchiveLinks.php
@@ -19,14 +19,18 @@
2020
2121 $wgHooks['ArticleSaveComplete'][] = 'ArchiveLinks::queueExternalLinks';
2222 $wgHooks['LinkerMakeExternalLink'][] = 'ArchiveLinks::rewriteLinks';
 23+$wgHooks['LoadExtensionSchemaUpdates'][] = 'ArchiveLinks::schemaUpdates';
2324
2425 $wgSpecialPages['ModifyArchiveBlacklist'] = 'SpecialModifyArchiveBlacklist';
2526 $wgSpecialPages['ViewArchive'] = 'SpecialViewArchive';
2627
 28+$wgAutoloadClasses['ApiQueryArchiveFeed'] = "$path/ApiQueryArchiveFeed.php";
 29+$wgAPIListModules['archivefeed'] = 'ApiQueryArchiveFeed';
 30+
2731 $wgArchiveLinksConfig = array(
28 - 'archive_service' => 'wikiwix',
 32+ 'archive_service' => 'internet_archive',
2933 'use_multiple_archives' => false,
3034 'run_spider_in_loop' => false,
3135 'in_progress_ignore_delay' => 7200,
32 - 'generate_feed' => true,
 36+ 'generate_feed' => false,
3337 );
\ No newline at end of file
Index: trunk/extensions/ArchiveLinks/setuptables.sql
@@ -1,22 +1,22 @@
2 -CREATE TABLE IF NOT EXISTS `el_archive_blacklist` (
 2+CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/`el_archive_blacklist` (
33 `bl_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
44 `bl_type` tinyint(4) NOT NULL,
55 `bl_url` varchar(10000) NOT NULL,
66 `bl_expiry` int(11) unsigned NOT NULL,
77 `bl_reason` varchar(255) NOT NULL,
88 PRIMARY KEY (`bl_id`)
9 -) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
 9+) /*$wgDBTableOptions*/;
1010
11 -CREATE TABLE IF NOT EXISTS `el_archive_log` (
 11+CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/`el_archive_log` (
1212 `log_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
1313 `log_result` tinyint(4) NOT NULL,
1414 `log_url` varchar(10000) NOT NULL,
1515 `log_time` int(11) unsigned NOT NULL,
1616 `log_http_code` varchar(255) NOT NULL,
1717 PRIMARY KEY (`log_id`)
18 -) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
 18+) /*$wgDBTableOptions*/;
1919
20 -CREATE TABLE IF NOT EXISTS `el_archive_queue` (
 20+CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/`el_archive_queue` (
2121 `queue_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
2222 `page_id` int(11) unsigned NOT NULL,
2323 `url` varchar(10000) NOT NULL,
@@ -24,12 +24,20 @@
2525 `insertion_time` int(11) unsigned NOT NULL,
2626 `in_progress` varchar(50) NOT NULL,
2727 PRIMARY KEY (`queue_id`)
28 -) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=105 ;
 28+) /*$wgDBTableOptions*/;
2929
30 -CREATE TABLE IF NOT EXISTS `el_archive_link_history` (
 30+CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/`el_archive_link_history` (
3131 `hist_id` int(11) unsigned NOT NULL,
3232 `hist_page_id` int(11) unsigned NOT NULL,
3333 `hist_url` varchar(10000) NOT NULL,
3434 `hist_insertion_time` int(11) unsigned NOT NULL,
3535 PRIMARY KEY (`hist_id`)
36 -) ENGINE=InnoDB DEFAULT CHARSET=utf8;
\ No newline at end of file
 36+) /*$wgDBTableOptions*/;
 37+
 38+CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/`el_archive_resource` (
 39+ `resource_id` int(11) NOT NULL,
 40+ `el_id` int(11) NOT NULL,
 41+ `resource_url` varchar(10000) NOT NULL,
 42+ `resource_location` varchar(10000) NOT NULL,
 43+ PRIMARY KEY (`resource_id`)
 44+) /*$wgDBTableOptions*/;
Index: trunk/extensions/ArchiveLinks/ArchiveLinks.class.php
@@ -42,6 +42,8 @@
4343 $old_id = $article->getTitle();
4444 $old_id = $old_id->getPreviousRevisionID( $page_id );
4545
 46+ die('firing');
 47+
4648 $db_result['links_on_page'] = $db_master->select( 'el_archive_link_history', '*', array( 'hist_page_id' => $page_id ), __METHOD__ );
4749
4850 $old_external_links = array();
@@ -55,7 +57,7 @@
5658 $new_external_links = array_diff( $external_links, $old_external_links );
5759 unset( $old_external_links );
5860
59 - die( var_dump( $old_external_links ) );
 61+ //die( var_dump( $old_external_links ) );
6062 } elseif ( count( $external_links ) > 0 ) {
6163 $new_external_links = $external_links;
6264 }
@@ -67,27 +69,13 @@
6870 if ( count( $new_external_links ) <= $wgArchiveLinksConfig['link_insert_max'] ) {
6971 //insert the links into the queue now
7072 foreach( $new_external_links as $link ) {
71 - /*$db_result['blacklist'] = $db_slave->select( 'el_archive_blacklist', '*', array( 'bl_url' => $link ), __METHOD__, array( 'LIMIT' => '1', ) );
 73+ $this->feed_insert_links( $link );
 74+
 75+ /*
7276
7377
7478 /*
75 - if ( $db_result['blacklist-numrows'] === 0 && $db_result['queue-numrows'] === 0 ) {
76 - //this link is new to the wiki
77 - $db_master->insert( 'el_archive_queue', array(
78 - 'page_id' => $page_id,
79 - 'url' => $link,
80 - 'delay_time' => '0',
81 - 'insertion_time' => $time,
82 - 'in_progress' => '0',
83 - ));
84 -
85 - $db_master->insert( 'el_archive_link_history', array(
86 - 'page_id' => $page_id,
87 - 'url' => $link,
88 - 'delay_time' => '0',
89 - 'insertion_time' => $time,
90 - 'in_progress' => '0',
91 - ));
 79+
9280 } elseif ( $db_result['history-row']['hist_insertion_time'] >= $time - $wgArchiveLinksConfig['global_rearchive_time'] ) {
9381 $db_result['history_page'] = $db_slave->select( 'el_archive_link_history', '*', array( 'hist_url' => $link, 'page_id' => $page_id ), __METHOD__, array( 'LIMIT' => '1', 'ORDER BY' => 'hist_id DESC' ) );
9482
@@ -224,11 +212,64 @@
225213 $url = $this->strencode( $url );
226214 }
227215
228 - $db_result['queue'] = $db_slave->select( 'el_archive_queue', '*', array( 'url' => $link ), __METHOD__, array( 'LIMIT' => '1', ) );
229 -
230 - $db_result['queue-numrows'] = $db_result['queue']->numRows();
231 - $db_result['blacklist-numrows'] = $db_result['blacklist']->numRows();
 216+ $db_result['queue'] = $db_slave->select( 'el_archive_queue', '*', array( 'url' => $link ), __METHOD__, array( 'LIMIT' => '1', ) );
 217+ $db_result['blacklist'] = $db_slave->select( 'el_archive_blacklist', '*', array( 'bl_url' => $link ), __METHOD__, array( 'LIMIT' => '1', ) );
 218+
 219+ $db_result['queue-numrows'] = $db_result['queue']->numRows();
 220+ $db_result['blacklist-numrows'] = $db_result['blacklist']->numRows();
 221+
 222+ if ( $db_result['blacklist-numrows'] === 0 && $db_result['queue-numrows'] === 0 ) {
 223+ $db_master->insert( 'el_archive_queue', array(
 224+ 'page_id' => $page_id,
 225+ 'url' => $link,
 226+ 'delay_time' => '0',
 227+ 'insertion_time' => $time,
 228+ 'in_progress' => '0',
 229+ ));
 230+
 231+ $db_master->insert( 'el_archive_link_history', array(
 232+ 'page_id' => $page_id,
 233+ 'url' => $link,
 234+ 'delay_time' => '0',
 235+ 'insertion_time' => $time,
 236+ 'in_progress' => '0',
 237+ ));
 238+ }
232239 }
 240+
 241+ public static function schemaUpdate ( $updater = null ) {
 242+ $path = dirname( __FILE__ );
 243+ $updater->addExtesionUpdate( array(
 244+ 'addTable',
 245+ 'el_archive_link_history',
 246+ $path . '/setuptables.sql',
 247+ true
 248+ ));
 249+ $updater->addExtesionUpdate( array(
 250+ 'addTable',
 251+ 'el_archive_queue',
 252+ $path . '/setuptables.sql',
 253+ true
 254+ ));
 255+ $updater->addExtesionUpdate( array(
 256+ 'addTable',
 257+ 'el_archive_log',
 258+ $path . '/setuptables.sql',
 259+ true
 260+ ));
 261+ $updater->addExtesionUpdate( array(
 262+ 'addTable',
 263+ 'el_archive_resource',
 264+ $path . '/setuptables.sql',
 265+ true
 266+ ));
 267+ $updater->addExtesionUpdate( array(
 268+ 'addTable',
 269+ 'el_archive_link_blacklist',
 270+ $path . '/setuptables.sql',
 271+ true
 272+ ));
 273+ }
233274 }
234275
235276 class InsertURLsIntoQueue extends Job {

Follow-up revisions

RevisionCommit summaryAuthorDate
r94157fix typos from r94118kbrown15:22, 10 August 2011
r94164fix partial excaping problem on setuptables.sql, follow up to r94118kbrown16:20, 10 August 2011
r94165gah, fix sql statement, forgot to remove *other* backtick... r94118...kbrown16:37, 10 August 2011

Comments

#Comment by NeilK (talk | contribs)   16:02, 10 August 2011

I think you left a debug die() on line 45 of ArchiveLinks.class.php. Otherwise looks okay

#Comment by NeilK (talk | contribs)   16:10, 10 August 2011

In general I'm finding it hard to follow queueExternalLinks -- please break it up into a couple of functions & remove the commented code. Getting close to the end of GSoC!

#Comment by NeilK (talk | contribs)   15:55, 16 August 2011

marking ok as debugging statements removed, dead code removed, in folowups.

Status & tagging log