Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 35
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
DumpLinks
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 2
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2/**
3 * Quick demo hack to generate a plaintext link dump,
4 * per the proposed wiki link database standard:
5 * http://www.usemod.com/cgi-bin/mb.pl?LinkDatabase
6 *
7 * Includes all (live and broken) intra-wiki links.
8 * Does not include interwiki or URL links.
9 * Dumps ASCII text to stdout; command-line.
10 *
11 * Copyright © 2005 Brooke Vibber <bvibber@wikimedia.org>
12 * https://www.mediawiki.org/
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 * http://www.gnu.org/copyleft/gpl.html
28 *
29 * @file
30 * @ingroup Maintenance
31 */
32
33require_once __DIR__ . '/Maintenance.php';
34
35use MediaWiki\Title\Title;
36
37/**
38 * Maintenance script that generates a plaintext link dump.
39 *
40 * @ingroup Maintenance
41 */
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;