Difference between revisions of "Copy.php"
m |
m |
||
Line 27: | Line 27: | ||
$list = array($nstxt); | $list = array($nstxt); | ||
if ($xml) ereg('^Xml:',$title) | if ($xml) ereg('^Xml:',$title) | ||
− | ? $msg .= " | + | ? $msg .= "<li>Properties not copied, [[$title]] is already a properties article!</li>" |
: array_push($list,"Xml:$nstxt"); | : array_push($list,"Xml:$nstxt"); | ||
if ($talk) $ns & 1 | if ($talk) $ns & 1 | ||
− | ? $msg .= " | + | ? $msg .= "<li>Talk page not copied, [[$title]] is already a talk page!</li>" |
: array_push($list,$wgContLang->getNsText($ns|1).':'); | : array_push($list,$wgContLang->getNsText($ns|1).':'); | ||
Line 39: | Line 39: | ||
$ot = Title::newFromText($nstxt.$title); | $ot = Title::newFromText($nstxt.$title); | ||
$nt = Title::newFromText($nstxt.$target); | $nt = Title::newFromText($nstxt.$target); | ||
− | if ($ot->getArticleID() == 0) $msg .= $err = " | + | if ($ot->getArticleID() == 0) $msg .= $err = "<li>$nstxt"."Article does't exist</li>"; |
− | else if ($nt->getArticleID()) $msg .= $err = " | + | else if ($nt->getArticleID()) $msg .= $err = "<li><b>Could not $action to $nlink because it already exists!</b></li>"; |
else { | else { | ||
$oa = new Article($ot); | $oa = new Article($ot); | ||
Line 46: | Line 46: | ||
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"; | + | $msg .= "<li>New copy of $olink successfully created as $nlink</li>"; |
} | } | ||
else { | else { | ||
− | if (($err = $ot->moveTo($nt)) != 1) $msg .= $err = " | + | if (($err = $ot->moveTo($nt)) != 1) $msg .= $err = "<li><b>Move from $olink to $nlink failed:</b> $err</li>"; |
else { | else { | ||
$err = ''; | $err = ''; | ||
− | $msg .= " | + | $msg .= "<li>$olink successfully moved to $nlink</li>"; |
if ($action == 'rename') { | if ($action == 'rename') { | ||
$dbw =& wfGetDB(DB_MASTER); | $dbw =& wfGetDB(DB_MASTER); | ||
Line 64: | Line 64: | ||
if (($i == 0) && $err) { $msg = $err; break; } # bail if problem moving the main article | if (($i == 0) && $err) { $msg = $err; break; } # bail if problem moving the main article | ||
} | } | ||
− | $article = "$msg | + | $article = preg_replace('/(?<=<!-- start content -->)(.+)(?=<!-- end content -->)/s',"<ul>$msg</ul><br><br>$1",$article); |
} | } | ||
else { | else { | ||
Line 70: | Line 70: | ||
$msg = "<h3>Rename/copy article:</h3><form action=\"/wiki/index.php\"> | $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: | + | <input type=hidden name=\"xpath:/properties:view\" value=\"$tTitle\"> |
<input type=hidden name=\"xpath:/properties:copy\"> | <input type=hidden name=\"xpath:/properties:copy\"> | ||
<table border=0> | <table border=0> |
Revision as of 09:44, 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 (called on data event)
global $wgContLang,$wgArticlePath; if ($summary) $summary = " : $summary"; $target = ucfirst(str_replace(' ', '_', $target)); $ot = Title::newFromText($title); $nt = Title::newFromText($target); $ns = $ot->getNamespace(); $nstxt = $wgContLang->getNsText($ns).':'; $err = $msg = ; $link = str_replace('$1',,$wgArticlePath); $olink = $action == 'rename' ? ' class="new"' : ; $olink = "<a$olink href=\"$link$title\">$title</a>"; $nlink = "<a href=\"$link$target\">$target</a>";
# Create list of articles to apply the process to (main, talk, xml) $list = array($nstxt); if ($xml) ereg('^Xml:',$title)
? $msg .= "
"
: array_push($list,"Xml:$nstxt"); if ($talk) $ns & 1
? $msg .= "
"
: array_push($list,$wgContLang->getNsText($ns|1).':');
# Loop through the list and apply the requested action to each $title = $ot->getText(); $target = $nt->getText(); foreach ($list as $i => $nstxt) { $ot = Title::newFromText($nstxt.$title); $nt = Title::newFromText($nstxt.$target);
if ($ot->getArticleID() == 0) $msg .= $err = "
"; else if ($nt->getArticleID()) $msg .= $err = "
";
else { $oa = new Article($ot); $na = new Article($nt); if ($action == 'copy') { $na->insertNewArticle($article, "Copied from $nstxt$title$summary", false, false);
$msg .= "
";
} else {
if (($err = $ot->moveTo($nt)) != 1) $msg .= $err = "
";
else { $err = ;
$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 }
$article = preg_replace('/(?<=)(.+)(?=)/s',"
- $msg
$1",$article);
} else { # Replace article content with form (called on view event bu xpath-query in button-url)
$msg = "
Rename/copy article:
<form action=\"/wiki/index.php\">
<input type=hidden name=title value=\"$title\"> <input type=hidden name=\"xpath:/properties:view\" 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); }
?>