]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - maintenance/dumpLinks.php
MediaWiki 1.16.4
[autoinstalls/mediawiki.git] / maintenance / dumpLinks.php
1 <?php
2 /**
3  * Copyright (C) 2005 Brion Vibber <brion@pobox.com>
4  * http://www.mediawiki.org/
5  *
6  * Quick demo hack to generate a plaintext link dump,
7  * per the proposed wiki link database standard:
8  * http://www.usemod.com/cgi-bin/mb.pl?LinkDatabase
9  *
10  * Includes all (live and broken) intra-wiki links.
11  * Does not include interwiki or URL links.
12  * Dumps ASCII text to stdout; command-line.
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  * @ingroup Mainatenance
30  */
31
32 require_once( dirname(__FILE__) . '/Maintenance.php' );
33
34 class DumpLinks extends Maintenance {
35         public function __construct() {
36                 parent::__construct();
37                 $this->mDescription = "Quick demo hack to generate a plaintext link dump";
38         }
39
40         public function execute() {
41                 $dbr = wfGetDB( DB_SLAVE );
42                 $result = $dbr->select( array( 'pagelinks', 'page' ),
43                         array(
44                                 'page_id',
45                                 'page_namespace',
46                                 'page_title',
47                                 'pl_namespace',
48                                 'pl_title' ),
49                         array( 'page_id=pl_from' ),
50                         __METHOD__,
51                         array( 'ORDER BY' => 'page_id' ) );
52         
53                 $lastPage = null;
54                 foreach( $result as $row ) {
55                         if( $lastPage != $row->page_id ) {
56                                 if( isset( $lastPage ) ) {
57                                         $this->output( "\n" );
58                                 }
59                                 $page = Title::makeTitle( $row->page_namespace, $row->page_title );
60                                 $this->output( $page->getPrefixedUrl() );
61                                 $lastPage = $row->page_id;
62                         }
63                         $link = Title::makeTitle( $row->pl_namespace, $row->pl_title );
64                         $this->output( " " . $link->getPrefixedUrl() );
65                 }
66                 if( isset( $lastPage ) )
67                         $this->output( "\n" );
68         }
69 }
70
71 $maintClass = "DumpLinks";
72 require_once( DO_MAINTENANCE );
73