return $this->getSize() == 0;
}
+ public function equals( Content $that ) {
+ if ( empty( $that ) ) return false;
+ if ( $that === $this ) return true;
+ if ( $that->getModelName() !== $this->getModelName() ) return false;
+
+ return $this->getNativeData() == $that->getNativeData();
+ }
+
/**
* Returns true if this content is countable as a "real" wiki page, provided
* that it's also in a countable location (e.g. a current revision in the main namespace).
# XXX: isCacheable( ) # can/should we do this here?
# TODO: WikiPage::getUndoText( Revision $undo, Revision $undoafter = null )
- # TODO: WikiPage::getAutosummary( $oldtext, $text, $flags )
# TODO: EditPage::getPreloadedText( $preload ) // $wgParser->getPreloadText
# TODO: tie into EditPage, make it use Content-objects throughout, make edit form aware of content model and format
- # TODO: tie into WikiPage, make it use Content-objects throughout, especially in doEdit(), doDelete(), etc
+ # TODO: tie into WikiPage, make it use Content-objects throughout, especially in doEdit(), doDelete(), updateRevisionOn(), etc
# TODO: make model-aware diff view!
# TODO: handle ImagePage and CategoryPage
return $reason;
}
+ /**
+ * Get the Content object that needs to be saved in order to undo all revisions
+ * between $undo and $undoafter. Revisions must belong to the same page,
+ * must exist and must not be deleted
+ * @param $undo Revision
+ * @param $undoafter Revision Must be an earlier revision than $undo
+ * @return mixed string on success, false on failure
+ */
+ public function getUndoContent( Revision $current, Revision $undo, Revision $undoafter ) {
+ $cur_content = $current->getContent();
+
+ if ( empty( $cur_content ) ) {
+ return false; // no page
+ }
+
+ $undo_content = $undo->getContent();
+ $undoafter_content = $undoafter->getContent();
- #TODO: cover patch/undo just like merge3.
+ if ( $cur_content->equals( $undo_content ) ) {
+ # No use doing a merge if it's just a straight revert.
+ return $undoafter_content;
+ }
+
+ $undone_content = $this->merge3( $undo_content, $undoafter_content, $cur_content );
+
+ return $undone_content;
+ }
#TODO: how to handle extra message for JS/CSS previews??
#TODO: Article::showCssOrJsPage ---> specialized classes!
return $this->getText( Revision::RAW );
}
+ /**
+ * Get the content of the current revision. No side-effects...
+ *
+ * @return Contet|false The text of the current revision
+ */
protected function getNativeData() {
$content = $this->getContent( Revision::RAW );
if ( !$content ) return null;
* @param $undo Revision
* @param $undoafter Revision Must be an earlier revision than $undo
* @return mixed string on success, false on failure
+ * @deprecated since 1.20: use ContentHandler::getUndoContent() instead.
*/
- public function getUndoText( Revision $undo, Revision $undoafter = null ) { #FIXME: move undo logic to ContentHandler
- $cur_text = $this->getRawText();
- if ( $cur_text === false ) {
- return false; // no page
- }
- $undo_text = $undo->getText();
- $undoafter_text = $undoafter->getText();
-
- if ( $cur_text == $undo_text ) {
- # No use doing a merge if it's just a straight revert.
- return $undoafter_text;
- }
+ public function getUndoText( Revision $undo, Revision $undoafter = null ) { #FIXME: replace usages.
+ $this->loadLastEdit();
- $undone_text = '';
+ if ( $this->mLastRevision ) {
+ $handler = ContentHandler::getForTitle( $this->getTitle() );
+ $undone = $handler->getUndoContent( $this->mLastRevision, $undo, $undoafter );
- if ( !wfMerge( $undo_text, $undoafter_text, $cur_text, $undone_text ) ) {
- return false;
- }
+ return ContentHandler::getContentText( $undone );
+ }
- return $undone_text;
+ return false;
}
/**