Skip to content

Commit

Permalink
Merge branch 'main' into T267849
Browse files Browse the repository at this point in the history
  • Loading branch information
tonisevener committed Nov 19, 2020
2 parents fc8a171 + 072dba7 commit 88aee0a
Show file tree
Hide file tree
Showing 59 changed files with 645 additions and 96 deletions.
4 changes: 2 additions & 2 deletions WMF Framework/CommonStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ public class CommonStrings: NSObject {
"aaald-revision-userInfo",
value:"Edit by %1$@ (%2$@ edits)", comment: "Text describing details about the user that made a significant revision in the article as a living document view. %1$@ is replaced by the editor name and %2$d is replaced by the number of edits they have made.")

static let revisionUserInfoAnonymous = WMFLocalizedString("aaald-revision-userInfo-anonymous",
value:"Edit by %1$@", comment: "Text describing details about the anonymous user that made a significant revision in the article as a living document view. %1$@ is replaced by the editor's anonymous name.")
static let revisionUserInfoAnonymous = WMFLocalizedString("aaald-revision-by-anonymous",
value:"Edit by anonymous user", comment: "Text describing the anonymous user that made a significant revision in the article as a living document view.")

static let articleAsLivingDocSummaryTitle = WMFLocalizedString(
"aaald-summary-title",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,7 @@ public extension ArticleAsLivingDocViewModel.Event.Large {
if let urlString = urlString, let url = URL(string: urlString), let externalLinkIcon = UIImage(named: "mini-external") {
if #available(iOSApplicationExtension 13.0, *) {
mutableAttributedString = NSMutableAttributedString(string: text.trimmingCharacters(in: .whitespaces), attributes: textAttributes)
mutableAttributedString.append(NSAttributedString(string: " "))
let externalLinkString = NSAttributedString(attachment: NSTextAttachment(image: externalLinkIcon))
mutableAttributedString.append(externalLinkString)
mutableAttributedString.append(NSAttributedString(string: " "))
Expand Down Expand Up @@ -1620,6 +1621,8 @@ public extension ArticleAsLivingDocViewModel.Event.Large {
static var botIconName: String {
return "article-as-living-doc-svg-bot"
}

static var anonymousIconName: String = "article-as-living-doc-svg-anon"

private func userInfoHtmlSnippet() -> String? {
guard let userNameAndEditCount = self.userNameAndEditCount() else {
Expand Down Expand Up @@ -1659,8 +1662,8 @@ public extension ArticleAsLivingDocViewModel.Event.Large {
}
}
} else {
let anonymousUserInfo = String.localizedStringWithFormat(CommonStrings.revisionUserInfoAnonymous, userName)
return anonymousUserInfo
return "<img src='\(Self.anonymousIconName)' style='margin: 0em .2em .35em .1em; width: 1em' />\(CommonStrings.revisionUserInfoAnonymous)"

}

return nil
Expand All @@ -1681,12 +1684,19 @@ public extension ArticleAsLivingDocViewModel.Event.Large {

guard let editCount = maybeEditCount,
userType != .anonymous else {
let anonymousUserInfo = String.localizedStringWithFormat(CommonStrings.revisionUserInfoAnonymous, userName)
let anonymousUserInfo = CommonStrings.revisionUserInfoAnonymous

let font = UIFont.wmf_font(.subheadline, compatibleWithTraitCollection: traitCollection)
let attributes = [NSAttributedString.Key.font: font,
NSAttributedString.Key.foregroundColor: theme.colors.secondaryText]
let attributedString = NSAttributedString(string: anonymousUserInfo, attributes: attributes)
let mutableAttributedString = NSMutableAttributedString(string: anonymousUserInfo, attributes: attributes)
addIcon(to: mutableAttributedString, at: 0, for: userType)
// Need this next line to appropriately color the icon
mutableAttributedString.addAttributes(attributes, range: NSRange(location: 0, length: 2))
guard let attributedString = mutableAttributedString.copy() as? NSAttributedString else {
return nil
}

self.userInfo = attributedString
return attributedString
}
Expand All @@ -1711,21 +1721,25 @@ public extension ArticleAsLivingDocViewModel.Event.Large {
let mutableAttributedString = NSMutableAttributedString(string: userInfo, attributes: attributes)
mutableAttributedString.addAttribute(NSAttributedString.Key.link, value: userNameURL as NSURL, range: rangeOfUserName)
mutableAttributedString.addAttribute(NSAttributedString.Key.foregroundColor, value: theme.colors.link, range: rangeOfUserName)

if userType == .bot {
let imageAttachment = NSTextAttachment()
imageAttachment.image = UIImage(named: Self.botIconName)
let imageString = NSAttributedString(attachment: imageAttachment)
mutableAttributedString.insert(imageString, at: rangeOfUserName.location)
mutableAttributedString.insert(NSAttributedString(string: " "), at: rangeOfUserName.location + imageString.length)
}


addIcon(to: mutableAttributedString, at: rangeOfUserName.location, for: userType)

guard let attributedString = mutableAttributedString.copy() as? NSAttributedString else {
return nil
}

self.userInfo = attributedString
return attributedString
}

func addIcon(to mutableAttributedString: NSMutableAttributedString, at location: Int, for userType: UserType) {
if userType == .bot || userType == .anonymous {
let imageAttachment = NSTextAttachment()
imageAttachment.image = UIImage(named: (userType == .bot ? Self.botIconName : Self.anonymousIconName))
let imageString = NSAttributedString(attachment: imageAttachment)
mutableAttributedString.insert(imageString, at: location)
mutableAttributedString.insert(NSAttributedString(string: " "), at: location + imageString.length)
}
}

}
13 changes: 12 additions & 1 deletion Wikipedia/Code/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public class Session: NSObject {

public func dataTask(with request: URLRequest, callback: Callback) -> URLSessionTask? {

//odd workaround to show an article as living doc bot icon in the article content web view.
//odd workaround to show an article as living doc icons in the article content web view.
let botIconName = ArticleAsLivingDocViewModel.Event.Large.botIconName
if let url = request.url,
url.absoluteString.contains(botIconName),
Expand All @@ -275,6 +275,17 @@ public class Session: NSObject {
callback.success()
return nil
}

let anonIconName = ArticleAsLivingDocViewModel.Event.Large.anonymousIconName
if let url = request.url,
url.absoluteString.contains(anonIconName),
let imageData = UIImage(named: anonIconName)?.pngData() {
let response = URLResponse(url: url, mimeType: "image/png", expectedContentLength: imageData.count, textEncodingName: nil)
callback.response?(response)
callback.data?(imageData)
callback.success()
return nil
}

if request.cachePolicy == .returnCacheDataElseLoad,
let cachedResponse = permanentCache?.urlCache.cachedResponse(for: request) {
Expand Down
10 changes: 5 additions & 5 deletions Wikipedia/Images.xcassets/anon.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "logged-in.pdf"
"filename" : "anon.pdf",
"idiom" : "universal"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "Anonymous - default.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
5 changes: 3 additions & 2 deletions Wikipedia/Localizations/ca.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
// Author: Vriullop
// Author: Xavier Dengra

"aaald-added-text-description" = "{{PLURAL:$1|0=0 caràcters|$1 caràcter|$1 caràcters}} afegits";
"aaald-added-text-description-2" = "$1 afegit";
"aaald-article-description-updated-description" = "La descripció del títol de l'article s'ha actualitzat";
"aaald-article-insert-header" = "Actualitzacions significatives";
"aaald-article-insert-last-updated" = "Darrera actualització";
"aaald-article-insert-new-changes" = "Canvis recents";
"aaald-article-insert-read-more" = "Mostra les darreres actualitzacions";
"aaald-deleted-text-description" = "{{PLURAL:$1|0=S'han suprimit 0 caràcters|S'ha suprimit $1 caràcter|S'han suprimit $1 caràcters}}";
"aaald-characters-text-description" = "{{PLURAL:$1|0=caràcters|caràcter|caràcters}}";
"aaald-deleted-text-description-2" = "$1 eliminat";
"aaald-error-subitle" = "Refresqueu per a tornar-ho a provar";
"aaald-error-title" = "No s'ha pogut carregar en línia l'historial de l'article";
"aaald-many-sections-description" = "a $1 seccions";
Expand Down
13 changes: 13 additions & 0 deletions Wikipedia/Localizations/cs.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// Author: Frettie
// Author: H4nek
// Author: Ilimanaq29
// Author: Jan Myšák
// Author: Juandev
// Author: Korytaacheck
// Author: Luky001
Expand All @@ -28,6 +29,16 @@
// Author: Walter Klosse
// Author: Zbyso23

"aaald-added-text-description-2" = "přidáno $1";
"aaald-multiple-changes-description" = "Provedeno více změn";
"aaald-multiple-references-added-description" = "Přidáno více referencí";
"aaald-new-book-reference-title" = "Kniha";
"aaald-new-discussion" = "Nová diskuse";
"aaald-new-news-reference-title" = "Novinky";
"aaald-new-talk-topic-description-format" = "$1 o tomto článku";
"aaald-new-website-reference-archive-url-text" = "URL Archive.org";
"aaald-new-website-reference-title" = "Webová stránka";
"aaald-view-full-history-button" = "Zobrazit celou historii článku";
"about-content-license" = "Licence obsahu";
"about-content-license-details" = "Pokud není uvedeno jinak, obsah je k dispozici pod $1.";
"about-content-license-details-share-alike-license" = "Creative Commons Uveďte autora-Zachovejte licenci";
Expand Down Expand Up @@ -680,6 +691,7 @@
"reading-themes-controls-accessibility-syntax-highlighting-switch" = "Zvýraznění syntaxe";
"reading-themes-controls-accessibility-text-size-slider" = "Posuvník velikosti textu";
"reading-themes-controls-syntax-highlighting" = "Zvýraznění syntaxe";
"reference-section-button-accessibility-label" = "Skočit na sekci referencí";
"reference-title" = "Reference $1";
"relative-date-days-ago" = "{{PLURAL:$1|0=Dnes|1=Včera|2=Předevčírem|Před $1 dny}}";
"relative-date-hours-abbreviated" = "$1 h";
Expand Down Expand Up @@ -790,6 +802,7 @@
"table-of-contents-close-accessibility-label" = "Schovat obsah";
"table-of-contents-heading" = "Obsah";
"table-of-contents-hide-button-label" = "Skrýt tabulku s obsahem";
"table-of-contents-subheading-label" = "Podnadpis $1";
"talk-page-add-discussion-accessibility-label" = "Přidat diskusi";
"talk-page-discussion-accessibility-hint" = "Dvakrát poklepejte pro založení nového vlákna";
"talk-page-discussion-read-accessibility-label" = "Přečteno";
Expand Down
2 changes: 1 addition & 1 deletion Wikipedia/Localizations/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"aaald-new-website-reference-title" = "Website";
"aaald-numerical-multiple-references-added-description" = "{{PLURAL:$1|0=0 references|$1 reference|$1 references}} added";
"aaald-one-section-description" = "in the $1 section";
"aaald-revision-by-anonymous" = "Edit by anonymous user";
"aaald-revision-userInfo" = "Edit by $1 ($2 edits)";
"aaald-revision-userInfo-anonymous" = "Edit by $1";
"aaald-single-reference-added-description" = "Reference added";
"aaald-small-change-description" = "{{PLURAL:$1|0=No small changes made|$1 small change made|$1 small changes made}}";
"aaald-summary-title" = "{{PLURAL:$1|0=0 changes|$1 change|$1 changes}} by {{PLURAL:$2|0=0 editors|$2 editor|$2 editors}} in {{PLURAL:$3|0=0 days|$3 day|$3 days}}";
Expand Down
Loading

0 comments on commit 88aee0a

Please sign in to comment.