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