We have citation that link to uploaded documents. The citations are on
their own pages. The citation pages contain information about the
copyright and classification status of the documents. In the past we
have not put the documents into categories, but it is becoming important
to know easily which documents are copyrighted. Since we have that
information I was asked to make it easier on our editors by writing
something to add the categories based on what is on the citation pages.
That part works. What I can't figure out is why, on my recent changes
page, I am seeing two edits for every one time I run the script. I call
the script by going to a special page. Any help would be greatly
appreciated.
Here is the code:
function execute($par) {
global $wgOut;
$this->setHeaders();
if ( NULL == $par ) {
$wgOut->addHTML(wfMsg('cfm-failsafe'));
return FALSE;
}
$citationPagesArray = getPagesInCategory('Citations');
/*
* TODO: Make sure files do not already have category
information
*/
$summary = wfMsg('cfm-summary');
foreach ( $citationPagesArray as $onePage ) {
$citeTitle = Title::newFromText($onePage);
$citeArticle = Revision::newFromTitle($citeTitle);
$citeText = $citeArticle->getText();
if ( isXmlStyle($citeText) ) {
$citeInfoXML = new CitationXML($citeText);
$citeInfoArray = $citeInfoXML->getXMLasArray();
@list($classification, $caveat) = split("//",
$citeInfoArray['documentClassification']);
$docLinkTitle =
Title::newFromText($citeInfoArray['docLink'], NS_IMAGE);
if ( ($docLinkTitle) &&
($docLinkTitle->exists()) ) {
$docLinkRevision =
Revision::newFromTitle($docLinkTitle);
$docLinksCategoryArr =
$docLinkTitle->getParentCategories();
print "<pre>";
var_dump($docLinksCategoryArr);
print "\n" .
count($docLinksCategoryArr);
print "</pre>";
//die();
if ( 1 >= count($docLinksCategoryArr) )
{
$docLinkText =
$docLinkRevision->getText();
$classification =
$this->categorize($classification);
$caveat =
$this->categorize($caveat);
$copyright =
$this->categorize($citeInfoArray['copyright']);
$docLinkText .= $classification
. $caveat . $copyright;
$docLinkArticle = new
Article($docLinkTitle);
print "checking how many times
this runs";
$docLinkArticle->doEdit($docLinkText, $summary, EDIT_MINOR);
}
}
}
}
$wgOut->addHTML(wfMsg('cfm-completed'));
return TRUE;
}
Courtney Christensen
Show replies by date