Personal tools

File.pl

From OrganicDesign Wiki

Jump to: navigation, search
Image:legacy.png
Legacy: This article describes a concept that has been superseded in the course of ongoing development on the Organic Design wiki. Please do not develop this any further or base work on this concept, this is only useful for a historic record of work done. You may find a link to the currently used concept or function in this article, if not you can contact the author to find out what has taken the place of this legacy item.


FileSync has now been replaced by a MediaWiki extension called MW:Extension:FileSync. The code is the local Extension:FileSync.php article.
# Return content of passed file
sub readFile {
	my $file = shift;
	if ( open FH, '<', $file ) {
		binmode FH;
		sysread FH, (my $out), -s $file;
		close FH;
		return $out;
		}
	}
 
# Write passed content to passed file
sub writeFile {
	my $file = shift;
	if ( open FH, '>', $file ) {
		binmode FH;
		print FH shift;
		close FH;
		return $file;
		}
	}
 
# Sync local files with articles on local wiki
sub fileSync {
 
	wikiLogin( $::wiki, $::peer, $::pwd1 );
	my $updated = 0;
	my $udfile;
 
	# todo: this should be using %{ links:anchors } = wikiGetList( $::wiki, "$peer/fileSync" )
 
	for ( split /\n/, wikiRawPage( $::wiki, "$peer/fileSync" ) ) {
 
		# Don't allow fileSync to pathnames for now
		if ( /^\*\s*\[*([^\]\|]+)(\|([^\]]+))?\]*/ ) {
			my $page = $1;
			my $file = ( $3 or $1 );
			my $wikiContent = wikiRawPage( $::wiki, $page );
			$wikiContent .= "\n" if $page =~ /\.[hc]$/i;
			my $fileContent = readFile( $file );
			if ( $fileContent ne $wikiContent ) {
				logAdd "updating localFS \"$file\"";
				writeFile( $file, $wikiContent );
				$updated++;
				$udfile = "[[$page|$file]]";
				}
			}
 
		}
 
	# Log summary on local wiki if any updated
	if ( $updated ) {
		my $comment = ($updated-1) ? "$updated articles" : $udfile;
		$comment .= ' updated on local FS';
		wikiPageAppend( $::wiki, $::wikilog, "\n*".localtime()." : $comment", $comment );
		}
 
	logAdd 'Exit';
	}

The GNU Project Debian Linux Ubuntu Linux Wikipedia online encycopedia MediaWiki