MediaWiki  1.34.0
dumpLinks.php
Go to the documentation of this file.
1 <?php
33 require_once __DIR__ . '/Maintenance.php';
34 
40 class DumpLinks extends Maintenance {
41  public function __construct() {
42  parent::__construct();
43  $this->addDescription( 'Quick demo hack to generate a plaintext link dump' );
44  }
45 
46  public function execute() {
47  $dbr = $this->getDB( DB_REPLICA );
48  $result = $dbr->select( [ 'pagelinks', 'page' ],
49  [
50  'page_id',
51  'page_namespace',
52  'page_title',
53  'pl_namespace',
54  'pl_title' ],
55  [ 'page_id=pl_from' ],
56  __METHOD__,
57  [ 'ORDER BY' => 'page_id' ] );
58 
59  $lastPage = null;
60  foreach ( $result as $row ) {
61  if ( $lastPage != $row->page_id ) {
62  if ( $lastPage !== null ) {
63  $this->output( "\n" );
64  }
65  $page = Title::makeTitle( $row->page_namespace, $row->page_title );
66  $this->output( $page->getPrefixedURL() );
67  $lastPage = $row->page_id;
68  }
69  $link = Title::makeTitle( $row->pl_namespace, $row->pl_title );
70  $this->output( " " . $link->getPrefixedURL() );
71  }
72  if ( $lastPage !== null ) {
73  $this->output( "\n" );
74  }
75  }
76 }
77 
78 $maintClass = DumpLinks::class;
79 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:348
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:82
$dbr
$dbr
Definition: testCompression.php:50
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:586
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
Maintenance\getDB
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1396
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:453