r38006 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r38005‎ | r38006 | r38007 >
Date:18:21, 24 July 2008
Author:yaron
Status:old
Tags:
Comment:
Added handling for bad page names, and query strings on sites that don't
do URL rewriting
Modified paths:
  • /trunk/extensions/SemanticForms/specials/SF_AddPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/specials/SF_AddPage.php
@@ -63,12 +63,19 @@
6464 if ('' != $page_name) {
6565 // Append the namespace prefix to the page name,
6666 // if a namespace was not already entered.
67 - if (strpos($page_name,":") === false)
 67+ if (strpos($page_name,":") === false && $target_namespace != '')
6868 $page_name = $target_namespace . ":" . $page_name;
6969 // find out whether this page already exists,
7070 // and send user to the appropriate form
7171 $page_title = Title::newFromText($page_name);
72 - if ($page_title && $page_title->exists()) {
 72+ if (! $page_title) {
 73+ // if there was no page title, it's probably
 74+ // an invalid page name, containing forbidden
 75+ // characters
 76+ $error_msg = wfMsg('sf_addpage_badtitle', $page_name);
 77+ $wgOut->addHTML($error_msg);
 78+ return;
 79+ } elseif ($page_title->exists()) {
7380 // it exists - see if page is a redirect; if
7481 // it is, edit the target page instead
7582 $article = new Article($page_title);
@@ -98,25 +105,22 @@
99106 // 'AddData' only 'preload' and specific form
100107 // fields - we can tell the latter because
101108 // they show up as 'arrays'
102 - $first_val_added = false;
103109 foreach ($_REQUEST as $key => $val) {
104110 if (is_array($val)) {
105111 $template_name = $key;
106112 foreach ($val as $field_name => $value) {
107 - $redirect_url .= ($first_val_added) ? '&' : '?';
 113+ $redirect_url .= (strpos($redirect_url, "?") > -1) ? '&' : '?';
108114 $redirect_url .= $template_name . '[' . $field_name . ']=' . $value;
109 - $first_val_added = true;
110115 }
111116 } elseif ($key == 'preload') {
112 - $redirect_url .= ($first_val_added) ? '&' : '?';
 117+ $redirect_url .= (strpos($redirect_url, "?") > -1) ? '&' : '?';
113118 $redirect_url .= "$key=$val";
114 - $first_val_added = true;
115119 }
116120 }
117121 }
118122
119123 if ('' != $params) {
120 - $redirect_url .= ($first_val_added) ? '&' : '?';
 124+ $redirect_url .= (strpos($redirect_url, "?") > -1) ? '&' : '?';
121125 $redirect_url .= $params;
122126 }
123127

Status & tagging log