Index: trunk/extensions/ArchiveLinks/ArchiveLinks.php |
— | — | @@ -45,10 +45,16 @@ |
46 | 46 | |
47 | 47 | //$wgHooks['LinkerMakeExternalLink'][] = 'getExternalLinks'; |
48 | 48 | //$wgHooks['EditPage::attemptSave'][] = 'getExternalLinks'; |
49 | | -$wgHooks['ArticleSaveComplete'][] = 'ArchiveLinks::getExternalLinks'; #We want to use this hook in production |
50 | 49 | |
| 50 | +$wgHooks['ArticleSaveComplete'][] = 'ArchiveLinks::queueExternalLinks'; |
| 51 | +$wgHooks['LinkerMakeExternalLink'][] = 'ArchiveLinks::rewriteLinks'; |
| 52 | + |
| 53 | +$wgArchiveService = 'wikiwix'; |
| 54 | +$wgUseMultipleArchives = false; |
| 55 | +$wgWhatToCallArchive = '[cache]'; |
| 56 | + |
51 | 57 | class ArchiveLinks { |
52 | | - public static function getExternalLinks ( &$article ) { |
| 58 | + public static function queueExternalLinks ( &$article ) { |
53 | 59 | global $wgParser; |
54 | 60 | $external_links = $wgParser->getOutput(); |
55 | 61 | $external_links = $external_links->mExternalLinks; |
— | — | @@ -59,7 +65,7 @@ |
60 | 66 | $db_slave = wfGetDB( DB_SLAVE ); |
61 | 67 | $db_result = array(); |
62 | 68 | |
63 | | - //$db_master->begin(); |
| 69 | + $db_master->begin(); |
64 | 70 | |
65 | 71 | foreach ( $external_links as $link => $unused_value ) { |
66 | 72 | //$db_result['resource'] = $db_slave->select( 'el_archive_resource', '*', '`el_archive_resource`.`resource_url` = "' . $db_slave->strencode( $link ) . '"'); |
— | — | @@ -76,7 +82,7 @@ |
77 | 83 | $db_master->insert( 'el_archive_queue', array ( |
78 | 84 | 'page_id' => $article->getID(), |
79 | 85 | 'url' => $link, |
80 | | - //'delay_time' => '', |
| 86 | + 'delay_time' => '0', |
81 | 87 | 'insertion_time' => time(), |
82 | 88 | 'in_progress' => '0', |
83 | 89 | )); |
— | — | @@ -94,10 +100,47 @@ |
95 | 101 | //$db_master->insert('el_archive_queue', $array ); |
96 | 102 | } |
97 | 103 | |
98 | | - //$db_master->commit(); |
| 104 | + $db_master->commit(); |
99 | 105 | |
100 | 106 | return true; |
101 | 107 | } |
| 108 | + |
| 109 | + public static function rewriteLinks ( &$url, &$text, &$link, &$attributes ) { |
| 110 | + if ( array_key_exists('rel', $attributes) && $attributes['rel'] === 'nofollow' ) { |
| 111 | + global $wgArchiveService; |
| 112 | + global $wgUseMultipleArchives; |
| 113 | + global $wgWhatToCallArchive; |
| 114 | + if ( $wgUseMultipleArchives ) { |
| 115 | + //add support for more than one archival service at once |
| 116 | + // (a page where you can select more than one) |
| 117 | + } else { |
| 118 | + switch ( $wgArchiveService ) { |
| 119 | + case 'local': |
| 120 | + //We need to have something to figure out where the filestore is... |
| 121 | + $link_to_archive = urlencode( substr_replace( $url, '', 0, 7 ) ); |
| 122 | + break; |
| 123 | + case 'wikiwix': |
| 124 | + $link_to_archive = 'http://archive.wikiwix.org/cache/?url=' . $link; |
| 125 | + break; |
| 126 | + case 'internet_archive': |
| 127 | + $link_to_archive = 'http://wayback.archive.org/web/*/' . $link; |
| 128 | + break; |
| 129 | + case 'webcitation': |
| 130 | + $link_to_archive = 'http://webcitation.org/query?url=' . $link; |
| 131 | + break; |
| 132 | + } |
| 133 | + } |
| 134 | + $link = "<a rel=\"nofollow\" class=\"{$attributes['class']}\" href=\"{$url}\">{$text}</a> <sup><small><a href=\"" |
| 135 | + . $link_to_archive . "\">{$wgWhatToCallArchive}</a></small></sup> "; |
| 136 | + return false; |
| 137 | + } else { |
| 138 | + return true; |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + /*function retrieveLinks ( ) { |
| 143 | + |
| 144 | + }*/ |
102 | 145 | |
103 | 146 | /*function queueURL ( $url, &$db_master ) { |
104 | 147 | |
— | — | @@ -115,17 +158,19 @@ |
116 | 159 | 'bl_reason' => 'test' |
117 | 160 | ));*/ |
118 | 161 | |
119 | | - $db_slave = wfGetDB( DB_SLAVE ); |
| 162 | + //$db_slave = wfGetDB( DB_SLAVE ); |
120 | 163 | |
121 | 164 | /*$db_result = $db_slave->select( 'el_archive_blacklist', '*', |
122 | 165 | '`el_archive_blacklist`.`bl_url` = "' . $db_slave->strencode( 'http://example.com' ) . '"'); |
123 | 166 | */ |
124 | | - $db_result['queue'] = $db_slave->select( 'el_archive_queue', '*', '`el_archive_queue`.`url` = "' . $db_slave->strencode( 'http://example.com' ) . '"' ); |
| 167 | + //$db_result['queue'] = $db_slave->select( 'el_archive_queue', '*', '`el_archive_queue`.`url` = "' . $db_slave->strencode( 'http://example.com' ) . '"' ); |
125 | 168 | |
126 | | - file_put_contents ( './extensions/ArchiveLinks/stuff.txt', var_export( $db_result['queue']->numRows() , TRUE )); |
| 169 | + //file_put_contents ( './extensions/ArchiveLinks/stuff.txt', var_export( $db_result['queue']->numRows() , TRUE )); |
127 | 170 | //$add_quotes = 'http://example.com'; |
128 | 171 | //file_put_contents ( './extensions/ArchiveLinks/stuff.txt', var_export( $db_slave->addQuotes( $add_quotes ) , TRUE )); |
129 | 172 | |
| 173 | + |
| 174 | + |
130 | 175 | return false; |
131 | 176 | } |
132 | 177 | /* |