Copy.php

From Organic Design wiki
Revision as of 05:33, 25 October 2006 by Nad (talk | contribs) (add the actual move/delete code)

<?

  1. 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; 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 = ;

$list = array(); if ($xml) ereg('^Xml:',$title) ? xwMessage('Properties not copied, article is already a properties article!','red') : array_push($list,'Xml:'); if ($talk) $ns & 1 ? xwMessage('Talk page not copied, article is already a talk page!','red') : 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 = xwMessage("Could not copy to \"$nstxt$target\", already exists!", 'red'); else { xwMessage("Applying to \"$nstxt$title\""); $oa = new Article($ot); $na = new Article($nt); if ($action == 'copy') { xwMessage("copying $nstxt$title to $nstxt$target"); $na->insertNewArticle($article, "Copied from $nstxt$title$summary", false, false); } else { xwMessage("moving $nstxt$title to $nstxt$target"); $err = $ot->moveTo($nt); if (($action == 'rename') && ($err == )) { xwMessage('removing $nstxt$title'); $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 } } else { # Define the form

$form = "

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
Changes the title of the article applying to current content and all the history.
The original title becomes unused and all links to that title will become red creation links.

Redirect
Changes the title of the article applying to current content and all the history.
Any links referring to the original title are automatically redirected to the new title
(unless redir=no is included in the query-string).
This is the action MediaWiki takes when \"move\" is applied to an article.

Copy
Creates a new article with the same content as the original, but exhibiting no history.
The original title is left unaffected by this operation.

</form>";

# Replace article content with form $article = preg_replace('/(?<=).+(?=)/s',$form,$article); }

?>