MediaWiki 1.40.4
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->getDB( DB_REPLICA );
50
51 $result = $dbr->newSelectQueryBuilder()
52 ->select( [
53 'page_id',
54 'page_namespace',
55 'page_title',
56 'pl_namespace',
57 'pl_title'
58 ] )
59 ->from( 'page' )
60 ->join( 'pagelinks', null, [ 'page_id=pl_from' ] )
61 ->orderBy( 'page_id' )
62 ->caller( __METHOD__ )
63 ->fetchResultSet();
64
65 $lastPage = null;
66 foreach ( $result as $row ) {
67 if ( $lastPage != $row->page_id ) {
68 if ( $lastPage !== null ) {
69 $this->output( "\n" );
70 }
71 $page = Title::makeTitle( $row->page_namespace, $row->page_title );
72 $this->output( $page->getPrefixedURL() );
73 $lastPage = $row->page_id;
74 }
75 $link = Title::makeTitle( $row->pl_namespace, $row->pl_title );
76 $this->output( " " . $link->getPrefixedURL() );
77 }
78 if ( $lastPage !== null ) {
79 $this->output( "\n" );
80 }
81 }
82}
83
84$maintClass = DumpLinks::class;
85require_once RUN_MAINTENANCE_IF_MAIN;
getDB()
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
addDescription( $text)
Set the description text.
Represents a title within MediaWiki.
Definition Title.php:82
const DB_REPLICA
Definition defines.php:26