(bug 4860) Expose Title->userCan() as Hooks
[lhc/web/wiklou.git] / maintenance / nukePage.inc
1 <?php
2
3 /**
4 * Support functions for the nukeArticle script
5 *
6 * @package MediaWiki
7 * @subpackage Maintenance
8 * @author Rob Church <robchur@gmail.com>
9 */
10
11 require_once( 'purgeOldText.inc' );
12
13 function NukePage( $name, $delete = false ) {
14
15 $dbw =& wfGetDB( DB_MASTER );
16 $dbw->begin();
17
18 $tbl_pag = $dbw->tableName( 'page' );
19 $tbl_rev = $dbw->tableName( 'revision' );
20
21 # Get page ID
22 echo( "Searching for \"$name\"..." );
23 $title = Title::newFromText( $name );
24 if( $title ) {
25 $id = $title->getArticleID();
26 $real = $title->getPrefixedText();
27 echo( "found \"$real\" with ID $id.\n" );
28
29 # Get corresponding revisions
30 echo( "Searching for revisions..." );
31 $res = $dbw->query( "SELECT rev_id FROM $tbl_rev WHERE rev_page = $id" );
32 while( $row = $dbw->fetchObject( $res ) ) {
33 $revs[] = $row->rev_id;
34 }
35 $count = count( $revs );
36 echo( "found $count.\n" );
37
38 # Delete the page itself
39 if( $delete ) {
40 echo( "Deleting page record..." );
41 $dbw->query( "DELETE FROM $tbl_pag WHERE page_id = $id" );
42 echo( "done.\n" );
43 }
44
45 $dbw->commit();
46
47 # Delete revisions as appropriate
48 if( $delete && $count ) {
49 echo( "Deleting revisions..." );
50 DeleteRevisions( $revs );
51 echo( "done.\n" );
52 PurgeRedundantText( true );
53 }
54
55 } else {
56 echo( "not found in database.\n" );
57 $dbw->commit();
58 }
59
60 }
61
62 function DeleteRevisions( $ids ) {
63
64 $dbw =& wfGetDB( DB_MASTER );
65 $dbw->begin();
66
67 $tbl_rev = $dbw->tableName( 'revision' );
68
69 $set = implode( ', ', $ids );
70 $dbw->query( "DELETE FROM $tbl_rev WHERE rev_id IN ( $set )" );
71
72 $dbw->commit();
73
74 }
75
76 ?>