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

Commit

Permalink
replaced double with single quotes where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
WMDE-Fisch committed Sep 1, 2015
1 parent 42b915f commit b68a925
Showing 1 changed file with 35 additions and 36 deletions.
71 changes: 35 additions & 36 deletions SpecialContentStaging.php
Expand Up @@ -29,18 +29,17 @@ function execute( $par ) {
$target = $request->getText( 'target' );
$showArchived = $request->getBool( 'showArchived' );

$baseUrl = "?title=Special:ContentStaging";
$baseUrl .= $showArchived ? "&showArchived=1" : "";

$baseUrl = '?title=Special:ContentStaging';
$baseUrl .= $showArchived ? '&showArchived=1' : '';

if ( !empty( $this->pagePrefix ) ) {
if ( $action === "copy" ) {
if ( $action === 'copy' ) {
$this->copyPage( $this->pagePrefix, $page, $source, $target );
}
if ( $action === "archive" ) {
if ( $action === 'archive' ) {
$this->archivePage( $page );
}
if ( $action === "recover" ) {
if ( $action === 'recover' ) {
$this->recoverPage( $page );
}

Expand Down Expand Up @@ -87,15 +86,15 @@ function execute( $par ) {
$currPage = $stages[$stage];
$pageNextStage = $stages[$target];

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

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>";
$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>';
}
$resultTable .= "| style='text-align: center;' | " . $stagingStatus . "\n";
} else {
Expand All @@ -104,23 +103,23 @@ function execute( $par ) {
}

if ( !$showArchived ) {
$archiveOption = "<html><a href=\"". $baseUrl .
"&action=archive&page=" . $title .
"\" style=\"font-weight:bold\">&#128448;</a></html>";
$archiveOption = '<html><a href="'. $baseUrl .
'&action=archive&page=' . $title .
'" style="font-weight:bold">&#128448;</a></html>';
} else {
$archiveOption = "<html><a href=\"". $baseUrl .
"&action=recover&page=" . $title .
"\" style=\"font-weight:bold\">&#128449;</a></html>";
$archiveOption = '<html><a href="'. $baseUrl .
'&action=recover&page=' . $title .
'" style="font-weight:bold">&#128449;</a></html>';
}

$resultTable .= "| style='text-align: center;' | " . $archiveOption . "\n";
}
$resultTable .= "|}\n";

if ( !$showArchived ) {
$archiveLink = "<html><a href=\"?title=Special:ContentStaging&showArchived=1\">&#128448; View Archive</a></html>";
$archiveLink = '<html><a href="?title=Special:ContentStaging&showArchived=1">&#128448; View Archive</a></html>';
} else {
$archiveLink = "<html><a href=\"?title=Special:ContentStaging\">&#128449; View List</a></html>";
$archiveLink = '<html><a href="?title=Special:ContentStaging">&#128449; View List</a></html>';
}

$output->addWikiText( $archiveLink . "\n" . $resultTable );
Expand All @@ -130,9 +129,9 @@ function execute( $par ) {
function getPagesByStage( $prefix, $stage = "" ) {
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select(
array( "page" ),
array( "page_id", "page_title", "page_namespace" ),
array( "page_namespace = " . $this->mwNamespaceIndex, "page_title LIKE '" . $prefix . "/" . $stage . "%'" )
array( 'page' ),
array( 'page_id', 'page_title', 'page_namespace' ),
array( 'page_namespace = ' . $this->mwNamespaceIndex, 'page_title LIKE "' . $prefix . '/' . $stage . '%"' )
);

return $res;
Expand All @@ -141,30 +140,30 @@ function getPagesByStage( $prefix, $stage = "" ) {
function getPagesByPrefix( $prefix ) {
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select(
array( "page" ),
array( "page_id", "page_title", "page_namespace" ),
array( "page_namespace = " . $this->mwNamespaceIndex, "page_title LIKE '" . $prefix . "%'" )
array( 'page' ),
array( 'page_id', 'page_title', 'page_namespace' ),
array( 'page_namespace = ' . $this->mwNamespaceIndex, 'page_title LIKE "' . $prefix . '%"' )
);

return $res;
}

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

function getTitleWithoutPrefixes( $fullTitle ) {
$arrTitle = explode( "/", $fullTitle, 3 );
$arrTitle = explode( '/', $fullTitle, 3 );
return $arrTitle[sizeof( $arrTitle ) - 1];
}

function getStage( $fullTitle ) {
$arrTitle = explode( "/", $fullTitle, 3 );
return sizeof( $arrTitle ) > 2 ? $arrTitle[sizeof( $arrTitle ) - 2] : "unstaged";
$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 );
return str_replace( $prefix . '/' . $source, $prefix . '/' . $target, $page );
}

function copyPage( $prefix, $page, $source, $target ) {
Expand All @@ -174,17 +173,17 @@ function copyPage( $prefix, $page, $source, $target ) {
$objSrc = $page;
}
$titleSrc = $objSrc->getTitle()->mTextform;
if( $source === "" ) {
$titleTarget = $this->mwNamespace . str_replace( $prefix . "/", $prefix . "/" . $target . "/", $titleSrc );
if( $source === '' ) {
$titleTarget = $this->mwNamespace . str_replace( $prefix . '/', $prefix . '/' . $target . '/', $titleSrc );
} else {
$titleTarget = $this->mwNamespace . str_replace( $prefix . "/" . $source, $prefix . "/" . $target, $titleSrc );
$titleTarget = $this->mwNamespace . str_replace( $prefix . '/' . $source, $prefix . '/' . $target, $titleSrc );
}

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

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

return $objTarget;
}
Expand Down

0 comments on commit b68a925

Please sign in to comment.