Difference between revisions of "Copy.php"
m |
m ({{legacy}}, Category:MediaWiki) |
||
(29 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | <? | + | {{legacy}} |
+ | <php><? | ||
+ | global $wgContLang,$wgArticlePath,$xwAnonymous; | ||
+ | $xwIsAdmin = true; | ||
# Get copy-target and summary-text from form | # Get copy-target and summary-text from form | ||
Line 8: | Line 11: | ||
xwGetProperty($properties, 'copy/action', $action); | xwGetProperty($properties, 'copy/action', $action); | ||
− | if ($ | + | if ($summary) $summary = " : $summary"; |
− | + | if (!$xwIsAdmin) $action = 'copy'; | |
− | + | $target = ucfirst(str_replace(' ', '_', $target)); | |
− | + | $ot = Title::newFromText($title); | |
− | + | $nt = Title::newFromText($target); | |
− | + | $ns = $ot->getNamespace(); | |
− | + | if ($nstxt = $wgContLang->getNsText($ns)) $nstxt .= ':'; | |
− | + | $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>"; | ||
+ | if ($target && !$xwAnonymous) { | ||
# Create list of articles to apply the process to (main, talk, xml) | # Create list of articles to apply the process to (main, talk, xml) | ||
− | $list = array( | + | $list = array($nstxt); |
if ($xml) ereg('^Xml:',$title) | if ($xml) ereg('^Xml:',$title) | ||
− | ? $msg .= " | + | ? $msg .= "<li>Properties not copied, $olink is already a properties article!</li>" |
− | : array_push($list, | + | : array_push($list,"Xml:$nstxt"); |
if ($talk) $ns & 1 | if ($talk) $ns & 1 | ||
− | ? $msg .= " | + | ? $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).':'); | ||
Line 35: | Line 40: | ||
$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 = " | + | $olink = $action == 'rename' ? ' class="new"' : ''; |
− | else if ($nt->getArticleID()) $msg .= $err = " | + | $olink = "<a$olink href=\"$link$nstxt$title\">$nstxt$title</a>"; |
+ | $nlink = "<a href=\"$link$nstxt$target\">$nstxt$target</a>"; | ||
+ | if ($ot->getArticleID() == 0) $msg .= $err = "<li>$nstxt"."Article does't exist</li>"; | ||
+ | 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); | ||
$na = new Article($nt); | $na = new Article($nt); | ||
if ($action == 'copy') { | if ($action == 'copy') { | ||
− | $na->insertNewArticle($ | + | $text = xwArticleContent($nstxt.$title); |
− | $msg .= "New copy of | + | $na->insertNewArticle($text, "[[talk:copy.php|Copied]] from [[$nstxt$title]]$summary", false, false); |
+ | $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); | ||
− | $dbw->delete('cur', array('cur_namespace' => $ns, 'cur_title' => $ | + | $okey = $ot->getDBkey(); |
− | $dbw->delete('old', array('old_namespace' => $ns, 'old_title' => $ | + | $dbw->delete('cur', array('cur_namespace' => $ns, 'cur_title' => $okey)); |
− | $dbw->delete('recentchanges', array('rc_namespace' => $ns, 'rc_title' => $ | + | $dbw->delete('old', array('old_namespace' => $ns, 'old_title' => $okey)); |
+ | $dbw->delete('recentchanges', array('rc_namespace' => $ns, 'rc_title' => $okey)); | ||
} | } | ||
} | } | ||
Line 60: | Line 70: | ||
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 { | ||
# Replace article content with form (called on view event bu xpath-query in button-url) | # Replace article content with form (called on view event bu xpath-query in button-url) | ||
− | $msg = "<h3>Rename/copy article:</h3><form action=\"/wiki/index.php\"> | + | $msg = "<h3>Rename/copy article:</h3><form action=\"/wiki/index.php\" method=\"GET\"><br> |
<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 cellpadding=0 cellspacing=5> |
<tr><td align=right>New title:<td><input type=text name=\"xpath:/properties/copy:target\"> | <tr><td align=right>New title:<td><input type=text name=\"xpath:/properties/copy:target\"> | ||
<tr><td align=right>Reason:<td><input type=text name=\"xpath:/properties/copy:summary\"> | <tr><td align=right>Reason:<td><input type=text name=\"xpath:/properties/copy:summary\"> | ||
<tr><td align=right>Action: | <tr><td align=right>Action: | ||
− | <td><input type=radio name=\"xpath:/properties/copy:action\" value=rename checked>Rename | + | <td>".($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=redir>Redirect | ||
− | <input type=radio name=\"xpath:/properties/copy:action\" value=copy>Copy | + | ":'')."<input type=radio name=\"xpath:/properties/copy:action\" value=copy".($xwIsAdmin?' ':' checked').">Copy |
<tr><td><td><input type=checkbox checked=checked value=1 name=\"xpath:/properties/copy:xml\"> | <tr><td><td><input type=checkbox checked=checked value=1 name=\"xpath:/properties/copy:xml\"> | ||
Also apply to <b>properties</b> | Also apply to <b>properties</b> | ||
Line 81: | Line 91: | ||
<tr><td><td><input type=submit value=\" Commit \"> | <tr><td><td><input type=submit value=\" Commit \"> | ||
<tr><td colspan=2><br><br><br> | <tr><td colspan=2><br><br><br> | ||
+ | <h3>Bugs</h3> | ||
+ | <ul> | ||
+ | <li>Rename's not showing up in changes</li> | ||
+ | <li>$ in name not working</li> | ||
+ | </ul> | ||
<h3>Help</h3> | <h3>Help</h3> | ||
− | <b>Rename</b><br> | + | <i>For information and discussion about this form, see <a href=\"".$link."talk:copy.php\">talk:copy.php</a></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> | ||
Line 96: | Line 112: | ||
$article = preg_replace('/(?<=<!-- start content -->).+(?=<!-- end content -->)/s',$msg,$article); | $article = preg_replace('/(?<=<!-- start content -->).+(?=<!-- end content -->)/s',$msg,$article); | ||
} | } | ||
− | + | ?></php> | |
− | ?> |
Latest revision as of 11:56, 18 July 2007
<php><? global $wgContLang,$wgArticlePath,$xwAnonymous; $xwIsAdmin = true;
- 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 ($summary) $summary = " : $summary"; if (!$xwIsAdmin) $action = 'copy'; $target = ucfirst(str_replace(' ', '_', $target)); $ot = Title::newFromText($title); $nt = Title::newFromText($target); $ns = $ot->getNamespace(); if ($nstxt = $wgContLang->getNsText($ns)) $nstxt .= ':'; $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>";
if ($target && !$xwAnonymous) { # 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); $olink = $action == 'rename' ? ' class="new"' : ; $olink = "<a$olink href=\"$link$nstxt$title\">$nstxt$title</a>"; $nlink = "<a href=\"$link$nstxt$target\">$nstxt$target</a>";
if ($ot->getArticleID() == 0) $msg .= $err = "
"; else if ($nt->getArticleID()) $msg .= $err = "
";
else { $oa = new Article($ot); $na = new Article($nt); if ($action == 'copy') { $text = xwArticleContent($nstxt.$title); $na->insertNewArticle($text, "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); $okey = $ot->getDBkey(); $dbw->delete('cur', array('cur_namespace' => $ns, 'cur_title' => $okey)); $dbw->delete('old', array('old_namespace' => $ns, 'old_title' => $okey)); $dbw->delete('recentchanges', array('rc_namespace' => $ns, 'rc_title' => $okey)); } } } } 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 \"> | |
Bugs
Help For information and discussion about this form, see <a href=\"".$link."talk:copy.php\">talk:copy.php</a> |
</form>";
$article = preg_replace('/(?<=).+(?=)/s',$msg,$article); } ?></php>