- }
-
- /**
- * 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_' ) {
- # 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 {
- return false;
- }
-
- if ( in_array( 'link', $flags ) ) {
- # Handle link type
- $text = Article::followLink( $text );
- } elseif ( 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.
- return gzinflate( $text );
- }
- return $text;
- }
-
- /**
- * If $wgCompressRevisions is enabled, we will compress datas
- * @static
- * @param mixed $text reference to a text
- * @return string 'gzip' if it get compressed, '' overwise
- */
- function compressRevisionText( &$text ) {
- global $wgCompressRevisions;
- if( !$wgCompressRevisions ) {
- return '';
- }
- if( !function_exists( 'gzdeflate' ) ) {
- wfDebug( "Article::compressRevisionText() -- no zlib support, not compressing\n" );
- return '';
- }
- $text = gzdeflate( $text );
- return 'gzip';
- }
-
- /**
- * Returns the text associated with a "link" type old table row
- * @static
- * @param mixed $link
- * @return string $text|false
- */
- function followLink( $link ) {
- # Split the link into fields and values
- $lines = explode( '\n', $link );
- $hash = '';
- $locations = array();
- foreach ( $lines as $line ) {
- # Comments
- if ( $line{0} == '#' ) {
- continue;
- }
- # Field/value pairs
- if ( preg_match( '/^(.*?)\s*:\s*(.*)$/', $line, $matches ) ) {
- $field = strtolower($matches[1]);
- $value = $matches[2];
- if ( $field == 'hash' ) {
- $hash = $value;
- } elseif ( $field == 'location' ) {
- $locations[] = $value;
- }
- }
- }
-
- if ( $hash === '' ) {
- return false;
- }
-
- # Look in each specified location for the text
- $text = false;
- foreach ( $locations as $location ) {
- $text = Article::fetchFromLocation( $location, $hash );
- if ( $text !== false ) {
- break;
- }
- }
-
- return $text;
- }
-
- /**
- * @static
- * @param $location
- * @param $hash
- */
- function fetchFromLocation( $location, $hash ) {
- global $wgLoadBalancer;
- $fname = 'fetchFromLocation';
- wfProfileIn( $fname );
-
- $p = strpos( $location, ':' );
- if ( $p === false ) {
- wfProfileOut( $fname );
- return false;
- }
-
- $type = substr( $location, 0, $p );
- $text = false;
- switch ( $type ) {
- case 'mysql':
- # MySQL locations are specified by mysql://<machineID>/<dbname>/<tblname>/<index>
- # Machine ID 0 is the current connection
- if ( preg_match( '/^mysql:\/\/(\d+)\/([A-Za-z_]+)\/([A-Za-z_]+)\/([A-Za-z_]+)$/',
- $location, $matches ) ) {
- $machineID = $matches[1];
- $dbName = $matches[2];
- $tblName = $matches[3];
- $index = $matches[4];
- if ( $machineID == 0 ) {
- # Current connection
- $db =& $this->getDB();
- } else {
- # Alternate connection
- $db =& $wgLoadBalancer->getConnection( $machineID );
-
- if ( array_key_exists( $machineId, $wgKnownMysqlServers ) ) {
- # Try to open, return false on failure
- $params = $wgKnownDBServers[$machineId];
- $db = Database::newFromParams( $params['server'], $params['user'], $params['password'],
- $dbName, 1, DBO_IGNORE );
- }
- }
- if ( $db->isOpen() ) {
- $index = $db->strencode( $index );
- $res = $db->query( "SELECT blob_data FROM $dbName.$tblName " .
- "WHERE blob_index='$index' " . $this->getSelectOptions(), $fname );
- $row = $db->fetchObject( $res );
- $text = $row->text_data;
- }
- }
- break;
- case 'file':
- # File locations are of the form file://<filename>, relative to the current directory
- if ( preg_match( '/^file:\/\/(.*)$', $location, $matches ) )
- $filename = strstr( $location, 'file://' );
- $text = @file_get_contents( $matches[1] );
- }
- if ( $text !== false ) {
- # Got text, now we need to interpret it
- # The first line contains information about how to do this
- $p = strpos( $text, '\n' );
- $type = substr( $text, 0, $p );
- $text = substr( $text, $p + 1 );
- switch ( $type ) {
- case 'plain':
- break;
- case 'gzip':
- $text = gzinflate( $text );
- break;
- case 'object':
- $object = unserialize( $text );
- $text = $object->getItem( $hash );
- break;
- default:
- $text = false;
- }
- }
- wfProfileOut( $fname );
- return $text;