r90691 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90690‎ | r90691 | r90692 >
Date:06:11, 24 June 2011
Author:kbrown
Status:deferred (Comments)
Tags:
Comment:
Fix problems in r90526. Started adding proper i18n support as well as replaced individual global config with one array of config options.
Modified paths:
  • /trunk/extensions/ArchiveLinks/ArchiveLinks.i18n.php (added) (history)
  • /trunk/extensions/ArchiveLinks/ArchiveLinks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArchiveLinks/ArchiveLinks.i18n.php
@@ -0,0 +1,11 @@
 2+<?php
 3+/**
 4+ * Internationalization File for Archive Links
 5+ */
 6+
 7+$messages = array();
 8+
 9+//English
 10+$messages['en'] = array (
 11+ 'archive-links-cache-title' => '[cache]',
 12+);
\ No newline at end of file
Property changes on: trunk/extensions/ArchiveLinks/ArchiveLinks.i18n.php
___________________________________________________________________
Added: svn:eol-style
113 + native
Index: trunk/extensions/ArchiveLinks/ArchiveLinks.php
@@ -46,12 +46,15 @@
4747 //$wgHooks['LinkerMakeExternalLink'][] = 'getExternalLinks';
4848 //$wgHooks['EditPage::attemptSave'][] = 'getExternalLinks';
4949
 50+$wgExtensionMessagesFiles['ArchiveLinks'] = dirname( __FILE__ ) . '/ArchiveLinks.i18n.php';
 51+
5052 $wgHooks['ArticleSaveComplete'][] = 'ArchiveLinks::queueExternalLinks';
5153 $wgHooks['LinkerMakeExternalLink'][] = 'ArchiveLinks::rewriteLinks';
5254
53 -$wgArchiveService = 'wikiwix';
54 -$wgUseMultipleArchives = false;
55 -$wgWhatToCallArchive = '[cache]';
 55+$wgArchiveLinksConfig = array (
 56+ 'archive_service' => 'wikiwix',
 57+ 'use_multiple_archives' => false,
 58+);
5659
5760 class ArchiveLinks {
5861 public static function queueExternalLinks ( &$article ) {
@@ -70,9 +73,7 @@
7174 foreach ( $external_links as $link => $unused_value ) {
7275 //$db_result['resource'] = $db_slave->select( 'el_archive_resource', '*', '`el_archive_resource`.`resource_url` = "' . $db_slave->strencode( $link ) . '"');
7376 $db_result['blacklist'] = $db_slave->select( 'el_archive_blacklist', '*', '`el_archive_blacklist`.`bl_url` = "' . $db_slave->strencode( $link ) . '"');
74 -
75 - //we need to know if the URL is already in the queue to prevent a page from being archived twice, so we will query the master
76 - $db_result['queue'] = $db_master->select( 'el_archive_queue', '*', '`el_archive_queue`.`url` = "' . $db_slave->strencode( $link ) . '"' );
 77+ $db_result['queue'] = $db_slave->select( 'el_archive_queue', '*', '`el_archive_queue`.`url` = "' . $db_slave->strencode( $link ) . '"' );
7778
7879 if ( $db_result['blacklist']->numRows() === 0 ) {
7980 if ( $db_result['queue']->numRows() === 0 ) {
@@ -107,31 +108,30 @@
108109
109110 public static function rewriteLinks ( &$url, &$text, &$link, &$attributes ) {
110111 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)
 112+ global $wgArchiveLinksConfig;
 113+ if ( $wgArchiveLinksConfig['use_multiple_archives'] ) {
 114+ //need to add support for more than one archival service at once
 115+ // (a page where you can select one from a list of choices)
117116 } else {
118 - switch ( $wgArchiveService ) {
 117+ switch ( $wgArchiveLinksConfig['archive_service'] ) {
119118 case 'local':
120119 //We need to have something to figure out where the filestore is...
121120 $link_to_archive = urlencode( substr_replace( $url, '', 0, 7 ) );
122121 break;
123122 case 'wikiwix':
124 - $link_to_archive = 'http://archive.wikiwix.org/cache/?url=' . $link;
 123+ $link_to_archive = 'http://archive.wikiwix.com/cache/?url=' . $url;
125124 break;
126125 case 'internet_archive':
127 - $link_to_archive = 'http://wayback.archive.org/web/*/' . $link;
 126+ $link_to_archive = 'http://wayback.archive.org/web/*/' . $url;
128127 break;
129128 case 'webcitation':
130 - $link_to_archive = 'http://webcitation.org/query?url=' . $link;
 129+ $link_to_archive = 'http://webcitation.org/query?url=' . $url;
131130 break;
132131 }
133132 }
134 - $link = "<a rel=\"nofollow\" class=\"{$attributes['class']}\" href=\"{$url}\">{$text}</a>&nbsp;<sup><small><a href=\""
135 - . $link_to_archive . "\">{$wgWhatToCallArchive}</a></small></sup>&nbsp;";
 133+ //Note to self: need to fix this to use Html.php instead of direct html
 134+ $link = "<a rel=\"nofollow\" class=\"{$attributes['class']}\" href=\"{$url}\">{$text}</a>&#160;<sup><small><a href=\""
 135+ . "{$link_to_archive}\">" . wfMsg( 'archive-links-cache-title' ) . '</a></small></sup>&#160;';
136136 return false;
137137 } else {
138138 return true;
@@ -160,7 +160,7 @@
161161
162162 //$db_slave = wfGetDB( DB_SLAVE );
163163
164 - /*$db_result = $db_slave->select( 'el_archive_blacklist', '*',
 164+ /*db_result = $db_slave->select( 'el_archive_blacklist', '*',
165165 '`el_archive_blacklist`.`bl_url` = "' . $db_slave->strencode( 'http://example.com' ) . '"');
166166 */
167167 //$db_result['queue'] = $db_slave->select( 'el_archive_queue', '*', '`el_archive_queue`.`url` = "' . $db_slave->strencode( 'http://example.com' ) . '"' );

Follow-up revisions

RevisionCommit summaryAuthorDate
r91317* rename SpecialModifyBlacklist to SpecialModifyArchiveBlacklist to avoid con...kbrown22:53, 1 July 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r90526add hook and function for rewriting links external links to have a link to th...kbrown14:08, 21 June 2011

Comments

#Comment by NeilK (talk | contribs)   17:32, 1 July 2011

The message strings are considered to be wikitext, so you should remove the square brackets from 'cache'. Insert them at the moment you add it to the HTML.

#Comment by 😂 (talk | contribs)   00:04, 10 September 2011

Doing something like $str = '[' . wfMsg( 'foo' ) . ']' is bad i18n, so I wouldn't recommend that. Yes, messages are (usually) considered to be wikitext, but [foo] isn't going to turn into anything since it doesn't match any link protocols. If you're super paranoid though, you could use wfMsgNoTrans( 'foo' ).

#Comment by Kevin Brown (talk | contribs)   16:05, 19 September 2011

This was changed to

HTML::element('a', array ( 'rel' => 'nofollow', 'href' => $link_to_archive ), '[' . wfMsg( 'archivelinks-cache-title') . ']')

Is this okay or is wfMsgNoTrans(); preferred?

Status & tagging log