8 require_once( 'Database.php' );
9 require_once( 'Article.php' );
17 * Load a page revision from a given revision ID number.
18 * Returns null if no such revision can be found.
24 function &newFromId( $id ) {
25 return Revision
::newFromConds(
26 array( 'page_id=rev_page',
27 'rev_id' => IntVal( $id ),
32 * Load either the current, or a specified, revision
33 * that's attached to a given title. If not attached
34 * to that title, will return null.
41 function &newFromTitle( &$title, $id = 0 ) {
43 $matchId = IntVal( $id );
45 $matchId = 'page_latest';
47 return Revision
::newFromConds(
48 array( "rev_id=$matchId",
50 'page_namespace' => $title->getNamespace(),
51 'page_title' => $title->getDbkey(),
56 * Given a set of conditions, fetch a revision.
58 * @param array $conditions
63 function &newFromConds( $conditions ) {
64 $res =& Revision
::fetchFromConds( $conditions );
66 $row = $res->fetchObject();
69 return new Revision( $row );
76 * Return a wrapper for a series of database rows to
77 * fetch all of a given page's revisions in turn.
78 * Each row can be fed to the constructor to get objects.
81 * @return ResultWrapper
85 function &fetchAllRevisions( &$title ) {
86 return Revision
::fetchFromConds(
87 array( 'page_namespace' => $title->getNamespace(),
88 'page_title' => $title->getDbkey(),
94 * Return a wrapper for a series of database rows to
95 * fetch all of a given page's revisions in turn.
96 * Each row can be fed to the constructor to get objects.
99 * @return ResultWrapper
103 function &fetchRevision( &$title ) {
104 return Revision
::fetchFromConds(
105 array( 'rev_id=page_latest',
106 'page_namespace' => $title->getNamespace(),
107 'page_title' => $title->getDbkey(),
112 * Given a set of conditions, return a ResultWrapper
113 * which will return matching database rows with the
114 * fields necessary to build Revision objects.
116 * @param array $conditions
117 * @return ResultWrapper
121 function &fetchFromConds( $conditions ) {
122 $dbr =& wfGetDB( DB_SLAVE
);
124 array( 'page', 'revision', 'text' ),
125 array( 'page_namespace',
138 'Revision::fetchRow' );
139 return $dbr->resultObject( $res );
146 function Revision( $row ) {
147 $this->mId
= IntVal( $row->rev_id
);
148 $this->mPage
= IntVal( $row->rev_page
);
149 $this->mComment
= $row->rev_comment
;
150 $this->mUserText
= $row->rev_user_text
;
151 $this->mUser
= IntVal( $row->rev_user
);
152 $this->mMinorEdit
= IntVal( $row->rev_minor_edit
);
153 $this->mTimestamp
= $row->rev_timestamp
;
155 $this->mCurrent
= ( $row->rev_id
== $row->page_latest
);
156 $this->mTitle
= Title
::makeTitle( $row->page_namespace
,
158 $this->mText
= $this->getRevisionText( $row );
173 * Returns the title of the page associated with this entry.
176 function &getTitle() {
177 if( isset( $this->mTitle
) ) {
178 return $this->mTitle
;
180 $dbr =& wfGetDB( DB_SLAVE
);
181 $row = $dbr->selectRow(
182 array( 'page', 'revision' ),
183 array( 'page_namespace', 'page_title' ),
184 array( 'page_id=rev_page',
185 'rev_id' => $this->mId
),
186 'Revision::getTItle' );
188 $this->mTitle
=& Title
::makeTitle( $row->page_namespace
,
191 return $this->mTitle
;
204 function getUserText() {
205 return $this->mUserText
;
211 function getComment() {
212 return $this->mComment
;
219 return (bool)$this->mMinorEdit
;
232 function getTimestamp() {
233 return $this->mTimestamp
;
239 function isCurrent() {
240 return $this->mCurrent
;
246 function &getPrevious() {
247 $prev = $this->mTitle
->getPreviousRevisionID( $this->mId
);
248 return Revision
::newFromTitle( $this->mTitle
, $prev );
254 function &getNext() {
255 $next = $this->mTitle
->getNextRevisionID( $this->mId
);
256 return Revision
::newFromTitle( $this->mTitle
, $next );
261 * Get revision text associated with an old or archive row
262 * $row is usually an object from wfFetchRow(), both the flags and the text
263 * field must be included
265 * @param integer $row Id of a row
266 * @param string $prefix table prefix (default 'old_')
267 * @return string $text|false the text requested
269 function getRevisionText( $row, $prefix = 'old_' ) {
270 $fname = 'Revision::getRevisionText';
271 wfProfileIn( $fname );
274 $textField = $prefix . 'text';
275 $flagsField = $prefix . 'flags';
277 if( isset( $row->$flagsField ) ) {
278 $flags = explode( ',', $row->$flagsField );
283 if( isset( $row->$textField ) ) {
284 $text = $row->$textField;
286 wfProfileOut( $fname );
290 if( in_array( 'gzip', $flags ) ) {
291 # Deal with optional compression of archived pages.
292 # This can be done periodically via maintenance/compressOld.php, and
293 # as pages are saved if $wgCompressRevisions is set.
294 $text = gzinflate( $text );
297 if( in_array( 'object', $flags ) ) {
298 # Generic compressed storage
299 $obj = unserialize( $text );
301 # Bugger, corrupted my test database by double-serializing
302 if ( !is_object( $obj ) ) {
303 $obj = unserialize( $obj );
306 $text = $obj->getText();
309 global $wgLegacyEncoding;
310 if( $wgLegacyEncoding && !in_array( 'utf-8', $flags ) ) {
311 # Old revisions kept around in a legacy encoding?
312 # Upconvert on demand.
313 global $wgInputEncoding, $wgContLang;
314 $text = $wgContLang->iconv( $wgLegacyEncoding, $wgInputEncoding, $text );
316 wfProfileOut( $fname );
321 * If $wgCompressRevisions is enabled, we will compress data.
322 * The input string is modified in place.
323 * Return value is the flags field: contains 'gzip' if the
324 * data is compressed, and 'utf-8' if we're saving in UTF-8
328 * @param mixed $text reference to a text
331 function compressRevisionText( &$text ) {
332 global $wgCompressRevisions, $wgUseLatin1;
334 if( !$wgUseLatin1 ) {
335 # Revisions not marked this way will be converted
336 # on load if $wgLegacyCharset is set in the future.
339 if( $wgCompressRevisions ) {
340 if( function_exists( 'gzdeflate' ) ) {
341 $text = gzdeflate( $text );
344 wfDebug( "Revision::compressRevisionText() -- no zlib support, not compressing\n" );
347 return implode( ',', $flags );