MediaWiki  1.30.0
fetchText.php
Go to the documentation of this file.
1 <?php
25 require_once __DIR__ . '/Maintenance.php';
26 
28 
34 class 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";
96 require_once RUN_MAINTENANCE_IF_MAIN;
FetchText
Maintenance script used to fetch page text in a subprocess.
Definition: fetchText.php:34
Maintenance\getStdin
getStdin( $len=null)
Return input from stdin.
Definition: Maintenance.php:346
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:287
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Revision\getRevisionText
static getRevisionText( $row, $prefix='old_', $wiki=false)
Get revision text associated with an old or archive row.
Definition: Revision.php:1266
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
FetchText\execute
execute()
returns a string containing the following in order: textid \n length of text (-1 on error = failure t...
Definition: fetchText.php:53
php
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:35
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:40
$maintClass
$maintClass
Definition: fetchText.php:95
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
FetchText\doGetText
doGetText( $db, $id)
May throw a database error if, say, the server dies during query.
Definition: fetchText.php:80
$line
$line
Definition: cdb.php:58
Maintenance\getDB
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1251
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:373
FetchText\__construct
__construct()
Default constructor.
Definition: fetchText.php:35