Skip to content
This repository has been archived by the owner on Jan 29, 2019. It is now read-only.

Commit

Permalink
fixed page parsing when page is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
WMDE-Fisch committed Sep 1, 2015
1 parent 156b801 commit 90a23ba
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions SpecialContentStaging.php
@@ -1,6 +1,6 @@
<?php
class SpecialContentStaging extends SpecialPage {

private $mwNamespaceIndex;
private $mwNamespace;
private $pagePrefix;
Expand Down Expand Up @@ -89,17 +89,17 @@ function execute( $par ) {
if ( $stage !== "production" ) $target = $keys[$element + 1];

$currPage = $stages[$stage];
$pageNextStage = null;
if ( !empty( $target ) ) {
$pageNextStage = $stages[$target];
}
$pageNextStage = $stages[$target];

$stagingStatus = "<span style=\"color: green\">&#10003;</span>";

if ( $stage !== "production" && ( !$pageNextStage || $this->replaceStageInternalRefs( $this->pagePrefix, $currPage->getText(), $source, $target ) !== $pageNextStage->getText() ) ) {
$stagingStatus = "<html><a href=\"". $baseUrl .
if( get_class( $currPage ) !== 'WikiPage' ) {
$stagingStatus = "";
} elseif ( $stage !== "production" && ( get_class( $pageNextStage ) !== 'WikiPage' || $this->replaceStageInternalRefs( $this->pagePrefix, $currPage->getText(), $source, $target ) !== $pageNextStage->getText() ) ) {
$stagingStatus = "<html><a href=\"" . $baseUrl .
"&action=copy&page=" . $currPage->getId() .
"&source=" . $source .
"&target=" . $target ."\" style=\"color: red;\">&#10007;</a></html>";
"&target=" . $target . "\" style=\"color: red;\">&#10007;</a></html>";
}
$resultTable .= "| style='text-align: center;' | " . $stagingStatus . "\n";
} else {
Expand Down Expand Up @@ -130,7 +130,7 @@ function execute( $par ) {
$output->addWikiText( $archiveLink . "\n" . $resultTable );
}
}

function getPagesByStage( $prefix, $stage = "" ) {
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select(
Expand All @@ -141,7 +141,7 @@ function getPagesByStage( $prefix, $stage = "" ) {

return $res;
}

function getPagesByPrefix( $prefix ) {
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select(
Expand All @@ -152,11 +152,11 @@ function getPagesByPrefix( $prefix ) {

return $res;
}

function replaceGeneralPrefix( $title, $prefix ) {
return str_replace( $prefix . "/", "", $title );
}

function getTitleWithoutPrefixes( $fullTitle ) {
$arrTitle = explode( "/", $fullTitle, 3 );
return $arrTitle[sizeof( $arrTitle ) - 1];
Expand All @@ -166,11 +166,11 @@ function getStage( $fullTitle ) {
$arrTitle = explode( "/", $fullTitle, 3 );
return sizeof( $arrTitle ) > 2 ? $arrTitle[sizeof( $arrTitle ) - 2] : "unstaged";
}

function replaceStageInternalRefs( $prefix, $page, $source, $target ) {
return str_replace( $prefix . "/" . $source, $prefix . "/" . $target, $page );
}

function copyPage( $prefix, $page, $source, $target ) {
if ( is_string( $page ) ) {
$objSrc = WikiPage::newFromID( intval( $page ) );
Expand All @@ -183,13 +183,13 @@ function copyPage( $prefix, $page, $source, $target ) {
} else {
$titleTarget = $this->mwNamespace . str_replace( $prefix . "/" . $source, $prefix . "/" . $target, $titleSrc );
}

$pageContent = $objSrc->getContent();
$pageContent = $this->replaceStageInternalRefs( $prefix, $pageContent, $source, $target );

$objTarget = WikiPage::factory ( Title::newFromText( $titleTarget ) );
$objTarget->doEditContent( $pageContent, "Staging content from " . $source . " to " . $target );

return $objTarget;
}

Expand All @@ -202,12 +202,12 @@ private function archivePage( $title ) {
}

private function doArchivePage( WikiPage $page ) {
if( $this->isArchivedPage( $page ) ) {
$oldContent = $page->getContent();

if( $oldContent === null || $this->isArchivedPage( $page ) ) {
return false;
}


$oldContent = $page->getContent();
$text = $oldContent->getNativeData();

$text .= "\n[[Category:ContentStagingArchive]]";
Expand All @@ -225,11 +225,11 @@ private function recoverPage( $title ) {
}

private function doRecoverPage( WikiPage $page ) {
if( !$this->isArchivedPage( $page ) ) {
$oldContent = $page->getContent();
if( $oldContent === null || !$this->isArchivedPage( $page ) ) {
return false;
}

$oldContent = $page->getContent();
$text = $oldContent->getNativeData();

$text = str_replace('[[Category:ContentStagingArchive]]', '', $text );
Expand Down

0 comments on commit 90a23ba

Please sign in to comment.