r31796 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r31795‎ | r31796 | r31797 >
Date:16:39, 11 March 2008
Author:yaron
Status:old
Tags:
Comment:
Added handling for automatic page-name setting
Modified paths:
  • /trunk/extensions/SemanticForms/specials/SF_AddData.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/specials/SF_AddData.php
@@ -52,19 +52,14 @@
5353 $wgOut->addHTML( "<p class='error'>" . wfMsg('sf_adddata_badurl') . '</p>');
5454 return;
5555 } elseif ($target_name == '') {
56 - if (count($alt_forms) > 0) {
57 - // if there's just a target and list of alternate
58 - // forms, but no main form, display just a list of
59 - // links on the page
60 - $target_name = $form_name;
61 - $target_title = Title::newFromText($target_name);
62 - $s = wfMsg('sf_adddata_title', "", $target_title->getPrefixedText());
63 - $wgOut->setPageTitle($s);
64 - $text = '<p>' . wfMsg('sf_adddata_altformsonly') . ' ';
65 - $text .= printAltFormsList($alt_forms, $target_name);
66 - $text .= "</p>\n";
67 - $wgOut->addHTML($text);
68 - return;
 56+ // parse the form to see if it has a 'page name' value set
 57+ $form_title = Title::newFromText($form_name, SF_NS_FORM);
 58+ $form_article = new Article($form_title);
 59+ $form_definition = $form_article->getContent();
 60+ $form_definition = StringUtils::delimiterReplace('<noinclude>', '</noinclude>', '', $form_definition);
 61+ $matches;
 62+ if (preg_match('/{{{info.*page name=([^\|}]*)/', $form_definition, $matches)) {
 63+ $page_name_formula = str_replace('_', ' ', $matches[1]);
6964 } else {
7065 $wgOut->addWikiText( "<p class='error'>" . wfMsg('sf_adddata_badurl') . '</p>');
7166 return;
@@ -72,17 +67,19 @@
7368 }
7469
7570 $form_title = Title::newFromText($form_name, SF_NS_FORM);
76 - $target_title = Title::newFromText($target_name);
7771
78 - $s = wfMsg('sf_adddata_title', $form_title->getText(), $target_title->getPrefixedText());
79 - $wgOut->setPageTitle($s);
 72+ if ($target_name != '') {
 73+ $target_title = Title::newFromText($target_name);
 74+ $s = wfMsg('sf_adddata_title', $form_title->getText(), $target_title->getPrefixedText());
 75+ $wgOut->setPageTitle($s);
 76+ }
8077
8178 // target_title should be null - we shouldn't be adding a page that
8279 // already exists
8380 if ($target_title && $target_title->exists()) {
8481 $wgOut->addWikiText( "<p class='error'>" . wfMsg('articleexists') . '</p>');
8582 return;
86 - } else {
 83+ } elseif ($target_name != '') {
8784 $page_title = str_replace('_', ' ', $target_name);
8885 }
8986
@@ -91,11 +88,11 @@
9289 $text = '<p>' . wfMsg('sf_adddata_badurl') . "</p>\n";
9390 else
9491 $text = '<p>' . wfMsg('sf_addpage_badform', sffLinkText(SF_NS_FORM, $form_name)) . ".</p>\n";
95 - } elseif ($target_name == '') {
 92+ } elseif ($target_name == '' && $page_name_formula == '') {
9693 $text = '<p>' . wfMsg('sf_adddata_badurl') . "</p>\n";
9794 } else {
98 - $formArticle = new Article($form_title);
99 - $form_definition = $formArticle->getContent();
 95+ $form_article = new Article($form_title);
 96+ $form_definition = $form_article->getContent();
10097
10198 $save_page = $wgRequest->getCheck('wpSave');
10299 $preview_page = $wgRequest->getCheck('wpPreview');
@@ -109,15 +106,39 @@
110107 $page_is_source = false;
111108 $page_contents = null;
112109 }
113 - list ($form_text, $javascript_text, $data_text, $form_page_title) =
114 - $sfgFormPrinter->formHTML($form_definition, $form_submitted, $page_is_source, $page_contents, $page_title);
 110+ list ($form_text, $javascript_text, $data_text, $form_page_title, $generated_page_name) =
 111+ $sfgFormPrinter->formHTML($form_definition, $form_submitted, $page_is_source, $page_contents, $page_title, $page_name_formula);
115112 if ($form_submitted) {
 113+ if ($page_name_formula != '') {
 114+ // replace "unique number" tag with one that
 115+ // won't get erased by the next line
 116+ $target_name = preg_replace('/<unique number>/', '{num}', $generated_page_name, 1);
 117+ // if any formula stuff is still in the name
 118+ // after the parsing, just remove it
 119+ $target_name = StringUtils::delimiterReplace('<', '>', '', $target_name);
 120+ if (strpos($target_name, '{num}')) {
 121+ // cycle through numbers for this tag
 122+ // until we find one that gives a
 123+ // nonexistent page title
 124+ $title_number = 1;
 125+ do {
 126+ $target_title = Title::newFromText(str_replace('{num}', $title_number, $target_name));
 127+ $title_number++;
 128+ } while ($target_title->exists());
 129+ } else {
 130+ $target_title = Title::newFromText($target_name);
 131+ }
 132+ }
116133 $text = sffPrintRedirectForm($target_title, $data_text, $wgRequest->getVal('wpSummary'), $save_page, $preview_page, $diff_page, $wgRequest->getCheck('wpMinoredit'), $wgRequest->getCheck('wpWatchthis'));
117134 } else {
118135 // override the default title for this page if
119136 // a title was specified in the form
120137 if ($form_page_title != NULL) {
121 - $wgOut->setPageTitle("$form_page_title: {$target_title->getPrefixedText()}");
 138+ if ($target_name == '') {
 139+ $wgOut->setPageTitle($form_page_title);
 140+ } else {
 141+ $wgOut->setPageTitle("$form_page_title: {$target_title->getPrefixedText()}");
 142+ }
122143 }
123144 $text = "";
124145 if (count($alt_forms) > 0) {

Status & tagging log