#!/usr/bin/perl -w # # This file is part of the LibreOffice project. # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # use MediaWiki::API; use File::Find(); use File::Slurp; use Getopt::Std; use Digest::SHA1 qw(sha1 sha1_hex sha1_base64); # help sub usage { print < upload= name= password= upload-wiki.pl operates on the output of help-to-wiki.py, needing particularly these: wiki/ - directory with all the pages generated out of the help .xhp files images.txt - list of the images used in help Additionally you need: images/ - directory with an unpack of images_tango.zip EOM exit 1; } %options = (); getopts( "hipr", \%options ); usage() if ( defined $options{h} ); my $upload_images = 0; my $upload_pages = 1; my $upload_redirects = 0; $upload_images = 1 if ( defined $options{i} ); $upload_pages = 0 if ( defined $options{p} ); $upload_redirects = 1 if ( defined $options{r} ); # first of all, read the configuration from wikisetup.txt my ( $url, $upload_url, $name, $password ); if ( ! open( IN, "wikisetup.txt" ) ) { print "Missing wikisetup.txt\n\n"; usage(); } while ( my $line = ) { if ( $line =~ /^([^=]*)=(.*)$/ ) { my $k = $1; my $v = $2; chomp $k; chomp $v; if ( $k eq 'wiki' ) { $url = $v; } elsif ( $k eq 'upload' ) { $upload_url = $v; } elsif ( $k eq 'name' ) { $name = $v; } elsif ( $k eq 'password' ) { $password = $v; } } } close( IN ); if ( !defined( $url ) || !defined( $upload_url ) || !defined( $name ) || !defined( $password ) ) { print "wikisetup.txt does not contain all the info.\n\n"; usage(); } if ( ! -d 'wiki' ) { print "Missing the wiki/ subdir, re-run help-to-wiki.py.\n\n"; usage(); } if ( $upload_images ) { if ( ! -f 'images.txt' ) { print "Missing images.txt, re-run help-to-wiki.py.\n\n"; usage(); } if ( ! -d 'images' ) { print "Missing images/ subdir - mkdir images ; cd images ; unzip /path/to/images_tango.zip\n\n"; usage(); } } $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0; # initialize the wiki my $mw = MediaWiki::API->new(); $mw->{config}->{api_url} = $url; $mw->{config}->{upload_url} = $upload_url; # log in to the wiki $mw->login( { lgname => $name, lgpassword => $password } ) || die $mw->{error}->{code} . ': ' . $mw->{error}->{details}; # upload the articles sub upload_article { -f || return; my $pagename = $File::Find::name; $pagename =~ s/^wiki\///; $pagename =~ s/\/MAIN$//; $pagename =~ s/%2F/\//g; # pages starting with lowercase 's' are redirects if ( $pagename =~ /^s/ ) { return if ( !$upload_redirects ); } else { return if ( !$upload_pages ); } my $text = read_file( $_ ); RETRY: print "Uploading page '$pagename'\n"; unless ( $mw->edit( { action => 'edit', title => $pagename, text => $text }, { skip_encoding => 1 } ) ) { print 'Error: ' . $mw->{error}->{code} . ': ' . $mw->{error}->{details} . "\n"; print "Waiting for 10 seconds...\n"; sleep 10; print "Retry!\n"; goto RETRY; } } File::Find::find( {wanted => \&upload_article}, 'wiki/' ); # upload the images if ( $upload_images ) { open( IN, "images.txt" ) || usage(); my $imagename = ''; my $imageuploadmsg = ''; my $image = ''; while ( my $line = ) { chomp( $line ); my $fname = "images/$line"; if ( ! -f $fname ) { print "Image '$fname' not found, skipped.\n"; next; } if ( ! $fname =~ /\.(png|gif|jpg|jpeg)$/ ) { print "Image '$line' ignored, not a jpg/png/gif.\n"; next; } $imagename = $line; if ( $line =~ /\/([^\/]*)$/ ) { $imagename = $1; } sub upload_file_to_mw { $mw->upload( { title => 'File:'.$imagename, summary => $imageuploadmsg, data => $image } ) || die $mw->{error}->{code} . ': ' . $mw->{error}->{details}; } $image = read_file( $fname ); # don't reupload an image if it is already present - otherwise it only bloats the wiki my $imagesha1 = sha1_hex($image); # get the sha1 request directly from the wiki my $mwquery = $mw->api( { action => 'query', prop => 'imageinfo', iiprop => 'sha1', titles => 'File:'.$imagename } ); my $mwimagesha1 = ""; #FIXME: bad style, this foreach should consist only ONE imageid --> do that nicelier foreach my $imageid (keys $mwquery->{'query'}{'pages'}) { $mwimagesha1 = $mwquery->{'query'}{'pages'}{$imageid}{'imageinfo'}->[0]->{'sha1'}; } if (($imagesha1 ne $mwimagesha1) and ($mwimagesha1 ne '')) { print "Updating image '$imagename', sha1 is different from already uploaded image.\n"; $imageuploadmsg = 'Updating image.'; upload_file_to_mw(); } elsif ($mwimagesha1 eq '') { print "Initial upload of image '$imagename'\n"; $imageuploadmsg = 'Initial upload.'; upload_file_to_mw(); } else { print "Skipping image '$imagename', sha1 identically to already uploaded image.\n"; } } } # clean up $mw->logout(); # vim:set shiftwidth=4 softtabstop=4 expandtab: reoffice-4-1-6+backports LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2022-08-18Move tools/diagnose_ex.h to comphelper/diagnose_ex.hxxStephan Bergmann
...so that its TOOLS_WARN_EXCEPTION can be used in comphelper/source/misc/logging.cxx in a follow-up commit. (And while at it, rename from diangose_ex.h to the more appropriate diagnose_ex.hxx. The comphelper module is sufficiently low-level for this immediate use case, so use that at least for now; o3tl might be even more suitable but doesn't have a Library until now. Also, for the immediate use case it would have sufficed to only break DbgGetCaughtException, exceptionToString, TOOLS_WARN_EXCEPTION, TOOLS_WARN_EXCEPTION_IF, and TOOLS_INFO_EXCEPTION out of include/tools/diagnose_ex.h into an additional new include/comphelper/diagnose_ex.hxx, but its probably easier overall to just move the complete include file as is.) Change-Id: I9f3222d4ccf1a9ac29d7eb9ba1530d53e2affaee Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138451 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-03-11tdf#42949 Fix IWYU warnings in extensions/*/*cxxGabor Kelemen
Except for Windows-specific parts Found with bin/find-unneeded-includes Only removal proposals are dealt with here. Change-Id: I36c81bced6c8b1567e52ba3a4a688a963f294bb0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90179 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
2019-12-26use more TOOLS_WARN_EXCEPTIONNoel Grandin
so we get more useful log messages when stuff goes wrong Change-Id: Ia55db7ab1a4d79b0f281673fbbb06c61745fa89e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85829 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-07-19loplugin:referencecasting in extensionsNoel Grandin
Change-Id: Ib03be019b2fedc67b3114c107162722eabce0218 Reviewed-on: https://gerrit.libreoffice.org/75955 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2018-09-17New loplugin:externalStephan Bergmann
...warning about (for now only) functions and variables with external linkage that likely don't need it. The problems with moving entities into unnamed namespacs and breaking ADL (as alluded to in comments in compilerplugins/clang/external.cxx) are illustrated by the fact that while struct S1 { int f() { return 0; } }; int f(S1 s) { return s.f(); } namespace N { struct S2: S1 { int f() { return 1; } }; int f(S2 s) { return s.f(); } } int main() { return f(N::S2()); } returns 1, both moving just the struct S2 into an nunnamed namespace, struct S1 { int f() { return 0; } }; int f(S1 s) { return s.f(); } namespace N { namespace { struct S2: S1 { int f() { return 1; } }; } int f(S2 s) { return s.f(); } } int main() { return f(N::S2()); } as well as moving just the function f overload into an unnamed namespace, struct S1 { int f() { return 0; } }; int f(S1 s) { return s.f(); } namespace N { struct S2: S1 { int f() { return 1; } }; namespace { int f(S2 s) { return s.f(); } } } int main() { return f(N::S2()); } would each change the program to return 0 instead. Change-Id: I4d09f7ac5e8f9bcd6e6bde4712608444b642265c Reviewed-on: https://gerrit.libreoffice.org/60539 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>