Index: trunk/extensions/PageSchemas/specials/PS_GeneratePages.php |
— | — | @@ -0,0 +1,84 @@ |
| 2 | +<?php
|
| 3 | +/**
|
| 4 | + * Displays an interface to let users create all pages based on xml
|
| 5 | + *
|
| 6 | + * @author Ankit Garg
|
| 7 | + */
|
| 8 | +
|
| 9 | +class GeneratePages extends IncludableSpecialPage {
|
| 10 | + function __construct() {
|
| 11 | + parent::__construct( 'GeneratePages' );
|
| 12 | + wfLoadExtensionMessages('GeneratePages');
|
| 13 | + }
|
| 14 | +
|
| 15 | + function execute( $category ) {
|
| 16 | + global $wgRequest, $wgOut;
|
| 17 | + global $wgSkin;
|
| 18 | + $this->setHeaders();
|
| 19 | + $generate_page_text = wfMsg( 'ps-generatepages' );
|
| 20 | + $generate_page_desc = wfMsg( 'ps-generatepages-desc' );
|
| 21 | + $param = $wgRequest->getText('param');
|
| 22 | + $text_1 = '<p>All pages will be generated! </p>';
|
| 23 | + if ( $param != "" && $category != "" ) {
|
| 24 | + $this->generate_pages( $param, $_POST['page'] );
|
| 25 | + $wgOut->addHTML($text_1);
|
| 26 | + }else {
|
| 27 | + if( $category == ""){
|
| 28 | + $cat_titles = array();
|
| 29 | + $count_title = 0;
|
| 30 | + $text = "";
|
| 31 | + $dbr = wfGetDB( DB_SLAVE );
|
| 32 | + //get the result set, query : slect page_props
|
| 33 | + $res = $dbr->select( 'page_props',
|
| 34 | + array(
|
| 35 | + 'pp_page',
|
| 36 | + 'pp_propname',
|
| 37 | + 'pp_value'
|
| 38 | + ),
|
| 39 | + array(
|
| 40 | + 'pp_propname' => 'PageSchema'
|
| 41 | + )
|
| 42 | + );
|
| 43 | + while ( $row = $dbr->fetchRow( $res ) ) {
|
| 44 | + if( $row[2] != null ){
|
| 45 | + $page_id_cat = $row[0];
|
| 46 | + if( Title::newFromId($page_id_cat)->getNamespace() == NS_CATEGORY){
|
| 47 | + $cat_text = Title::newFromId($page_id_cat)->getText();
|
| 48 | + $generatePagesPage = SpecialPage::getTitleFor( 'GeneratePages' );
|
| 49 | + $url = $generatePagesPage ->getFullURL() . '/' . $cat_text;
|
| 50 | + $text .= '<a href='.$url.'>'.$cat_text.' </a> <br /> ';
|
| 51 | + }
|
| 52 | + }
|
| 53 | + }
|
| 54 | + $dbr->freeResult( $res );
|
| 55 | + $wgOut->addHTML( $text );
|
| 56 | + }else {
|
| 57 | + //this is when Special:GeneratePages/Category is accessed first time
|
| 58 | + //Here check for the valid Category name and allow for generating pages
|
| 59 | + $pageSchemaObj = new PSSchema( $category );
|
| 60 | + if(!$pageSchemaObj->isPSDefined()){
|
| 61 | + $text = "<p>Error: there is no psssage schema defined for that category in the wiki. </p>";
|
| 62 | + $wgOut->addHTML( $text );
|
| 63 | + }else{
|
| 64 | + $text_2 = '<p>'.$generate_page_desc.'</p> <form method="post"> <input type="hidden" name="param" value="'.$category.'" /><br /> ';
|
| 65 | + //add code to generate a list of check-box for pages to be generated.
|
| 66 | + $pageList = array();
|
| 67 | + wfRunHooks( 'PageSchemasGetPageList', array( $pageSchemaObj, &$pageList )); //will return an array of string, with each value as a title of the page to be created.
|
| 68 | + foreach( $pageList as $page ){
|
| 69 | + //$page_link = $wgSkin->link( $page );
|
| 70 | + $page_link = $page->getFullUrl();
|
| 71 | + $page_val = PageSchemas::titleString( $page );
|
| 72 | + $text_2 .= '<input type="checkbox" name="page[]" value="'.$page_val.'" /> '.$page_link.' <br />';
|
| 73 | + }
|
| 74 | + $text_2 .= '<br /> <input type="submit" value="'.$generate_page_text.'" /> <br /> <br /></form>';
|
| 75 | + $wgOut->addHTML($text_2);
|
| 76 | + }
|
| 77 | + }
|
| 78 | + }
|
| 79 | + }
|
| 80 | + function generate_pages ( $categoryName, $toGenPageList ) {
|
| 81 | + global $wgRequest, $wgOut;
|
| 82 | + $pageSchema = new PSSchema( $categoryName );
|
| 83 | + $pageSchema->generateAllPages( $toGenPageList );
|
| 84 | + }
|
| 85 | +}
|