Difference between revisions of "Copy.php"
(add the actual move/delete code) |
(output results to page content) |
||
Line 11: | Line 11: | ||
# Perform the operation if target defined | # Perform the operation if target defined | ||
− | global $wgContLang; | + | global $wgContLang,$wgArticlePath; |
if ($summary) $summary = " : $summary"; | if ($summary) $summary = " : $summary"; | ||
$target = ucfirst(str_replace(' ', '_', $target)); | $target = ucfirst(str_replace(' ', '_', $target)); | ||
Line 20: | Line 20: | ||
$target = $nt->getText(); | $target = $nt->getText(); | ||
$err = ''; | $err = ''; | ||
+ | $link = str_replace('$1','',$wgArticlePath); | ||
+ | $olink = "<a href=\"$link".$ns.$title.">$ns$title</a>"; | ||
+ | $nlink = "<a href=\"$link".$ns.$target.">$ns$target</a>"; | ||
$list = array(''); | $list = array(''); | ||
if ($xml) ereg('^Xml:',$title) | if ($xml) ereg('^Xml:',$title) | ||
− | ? | + | ? $msg .= "<li>Properties not copied, $olink is already a properties article!</li>" |
: array_push($list,'Xml:'); | : array_push($list,'Xml:'); | ||
if ($talk) $ns & 1 | if ($talk) $ns & 1 | ||
− | ? | + | ? $msg .= "<li>Talk page not copied, $olink is already a talk page!</li>" |
: array_push($list,$wgContLang->getNsText($ns|1).':'); | : array_push($list,$wgContLang->getNsText($ns|1).':'); | ||
foreach ($list as $i => $nstxt) { | foreach ($list as $i => $nstxt) { | ||
$ot = Title::newFromText($nstxt.$title); | $ot = Title::newFromText($nstxt.$title); | ||
$nt = Title::newFromText($nstxt.$target); | $nt = Title::newFromText($nstxt.$target); | ||
− | if ($nt->getArticleID()) $err = | + | if ($nt->getArticleID()) $err = "<li><b>Could not copy to \"$nstxt$target\", already exists!", 'red'); |
else { | else { | ||
− | |||
$oa = new Article($ot); | $oa = new Article($ot); | ||
$na = new Article($nt); | $na = new Article($nt); | ||
if ($action == 'copy') { | if ($action == 'copy') { | ||
− | |||
$na->insertNewArticle($article, "[[talk:copy.php|Copied]] from [[$nstxt$title]]$summary", false, false); | $na->insertNewArticle($article, "[[talk:copy.php|Copied]] from [[$nstxt$title]]$summary", false, false); | ||
+ | $msg .= "New copy of $olink successfully created as $nlink"; | ||
} | } | ||
else { | else { | ||
− | + | if ($err = $ot->moveTo($nt)) $msg .= "<li><b>Move from $olink to $nlink failed:</b> $err</li>"; | |
− | $ | + | else { |
− | + | $msg .= "<li>$olink successfully moved to $nlink</li>"; | |
− | + | if ($action == 'rename') { | |
− | + | $dbw =& wfGetDB(DB_MASTER); | |
− | + | $dbw->delete('cur', array('cur_namespace' => $ns, 'cur_title' => $title)); | |
− | + | $dbw->delete('old', array('old_namespace' => $ns, 'old_title' => $title)); | |
− | + | $dbw->delete('recentchanges', array('rc_namespace' => $ns, 'rc_title' => $title)); | |
+ | } | ||
} | } | ||
} | } | ||
} | } | ||
− | if (($i == 0) && $err) break; # bail if problem moving the main article | + | if (($i == 0) && $err) { $msg = $err; break; } # bail if problem moving the main article |
} | } | ||
} | } | ||
else { | else { | ||
# Define the form | # Define the form | ||
− | $ | + | $msg = "<h3>Rename/copy article:</h3><form action=\"/wiki/index.php\"> |
<input type=hidden name=title value=\"$title\"> | <input type=hidden name=title value=\"$title\"> | ||
<input type=hidden name=\"xpath:/properties:data\" value=\"$tTitle\"> | <input type=hidden name=\"xpath:/properties:data\" value=\"$tTitle\"> | ||
Line 87: | Line 90: | ||
The original title is left unaffected by this operation.<br> | The original title is left unaffected by this operation.<br> | ||
</table></form>"; | </table></form>"; | ||
− | |||
− | |||
− | |||
} | } | ||
+ | $article = preg_replace('/(?<=<!-- start content -->).+(?=<!-- end content -->)/s',$msg,$article); | ||
?> | ?> |
Revision as of 05:58, 25 October 2006
<?
- Get copy-target and summary-text from form
xwGetProperty($properties, 'copy/target', $target); xwGetProperty($properties, 'copy/summary', $summary); xwGetProperty($properties, 'copy/xml', $xml); # move/copy properties too? xwGetProperty($properties, 'copy/talk', $talk); # move/copy talk too? xwGetProperty($properties, 'copy/action', $action);
if ($target) { # Perform the operation if target defined
global $wgContLang,$wgArticlePath; if ($summary) $summary = " : $summary"; $target = ucfirst(str_replace(' ', '_', $target)); $ot = Title::newFromText($title); $nt = Title::newFromText($target); $ns = $ot->getNamespace(); $title = $ot->getText(); $target = $nt->getText(); $err = ; $link = str_replace('$1',,$wgArticlePath); $olink = "<a href=\"$link".$ns.$title.">$ns$title</a>"; $nlink = "<a href=\"$link".$ns.$target.">$ns$target</a>";
$list = array(); if ($xml) ereg('^Xml:',$title)
? $msg .= "
"
: array_push($list,'Xml:'); if ($talk) $ns & 1
? $msg .= "
"
: array_push($list,$wgContLang->getNsText($ns|1).':'); foreach ($list as $i => $nstxt) { $ot = Title::newFromText($nstxt.$title); $nt = Title::newFromText($nstxt.$target);
if ($nt->getArticleID()) $err = "
";
else {
$msg .= "
";
if ($action == 'rename') { $dbw =& wfGetDB(DB_MASTER); $dbw->delete('cur', array('cur_namespace' => $ns, 'cur_title' => $title)); $dbw->delete('old', array('old_namespace' => $ns, 'old_title' => $title)); $dbw->delete('recentchanges', array('rc_namespace' => $ns, 'rc_title' => $title)); } } } } if (($i == 0) && $err) { $msg = $err; break; } # bail if problem moving the main article } } else { # Define the form
$msg = "
Rename/copy article:
<form action=\"/wiki/index.php\">
<input type=hidden name=title value=\"$title\"> <input type=hidden name=\"xpath:/properties:data\" value=\"$tTitle\"> <input type=hidden name=\"xpath:/properties:copy\">
New title: | <input type=text name=\"xpath:/properties/copy:target\"> |
Reason: | <input type=text name=\"xpath:/properties/copy:summary\"> |
Action: | <input type=radio name=\"xpath:/properties/copy:action\" value=rename checked>Rename
<input type=radio name=\"xpath:/properties/copy:action\" value=redir>Redirect <input type=radio name=\"xpath:/properties/copy:action\" value=copy>Copy |
<input type=checkbox checked=checked value=1 name=\"xpath:/properties/copy:xml\">
Also apply to properties | |
<input type=checkbox checked=checked value=1 name=\"xpath:/properties/copy:talk\">
Also apply to discussion | |
<input type=submit value=\" Commit \"> | |
Help Rename |
</form>";
}
$article = preg_replace('/(?<=).+(?=)/s',$msg,$article); ?>