r25105 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25104‎ | r25105 | r25106 >
Date:06:36, 24 August 2007
Author:yaron
Status:old
Tags:
Comment:
Improved PHP to eliminate reporting errors in PHP debug mode,
simplified call of wfGetDB()
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormEditTab.php (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_GlobalFunctions.php (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_TemplateField.inc (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_AddData.php (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_CreateForm.php (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_CreateTemplate.php (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_Forms.php (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_Templates.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/specials/SF_AddData.php
@@ -23,8 +23,8 @@
2424 // if query string did not contain these variables, try the URL
2525 if (! $form_name && ! $target_name) {
2626 $queryparts = explode('/', $query, 2);
27 - $form_name = $queryparts[0];
28 - $target_name = $queryparts[1];
 27+ $form_name = isset($queryparts[0]) ? $queryparts[0] : '';
 28+ $target_name = isset($queryparts[1]) ? $queryparts[1] : '';
2929 }
3030
3131 // get contents of template
@@ -34,8 +34,9 @@
3535
3636 // target_title should be null - we shouldn't be adding a page that
3737 // already exists
38 - // TODO - handle this contingency
3938 if ($target_title && $target_title->exists()) {
 39+ $wgOut->addWikiText( "<p class='error'>" . wfMsg('articleexists') . '</p>');
 40+ return;
4041 } else {
4142 $page_title = str_replace('_', ' ', $target_name);
4243 }
@@ -94,6 +95,7 @@
9596 ));
9697 $wgOut->addScript('<script src="' . $sfgScriptPath . '/libs/scriptaculous-js-1.7.0/lib/prototype.js" type="text/javascript"></script>' . "\n");
9798 $wgOut->addScript(' <script src="' . $sfgScriptPath . '/libs/scriptaculous-js-1.7.0/src/scriptaculous.js" type="text/javascript"></script>' . "\n");
98 - $wgOut->addScript(' <script type="text/javascript">' . "\n" . $javascript_text . '</script>' . "\n");
 99+ if (! empty($javascript_text))
 100+ $wgOut->addScript(' <script type="text/javascript">' . "\n" . $javascript_text . '</script>' . "\n");
99101 $wgOut->addHTML($text);
100102 }
Index: trunk/extensions/SemanticForms/specials/SF_Forms.php
@@ -36,7 +36,7 @@
3737
3838 function getSQL() {
3939 $NSform = SF_NS_FORM;
40 - $dbr =& wfGetDB( DB_SLAVE );
 40+ $dbr = wfGetDB( DB_SLAVE );
4141 $page = $dbr->tableName( 'page' );
4242 // QueryPage uses the value from this SQL in an ORDER clause,
4343 // so return page_title as title.
Index: trunk/extensions/SemanticForms/specials/SF_CreateForm.php
@@ -8,7 +8,7 @@
99
1010 if (!defined('MEDIAWIKI')) die();
1111
12 -global $IP;
 12+global $IP, $sfgIP;
1313 require_once( "$IP/includes/SpecialPage.php" );
1414 require_once( "$sfgIP/includes/SF_FormClasses.inc" );
1515
@@ -16,8 +16,7 @@
1717
1818 function doSpecialCreateForm() {
1919 global $wgOut, $wgRequest, $wgUser;
20 - $fname = "CreateForm::doSpecialCreateForm()";
21 - $db =& wfGetDB( DB_SLAVE );
 20+ $db = wfGetDB( DB_SLAVE );
2221
2322 # get the names of all templates on this site
2423 $all_templates = array();
@@ -37,18 +36,21 @@
3837 # handle inputs
3938 $form_name = $wgRequest->getVal('form_name');
4039 foreach ($wgRequest->getValues() as $var => $val) {
41 - # get the template declarations and work from there
42 - list ($action, $id) = explode("_", $var);
43 - if ($action == "template") {
44 - # if the button was pressed to remove this template, just don't
45 - # add it to the array
46 - if ($wgRequest->getVal("del_$id") != "Remove template") {
47 - $form_template = SFTemplateInForm::create($val,
48 - $wgRequest->getVal("label_$id"),
49 - $wgRequest->getVal("allow_multiple_$id"));
50 - $form_templates[] = $form_template;
51 - } else {
52 - $deleted_template_loc = $id;
 40+ # ignore variables that are not of the right form
 41+ if (strpos($var, "_") != false) {
 42+ # get the template declarations and work from there
 43+ list ($action, $id) = explode("_", $var, 2);
 44+ if ($action == "template") {
 45+ # if the button was pressed to remove this template, just don't
 46+ # add it to the array
 47+ if ($wgRequest->getVal("del_$id") != "Remove template") {
 48+ $form_template = SFTemplateInForm::create($val,
 49+ $wgRequest->getVal("label_$id"),
 50+ $wgRequest->getVal("allow_multiple_$id"));
 51+ $form_templates[] = $form_template;
 52+ } else {
 53+ $deleted_template_loc = $id;
 54+ }
5355 }
5456 }
5557 }
@@ -127,7 +129,10 @@
128130 $text .= ' <form action="" method="get">' . "\n";
129131 // set 'title' field, in case there's no URL niceness
130132 $text .= ' <input type="hidden" name="title" value="Special:CreateForm">' . "\n";
131 - $text .= ' <p>' . wfMsg('sf_createform_nameinput') . ' <input size=25 name="form_name" value="' . $form_name . '"> <font color="red">' . $form_name_error_str . '</font></p>' . "\n";
 133+ $text .= ' <p>' . wfMsg('sf_createform_nameinput') . ' <input size=25 name="form_name" value="' . $form_name . '">';
 134+ if (! empty($form_name_error_str))
 135+ $text .= ' <font color="red">' . $form_name_error_str . '</font>';
 136+ $text .= "</p>\n";
132137
133138 $text .= $form->creationHTML();
134139
Index: trunk/extensions/SemanticForms/specials/SF_Templates.php
@@ -36,7 +36,7 @@
3737
3838 function getSQL() {
3939 $NStemp = NS_TEMPLATE;
40 - $dbr =& wfGetDB( DB_SLAVE );
 40+ $dbr = wfGetDB( DB_SLAVE );
4141 $page = $dbr->tableName( 'page' );
4242 // QueryPage uses the value from this SQL in an ORDER clause,
4343 // so return page_title as title.
Index: trunk/extensions/SemanticForms/specials/SF_CreateTemplate.php
@@ -27,7 +27,7 @@
2828 }
2929 }
3030 function getSemanticProperties() {
31 - $dbr =& wfGetDB( DB_SLAVE );
 31+ $dbr = wfGetDB( DB_SLAVE );
3232 $all_properties = array();
3333
3434 $res = $dbr->query("SELECT page_title FROM " . $dbr->tableName('page') .
Index: trunk/extensions/SemanticForms/includes/SF_TemplateField.inc
@@ -30,7 +30,7 @@
3131 // this whole section of code could be made much simpler if it were
3232 // to use the SMWTypeHandlerFactory class; but that would mean it
3333 // would require SMW 0.7, which it might be too early for
34 - $db =& wfGetDB( DB_SLAVE );
 34+ $db = wfGetDB( DB_SLAVE );
3535 // value has underscores in the database
3636 $semantic_field_db_str = str_replace(' ', '_', $f->semantic_field);
3737 $conditions = "subject_namespace = " . SMW_NS_ATTRIBUTE . " AND subject_title = '$semantic_field_db_str' AND property_id = 1";
Index: trunk/extensions/SemanticForms/includes/SF_GlobalFunctions.php
@@ -5,7 +5,7 @@
66 * @author Yaron Koren
77 */
88
9 -define('SF_VERSION','0.5.3');
 9+define('SF_VERSION','0.5.4');
1010
1111 $wgExtensionFunctions[] = 'sfgSetupExtension';
1212 $wgExtensionFunctions[] = 'sfgParserFunctions';
@@ -222,7 +222,7 @@
223223 // get all relations that have this page as an object,
224224 // and see if any of them have a default form specified
225225 $fname = 'sffAddDataLink';
226 - $db =& wfGetDB( DB_SLAVE );
 226+ $db = wfGetDB( DB_SLAVE );
227227 $sql = "SELECT DISTINCT relation_title FROM {$db->tableName('smw_relations')} WHERE object_title = '" . $db->strencode($title->getDBkey()) . "' AND object_namespace = '" . $title->getNamespace() . "'";
228228 $res = $db->query( $sql );
229229 if ($db->numRows( $res ) > 0) {
@@ -244,7 +244,7 @@
245245
246246 function sffFormDropdownHTML() {
247247 // create a dropdown of possible form names
248 - $dbr =& wfGetDB( DB_SLAVE );
 248+ $dbr = wfGetDB( DB_SLAVE );
249249 $query = "SELECT page_title FROM " . $dbr->tableName( 'page' ) .
250250 " WHERE page_namespace = " . SF_NS_FORM .
251251 " AND page_is_redirect = 0";
Index: trunk/extensions/SemanticForms/includes/SF_FormEditTab.php
@@ -10,7 +10,7 @@
1111 $fname = 'SFFormEditTab::getCategoriesForArticle()';
1212 $categories = array();
1313 $titlekey = $article->mTitle->getArticleId();
14 - $db =& wfGetDB( DB_SLAVE );
 14+ $db = wfGetDB( DB_SLAVE );
1515 $conditions = "cl_from='$titlekey'";
1616 $res = $db->select( $db->tableName('categorylinks'),
1717 'cl_to',
@@ -31,7 +31,7 @@
3232 */
3333 function sffFormEditTab($obj, $content_actions) {
3434 $fname = 'SFFormEditTab';
35 - $db =& wfGetDB( DB_SLAVE );
 35+ $db = wfGetDB( DB_SLAVE );
3636 // make sure that this is not itself a category page, and that the user
3737 // is allowed to edit it
3838 if (($obj->mTitle != null) && ($obj->mTitle->getNamespace() != NS_CATEGORY)) {

Status & tagging log