MediaWiki REL1_31
fetchText.php
Go to the documentation of this file.
1<?php
25require_once __DIR__ . '/Maintenance.php';
26
28
34class FetchText extends Maintenance {
35 public function __construct() {
36 parent::__construct();
37 $this->addDescription( "Fetch the raw revision blob from an old_id.\n" .
38 "NOTE: Export transformations are NOT applied. " .
39 "This is left to backupTextPass.php"
40 );
41 }
42
53 public function execute() {
54 $db = $this->getDB( DB_REPLICA );
55 $stdin = $this->getStdin();
56 while ( !feof( $stdin ) ) {
57 $line = fgets( $stdin );
58 if ( $line === false ) {
59 // We appear to have lost contact...
60 break;
61 }
62 $textId = intval( $line );
63 $text = $this->doGetText( $db, $textId );
64 if ( $text === false ) {
65 # actual error, not zero-length text
66 $textLen = "-1";
67 } else {
68 $textLen = strlen( $text );
69 }
70 $this->output( $textId . "\n" . $textLen . "\n" . $text );
71 }
72 }
73
80 private function doGetText( $db, $id ) {
81 $id = intval( $id );
82 $row = $db->selectRow( 'text',
83 [ 'old_text', 'old_flags' ],
84 [ 'old_id' => $id ],
85 __METHOD__ );
86 $text = Revision::getRevisionText( $row );
87 if ( $text === false ) {
88 return false;
89 }
90
91 return $text;
92 }
93}
94
95$maintClass = FetchText::class;
96require_once RUN_MAINTENANCE_IF_MAIN;
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$line
Definition cdb.php:59
Maintenance script used to fetch page text in a subprocess.
Definition fetchText.php:34
doGetText( $db, $id)
May throw a database error if, say, the server dies during query.
Definition fetchText.php:80
__construct()
Default constructor.
Definition fetchText.php:35
execute()
returns a string containing the following in order: textid \n length of text (-1 on error = failure t...
Definition fetchText.php:53
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getStdin( $len=null)
Return input from stdin.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
addDescription( $text)
Set the description text.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
$maintClass
Definition fetchText.php:95
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
require_once RUN_MAINTENANCE_IF_MAIN
const DB_REPLICA
Definition defines.php:25