r93190 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93189‎ | r93190 | r93191 >
Date:15:10, 26 July 2011
Author:ankitgarg833
Status:deferred
Tags:
Comment:
deleting to files, renaming it to PS_*
Modified paths:
  • /trunk/extensions/PageSchemas/specials/EditSchema.php (deleted) (history)
  • /trunk/extensions/PageSchemas/specials/GeneratePages.php (deleted) (history)

Diff [purge]

Index: trunk/extensions/PageSchemas/specials/GeneratePages.php
@@ -1,84 +0,0 @@
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 -}
Index: trunk/extensions/PageSchemas/specials/EditSchema.php
@@ -1,215 +0,0 @@
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 EditSchema extends IncludableSpecialPage {
10 - function __construct() {
11 - parent::__construct( 'EditSchema' );
12 - wfLoadExtensionMessages('EditSchema');
13 - }
14 - public static function addJavascript() {
15 - global $wgOut;
16 -
17 - PageSchemas::addJavascriptAndCSS();
18 -
19 - // TODO - this should be in a JS file
20 - $template_name_error_str = wfMsg( 'sf_blank_error' );
21 - $jsText =<<<END
22 -<script type="text/javascript">
23 -var fieldNum = 1;
24 -var templateNum = 1;
25 -function createTemplateAddField(template_num) {
26 - fieldNum++;
27 - newField = jQuery('#starterField').clone().css('display', '').removeAttr('id');
28 - newHTML = newField.html().replace(/starter/g, fieldNum);
29 - newField.html(newHTML);
30 - newField.find(".deleteField").click( function() {
31 - // Remove the encompassing div for this instance.
32 - jQuery(this).closest(".fieldBox")
33 - .fadeOut('fast', function() { jQuery(this).remove(); });
34 - });
35 - jQuery('#fieldsList_'+template_num).append(newField);
36 -}
37 -function createAddTemplate() {
38 - templateNum++;
39 - newField = jQuery('#starterTemplate').clone().css('display', '').removeAttr('id');
40 - newHTML = newField.html().replace(/starter/g, templateNum);
41 - newField.html(newHTML);
42 - newField.find(".deleteTemplate").click( function() {
43 - // Remove the encompassing div for this instance.
44 - jQuery(this).closest(".templateBox")
45 - .fadeOut('fast', function() { jQuery(this).remove(); });
46 - });
47 - jQuery('#templatesList').append(newField);
48 -}
49 -
50 -
51 -jQuery(document).ready(function() {
52 - jQuery(".deleteField").click( function() {
53 - // Remove the encompassing div for this instance.
54 - jQuery(this).closest(".fieldBox")
55 - .fadeOut('fast', function() { jQuery(this).remove(); });
56 - });
57 - jQuery(".deleteTemplate").click( function() {
58 - // Remove the encompassing div for this instance.
59 - jQuery(this).closest(".templateBox")
60 - .fadeOut('fast', function() { jQuery(this).remove(); });
61 - });
62 -});
63 -</script>
64 -
65 -END;
66 - $wgOut->addScript( $jsText );
67 - }
68 -
69 - function execute( $category ) {
70 - global $wgRequest, $wgOut;
71 - global $wgSkin;
72 - $this->setHeaders();
73 - $text_1 = '<p>This category does not exist yet. Create this category and its page schema: </p>';
74 - $text_2 = '<p>This category exists, but does not have a page schema. Create schema:" </p>';
75 - if ( $category != "" ) {
76 - $title = Title::newFromText( $category, NS_CATEGORY );
77 - $pageId = $title->getArticleID();
78 - $dbr = wfGetDB( DB_SLAVE );
79 - //get the result set, query : slect page_props
80 - $res = $dbr->select( 'page_props',
81 - array(
82 - 'pp_page',
83 - 'pp_propname',
84 - 'pp_value'
85 - ),
86 - array(
87 - 'pp_page' => $pageId,
88 - )
89 - );
90 - //first row of the result set
91 - $row = $dbr->fetchRow( $res );
92 - if( $row == null ){
93 - //Create form here
94 - self::addJavascript();
95 - $text = "";
96 - $text .= '<p>This category does not exist yet. Create this category and its page schema: </p>';
97 - $text .= ' <form id="createPageSchemaForm" action="" method="post">' . "\n";
98 - $text .= '<p>Name of schema: <input type="text" /> </p> ';
99 - $text .= '<p>Additional XML:
100 - <textarea rows=4 style="width: 100%" name="ps_add_xml"></textarea>
101 - </p> ';
102 - $text .= '<div id="templatesList">';
103 - $text .= '<div class="templateBox" >';
104 - $text .= '<fieldset style="background: #ddd;"><legend>Template</legend> ';
105 - $text .= '<p>Name: <input type="text" name="t_name_1"/></p> ';
106 - $text .= '<p><input type="checkbox" name="is_multiple_1"/> Allow multiple instances of this template</p> ';
107 - $text .= '<div id="fieldsList_1">';
108 - $text .= '<div class="fieldBox" >';
109 - $text .= '<fieldset style="background: #bbb;"><legend>Field</legend>
110 - <p>Field name: <input size="15" name="name_1">
111 - Display label: <input size="15" name="label_1">
112 - </p>
113 - <p><input type="checkbox" name="is_list_1"/>
114 - This field can hold multiple values
115 - </p>
116 - <p>Additional XML:
117 - <textarea rows=4 style="width: 100%" name="add_xml_1"></textarea>
118 - </p>
119 - <input type="button" value="Remove field" class="deleteField" /> </div>
120 -
121 -</div>
122 - </fieldset> ';
123 - $add_field_button = Xml::element( 'input',
124 - array(
125 - 'type' => 'button',
126 - 'value' => 'Add Field',
127 - 'onclick' => "createTemplateAddField(1)"
128 - )
129 - );
130 - $text .= Xml::tags( 'p', null, $add_field_button ) . "\n";
131 - $text .= '<hr />
132 - <p>Additional XML:
133 - <textarea rows=4 style="width: 100%" name="t_add_xml_1"></textarea>
134 - </p>
135 - <p><input type="button" value="Remove template" class="deleteTemplate" /></p>
136 - </fieldset> </div>';
137 - $text .= '<div class="templateBox" id="starterTemplate" style="display: none">
138 -<fieldset style="background: #ddd;">
139 -<legend>Template</legend>
140 -<p>Name: <input type="text" name="t_name_starter"/></p>
141 -<p><input type="checkbox" name="is_multiple_starter"/> Allow multiple instances of this template</p>
142 -<div id="fieldsList_starter">
143 -</div>
144 - <p><input type="button" value="Add Field" onclick="createTemplateAddField(starter)" /></p>
145 -
146 -<hr />
147 - <p>Additional XML:
148 - <textarea rows=4 style="width: 100%" name="t_add_xml_starter"></textarea>
149 - </p>
150 - <p><input type="button" value="Remove template" class="deleteTemplate" /></p>
151 - </fieldset>
152 - </div>
153 - </div>
154 - <hr /> ';
155 - $text .= '<div class="fieldBox" id="starterField" style="display: none">
156 - <p>Field name: <input size="15" name="name_starter">
157 - Display label: <input size="15" name="label_starter">
158 - </p>
159 - <p><input type="checkbox" name="is_list_starter" /> This field can hold a list of values, separated by commas
160 - &#160;&#160; <p>Additional XML:
161 - <textarea rows=4 style="width: 100%" name="add_xml_starter"></textarea>
162 - </p>
163 - <input type="button" value="Remove field" class="deleteField" />
164 -</p>
165 -</div>';
166 - $add_template_button = Xml::element( 'input',
167 - array(
168 - 'type' => 'button',
169 - 'value' => 'Add Template',
170 - 'onclick' => "createAddTemplate()"
171 - )
172 - );
173 - $text .= Xml::tags( 'p', null, $add_template_button ) . "\n";
174 - $text .= ' <hr />
175 - <p><input type="submit" value="Save" /></p> ';
176 - $text .= ' </form>';
177 - $wgOut->addHTML( $text );
178 - }else{
179 - if( ($row[1] == 'PageSchema') && ($row[2] != null )){
180 -
181 - }else{
182 - $wgOut->addHTML($text_2);
183 - }
184 - }
185 - }else {
186 - $cat_titles = array();
187 - $count_title = 0;
188 - $text = "";
189 - $dbr = wfGetDB( DB_SLAVE );
190 - //get the result set, query : slect page_props
191 - $res = $dbr->select( 'page_props',
192 - array(
193 - 'pp_page',
194 - 'pp_propname',
195 - 'pp_value'
196 - ),
197 - array(
198 - 'pp_propname' => 'PageSchema'
199 - )
200 - );
201 - while ( $row = $dbr->fetchRow( $res ) ) {
202 - if( $row[2] != null ){
203 - $page_id_cat = $row[0];
204 - if( Title::newFromId($page_id_cat)->getNamespace() == NS_CATEGORY){
205 - $cat_text = Title::newFromId($page_id_cat)->getText();
206 - $generatePagesPage = SpecialPage::getTitleFor( 'EditSchema' );
207 - $url = $generatePagesPage ->getFullURL() . '/' . $cat_text;
208 - $text .= '<a href='.$url.'>'.$cat_text.' </a> <br /> ';
209 - }
210 - }
211 - }
212 - $dbr->freeResult( $res );
213 - $wgOut->addHTML( $text );
214 - }
215 - }
216 -}

Status & tagging log