MediaWiki master
dumpLinks.php
Go to the documentation of this file.
1<?php
33require_once __DIR__ . '/Maintenance.php';
34
36
42class DumpLinks extends Maintenance {
43 public function __construct() {
44 parent::__construct();
45 $this->addDescription( 'Quick demo hack to generate a plaintext link dump' );
46 }
47
48 public function execute() {
49 $dbr = $this->getReplicaDB();
50 $linksMigration = $this->getServiceContainer()->getLinksMigration();
51 $queryInfo = $linksMigration->getQueryInfo( 'pagelinks' );
52 $queryInfo['tables'] = array_diff( $queryInfo['tables'], [ 'pagelinks' ] );
53 [ $blNamespace, $blTitle ] = $linksMigration->getTitleFields( 'pagelinks' );
54
55 $result = $dbr->newSelectQueryBuilder()
56 ->select( array_merge( [
57 'page_id',
58 'page_namespace',
59 'page_title',
60 ], $queryInfo['fields'] ) )
61 ->from( 'page' )
62 ->join( 'pagelinks', null, [ 'page_id=pl_from' ] )
63 ->joinConds( $queryInfo['joins'] )
64 ->tables( $queryInfo['tables'] )
65 ->orderBy( 'page_id' )
66 ->caller( __METHOD__ )
67 ->fetchResultSet();
68
69 $lastPage = null;
70 foreach ( $result as $row ) {
71 if ( $lastPage != $row->page_id ) {
72 if ( $lastPage !== null ) {
73 $this->output( "\n" );
74 }
75 $page = Title::makeTitle( $row->page_namespace, $row->page_title );
76 $this->output( $page->getPrefixedURL() );
77 $lastPage = $row->page_id;
78 }
79 $link = Title::makeTitle( $row->$blNamespace, $row->$blTitle );
80 $this->output( " " . $link->getPrefixedURL() );
81 }
82 if ( $lastPage !== null ) {
83 $this->output( "\n" );
84 }
85 }
86}
87
88$maintClass = DumpLinks::class;
89require_once RUN_MAINTENANCE_IF_MAIN;
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
Represents a title within MediaWiki.
Definition Title.php:78