r93181 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93180‎ | r93181 | r93182 >
Date:14:25, 26 July 2011
Author:ankitgarg833
Status:deferred (Comments)
Tags:
Comment:
renaming EditSchema to PS_EditSchema.php
Modified paths:
  • /trunk/extensions/PageSchemas/specials/PS_EditSchema.php (added) (history)

Diff [purge]

Index: trunk/extensions/PageSchemas/specials/PS_EditSchema.php
@@ -0,0 +1,215 @@
 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 a list of 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+}

Comments

#Comment by Nikerabbit (talk | contribs)   18:02, 26 July 2011

Please use svn move.

#Comment by 😂 (talk | contribs)   14:00, 10 August 2011

This should've been fixed back when it happened, but it didn't. This is very time-consuming to unwind now and repair. Considering it's an extension that's not even getting CR...can we kill the fixme and just hope it doesn't happen again?

Status & tagging log