+TO_ENCODE = ('title', 'editor')
+PERSISTENCE_RADIUS=7
+
+# this is a simple override of mwpersistence.DiffState that doesn't do anything special for reverts.
+class WikiqDiffState(mwpersistence.DiffState):
+ def _update(self, text=None, checksum=None, opdocs=None, revision=None):
+ if checksum is None:
+ if text is None:
+ raise TypeError("Either 'text' or 'checksum' must be " +
+ "specified.")
+ else:
+ checksum = sha1(bytes(text, 'utf8')).hexdigest()
+
+ current_version = Version()
+
+ # the main difference we have is that we don't do anything special for reverts
+ if opdocs is not None:
+ transition = apply_opdocs(opdocs, self.last.tokens or [])
+ current_version.tokens, _, _ = transition
+ else:
+ # NOTICE: HEAVY COMPUTATION HERE!!!
+ #
+ # Diffs usually run in O(n^2) -- O(n^3) time and most
+ # tokenizers produce a lot of tokens.
+ if self.diff_processor is None:
+ raise RuntimeError("DiffState cannot process raw text " +
+ "without a diff_engine specified.")
+ operations, _, current_tokens = \
+ self.diff_processor.process(text, token_class=Token)
+
+ transition = apply_operations(operations,
+ self.last.tokens or [],
+ current_tokens)
+ current_version.tokens, _, _ = transition
+
+ # Record persistence
+ persist_revision_once(current_version.tokens, revision)
+
+ # Update last version
+ self.last = current_version
+
+ # Return the tranisitoned state
+ return transition