MediaWiki REL1_39
dumpLinks.php
Go to the documentation of this file.
1<?php
33require_once __DIR__ . '/Maintenance.php';
34
40class 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
49 $result = $dbr->newSelectQueryBuilder()
50 ->select( [
51 'page_id',
52 'page_namespace',
53 'page_title',
54 'pl_namespace',
55 'pl_title'
56 ] )
57 ->from( 'page' )
58 ->join( 'pagelinks', null, [ 'page_id=pl_from' ] )
59 ->orderBy( 'page_id' )
60 ->caller( __METHOD__ )
61 ->fetchResultSet();
62
63 $lastPage = null;
64 foreach ( $result as $row ) {
65 if ( $lastPage != $row->page_id ) {
66 if ( $lastPage !== null ) {
67 $this->output( "\n" );
68 }
69 $page = Title::makeTitle( $row->page_namespace, $row->page_title );
70 $this->output( $page->getPrefixedURL() );
71 $lastPage = $row->page_id;
72 }
73 $link = Title::makeTitle( $row->pl_namespace, $row->pl_title );
74 $this->output( " " . $link->getPrefixedURL() );
75 }
76 if ( $lastPage !== null ) {
77 $this->output( "\n" );
78 }
79 }
80}
81
82$maintClass = DumpLinks::class;
83require_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.
const DB_REPLICA
Definition defines.php:26