[Mediawiki-l] Bacth deletion of pages

Hugh Prior mediawiki at localpin.com
Fri Jun 16 08:50:27 UTC 2006


I am doing a lot of development, creating pages, and every now and then, I 
want a clean sheet by deleting them again.

The following is the main bits of code which I have written to do this 
automatic deletion; it deletes ONLY the pages which you have created after 
installation is finished.  If you know PHP this should be everything you 
need.

Happy Deleting!


Hugh

// Delete all pages in the Main namespace (except "Main Page")
//
$mediaWiki = new MediaWiki();  // my own class defined below
$pages = new Pages;                    // another class of my own defined 
below
$pageName = $pages->getNextPageTitle();
while ($pageName <> "") {
    echo "Deleting page \"$pageName\"<br>";
    $mediaWiki->deleteWikiPage($pageName);

    $pageName = $pages->getNextPageTitle();
}

/**
* Methods for handling items in the wiki_page table
*/
class Pages {
 /**
 * Get next page title
 */
 function getNextPageTitle() {
  $dbWiki = new DbWiki;

  $pageTitle = "";

  $mainPageTitle = "Main_Page";

  $sql = "SELECT page_title FROM wiki_page ".
   "WHERE page_namespace = 0 " .
   "AND page_title <> \"$mainPageTitle\"";
    $result = $dbWiki->query($sql);
  if ($result) {
   list($pageTitle) = $dbWiki->fetchArray($result);
  }

  return $pageTitle;
 }

}

class MediaWiki {
/**
  * Delete a wiki page
  */
 function deleteWikiPage($pageName, $reason="No delete reason given.") {
  global $wgUser;

  $dbw =& wfGetDB( DB_MASTER );

  $wgUser = User::newFromName("DeletePageBot");

  $title = new Title();
  $title = $title->newFromText($pageName);

  $article = new Article( $title );

  $article->doDelete($reason);

  //Now commit any transactions
  //$wgLoadBalancer->commitAll();
  $dbw->commit();
 }
}

"Shai Shen-Orr" <shenorr at mcb.harvard.edu> wrote in 
message news:004801c69088$c9a5dc00$6d01a8c0 at mcb.harvard.edu...
> Hi all,
>
> I'd like to delete a large number of pages from my wiki and was wondering 
> if
> there was any easy way to do so (i.e. - asides from manually going into 
> each
> one and deleting it). I was thinking to do so by removing rows from the 
> PAGE
> table in mysql, but am afraid that links to the deleted pageIDs from other
> tables will bar me from doing this without the system crashing. Does 
> anyone
> have a clue ?
>
> Thanks,
>
> Shai 






More information about the MediaWiki-l mailing list