User:Lucas Werkmeister (WMDE)/How to get the raw text of a page or revision

From Wikitech
Jump to navigation Jump to search

Most of the usual methods to get revision text pass through the content handlers, which may deserialize and reserialize the content. For example, for Wikibase this means that you’ll always see the current serialization version, not what’s actually stored.

This snippet (shell.php or eval.php) gets you the raw text of a certain revision by ID:

$services = MediaWiki\MediaWikiServices::getInstance();
$revision = $services->getRevisionStore()->getRevisionById( 103 );
echo $services->getBlobStore()->getBlob( $revision->getSlot( 'main' )->getAddress() );

And by title (latest revision of that page):

$services = MediaWiki\MediaWikiServices::getInstance();
$revision = $services->getRevisionStore()->getRevisionByTitle( $services->getTitleParser()->parseTitle( 'Q1' ) );
echo $services->getBlobStore()->getBlob( $revision->getSlot( 'main' )->getAddress() );