MediaWiki master
dumpLinks.php
Go to the documentation of this file.
1<?php
33// @codeCoverageIgnoreStart
34require_once __DIR__ . '/Maintenance.php';
35// @codeCoverageIgnoreEnd
36
39
45class DumpLinks extends Maintenance {
46 public function __construct() {
47 parent::__construct();
48 $this->addDescription( 'Quick demo hack to generate a plaintext link dump' );
49 }
50
51 public function execute() {
52 $dbr = $this->getReplicaDB();
53 $linksMigration = $this->getServiceContainer()->getLinksMigration();
54 $queryInfo = $linksMigration->getQueryInfo( 'pagelinks' );
55 $queryInfo['tables'] = array_diff( $queryInfo['tables'], [ 'pagelinks' ] );
56 [ $blNamespace, $blTitle ] = $linksMigration->getTitleFields( 'pagelinks' );
57
58 $result = $dbr->newSelectQueryBuilder()
59 ->select( array_merge( [
60 'page_id',
61 'page_namespace',
62 'page_title',
63 ], $queryInfo['fields'] ) )
64 ->from( 'page' )
65 ->join( 'pagelinks', null, [ 'page_id=pl_from' ] )
66 ->joinConds( $queryInfo['joins'] )
67 ->tables( $queryInfo['tables'] )
68 ->orderBy( 'page_id' )
69 ->caller( __METHOD__ )
70 ->fetchResultSet();
71
72 $lastPage = null;
73 foreach ( $result as $row ) {
74 if ( $lastPage != $row->page_id ) {
75 if ( $lastPage !== null ) {
76 $this->output( "\n" );
77 }
78 $page = Title::makeTitle( $row->page_namespace, $row->page_title );
79 $this->output( $page->getPrefixedURL() );
80 $lastPage = $row->page_id;
81 }
82 $link = Title::makeTitle( $row->$blNamespace, $row->$blTitle );
83 $this->output( " " . $link->getPrefixedURL() );
84 }
85 if ( $lastPage !== null ) {
86 $this->output( "\n" );
87 }
88 }
89}
90
91// @codeCoverageIgnoreStart
92$maintClass = DumpLinks::class;
93require_once RUN_MAINTENANCE_IF_MAIN;
94// @codeCoverageIgnoreEnd
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