2016-10-25 20:44:26 +00:00
|
|
|
<?php
|
2018-03-28 19:47:04 +00:00
|
|
|
/**
|
|
|
|
* CollabPad special page
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
|
2018-03-28 19:47:04 +00:00
|
|
|
* @license MIT
|
|
|
|
*/
|
|
|
|
|
2016-10-25 20:44:26 +00:00
|
|
|
class SpecialCollabPad extends SpecialPage {
|
|
|
|
private $prefixes = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var null|Title
|
|
|
|
*/
|
|
|
|
private $title = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var null|ParserOutput
|
|
|
|
*/
|
|
|
|
private $output = null;
|
|
|
|
|
2017-12-30 22:29:40 +00:00
|
|
|
public function __construct() {
|
2016-10-25 20:44:26 +00:00
|
|
|
parent::__construct( 'CollabPad' );
|
|
|
|
}
|
|
|
|
|
2018-03-28 19:47:04 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2016-10-25 20:44:26 +00:00
|
|
|
protected function getGroupName() {
|
|
|
|
return 'wiki';
|
|
|
|
}
|
|
|
|
|
2018-03-28 19:47:04 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2016-10-25 20:44:26 +00:00
|
|
|
public function userCanExecute( User $user ) {
|
|
|
|
global $wgVisualEditorRebaserURL;
|
2019-02-06 09:03:37 +00:00
|
|
|
return (bool)$wgVisualEditorRebaserURL && parent::userCanExecute( $user );
|
2016-10-25 20:44:26 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 19:47:04 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2018-01-02 01:00:08 +00:00
|
|
|
public function isListed() {
|
2016-10-25 20:44:26 +00:00
|
|
|
global $wgVisualEditorRebaserURL;
|
2019-02-06 09:03:37 +00:00
|
|
|
return (bool)$wgVisualEditorRebaserURL;
|
2016-10-25 20:44:26 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 19:47:04 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2018-05-01 09:29:51 +00:00
|
|
|
public function execute( $subPage ) {
|
2016-10-25 20:44:26 +00:00
|
|
|
$this->setHeaders();
|
|
|
|
$this->checkPermissions();
|
|
|
|
|
|
|
|
$output = $this->getOutput();
|
|
|
|
|
2018-05-01 09:29:51 +00:00
|
|
|
$output->addJsConfigVars( 'collabPadPageName', $subPage );
|
2016-10-25 20:44:26 +00:00
|
|
|
$output->addModuleStyles( 'ext.visualEditor.collabTarget.init.styles' );
|
2018-05-18 09:43:29 +00:00
|
|
|
$output->addModuleStyles( 'oojs-ui.styles.icons-editing-core' );
|
|
|
|
$output->addModuleStyles( 'oojs-ui.styles.icons-content' );
|
|
|
|
|
2016-10-25 20:44:26 +00:00
|
|
|
$output->addModules( 'ext.visualEditor.collabTarget.init' );
|
|
|
|
|
|
|
|
$output->enableOOUI();
|
2017-05-20 19:22:44 +00:00
|
|
|
|
2018-05-18 09:43:29 +00:00
|
|
|
$documentNameFieldset = new OOUI\FieldsetLayout( [
|
|
|
|
'label' => $this->msg( 'visualeditor-rebase-client-document-create-edit' )->text(),
|
|
|
|
'icon' => 'edit',
|
|
|
|
'items' => [
|
|
|
|
new OOUI\ActionFieldLayout(
|
|
|
|
new OOUI\TextInputWidget( [
|
|
|
|
'classes' => [ 've-init-mw-collabTarget-nameInput' ],
|
|
|
|
'placeholder' => $this->msg( 'visualeditor-rebase-client-document-name' )->text(),
|
|
|
|
'autofocus' => true,
|
|
|
|
'infusable' => true
|
|
|
|
] ),
|
|
|
|
new OOUI\ButtonWidget( [
|
|
|
|
'classes' => [ 've-init-mw-collabTarget-nameButton' ],
|
|
|
|
'label' => $this->msg( 'visualeditor-rebase-client-document-create-edit' )->text(),
|
2018-08-01 19:34:43 +00:00
|
|
|
'flags' => [ 'primary', 'progressive' ],
|
2018-05-18 09:43:29 +00:00
|
|
|
// Only enable once JS has loaded
|
|
|
|
'disabled' => true,
|
|
|
|
'infusable' => true
|
|
|
|
] ),
|
|
|
|
[
|
|
|
|
'align' => 'top',
|
|
|
|
'classes' => [ 've-init-mw-collabTarget-nameField' ],
|
|
|
|
'infusable' => true
|
|
|
|
]
|
|
|
|
)
|
|
|
|
]
|
|
|
|
] );
|
|
|
|
$importFieldset = new OOUI\FieldsetLayout( [
|
|
|
|
'label' => $this->msg( 'visualeditor-rebase-client-import' )->text(),
|
|
|
|
'icon' => 'download',
|
|
|
|
'items' => [
|
|
|
|
new OOUI\ActionFieldLayout(
|
|
|
|
new MediaWiki\Widget\TitleInputWidget( [
|
|
|
|
'classes' => [ 've-init-mw-collabTarget-importInput' ],
|
|
|
|
'placeholder' => $this->msg( 'visualeditor-rebase-client-import-name' )->text(),
|
|
|
|
'infusable' => true,
|
|
|
|
] ),
|
|
|
|
new OOUI\ButtonWidget( [
|
|
|
|
'classes' => [ 've-init-mw-collabTarget-importButton' ],
|
|
|
|
'label' => $this->msg( 'visualeditor-rebase-client-import' )->text(),
|
|
|
|
// Only enable once JS has loaded
|
|
|
|
'disabled' => true,
|
|
|
|
'infusable' => true
|
|
|
|
] ),
|
|
|
|
[
|
|
|
|
'align' => 'top',
|
|
|
|
'classes' => [ 've-init-mw-collabTarget-importField' ],
|
|
|
|
'infusable' => true
|
|
|
|
]
|
|
|
|
)
|
2017-05-20 19:22:44 +00:00
|
|
|
]
|
2018-05-18 09:43:29 +00:00
|
|
|
] );
|
|
|
|
|
|
|
|
$form = new OOUI\FormLayout( [
|
|
|
|
'classes' => [ 've-init-mw-collabTarget-form' ],
|
|
|
|
'items' => [
|
|
|
|
$documentNameFieldset,
|
|
|
|
$importFieldset
|
|
|
|
],
|
|
|
|
'infusable' => true
|
|
|
|
] );
|
|
|
|
|
2017-05-20 19:22:44 +00:00
|
|
|
$progressBar = new OOUI\ProgressBarWidget( [
|
|
|
|
'classes' => [ 've-init-mw-collabTarget-loading' ],
|
|
|
|
'infusable' => true
|
|
|
|
] );
|
|
|
|
|
2018-05-01 09:29:51 +00:00
|
|
|
if ( $subPage ) {
|
|
|
|
$title = Title::newFromText( $subPage );
|
|
|
|
$output->setPageTitle( $this->msg( 'collabpad-doctitle', $title->getPrefixedText() ) );
|
2018-05-18 09:43:29 +00:00
|
|
|
$form->addClasses( [ 'oo-ui-element-hidden' ] );
|
2016-10-25 20:44:26 +00:00
|
|
|
} else {
|
|
|
|
// Scripts only, styles already added above
|
|
|
|
$output->addModules( 'ext.visualEditor.collabTarget' );
|
2017-05-20 19:22:44 +00:00
|
|
|
$progressBar->addClasses( [ 'oo-ui-element-hidden' ] );
|
2016-10-25 20:44:26 +00:00
|
|
|
}
|
2018-05-18 09:43:29 +00:00
|
|
|
$output->addHTML( $progressBar . $form );
|
2016-10-25 20:44:26 +00:00
|
|
|
}
|
2018-09-16 18:53:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the sub page from the current title
|
|
|
|
*
|
|
|
|
* @param Title $title Full title
|
|
|
|
* @return null|Title Sub page title
|
|
|
|
*/
|
|
|
|
public static function getSubPage( Title $title ) {
|
|
|
|
preg_match( '`^[^/]+/(.*)`', $title->getPrefixedText(), $matches );
|
|
|
|
return count( $matches ) ? Title::newFromText( $matches[ 1 ] ) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param SkinTemplate &$skin The skin template on which the UI is built.
|
|
|
|
* @param array &$links Navigation links.
|
|
|
|
* @return bool Always true.
|
|
|
|
*/
|
|
|
|
public static function onSkinTemplateNavigationSpecialPage( SkinTemplate &$skin, array &$links ) {
|
2018-09-19 20:25:27 +00:00
|
|
|
$title = $skin->getTitle();
|
|
|
|
if ( $title && $title->isSpecial( 'CollabPad' ) ) {
|
|
|
|
$subPage = self::getSubPage( $title );
|
|
|
|
$links['namespaces']['special']['text'] = $skin->msg( 'collabpad' )->text();
|
|
|
|
if ( $subPage ) {
|
|
|
|
$links['namespaces']['special']['href'] =
|
|
|
|
Title::newFromText( 'Special:CollabPad' )->getLocalURL();
|
|
|
|
$links['namespaces']['special']['class'] = '';
|
|
|
|
|
|
|
|
$links['namespaces']['pad']['text'] = $subPage->getPrefixedText();
|
|
|
|
$links['namespaces']['pad']['href'] = '';
|
|
|
|
$links['namespaces']['pad']['class'] = 'selected';
|
|
|
|
}
|
2018-09-16 18:53:24 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2016-10-25 20:44:26 +00:00
|
|
|
}
|