From 2b1127fe90d0122e6650c6c7761aa85707e6201f Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sun, 19 Dec 2004 12:21:29 +0000 Subject: [PATCH] Start splitting back-end functions from the Article user-interface class. Fix Special:Export for new schema. --- includes/Article.php | 107 +-------- includes/DifferenceEngine.php | 93 +++----- includes/HistoryBlob.php | 2 +- includes/MessageCache.php | 6 +- includes/RawPage.php | 34 ++- includes/Revision.php | 345 ++++++++++++++++++++++++++++++ includes/SpecialExport.php | 73 ++++--- includes/SpecialRecentchanges.php | 44 ++-- includes/SpecialSearch.php | 3 +- includes/SpecialUndelete.php | 8 +- maintenance/compressOld.inc | 6 +- tests/ArticleTest.php | 28 +-- 12 files changed, 493 insertions(+), 256 deletions(-) create mode 100644 includes/Revision.php diff --git a/includes/Article.php b/includes/Article.php index afeaacd383..c6f63cce39 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -7,7 +7,8 @@ /** * Need the CacheManager to be loaded */ -require_once ( 'CacheManager.php' ); +require_once( 'CacheManager.php' ); +require_once( 'Revision.php' ); $wgArticleCurContentFields = false; $wgArticleOldContentFields = false; @@ -58,96 +59,6 @@ class Article { $this->mForUpdate = false; } - /** - * Get revision text associated with an old or archive row - * $row is usually an object from wfFetchRow(), both the flags and the text - * field must be included - * @static - * @param integer $row Id of a row - * @param string $prefix table prefix (default 'old_') - * @return string $text|false the text requested - */ - function getRevisionText( $row, $prefix = 'old_' ) { - $fname = 'Article::getRevisionText'; - wfProfileIn( $fname ); - - # Get data - $textField = $prefix . 'text'; - $flagsField = $prefix . 'flags'; - - if( isset( $row->$flagsField ) ) { - $flags = explode( ',', $row->$flagsField ); - } else { - $flags = array(); - } - - if( isset( $row->$textField ) ) { - $text = $row->$textField; - } else { - wfProfileOut( $fname ); - return false; - } - - if( in_array( 'gzip', $flags ) ) { - # Deal with optional compression of archived pages. - # This can be done periodically via maintenance/compressOld.php, and - # as pages are saved if $wgCompressRevisions is set. - $text = gzinflate( $text ); - } - - if( in_array( 'object', $flags ) ) { - # Generic compressed storage - $obj = unserialize( $text ); - - # Bugger, corrupted my test database by double-serializing - if ( !is_object( $obj ) ) { - $obj = unserialize( $obj ); - } - - $text = $obj->getText(); - } - - global $wgLegacyEncoding; - if( $wgLegacyEncoding && !in_array( 'utf-8', $flags ) ) { - # Old revisions kept around in a legacy encoding? - # Upconvert on demand. - global $wgInputEncoding, $wgContLang; - $text = $wgContLang->iconv( $wgLegacyEncoding, $wgInputEncoding, $text ); - } - wfProfileOut( $fname ); - return $text; - } - - /** - * If $wgCompressRevisions is enabled, we will compress data. - * The input string is modified in place. - * Return value is the flags field: contains 'gzip' if the - * data is compressed, and 'utf-8' if we're saving in UTF-8 - * mode. - * - * @static - * @param mixed $text reference to a text - * @return string - */ - function compressRevisionText( &$text ) { - global $wgCompressRevisions, $wgUseLatin1; - $flags = array(); - if( !$wgUseLatin1 ) { - # Revisions not marked this way will be converted - # on load if $wgLegacyCharset is set in the future. - $flags[] = 'utf-8'; - } - if( $wgCompressRevisions ) { - if( function_exists( 'gzdeflate' ) ) { - $text = gzdeflate( $text ); - $flags[] = 'gzip'; - } else { - wfDebug( "Article::compressRevisionText() -- no zlib support, not compressing\n" ); - } - } - return implode( ',', $flags ); - } - /** * Note that getContent/loadContent may follow redirects if * not told otherwise, and so may cause a change to mTitle. @@ -394,7 +305,7 @@ class Article { # If we got a redirect, follow it (unless we've been told # not to by either the function parameter or the query if ( !$oldid && !$noredir ) { - $rt = Title::newFromRedirect( Article::getRevisionText( $s ) ); + $rt = Title::newFromRedirect( Revision::getRevisionText( $s ) ); # process if title object is valid and not special:userlogout if ( $rt && ! ( $rt->getNamespace() == NS_SPECIAL && $rt->getText() == 'Userlogout' ) ) { # Gotta hand redirects to special pages differently: @@ -443,7 +354,7 @@ class Article { $this->mTitle->mRestrictionsLoaded = true; $this->mTouched = wfTimestamp( TS_MW, $s->page_touched ); - $this->mContent = Article::getRevisionText( $s ); + $this->mContent = Revision::getRevisionText( $s ); $this->mUser = $s->rev_user; $this->mUserText = $s->rev_user_text; @@ -799,7 +710,7 @@ class Article { $isminor = ( $isminor && $wgUser->getID() ) ? 1 : 0; $mungedText = $text; - $flags = Article::compressRevisionText( $mungedText ); + $flags = Revision::compressRevisionText( $mungedText ); $dbw =& wfGetDB( DB_MASTER ); @@ -891,7 +802,7 @@ class Article { $fname ); $obj = $dbw->fetchObject( $result ); $dbw->freeResult( $result ); - $oldtext = Article::getRevisionText( $obj ); + $oldtext = Revision::getRevisionText( $obj ); return $oldtext; } @@ -1026,7 +937,7 @@ class Article { $won = wfInvertTimestamp( $now ); $mungedText = $text; - $flags = Article::compressRevisionText( $newtext ); + $flags = Revision::compressRevisionText( $newtext ); $lastRevision = $dbw->selectField( 'page', 'page_latest', array( 'page_id' => $this->getId() ) ); @@ -1517,7 +1428,7 @@ class Article { $text=$s->cur_text; } else { if($old) { - $text = Article::getRevisionText( $old ); + $text = Revision::getRevisionText( $old ); $blanked = true; } @@ -1849,7 +1760,7 @@ class Article { $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) ); $wgOut->setRobotpolicy( 'noindex,nofollow' ); $wgOut->addHTML( '

' . htmlspecialchars( $newcomment ) . "

\n
\n" ); - $this->updateArticle( Article::getRevisionText( $s ), $newcomment, 1, $this->mTitle->userIsWatching(), $bot ); + $this->updateArticle( Revision::getRevisionText( $s ), $newcomment, 1, $this->mTitle->userIsWatching(), $bot ); Article::onArticleEdit( $this->mTitle ); $wgOut->returnToMain( false ); } diff --git a/includes/DifferenceEngine.php b/includes/DifferenceEngine.php index 360e5f0170..3af5767f30 100644 --- a/includes/DifferenceEngine.php +++ b/includes/DifferenceEngine.php @@ -5,6 +5,8 @@ * @subpackage DifferenceEngine */ +require_once( 'Revision.php' ); + /** * @todo document * @access public @@ -258,79 +260,44 @@ class DifferenceEngine { $fname = 'DifferenceEngine::loadText'; $dbr =& wfGetDB( DB_SLAVE ); - if ( 0 == $this->mNewid || 0 == $this->mOldid ) { - /* Fetch current revision */ - $wgOut->setArticleFlag( true ); - $newLink = $wgTitle->escapeLocalUrl(); + if( $this->mNewid ) { + $this->newRev =& Revision::newFromId( $this->mNewid ); + } else { + $this->newRev =& Revision::newFromTitle( $wgTitle ); + } + + if( $this->newRev->isCurrent() ) { $this->mPagetitle = htmlspecialchars( wfMsg( 'currentrev' ) ); + $this->mNewPage = $wgTitle; + $newLink = $this->mNewPage->escapeLocalUrl(); $this->mNewtitle = "{$this->mPagetitle}"; - $id = $wgTitle->getArticleID(); - - $s = $dbr->selectRow( array( 'page', 'revision', 'text' ), - array( 'old_flags', 'old_text', 'rev_user_text', 'rev_comment' ), - "page_id=$id AND page_id=rev_page AND rev_id=old_id", $fname ); - if ( $s === false ) { - wfDebug( "Unable to load page_id $id\n" ); - return false; - } - - $this->mNewPage = &$wgTitle; - $this->mNewtext = Article::getRevisionText( $s ); - $this->mNewUser = $s->rev_user_text; - $this->mNewComment = $s->rev_comment; } else { - $s = $dbr->selectRow( array( 'page', 'revision', 'text' ), - array( 'page_namespace','page_title','rev_timestamp', 'old_text', - 'old_flags','rev_user_text','rev_comment' ), - "page_id=rev_page AND rev_id=old_id AND rev_id={$this->mNewid}", - $fname ); - - if ( $s === false ) { - wfDebug( "Unable to load old_id {$this->mNewid}\n" ); - return false; - } - - $this->mNewtext = Article::getRevisionText( $s ); - - $t = $wgLang->timeanddate( $s->rev_timestamp, true ); - $this->mNewPage = Title::MakeTitle( $s->page_namespace, $s->page_title ); - $newLink = $wgTitle->escapeLocalUrl ('oldid=' . $this->mNewid); + $this->mNewPage = $this->newRev->getTitle(); + $newLink = $this->mNewPage->escapeLocalUrl ('oldid=' . $this->mNewid ); + $t = $wgLang->timeanddate( $this->newRev->getTimestamp(), true ); $this->mPagetitle = htmlspecialchars( wfMsg( 'revisionasof', $t ) ); $this->mNewtitle = "{$this->mPagetitle}"; - $this->mNewUser = $s->rev_user_text; - $this->mNewComment = $s->rev_comment; } - if ( 0 == $this->mOldid ) { - $s = $dbr->selectRow( 'old', - array( 'old_namespace','old_title','old_timestamp','old_text', 'old_flags','old_user_text','old_comment' ), - array( /* WHERE */ - 'old_namespace' => $this->mNewPage->getNamespace(), - 'old_title' => $this->mNewPage->getDBkey() - ), $fname, array( 'ORDER BY' => 'inverse_timestamp', 'USE INDEX' => 'name_title_timestamp' ) - ); - if ( $s === false ) { - wfDebug( 'Unable to load ' . $this->mNewPage->getPrefixedDBkey() . " from old\n" ); - return false; - } + + if( $this->mOldid ) { + $this->oldRev =& Revision::newFromId( $this->mOldid ); } else { - $s = $dbr->selectRow( array( 'page', 'revision', 'text' ), - array( 'page_namespace','page_title','rev_timestamp','old_text','old_flags','rev_user_text','rev_comment'), - "page_id=rev_page AND rev_id=old_id AND rev_id={$this->mOldid}", - $fname - ); - if ( $s === false ) { - wfDebug( "Unable to load old_id {$this->mOldid}\n" ); - return false; - } + $this->oldRev =& $this->newRev->getPrevious(); } - $this->mOldPage = Title::MakeTitle( $s->page_namespace, $s->page_title ); - $this->mOldtext = Article::getRevisionText( $s ); + + $this->mOldPage = $this->oldRev->getTitle(); - $t = $wgLang->timeanddate( $s->rev_timestamp, true ); - $oldLink = $this->mOldPage->escapeLocalUrl ('oldid=' . $this->mOldid); + $t = $wgLang->timeanddate( $this->oldRev->getTimestamp(), true ); + $oldLink = $this->mOldPage->escapeLocalUrl( 'oldid=' . $this->mOldid ); $this->mOldtitle = "" . htmlspecialchars( wfMsg( 'revisionasof', $t ) ) . ''; - $this->mOldUser = $s->rev_user_text; - $this->mOldComment = $s->rev_comment; + + $this->mNewUser = $this->newRev->getUserText(); + $this->mNewComment = $this->newRev->getComment(); + $this->mNewtext = $this->newRev->getText(); + + $this->mOldUser = $this->oldRev->getUserText(); + $this->mOldComment = $this->oldRev->getComment(); + $this->mOldtext = $this->oldRev->getText(); return true; } diff --git a/includes/HistoryBlob.php b/includes/HistoryBlob.php index 611e34d7cc..c416bdd82c 100644 --- a/includes/HistoryBlob.php +++ b/includes/HistoryBlob.php @@ -30,7 +30,7 @@ class HistoryBlob # be other revisions in the same object function setText() {} - # Get default text. This is called from Article::getRevisionText() + # Get default text. This is called from Revision::getRevisionText() function getText() {} } diff --git a/includes/MessageCache.php b/includes/MessageCache.php index 9191d60889..04766226d3 100755 --- a/includes/MessageCache.php +++ b/includes/MessageCache.php @@ -4,6 +4,8 @@ * @package MediaWiki */ +require_once( 'Revision.php' ); + /** * */ @@ -149,7 +151,7 @@ class MessageCache $this->mCache = array(); for ( $row = $dbr->fetchObject( $res ); $row; $row = $dbr->fetchObject( $res ) ) { - $this->mCache[$row->page_title] = Article::getRevisionText( $row ); + $this->mCache[$row->page_title] = Revision::getRevisionText( $row ); } $dbr->freeResult( $res ); @@ -264,7 +266,7 @@ class MessageCache ' AND page_latest=old_id', 'MessageCache::get' ); if ( $result ) { - $message = Article::getRevisionText( $result ); + $message = Revision::getRevisionText( $result ); if ($this->mUseCache) { $this->mCache[$title]=$message; /* individual messages may be often diff --git a/includes/RawPage.php b/includes/RawPage.php index 8873dc8c43..2c9b8c5de1 100644 --- a/includes/RawPage.php +++ b/includes/RawPage.php @@ -10,6 +10,8 @@ * @package MediaWiki */ +require_once( 'Revision.php' ); + /** * @todo document * @package MediaWiki @@ -92,31 +94,19 @@ class RawPage { $fname = 'RawPage::getrawtext'; if( !$this->mTitle ) return ''; - $dbr =& wfGetDB( DB_SLAVE ); - extract( $dbr->tableNames( 'revision', 'page', 'text' ) ); - - $t = $dbr->strencode( $this->mTitle->getDBKey() ); - $ns = $this->mTitle->getNamespace(); - # special case - if($ns == NS_MEDIAWIKI) { - $rawtext = wfMsg($t); + + # Special case for MediaWiki: messages; we can hit the message cache. + if( $this->mTitle->getNamespace() == NS_MEDIAWIKI) { + $rawtext = wfMsg( $this->mTitle->getDbkey() ); return $rawtext; } + # else get it from the DB - $sql = "SELECT old_text AS text, rev_timestamp AS timestamp - FROM $text, $revision"; - if(!empty($this->mOldId)) { - $sql .= " WHERE old_id={$this->mOldId} AND rev_id={$this->mOldId}"; - } else { - $sql .= ", $page - WHERE page_namespace=$ns AND page_title='$t' - AND page_latest=rev_id AND rev_id=old_id"; - } - $res = $dbr->query( $sql, $fname ); - if( $s = $dbr->fetchObject( $res ) ) { - $rawtext = Article::getRevisionText( $s, "" ); - header( 'Last-modified: '.gmdate( "D, j M Y H:i:s", wfTimestamp( TS_UNIX, $s->timestamp )).' GMT' ); - return $rawtext; + $rev = Revision::newFromTitle( $this->mTitle, $this->mOldId ); + if( $rev ) { + $lastmod = wfTimestamp( TS_RFC2822, $rev->getTimestamp() ); + header( 'Last-modified: ' . $lastmod ); + return $rev->getText(); } else { return ''; } diff --git a/includes/Revision.php b/includes/Revision.php new file mode 100644 index 0000000000..85610498d8 --- /dev/null +++ b/includes/Revision.php @@ -0,0 +1,345 @@ + IntVal( $id ), + 'rev_id=old_id' ) ); + } + + /** + * Load either the current, or a specified, revision + * that's attached to a given title. If not attached + * to that title, will return null. + * + * @param Title $title + * @param int $id + * @return Revision + * @access public + */ + function &newFromTitle( &$title, $id = 0 ) { + if( $id ) { + $matchId = IntVal( $id ); + } else { + $matchId = 'page_latest'; + } + return Revision::newFromConds( + array( "rev_id=$matchId", + 'page_id=rev_page', + 'page_namespace' => $title->getNamespace(), + 'page_title' => $title->getDbkey(), + 'rev_id=old_id' ) ); + } + + /** + * Given a set of conditions, fetch a revision. + * + * @param array $conditions + * @return Revision + * @static + * @access private + */ + function &newFromConds( $conditions ) { + $res =& Revision::fetchFromConds( $conditions ); + if( $res ) { + $row = $res->fetchObject(); + $res->free(); + if( $row ) { + return new Revision( $row ); + } + } + return null; + } + + /** + * Return a wrapper for a series of database rows to + * fetch all of a given page's revisions in turn. + * Each row can be fed to the constructor to get objects. + * + * @param Title $title + * @return ResultWrapper + * @static + * @access public + */ + function &fetchAllRevisions( &$title ) { + return Revision::fetchFromConds( + array( 'page_namespace' => $title->getNamespace(), + 'page_title' => $title->getDbkey(), + 'page_id=rev_page', + 'rev_id=old_id' ) ); + } + + /** + * Return a wrapper for a series of database rows to + * fetch all of a given page's revisions in turn. + * Each row can be fed to the constructor to get objects. + * + * @param Title $title + * @return ResultWrapper + * @static + * @access public + */ + function &fetchRevision( &$title ) { + return Revision::fetchFromConds( + array( 'rev_id=page_latest', + 'page_namespace' => $title->getNamespace(), + 'page_title' => $title->getDbkey(), + 'page_id=rev_page', + 'rev_id=old_id' ) ); + } + /** + * Given a set of conditions, return a ResultWrapper + * which will return matching database rows with the + * fields necessary to build Revision objects. + * + * @param array $conditions + * @return ResultWrapper + * @static + * @access private + */ + function &fetchFromConds( $conditions ) { + $dbr =& wfGetDB( DB_SLAVE ); + $res = $dbr->select( + array( 'page', 'revision', 'text' ), + array( 'page_namespace', + 'page_title', + 'page_latest', + 'rev_id', + 'rev_page', + 'rev_comment', + 'rev_user_text', + 'rev_user', + 'rev_minor_edit', + 'rev_timestamp', + 'old_flags', + 'old_text' ), + $conditions, + 'Revision::fetchRow' ); + return $dbr->resultObject( $res ); + } + + /** + * @param object $row + * @access private + */ + function Revision( $row ) { + $this->mId = IntVal( $row->rev_id ); + $this->mPage = IntVal( $row->rev_page ); + $this->mComment = $row->rev_comment; + $this->mUserText = $row->rev_user_text; + $this->mUser = IntVal( $row->rev_user ); + $this->mMinorEdit = IntVal( $row->rev_minor_edit ); + $this->mTimestamp = $row->rev_timestamp; + + $this->mCurrent = ( $row->rev_id == $row->page_latest ); + $this->mTitle = Title::makeTitle( $row->page_namespace, + $row->page_title ); + $this->mText = $this->getRevisionText( $row ); + } + + /** @+ + * @access public + */ + + /** + * @return int + */ + function getId() { + return $this->mId; + } + + /** + * Returns the title of the page associated with this entry. + * @return Title + */ + function &getTitle() { + if( isset( $this->mTitle ) ) { + return $this->mTitle; + } + $dbr =& wfGetDB( DB_SLAVE ); + $row = $dbr->selectRow( + array( 'page', 'revision' ), + array( 'page_namespace', 'page_title' ), + array( 'page_id=rev_page', + 'rev_id' => $this->mId ), + 'Revision::getTItle' ); + if( $row ) { + $this->mTitle =& Title::makeTitle( $row->page_namespace, + $row->page_title ); + } + return $this->mTitle; + } + + /** + * @return int + */ + function getUser() { + return $this->mUser; + } + + /** + * @return string + */ + function getUserText() { + return $this->mUserText; + } + + /** + * @return string + */ + function getComment() { + return $this->mComment; + } + + /** + * @return bool + */ + function isMinor() { + return (bool)$this->mMinorEdit; + } + + /** + * @return string + */ + function getText() { + return $this->mText; + } + + /** + * @return string + */ + function getTimestamp() { + return $this->mTimestamp; + } + + /** + * @return bool + */ + function isCurrent() { + return $this->mCurrent; + } + + /** + * @return Revision + */ + function &getPrevious() { + $prev = $this->mTitle->getPreviousRevisionID( $this->mId ); + return Revision::newFromTitle( $this->mTitle, $prev ); + } + + /** + * @return Revision + */ + function &getNext() { + $next = $this->mTitle->getNextRevisionID( $this->mId ); + return Revision::newFromTitle( $this->mTitle, $next ); + } + /** @- */ + + /** + * Get revision text associated with an old or archive row + * $row is usually an object from wfFetchRow(), both the flags and the text + * field must be included + * @static + * @param integer $row Id of a row + * @param string $prefix table prefix (default 'old_') + * @return string $text|false the text requested + */ + function getRevisionText( $row, $prefix = 'old_' ) { + $fname = 'Revision::getRevisionText'; + wfProfileIn( $fname ); + + # Get data + $textField = $prefix . 'text'; + $flagsField = $prefix . 'flags'; + + if( isset( $row->$flagsField ) ) { + $flags = explode( ',', $row->$flagsField ); + } else { + $flags = array(); + } + + if( isset( $row->$textField ) ) { + $text = $row->$textField; + } else { + wfProfileOut( $fname ); + return false; + } + + if( in_array( 'gzip', $flags ) ) { + # Deal with optional compression of archived pages. + # This can be done periodically via maintenance/compressOld.php, and + # as pages are saved if $wgCompressRevisions is set. + $text = gzinflate( $text ); + } + + if( in_array( 'object', $flags ) ) { + # Generic compressed storage + $obj = unserialize( $text ); + + # Bugger, corrupted my test database by double-serializing + if ( !is_object( $obj ) ) { + $obj = unserialize( $obj ); + } + + $text = $obj->getText(); + } + + global $wgLegacyEncoding; + if( $wgLegacyEncoding && !in_array( 'utf-8', $flags ) ) { + # Old revisions kept around in a legacy encoding? + # Upconvert on demand. + global $wgInputEncoding, $wgContLang; + $text = $wgContLang->iconv( $wgLegacyEncoding, $wgInputEncoding, $text ); + } + wfProfileOut( $fname ); + return $text; + } + + /** + * If $wgCompressRevisions is enabled, we will compress data. + * The input string is modified in place. + * Return value is the flags field: contains 'gzip' if the + * data is compressed, and 'utf-8' if we're saving in UTF-8 + * mode. + * + * @static + * @param mixed $text reference to a text + * @return string + */ + function compressRevisionText( &$text ) { + global $wgCompressRevisions, $wgUseLatin1; + $flags = array(); + if( !$wgUseLatin1 ) { + # Revisions not marked this way will be converted + # on load if $wgLegacyCharset is set in the future. + $flags[] = 'utf-8'; + } + if( $wgCompressRevisions ) { + if( function_exists( 'gzdeflate' ) ) { + $text = gzdeflate( $text ); + $flags[] = 'gzip'; + } else { + wfDebug( "Revision::compressRevisionText() -- no zlib support, not compressing\n" ); + } + } + return implode( ',', $flags ); + } + + +} + + +?> \ No newline at end of file diff --git a/includes/SpecialExport.php b/includes/SpecialExport.php index 78ce26f275..c8f3052aac 100644 --- a/includes/SpecialExport.php +++ b/includes/SpecialExport.php @@ -17,6 +17,8 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # http://www.gnu.org/copyleft/gpl.html +require_once( 'Revision.php' ); + /** * * @package MediaWiki @@ -90,31 +92,35 @@ function page2xml( $page, $curonly, $full = false ) { } $dbr =& wfGetDB( DB_SLAVE ); - $s = $dbr->selectRow( 'cur', array( 'cur_id as id','cur_timestamp as timestamp','cur_user as user', - 'cur_user_text as user_text', 'cur_restrictions as restrictions','cur_comment as comment', - 'cur_text as text' ), $title->curCond(), $fname ); - if( $s !== false ) { + $s = $dbr->selectRow( 'page', + array( 'page_id', 'page_restrictions' ), + array( 'page_namespace' => $title->getNamespace(), + 'page_title' => $title->getDbkey() ) ); + if( $s ) { $tl = xmlsafe( $title->getPrefixedText() ); $xml = " \n"; $xml .= " $tl\n"; + if( $full ) { - $xml .= " $s->id\n"; + $xml .= " $s->page_id\n"; } - if( $s->restrictions ) { - $xml .= " $s->restrictions\n"; + if( $s->page_restrictions ) { + $xml .= " " . xmlsafe( $s->page_restrictions ) . "\n"; } - if( !$curonly ) { - $res = $dbr->select( 'old', array( 'old_id as id','old_timestamp as timestamp', - 'old_user as user', 'old_user_text as user_text', 'old_comment as comment', - 'old_text as text', 'old_flags as flags' ), $title->oldCond(), - $fname, array( 'ORDER BY' => 'old_timestamp' ) - ); - while( $s2 = $dbr->fetchObject( $res ) ) { - $xml .= revision2xml( $s2, $full, false ); + if( $curonly ) { + $res = Revision::fetchRevision( $title ); + } else { + $res = Revision::fetchAllRevisions( $title ); + } + if( $res ) { + while( $s = $res->fetchObject() ) { + $rev = new Revision( $s ); + $xml .= revision2xml( $rev, $full, false ); } + $res->free(); } - $xml .= revision2xml( $s, $full, true ); + $xml .= " \n"; wfProfileOut( $fname ); return $xml; @@ -124,31 +130,40 @@ function page2xml( $page, $curonly, $full = false ) { } } -function revision2xml( $s, $full, $cur ) { +/** + * @return string + * @param Revision $rev + * @param bool $full + * @access private + */ +function revision2xml( $rev, $full ) { $fname = 'revision2xml'; wfProfileIn( $fname ); - $ts = wfTimestamp2ISO8601( $s->timestamp ); $xml = " \n"; - if($full && !$cur) - $xml .= " $s->id\n"; + if( $full ) + $xml .= " " . $rev->getId() . "\n"; + + $ts = wfTimestamp2ISO8601( $rev->getTimestamp() ); $xml .= " $ts\n"; - if($s->user) { - $u = "" . xmlsafe( $s->user_text ) . ""; - if($full) - $u .= "$s->user"; + + if( $rev->getUser() ) { + $u = "" . xmlsafe( $rev->getUserText() ) . ""; + if( $full ) + $u .= "" . $rev->getUser() . ""; } else { - $u = "" . xmlsafe( $s->user_text ) . ""; + $u = "" . xmlsafe( $rev->getUserText() ) . ""; } $xml .= " $u\n"; - if( !empty( $s->minor ) ) { + + if( $rev->isMinor() ) { $xml .= " \n"; } - if($s->comment != "") { - $c = xmlsafe( $s->comment ); + if($rev->getComment() != "") { + $c = xmlsafe( $rev->getComment() ); $xml .= " $c\n"; } - $t = xmlsafe( Article::getRevisionText( $s, "" ) ); + $t = xmlsafe( $rev->getText() ); $xml .= " $t\n"; $xml .= " \n"; wfProfileOut( $fname ); diff --git a/includes/SpecialRecentchanges.php b/includes/SpecialRecentchanges.php index f5e6cf9aa4..1782843cac 100644 --- a/includes/SpecialRecentchanges.php +++ b/includes/SpecialRecentchanges.php @@ -10,6 +10,7 @@ */ require_once( 'Feed.php' ); require_once( 'ChangesList.php' ); +require_once( 'Revision.php' ); /** * Constructor @@ -349,37 +350,38 @@ function rcFormatDiff( $row ) { #$diff =& new DifferenceEngine( $row->rc_this_oldid, $row->rc_last_oldid, $row->rc_id ); #$diff->showDiffPage(); + $titleObj = Title::makeTitle( $row->rc_namespace, $row->rc_title ); $dbr =& wfGetDB( DB_SLAVE ); - if( $row->rc_this_oldid ) { - $newrow = $dbr->selectRow( 'old', - array( 'old_flags', 'old_text' ), - array( 'old_id' => $row->rc_this_oldid ) ); - $newtext = Article::getRevisionText( $newrow ); + $newrev =& Revision::newFromTitle( $titleObj, $row->rc_this_oldid ); + if( $newrev ) { + $newtext = $newrev->getText(); } else { - $newrow = $dbr->selectRow( 'cur', - array( 'cur_text' ), - array( 'cur_id' => $row->rc_cur_id ) ); - $newtext = $newrow->cur_text; + $diffText = "

Can't load revision $row->rc_this_oldid

"; + wfProfileOut( $fname ); + return $comment . $diffText; } + if( $row->rc_last_oldid ) { wfProfileIn( "$fname-dodiff" ); - $oldrow = $dbr->selectRow( 'old', - array( 'old_flags', 'old_text' ), - array( 'old_id' => $row->rc_last_oldid ) ); - $oldtext = Article::getRevisionText( $oldrow ); - + $oldrev =& Revision::newFromId( $row->rc_last_oldid ); + if( !$oldrev ) { + $diffText = "

Can't load old revision $row->rc_last_oldid

"; + wfProfileOut( $fname ); + return $comment . $diffText; + } + $oldtext = $oldrev->getText(); + global $wgFeedDiffCutoff; if( strlen( $newtext ) > $wgFeedDiffCutoff || - strlen( $oldtext ) > $wgFeedDiffCutoff ) { - $titleObj = Title::makeTitle( $row->rc_namespace, $row->rc_title ); + strlen( $oldtext ) > $wgFeedDiffCutoff ) { $diffLink = $titleObj->escapeFullUrl( 'diff=' . $row->rc_this_oldid . '&oldid=' . $row->rc_last_oldid ); - $diffText = '' . - htmlspecialchars( wfMsgForContent( 'difference' ) ) . - ''; + $diffText = '' . + htmlspecialchars( wfMsgForContent( 'difference' ) ) . + ''; } else { $diffText = DifferenceEngine::getDiff( $oldtext, $newtext, wfMsg( 'revisionasof', $wgContLang->timeanddate( $row->rc_timestamp ) ), diff --git a/includes/SpecialSearch.php b/includes/SpecialSearch.php index d4e5e64808..bebbfd2b35 100644 --- a/includes/SpecialSearch.php +++ b/includes/SpecialSearch.php @@ -24,6 +24,7 @@ */ require_once( 'SearchEngine.php' ); +require_once( 'Revision.php' ); function wfSpecialSearch( $par='' ) { global $wgRequest, $wgUser; @@ -305,7 +306,7 @@ class SpecialSearch { if ( '' == $contextchars ) { $contextchars = 50; } $link = $sk->makeKnownLinkObj( $t, '' ); - $text = Article::getRevisionText( $row ); + $text = Revision::getRevisionText( $row ); $size = wfMsg( 'nbytes', strlen( $text ) ); $lines = explode( "\n", $text ); diff --git a/includes/SpecialUndelete.php b/includes/SpecialUndelete.php index d450960895..3b5d385f2a 100644 --- a/includes/SpecialUndelete.php +++ b/includes/SpecialUndelete.php @@ -5,6 +5,8 @@ * @subpackage SpecialPage */ +require_once( 'Revision.php' ); + /** * */ @@ -76,7 +78,7 @@ class PageArchive { array( 'ar_namespace' => $this->title->getNamespace(), 'ar_title' => $this->title->getDbkey(), 'ar_timestamp' => $dbr->timestamp( $timestamp ) ) ); - return Article::getRevisionText( $row, "ar_" ); + return Revision::getRevisionText( $row, "ar_" ); } /** @@ -96,7 +98,7 @@ class PageArchive { 'PageArchive::getLastRevisionText', 'ORDER BY ar_timestamp DESC LIMIT 1' ); if( $row ) { - return Article::getRevisionText( $row, "ar_" ); + return Revision::getRevisionText( $row, "ar_" ); } else { return NULL; } @@ -162,7 +164,7 @@ class PageArchive { if( $restoreAll ) { $max = $s->ar_timestamp; } - $text = Article::getRevisionText( $s, "ar_" ); + $text = Revision::getRevisionText( $s, "ar_" ); $redirect = MagicWord::get( MAG_REDIRECT ); $redir = $redirect->matchStart( $text ) ? 1 : 0; diff --git a/maintenance/compressOld.inc b/maintenance/compressOld.inc index 30dec07f71..28ee16125a 100644 --- a/maintenance/compressOld.inc +++ b/maintenance/compressOld.inc @@ -4,6 +4,8 @@ * @subpackage Maintenance */ +require_once( '../includes/Revision.php' ); + /** */ function compressOldPages( $start = 0 ) { $fname = 'compressOldPages'; @@ -135,9 +137,9 @@ function compressWithConcat( $startId, $maxChunkSize, $maxChunkFactor, $factorTh $fname, 'FOR UPDATE' ); - $text = Article::getRevisionText( $textRow ); + $text = Revision::getRevisionText( $textRow ); } else { - $text = Article::getRevisionText( $revs[$i + $j] ); + $text = Revision::getRevisionText( $revs[$i + $j] ); } if ( $text === false ) { diff --git a/tests/ArticleTest.php b/tests/ArticleTest.php index 15b8eba100..953fd43c86 100644 --- a/tests/ArticleTest.php +++ b/tests/ArticleTest.php @@ -36,7 +36,7 @@ class ArticleTest extends PHPUnit_TestCase { $row->old_text = 'This is a bunch of revision text.'; $this->assertEquals( 'This is a bunch of revision text.', - Article::getRevisionText( $row ) ); + Revision::getRevisionText( $row ) ); } function testGetRevisionTextGzip() { @@ -45,7 +45,7 @@ class ArticleTest extends PHPUnit_TestCase { $row->old_text = gzdeflate( 'This is a bunch of revision text.' ); $this->assertEquals( 'This is a bunch of revision text.', - Article::getRevisionText( $row ) ); + Revision::getRevisionText( $row ) ); } function testGetRevisionTextUtf8Native() { @@ -55,7 +55,7 @@ class ArticleTest extends PHPUnit_TestCase { $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1'; $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !", - Article::getRevisionText( $row ) ); + Revision::getRevisionText( $row ) ); } function testGetRevisionTextUtf8Legacy() { @@ -65,7 +65,7 @@ class ArticleTest extends PHPUnit_TestCase { $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1'; $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !", - Article::getRevisionText( $row ) ); + Revision::getRevisionText( $row ) ); } function testGetRevisionTextUtf8NativeGzip() { @@ -75,7 +75,7 @@ class ArticleTest extends PHPUnit_TestCase { $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1'; $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !", - Article::getRevisionText( $row ) ); + Revision::getRevisionText( $row ) ); } function testGetRevisionTextUtf8LegacyGzip() { @@ -85,12 +85,12 @@ class ArticleTest extends PHPUnit_TestCase { $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1'; $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !", - Article::getRevisionText( $row ) ); + Revision::getRevisionText( $row ) ); } function testCompressRevisionTextUtf8() { $row->old_text = "Wiki est l'\xc3\xa9cole superieur !"; - $row->old_flags = Article::compressRevisionText( $row->old_text ); + $row->old_flags = Revision::compressRevisionText( $row->old_text ); $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ), "Flags should contain 'utf-8'" ); $this->assertFalse( false !== strpos( $row->old_flags, 'gzip' ), @@ -98,13 +98,13 @@ class ArticleTest extends PHPUnit_TestCase { $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !", $row->old_text, "Direct check" ); $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !", - Article::getRevisionText( $row ), "getRevisionText" ); + Revision::getRevisionText( $row ), "getRevisionText" ); } function testCompressRevisionTextLatin1() { $GLOBALS['wgUseLatin1'] = true; $row->old_text = "Wiki est l'\xe9cole superieur !"; - $row->old_flags = Article::compressRevisionText( $row->old_text ); + $row->old_flags = Revision::compressRevisionText( $row->old_text ); $this->assertFalse( false !== strpos( $row->old_flags, 'utf-8' ), "Flags should not contain 'utf-8'" ); $this->assertFalse( false !== strpos( $row->old_flags, 'gzip' ), @@ -112,13 +112,13 @@ class ArticleTest extends PHPUnit_TestCase { $this->assertEquals( "Wiki est l'\xe9cole superieur !", $row->old_text, "Direct check" ); $this->assertEquals( "Wiki est l'\xe9cole superieur !", - Article::getRevisionText( $row ), "getRevisionText" ); + Revision::getRevisionText( $row ), "getRevisionText" ); } function testCompressRevisionTextUtf8Gzip() { $GLOBALS['wgCompressRevisions'] = true; $row->old_text = "Wiki est l'\xc3\xa9cole superieur !"; - $row->old_flags = Article::compressRevisionText( $row->old_text ); + $row->old_flags = Revision::compressRevisionText( $row->old_text ); $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ), "Flags should contain 'utf-8'" ); $this->assertTrue( false !== strpos( $row->old_flags, 'gzip' ), @@ -126,7 +126,7 @@ class ArticleTest extends PHPUnit_TestCase { $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !", gzinflate( $row->old_text ), "Direct check" ); $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !", - Article::getRevisionText( $row ), "getRevisionText" ); + Revision::getRevisionText( $row ), "getRevisionText" ); } function testCompressRevisionTextLatin1Gzip() { @@ -134,7 +134,7 @@ class ArticleTest extends PHPUnit_TestCase { $GLOBALS['wgUseLatin1'] = true; $row = new stdClass; $row->old_text = "Wiki est l'\xe9cole superieur !"; - $row->old_flags = Article::compressRevisionText( $row->old_text ); + $row->old_flags = Revision::compressRevisionText( $row->old_text ); $this->assertFalse( false !== strpos( $row->old_flags, 'utf-8' ), "Flags should not contain 'utf-8'" ); $this->assertTrue( false !== strpos( $row->old_flags, 'gzip' ), @@ -142,7 +142,7 @@ class ArticleTest extends PHPUnit_TestCase { $this->assertEquals( "Wiki est l'\xe9cole superieur !", gzinflate( $row->old_text ), "Direct check" ); $this->assertEquals( "Wiki est l'\xe9cole superieur !", - Article::getRevisionText( $row ), "getRevisionText" ); + Revision::getRevisionText( $row ), "getRevisionText" ); } } -- 2.20.1