aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/codebase.rst4
-rw-r--r--docs/conf.py4
-rw-r--r--docs/contributinghowto.rst4
-rw-r--r--docs/designdecisions.rst4
-rw-r--r--docs/git.rst198
-rw-r--r--docs/hackinghowto.rst4
-rw-r--r--mediagoblin/process_media/__init__.py18
-rw-r--r--mediagoblin/tests/test_util.py19
-rw-r--r--mediagoblin/util.py27
9 files changed, 240 insertions, 42 deletions
diff --git a/docs/codebase.rst b/docs/codebase.rst
index 4f5f215f..898eadfe 100644
--- a/docs/codebase.rst
+++ b/docs/codebase.rst
@@ -4,6 +4,10 @@
Codebase Documentation
========================
+.. contents:: Sections
+ :local:
+
+
This chapter covers the libraries that GNU MediaGoblin uses as well as
various recipes for getting things done.
diff --git a/docs/conf.py b/docs/conf.py
index fedaf33c..0e75a617 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -48,9 +48,9 @@ copyright = u'2011, Free Software Foundation, Inc and contributors'
# built documents.
#
# The short X.Y version.
-version = '0.0.1'
+version = '0.0.2'
# The full version, including alpha/beta/rc tags.
-release = '0.0.1'
+release = '0.0.2'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
diff --git a/docs/contributinghowto.rst b/docs/contributinghowto.rst
index e980a5e0..06d2814e 100644
--- a/docs/contributinghowto.rst
+++ b/docs/contributinghowto.rst
@@ -4,6 +4,10 @@
Contributing HOWTO
====================
+.. contents:: Sections
+ :local:
+
+
.. _join-the-community-section:
Join the community!
diff --git a/docs/designdecisions.rst b/docs/designdecisions.rst
index 50dfe3e8..afa1e26b 100644
--- a/docs/designdecisions.rst
+++ b/docs/designdecisions.rst
@@ -4,6 +4,10 @@
Design Decisions
==================
+.. contents:: Sections
+ :local:
+
+
This chapter talks a bit about design decisions.
diff --git a/docs/git.rst b/docs/git.rst
index 0db1dacf..8eb038b2 100644
--- a/docs/git.rst
+++ b/docs/git.rst
@@ -2,11 +2,21 @@
Git, Cloning and Patches
==========================
-GNU MediaGoblin uses git for all our version control and we have
-the repositories hosted on `Gitorious <http://gitorious.org/>`_.
+.. contents:: Sections
+ :local:
-We have two repositories. One is for the project and the other is for
-the project website.
+
+GNU MediaGoblin uses git for all our version control and we have the
+repositories hosted on `Gitorious <http://gitorious.org/>`_. We have
+two repositories:
+
+* MediaGoblin software: http://gitorious.org/mediagoblin/mediagoblin
+* MediaGoblin website: http://gitorious.org/mediagoblin/mediagoblin-website
+
+It's most likely you want to look at the software repository--not the
+website one.
+
+The rest of this chapter talks about using the software repository.
How to clone the project
@@ -17,49 +27,173 @@ Do::
git clone git://gitorious.org/mediagoblin/mediagoblin.git
-How to send in patches
-======================
+How to contribute changes
+=========================
+
+Tie your changes to issues in the issue tracker
+-----------------------------------------------
All patches should be tied to issues in the `issue tracker
-<http://bugs.foocorp.net/projects/mediagoblin/issues>`_.
-That makes it a lot easier for everyone to track proposed changes and
-make sure your hard work doesn't get dropped on the floor!
+<http://bugs.foocorp.net/projects/mediagoblin/issues>`_. That makes
+it a lot easier for everyone to track proposed changes and make sure
+your hard work doesn't get dropped on the floor! If there isn't an
+issue for what you're working on, please create one. The better the
+description of what it is you're trying to fix/implement, the better
+everyone else is able to understand why you're doing what you're
+doing.
+
+
+Use bugfix branches to make changes
+-----------------------------------
+
+The best way to isolate your changes is to create a branch based off
+of the MediaGoblin repository master branch, do the changes related to
+that one issue there, and then let us know how to get it.
+
+It's much easier on us if you isolate your changes to a branch focused
+on the issue. Then we don't have to sift through things.
+
+It's much easier on you if you isolate your changes to a branch
+focused on the issue. Then when we merge your changes in, you just
+have to do a ``git fetch`` and that's it. This is especially true if
+we reject some of your changes, but accept others or otherwise tweak
+your changes.
+
+Further, if you isolate your changes to a branch, then you can work on
+multiple issues at the same time and they don't conflict with one
+another.
+
+
+Properly document your changes
+------------------------------
+
+Include comments in the code.
+
+Write comprehensive commit messages. The better your commit message
+is at describing what you did and why, the easier it is for us to
+quickly accept your patch.
+
+Write comprehensive comments in the issue tracker about what you're
+doing and why.
+
+
+How to send us your changes
+---------------------------
+
+There are three ways to let us know how to get it:
+
+1. (preferred) **push changes to publicly available git clone and let
+ us know where to find it**
+
+ Push your feature/bugfix/issue branch to your publicly available
+ git clone and add a comment to the issue with the url for your
+ clone and the branch to look at.
+
+2. **attaching the patch files to the issue**
+
+ Run::
+
+ git format-patch -o patches <remote>/master
+
+ Then tar up the newly created ``patches`` directory and attach the
+ directory to the issue.
+
+
+Example workflow
+================
+Here's an example workflow.
+
+
+Contributing changes
+--------------------
+
+Slartibartfast from the planet Magrathea far off in the universe has
+decided that he is bored with fjords and wants to fix issue 42 and
+send us the changes.
+
+Slartibartfast has cloned the MediaGoblin repository and his clone
+lives on gitorious.
+
+Slartibartfast works locally. The remote named ``origin`` points to
+his clone on gitorious. The remote named ``gmg`` points to the
+MediaGoblin repository.
+
+Slartibartfast does the following:
+
+1. Fetches the latest from the MediaGoblin repository::
+
+ git fetch --all -p
+
+2. Creates a branch from the tip of the MediaGoblin repository (the
+ remote is named ``gmg``) master branch called ``issue_42``::
+
+ git checkout -b issue_42 gmg/master
+
+3. Slartibartfast works hard on his changes in the ``issue_42``
+ branch. When done, he wants to notify us that he has made changes
+ he wants us to see.
+
+4. Slartibartfast pushes his changes to his clone (the remote is named
+ ``origin``)::
+
+ git push origin issue_42
+
+5. Slartibartfast adds a comment to issue 42 with the url for his
+ repository and the name of the branch he put the code in. He also
+ explains what he did and why it addresses the issue.
+
+
+Updating a contribution
+-----------------------
+
+Slartibartfast brushes his hands off with the sense of accomplishment
+that comes with the knowledge of a job well done. He stands, wanders
+over to get a cup of water, then realizes that he forgot to run the
+unit tests!
+
+He runs the unit tests and discovers there's a bug in the code!
+
+Then he does this:
+
+1. He checks out the ``issue_42`` branch::
-If there isn't an issue for what you're working on, please create
-one. The better the description of what it is you're trying to
-fix/implement, the better everyone else is able to understand why
-you're doing what you're doing.
+ git checkout issue_42
-There are two ways you could send in a patch.
+2. He fixes the bug and checks it into the ``issue_42`` branch.
+3. He pushes his changes to his clone (the remote is named ``origin``)::
-How to send in a patch from a publicly available clone
-------------------------------------------------------
+ git push origin issue_42
-Add a comment to the issue you're working on with the following bits
-of information:
+4. He adds another comment to issue 42 explaining about the mistake
+ and how he fixed it and that he's pushed the new change to the
+ ``issue_42`` branch of his publicly available clone.
-* the url for your clone
-* the revs you want looked at
-* any details, questions, or other things that should be known
+What happens next
+-----------------
-How to send in a patch if you don't have a publicly available clone
--------------------------------------------------------------------
+Slartibartfast is once again happy with his work. He finds issue 42
+in the issue tracker and adds a comment saying he submitted a merge
+request with his changes and explains what they are.
-Assuming that the remote is our repository on gitorious and the branch
-to compare against is master, do the following:
+Later, someone checks out his code and finds a problem with it. He
+adds a comment to the issue tracker specifying the problem and asks
+Slartibartfast to fix it. Slartibartfst goes through the above steps
+again, fixes the issue, pushes it to his ``issue_42`` branch and adds
+another comment to the issue tracker about how he fixed it.
-1. checkout the branch you did your work in
-2. do::
+Later, someone checks out his code and is happy with it. Someone
+pulls it into the master branch of the MediaGoblin repository and adds
+another comment to the issue and probably closes the issue out.
- git format-patch -o patches origin/master
+Slartibartfast is notified of this. Slartibartfast does a::
-3. either:
+ git fetch --all
- * tar up and attach the tarball to the issue you're working on, OR
- * attach the patch files to the issue you're working on one at a
- time
+The changes show up in the ``master`` branch of the ``gmg`` remote.
+Slartibartfast now deletes his ``issue_42`` branch because he doesn't
+need it anymore.
How to learn git
diff --git a/docs/hackinghowto.rst b/docs/hackinghowto.rst
index a9aadb62..d8bb9330 100644
--- a/docs/hackinghowto.rst
+++ b/docs/hackinghowto.rst
@@ -4,6 +4,10 @@
Hacking HOWTO
===============
+.. contents:: Sections
+ :local:
+
+
So you want to hack on GNU MediaGoblin?
=======================================
diff --git a/mediagoblin/process_media/__init__.py b/mediagoblin/process_media/__init__.py
index f37bf080..0dce1418 100644
--- a/mediagoblin/process_media/__init__.py
+++ b/mediagoblin/process_media/__init__.py
@@ -24,6 +24,13 @@ from mediagoblin import mg_globals as mgg
THUMB_SIZE = 200, 200
+def create_pub_filepath(entry, filename):
+ return mgg.public_store.get_unique_filepath(
+ ['media_entries',
+ unicode(entry['_id']),
+ filename])
+
+
@task
def process_media_initial(media_id):
workbench = mgg.workbench_manager.create_workbench()
@@ -45,10 +52,7 @@ def process_media_initial(media_id):
if thumb.mode != "RGB":
thumb = thumb.convert("RGB")
- thumb_filepath = mgg.public_store.get_unique_filepath(
- ['media_entries',
- unicode(entry['_id']),
- 'thumbnail.jpg'])
+ thumb_filepath = create_pub_filepath(entry, 'thumbnail.jpg')
thumb_file = mgg.public_store.get_file(thumb_filepath, 'w')
with thumb_file:
@@ -59,15 +63,13 @@ def process_media_initial(media_id):
queued_file = file(queued_filename, 'rb')
with queued_file:
- main_filepath = mgg.public_store.get_unique_filepath(
- ['media_entries',
- unicode(entry['_id']),
- queued_filepath[-1]])
+ main_filepath = create_pub_filepath(entry, queued_filepath[-1])
with mgg.public_store.get_file(main_filepath, 'wb') as main_file:
main_file.write(queued_file.read())
mgg.queue_store.delete_file(queued_filepath)
+ entry['queued_media_file'] = []
media_files_dict = entry.setdefault('media_files', {})
media_files_dict['thumb'] = thumb_filepath
media_files_dict['main'] = main_filepath
diff --git a/mediagoblin/tests/test_util.py b/mediagoblin/tests/test_util.py
index 7b00a074..75e28aca 100644
--- a/mediagoblin/tests/test_util.py
+++ b/mediagoblin/tests/test_util.py
@@ -103,3 +103,22 @@ def test_locale_to_lower_lower():
# crazy renditions. Useful?
assert util.locale_to_lower_lower('en-US') == 'en-us'
assert util.locale_to_lower_lower('en_us') == 'en-us'
+
+
+def test_html_cleaner():
+ # Remove images
+ result = util.clean_html(
+ '<p>Hi everybody! '
+ '<img src="http://example.org/huge-purple-barney.png" /></p>\n'
+ '<p>:)</p>')
+ assert result == (
+ '<div>'
+ '<p>Hi everybody! </p>\n'
+ '<p>:)</p>'
+ '</div>')
+
+ # Remove evil javascript
+ result = util.clean_html(
+ '<p><a href="javascript:nasty_surprise">innocent link!</a></p>')
+ assert result == (
+ '<p><a href="">innocent link!</a></p>')
diff --git a/mediagoblin/util.py b/mediagoblin/util.py
index f29f8570..fc380f41 100644
--- a/mediagoblin/util.py
+++ b/mediagoblin/util.py
@@ -30,6 +30,7 @@ import jinja2
import translitcodec
from paste.deploy.loadwsgi import NicerConfigParser
from webob import Response, exc
+from lxml.html.clean import Cleaner
from mediagoblin import mg_globals
from mediagoblin.db.util import ObjectId
@@ -373,6 +374,32 @@ def read_config_file(conf_file):
return mgoblin_conf
+# A super strict version of the lxml.html cleaner class
+HTML_CLEANER = Cleaner(
+ scripts=True,
+ javascript=True,
+ comments=True,
+ style=True,
+ links=True,
+ page_structure=True,
+ processing_instructions=True,
+ embedded=True,
+ frames=True,
+ forms=True,
+ annoying_tags=True,
+ allow_tags=[
+ 'div', 'b', 'i', 'em', 'strong', 'p', 'ul', 'ol', 'li', 'a', 'br'],
+ remove_unknown_tags=False, # can't be used with allow_tags
+ safe_attrs_only=True,
+ add_nofollow=True, # for now
+ host_whitelist=(),
+ whitelist_tags=set([]))
+
+
+def clean_html(html):
+ return HTML_CLEANER.clean_html(html)
+
+
SETUP_GETTEXTS = {}
def setup_gettext(locale):