Automate Moving PRFiles to Web Server

Take a picture with a camera

In Pier pictures can be added to a page by creating a PRFile, or by using a webserver and the IMG html tag. In the past I have avoided PRFiles because:

  • The IMG can include ALT text (alternative text), PRFiles do not have a field for this
  • using a separate webserver reduces the load on the machine serving Pier (in terms of both disk space and CPU)

Previously there were discussions on the Seaside/Pier newsgroup about saving pictures in PRFiles causing image bloat. In several tests I've ran, this didn't seem to be a problem - additional space taken by edits or space cleared by garbage collection well outpaced space changes from adding PRFiles. It may be that a test running over several weeks would indicate an issue.

Unfortunately using S3 or a separate image server requires a fair amount of technical skill for the wiki users. While I was on vacation I only had access to a phone and lacked the keys to add pictures to my usual S3 bucket, so using PRFiles were useful in this situation.

Why - what is the error if upload is used? Saving files in Pier does not appear to impact the image size significantly, it also puts more stress on the Pier system. Unfortunately the images served by Pier do not have alt-text, so using an external web server (like Amazon S3) allows this through HTML. Pictures also take up more space than text.

How:

  1. Create an embedded link for the picture like this and save the page:

    {{{html: <div style="clear: both">}}} *Picture_Name.png|embedded=true* {{{html: </div>}}}

    The HTML causes text below the picture to be on a separate line, otherwise it looks like:

    Sample text before an image, followed by an empty line.

    Sample text after the picture, with an empty line above and below. Note that the text is wrapped around the image, including:

    • lists
    • but not block-elements like lines
    • for the picture at the top of this page, if the div surrounding the img is removed the it is no longer right aligned

  2. In the page click the Picture_Name.png link and choose PRFile for the type
  3. Copy the name, save without uploading anything
  4. Search for the file name, click on the link that has the file name
  5. Choose edit
  6. Browse and find the file. Save without clicking upload
  7. The picture should be on the page

Questions:

  • Can I get rid of the upload button? It is from MAFileUploadComponent>>#renderUploadOn:
  • Why is the File: Input is conflicting with concurrent modification error popping up for the Toshiba laptop, but not for the one on the VC. Is there code cached somewhere? Could be Input is Conflicting with Concurrent Modification issues.

reportOfHealthCheckOnPageAt: aPathString

	| reportPage pagesWithUnusualChildren linksWithRaw |
	self guessTodoFromPath: aPathString.
	pagesWithUnusualChildren := Set new.
	self kernel root enumerator with all do: [ :e |
		(e childrenDecoration children anySatisfy: [ :child |
			 (#( #PRPage #PRToDo #PRFile #PBBlog #PRComponent #PBPost #PRToDoTask
			     #PBComment #PRWorkoutLog ) includes: child class name) not ])
			ifTrue: [ pagesWithUnusualChildren add: e decorated absolutePath ] ].
	linksWithRaw := Set new.
	self kernel root enumerator with all do: [ :page |
		page outgoingReferences do: [ :link |
			(link children anySatisfy: [ :child | child class = PRRaw ])
				ifTrue: [ linksWithRaw add: page absolutePath ] ] ].
	(reportPage := PRPathLookup start: self kernel root path: aPathString)
		ifNotNil: [
			reportPage contents: (String streamContents: [ :stream |
					 self class checkFSSpace
						 ifTrue: [
							 self
								 printReportHeaderOn: stream
								 fields:
								 '|!Count of Pages with Unusual Children|!Links with Raw HTML|!Image Size|!Disk Space' ]
						 ifFalse: [
							 self
								 printReportHeaderOn: stream
								 fields:
								 '|!Count of Pages with Unusual Children|!Links with Raw HTML|!Image Size' ].
					 stream nextPut: $|.
					 pagesWithUnusualChildren isEmpty
						 ifTrue: [ stream nextPutAll: 'none' ]
						 ifFalse: [
							 pagesWithUnusualChildren do: [ :string |
								 stream
									 nextPut: $*;
									 nextPutAll: string;
									 nextPut: $*;
									 space ] ].
					 stream nextPut: $|.
					 linksWithRaw isEmpty
						 ifTrue: [ stream nextPutAll: 'none' ]
						 ifFalse: [
							 linksWithRaw do: [ :string |
								 stream
									 nextPut: $*;
									 nextPutAll: string;
									 nextPutAll: '* ' ] ].
					 stream
						 nextPutAll: ' | ';
						 nextPutAll: Smalltalk imageFile humanReadableSize.
					 self class checkFSSpace ifTrue: [
						 stream
							 nextPutAll: ' | ';
							 nextPutAll: self runCheckDiskSpace ] ]) ]

reportOfHealthCheckOnPageAt: aPathString

	| reportPage pagesWithUnusualChildren linksWithRaw |
	self guessTodoFromPath: aPathString.
	pagesWithUnusualChildren := Set new.
	self kernel root enumerator with all do: [ :e |
		(e childrenDecoration children anySatisfy: [ :child |
			 (#( #PRPage #PRToDo #PRFile #PBBlog #PRComponent #PBPost #PRToDoTask
			     #PBComment #PRWorkoutLog ) includes: child class name) not ])
			ifTrue: [ pagesWithUnusualChildren add: e decorated absolutePath ] ].
	linksWithRaw := Set new.
	self kernel root enumerator with all do: [ :page |
		page outgoingReferences do: [ :link |
			(link children anySatisfy: [ :child | child class = PRRaw ])
				ifTrue: [ linksWithRaw add: page absolutePath ] ] ].
	(reportPage := PRPathLookup start: self kernel root path: aPathString)
		ifNotNil: [
			reportPage contents: (String streamContents: [ :stream |
					 self class checkFSSpace
						 ifTrue: [
							 self
								 printReportHeaderOn: stream
								 fields:
								 '|!Count of Pages with Unusual Children|!Links with Raw HTML|!Image Size|!Disk Space' ]
						 ifFalse: [
							 self
								 printReportHeaderOn: stream
								 fields:
								 '|!Count of Pages with Unusual Children|!Links with Raw HTML|!Image Size' ].
					 stream nextPut: $|.
					 pagesWithUnusualChildren isEmpty
						 ifTrue: [ stream nextPutAll: 'none' ]
						 ifFalse: [
							 pagesWithUnusualChildren do: [ :string |
								 stream
									 nextPut: $*;
									 nextPutAll: string;
									 nextPut: $*;
									 space ] ].
					 stream nextPut: $|.
					 linksWithRaw isEmpty
						 ifTrue: [ stream nextPutAll: 'none' ]
						 ifFalse: [
							 linksWithRaw do: [ :string |
								 stream
									 nextPut: $*;
									 nextPutAll: string;
									 nextPutAll: '* ' ] ].
					 stream
						 nextPutAll: ' | ';
						 nextPutAll: Smalltalk imageFile humanReadableSize.
					 self class checkFSSpace ifTrue: [
						 stream
							 nextPutAll: ' | ';
							 nextPutAll: self runCheckDiskSpace ] ]) ]
Posted by John Borden with tags Pier link