PortableInfobox/controllers/PortableInfoboxBuilderController.class.php

51 lines
1.6 KiB
PHP
Raw Normal View History

2015-08-27 08:30:25 +00:00
<?php
class PortableInfoboxBuilderController extends WikiaController {
const INFOBOX_BUILDER_PARAM = 'portableInfoboxBuilder';
2015-08-27 08:30:25 +00:00
public function getAssets() {
$response = $this->getResponse();
$response->setFormat( WikiaResponse::FORMAT_JSON );
$response->setVal( 'css', AssetsManager::getInstance()->getURL( 'portable_infobox_scss' ) );
2015-08-27 08:30:25 +00:00
}
2015-08-31 15:42:38 +00:00
public function publish() {
$response = $this->getResponse();
$response->setFormat( WikiaResponse::FORMAT_JSON );
2016-02-12 09:52:46 +00:00
$status = $this->attemptSave( $this->getRequest()->getParams() );
2015-08-31 15:42:38 +00:00
$response->setVal( 'success', $status->isOK() );
$response->setVal( 'errors', $status->getErrorsArray() );
$response->setVal( 'warnings', $status->getWarningsArray() );
2015-08-31 15:42:38 +00:00
}
2016-02-12 09:52:46 +00:00
private function attemptSave( $params ) {
$status = new Status();
// check for title
if ( !$params[ 'title' ] ) {
$status->fatal( 'no-title-provided' );
}
$title = $status->isGood() ? Title::newFromText( $params[ 'title' ], NS_TEMPLATE ) : false;
if ( $status->isGood() && !$title ) {
$status->fatal( 'no-title-object' );
}
if ( $status->isGood() && !$title->userCan( 'edit' ) ) {
$status->fatal( 'user-cant-edit' );
}
return $status->isGood() ? $this->save( $title, $params[ 'data' ] ) : $status;
}
private function save( Title $title, $data ) {
$article = new Article( $title );
$editPage = new EditPage( $article );
$editPage->initialiseForm();
$editPage->edittime = $article->getTimestamp();
$editPage->textbox1 = ( new PortableInfoboxBuilderService() )->translate( $data );
$status = $editPage->internalAttemptSave( $result );
return $status;
}
2015-08-27 08:30:25 +00:00
}