refactor infobox builder entry point on new template page

This commit is contained in:
Rafal Leszczynski 2015-09-02 13:02:33 +02:00
parent ac6219140d
commit be7681943c
4 changed files with 60 additions and 17 deletions

View file

@ -2,6 +2,7 @@
class PortableInfoboxHooks {
const PARSER_TAG_GALLERY = 'gallery';
const INFOBOX_BUILDER_SPECIAL_PAGE = 'Special:PortableInfoboxBuilder';
public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) {
if ( F::app()->checkSkin( 'monobook', $skin ) ) {
@ -50,20 +51,27 @@ class PortableInfoboxHooks {
return true;
}
public static function onAddPortableInfoboxBuilderText( &$article, &$text, &$wgOut ) {
//check if extension is on and user has rights
global $wgArticlePath;
/**
* @param $article
* @param $text
* @param $wgOut
*
* @return bool
*/
public static function onAddPortableInfoboxBuilderText( &$article, &$text, &$wgOut, &$errors ) {
if ( !count( $errors ) ) {
$text = '';
$templateTitle = $article->getTitle()->getText();
$text = '';
$newInfoboxTemplate = wfMessage( 'portable-infobox-builder-entry-point-new-template-infobox' )->escaped();
$newTemplate = wfMessage( 'portable-infobox-builder-entry-point-new-template-normal' )->escaped();
$templateTitle = $article->getTitle()->getText();
$templatePath = preg_replace('/(.+)/', $wgArticlePath, $templateTitle);
$infoboxBuilderLink = "/Special:PortableInfoboxBuilder/" . $templateTitle;
$editorLink = $templatePath . "?action=edit";
$HTML = '<a href="'. $infoboxBuilderLink . '" class="wikia-button">' . $newInfoboxTemplate . '</a> <a href="'. $editorLink . '" class="wikia-button">' . $newTemplate . '</a>';
$HTML = F::app()->renderView(
'PortableInfoboxBuilderSpecialController',
'renderCreateTemplateEntryPoint',
[ 'title' => $templateTitle ]
);
$wgOut->addHTML($HTML);
}
$wgOut->addHTML($HTML);
return true;
}

View file

@ -27,13 +27,41 @@ class PortableInfoboxBuilderSpecialController extends WikiaSpecialPageController
*/
public function index() {
$this->wg->SuppressPageHeader = true;
//TODO: use i18n message for title
$this->wg->out->setHTMLTitle( 'Infobox Builder' );
$this->wg->out->setHTMLTitle( wfMessage( 'portable-infobox-builder-tite' )->plain() );
//TODO: get better way of handling $this->getPar() to deal with "/dadada/adasdasd"
$url = $this->wg->server . '/' . infoboxBuilder . '/' . $this->getPar();
$title = $this->getTemplateTitle( $this->getPar() );
$noTemplateSet = empty( $title ) ? true : false;
if ( $noTemplateSet ) {
$this->response->setVal('noTemplateSet', true );
$this->response->setVal('setTemplateNameCallToAction', wfMessage(
'portable-infobox-builder-no-template-title-set' )->plain() );
} else {
$url = $this->wg->server . '/' . self::INFOBOX_BUILDER_MERCURY_ROUTE . '/' . $title;
$this->response->setVal( 'iframeUrl', $url );
}
$this->response->setVal('iframeUrl', $url);
$this->response->setTemplateEngine( WikiaResponse::TEMPLATE_ENGINE_MUSTACHE );
}
public function renderCreateTemplateEntryPoint() {
$this->response->setVal( 'createInfobox', wfMessage(
'portable-infobox-builder-create-template-entry-point-create-infobox' )->plain() );
$this->response->setVal( 'createTemplate', wfMessage(
'portable-infobox-builder-create-template-entry-point-create-regular-template' )->plain() );
$this->response->setVal( 'title', $this->request->getVal('title'), '' );
$this->response->setTemplateEngine( WikiaResponse::TEMPLATE_ENGINE_MUSTACHE );
}
/**
* @desc return template title base of the URL path
* @param string $par - URL path after Special:PortableInfoboxBuilder/
* @return string
*/
private function getTemplateTitle( $par ) {
$slicePos = strpos( $par, '/' );
return urlencode( is_int( $slicePos ) ? substr( $par, 0, $slicePos ) : $par );
}
}

View file

@ -1 +1,6 @@
{{#noTemplateSet}}
<p>{{setTemplateNameCallToAction}}</p>
{{/noTemplateSet}}
{{^noTemplateSet}}
<iframe id="infoboxBuilderIframe" width="100%" height="600" data-src="{{iframeUrl}}"></iframe>
{{/noTemplateSet}}

View file

@ -0,0 +1,2 @@
<a href="/Special:PortableInfoboxBuilder/{{title}}" class="wikia-button">{{createInfobox}}</a>
<a href="/wiki/{{title}}'action=edit" class="wikia-button">{{createTemplate}}</a>