Permalink
Browse files

Return objects where it begs for it

sub ParseData is fully backwards compatible. If some module runs it in list
context, then it will get listified hash like previously. New code should
always run it in scalar context though (everything in our code base
was changed according to that).

sub GetTextRevision is not backwards compatible (don't let “wantarray” usage
to confuse you). Most modules do not touch that subroutine, so we are probably
fine (modules from our git repo that do use were changed accordingly).

“EncodePage(%$page)” looks wrong. It seems like we should change it to accept
hash ref.
  • Loading branch information...
AlexDaniel committed Sep 4, 2015
1 parent 31c02d6 commit 1c4e0827558d220fb624fe1af3245f4f386bee86
@@ -126,8 +126,8 @@ sub DoAggregate {
}
}
foreach my $id (@pages) {
my %data = ParseData(ReadFileOrDie(GetPageFile(FreeToNormal($id))));
my $page = $data{text};
my $data = ParseData(ReadFileOrDie(GetPageFile(FreeToNormal($id))));
my $page = $data->{text};
my $size = length($page);
my $i = index($page, "\n=");
my $j = index($page, "\n----");
@@ -136,13 +136,13 @@ sub DoAggregate {
$page =~ s/^=.*\n//; # if it starts with a header
my $name = $id;
$name =~ s/_/ /g;
my $date = TimeToRFC822($data{ts});
my $host = $data{host};
my $username = $data{username};
my $date = TimeToRFC822($data->{ts});
my $host = $data->{host};
my $username = $data->{username};
$username = QuoteHtml($username);
$username = $host unless $username;
my $minor = $data{minor};
my $revision = $data{revision};
my $minor = $data->{minor};
my $revision = $data->{revision};
my $cluster = GetCluster($page);
my $description = ToString(sub { ApplyRules(QuoteHtml($page), 1, 0, undef, 'p') });
$description .= $q->p(GetPageLink($id, T('Learn more...')))
@@ -124,7 +124,7 @@ sub NewBanContributorsWriteRcLog {
and $OpenPageName eq $id and UserIsAdmin()) {
# we currently have the clean page loaded, so we need to reload
# the spammed revision (there is a possible race condition here)
my ($old) = GetTextRevision($Page{revision}-1, 1);
my $old = GetTextRevision($Page{revision} - 1, 1)->{text};
my %urls = map {$_ => 1 } $old =~ /$UrlPattern/g;
# we open the file again to force a load of the despammed page
foreach my $url ($Page{text} =~ /$UrlPattern/g) {
@@ -133,14 +133,14 @@ sub DespamPage {
# from DoHistory()
my @revisions = sort {$b <=> $a} map { m|/([0-9]+).kp$|; $1; } GetKeepFiles($OpenPageName);
foreach my $revision (@revisions) {
my ($text, $rev) = GetTextRevision($revision, 1); # quiet
my ($revisionPage, $rev) = GetTextRevision($revision, 1); # quiet
if (not $rev) {
print ': ' . Ts('Cannot find revision %s.', $revision);
return;
} elsif (not DespamBannedContent($text)) {
} elsif (not DespamBannedContent($revisionPage->{text})) {
my $summary = Tss('Revert to revision %1: %2', $revision, $rule);
print ': ' . $summary;
Save($OpenPageName, $text, $summary) unless GetParam('debug', 0);
Save($OpenPageName, $revisionPage->{text}, $summary) unless GetParam('debug', 0);
return;
}
}
@@ -48,10 +48,10 @@ sub DoDraft {
SetParam('msg', T('Draft saved')); # invalidate cache
print GetHttpHeader('', T('Draft saved'), '204 NO CONTENT');
} elsif (-f $draft) {
my %data = ParseData(ReadFileOrDie($draft));
my $data = ParseData(ReadFileOrDie($draft));
unlink ($draft);
$Message .= $q->p(T('Draft recovered'));
DoEdit($data{id}, $data{text}, 1);
DoEdit($data->{id}, $data->{text}, 1);
} else {
ReportError(T('No draft available to recover'), '404 NOT FOUND');
}
@@ -56,8 +56,8 @@ sub NewEnclosureRssItem {
my $id = shift;
my $rss = OldEnclosureRssItem($id, @_);
require MIME::Base64;
my %data = ParseData(ReadFileOrDie(GetPageFile($id)));
my @enclosures = split(' ', $data{enclosures});
my $data = ParseData(ReadFileOrDie(GetPageFile($id)));
my @enclosures = split(' ', $data->{enclosures});
my $enclosures = '';
foreach my $enclosure (@enclosures) {
# Don't add the enclosure if the page has been deleted in the mean
@@ -240,9 +240,9 @@ sub GdSecurityImageCheck {
if ($answer ne '' && GdSecurityImageIsValidId($id)) {
my ($status, $data) = ReadFile(GdSecurityImageGetTicketFile($id));
if ($status) {
my %page = ParseData($data);
if ($page{generation_time} + $GdSecurityImageDuration > $Now) {
if ($answer eq $page{string}) {
my $page = ParseData($data);
if ($page->{generation_time} + $GdSecurityImageDuration > $Now) {
if ($answer eq $page->{string}) {
$GdSecurityImageId = '';
if (!$GdSecurityImageRememberAnswer) {
SetParam('gd_security_image_id', '');
Oops, something went wrong.

0 comments on commit 1c4e082

Please sign in to comment.