Difference between revisions of "Copy.php"

From Organic Design wiki
m
(add link to talk in form)
Line 87: Line 87:
 
<tr><td colspan=2><br><br><br>
 
<tr><td colspan=2><br><br><br>
 
<h3>Help</h3>
 
<h3>Help</h3>
<b>Rename</b><br>
+
<i>For information and discussion about this form, see [[Talk:Copy.php]]</i><br><br>
 +
<b>Rename</b> <i>(admin only)</i><br>
 
Changes the title of the article applying to current content and all the history.<br>
 
Changes the title of the article applying to current content and all the history.<br>
 
The original title becomes unused and all links to that title will become red creation links.<br><br>
 
The original title becomes unused and all links to that title will become red creation links.<br><br>
<b>Redirect</b><br>
+
<b>Redirect</b> <i>(admin only)</i><br>
 
Changes the title of the article applying to current content and all the history.<br>
 
Changes the title of the article applying to current content and all the history.<br>
 
Any links referring to the original title are automatically redirected to the new title<br>
 
Any links referring to the original title are automatically redirected to the new title<br>

Revision as of 10:06, 25 October 2006

<? global $wgContLang,$wgArticlePath,$xwIsAdmin;

  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 (called on data event)

if ($summary) $summary = " : $summary"; if (!$xwIsAdmin) $action = 'copy'; $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 .= "

  • Properties not copied, $title is already a properties article!
  • "

    : array_push($list,"Xml:$nstxt"); if ($talk) $ns & 1

    ? $msg .= "

  • Talk page not copied, $title is already a talk page!
  • "

    : 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 = "

  • $nstxt"."Article does't exist
  • "; else if ($nt->getArticleID()) $msg .= $err = "

  • Could not $action to $nlink because it already exists!
  • ";

    else { $oa = new Article($ot); $na = new Article($nt); if ($action == 'copy') { $na->insertNewArticle($article, "Copied from $nstxt$title$summary", false, false);

    $msg .= "

  • New copy of $olink successfully created as $nlink
  • ";

    } else {

    if (($err = $ot->moveTo($nt)) != 1) $msg .= $err = "

  • Move from $olink to $nlink failed: $err
  • ";

    else { $err = ;

    $msg .= "

  • $olink successfully moved to $nlink
  • ";

    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\" method=\"GET\">

    <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: ".($xwIsAdmin?"<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'.($xwIsAdmin?:' checked').'>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

    For information and discussion about this form, see Talk:Copy.php

    Rename (admin only)
    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 (admin only)
    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>";

    $article = preg_replace('/(?<=).+(?=)/s',$msg,$article); }

    ?>