*/
class BatcheditMessage implements Serializable {
const ERROR = 1;
const WARNING = 2;
public $type;
public $data;
/**
*
*/
public function getClass() {
switch ($this->type) {
case self::ERROR:
return 'error';
case self::WARNING:
return 'notify';
}
return '';
}
/**
*
*/
public function getFormatId() {
switch ($this->type) {
case self::ERROR:
return 'msg_error';
case self::WARNING:
return 'msg_warning';
}
return '';
}
/**
*
*/
public function getId() {
return $this->data[0];
}
/**
*
*/
public function serialize() {
return serialize(array($this->type, $this->data));
}
/**
*
*/
public function unserialize($data) {
list($this->type, $this->data) = unserialize($data);
}
}
class BatcheditErrorMessage extends BatcheditMessage {
/**
* Accepts message array that starts with message id followed by optional arguments.
*/
public function __construct($message) {
$this->type = self::ERROR;
$this->data = $message;
}
}
class BatcheditWarningMessage extends BatcheditMessage {
/**
* Accepts message array that starts with message id followed by optional arguments.
*/
public function __construct($message) {
$this->type = self::WARNING;
$this->data = $message;
}
}
class BatcheditInterface {
private $plugin;
private $indent;
private $svgCache;
/**
*
*/
public function __construct($plugin) {
$this->plugin = $plugin;
$this->indent = 0;
$this->svgCache = array();
}
/**
*
*/
public function configure($config) {
foreach ($config->getConfig() as $id => $value) {
if (!empty($value) || $value === 0) {
$_REQUEST[$id] = $value;
}
else {
unset($_REQUEST[$id]);
}
}
}
/**
*
*/
public function printBeginning($sessionId) {
print('');
print('
');
$this->printJavascriptLang();
print('');
print('
');
print('');
}
/**
*
*/
public function printMessages($messages) {
if (empty($messages)) {
return;
}
print('');
foreach ($messages as $message) {
print('
');
print($this->getLang($message->getFormatId(), call_user_func_array(array($this, 'getLang'), $message->data)));
print('
');
}
print('
');
}
/**
*
*/
public function printTotalStats($command, $matchCount, $pageCount, $editCount) {
$matches = $this->getLangPlural('sts_matches', $matchCount);
$pages = $this->getLangPlural('sts_pages', $pageCount);
switch ($command) {
case BatcheditRequest::COMMAND_PREVIEW:
$stats = $this->getLang('sts_preview', $matches, $pages);
break;
case BatcheditRequest::COMMAND_APPLY:
$edits = $this->getLangPlural('sts_edits', $editCount);
$stats = $this->getLang('sts_apply', $matches, $pages, $edits);
break;
}
print('');
if ($editCount < $matchCount) {
$this->printApplyCheckBox('be-applyall', $stats, 'ttl_applyall');
}
else {
print($stats);
}
print('
');
}
/**
*
*/
public function printMatches($pages) {
foreach ($pages as $page) {
print('');
$this->printPageStats($page);
$this->printPageActions($page->getId());
$this->printPageMatches($page);
print('
');
}
}
/**
*
*/
public function printMainForm($enableApply) {
print('');
print('
');
print('
');
print('
');
$this->printFormEdit('lbl_ns', 'namespace');
$this->printFormEdit('lbl_search', 'search');
$this->printFormEdit('lbl_replace', 'replace');
$this->printFormEdit('lbl_summary', 'summary');
print('
');
print('
');
$this->printOptions();
print('
');
// Value for this hidden input is set before submit through jQuery, containing
// JSON-encoded list of all checked checkbox ids for single matches.
// Consolidating these inputs into a single string variable avoids problems for
// huge replacement sets exceeding `max_input_vars` in `php.ini`.
print('
');
print('
');
$this->printSubmitButton('cmd[preview]', 'btn_preview');
$this->printSubmitButton('cmd[apply]', 'btn_apply', $enableApply);
print('
');
print('
');
$this->printButton('cancel', 'btn_cancel');
print('
');
print('
');
print('
');
}
/**
*
*/
private function printJavascriptLang() {
print('');
}
/**
*
*/
private function printApplyCheckBox($id, $label, $title, $checked = FALSE) {
$checked = $checked ? ' checked="checked"' : '';
print('');
print(' ');
print('' . $label . ' ');
print(' ');
}
/**
*
*/
private function printPageStats($page) {
$stats = $this->getLang('sts_page', $page->getId(), $this->getLangPlural('sts_matches', count($page->getMatches())));
print('');
if ($page->hasUnappliedMatches()) {
$this->printApplyCheckBox($page->getId(), $stats, 'ttl_applyfile', !$page->hasUnmarkedMatches());
}
else {
print($stats);
}
print('
');
}
/**
*
*/
private function printPageActions($pageId) {
$link = wl($pageId);
print('');
$this->printAction($link, 'ttl_view', 'file-document');
$this->printAction($link . (strpos($link, '?') === FALSE ? '?' : '&') . 'do=edit', 'ttl_edit', 'pencil');
$this->printAction('#be-mainform', 'ttl_mainform', 'arrow-down');
print('
');
}
/**
*
*/
private function printAction($href, $titleId, $iconId) {
$action = '';
$action .= $this->getSvg($iconId);
$action .= ' ';
print($action);
}
/**
*
*/
private function printPageMatches($page) {
foreach ($page->getMatches() as $match) {
print('');
$this->printMatchHeader($page->getId(), $match);
$this->printMatchTable($match);
print('
');
}
}
/**
*
*/
private function printMatchHeader($pageId, $match) {
$id = $pageId . '#' . $match->getPageOffset();
print('');
if (!$match->isApplied()) {
$this->printApplyCheckBox($id, $id, 'ttl_applymatch', $match->isMarked());
}
else {
// Add hidden checked checkbox to ensure that marked status is not lost on
// applied matches if application is performed in multiple rounds. This can
// be the case when one apply command is timed out and user issues a second
// one to apply the remaining matches.
print(' ');
print($id);
}
print('
');
}
/**
*
*/
private function printMatchTable($match) {
$original = $this->prepareText($match->getOriginalText(), $match->isApplied() ? ' be-replaced' : 'be-preview');
$replaced = $this->prepareText($match->getReplacedText(), $match->isApplied() ? ' be-applied' : 'be-preview');
$before = $this->prepareText($match->getContextBefore());
$after = $this->prepareText($match->getContextAfter());
print('');
print('' . $before . $original . $after . ' ');
print('' . $this->getSvg('slide-arrow-right') . ' ');
print('' . $before . $replaced . $after . ' ');
print('
');
}
/**
* Prepare wiki text to be displayed as html
*/
private function prepareText($text, $highlight = '') {
$html = htmlspecialchars($text);
$html = str_replace("\n", ' ', $html);
if ($highlight != '') {
$html = '' . $html . ' ';
}
return $html;
}
/**
*
*/
private function printFormEdit($title, $name) {
print('');
print('' . $this->getLang($title) . ' ');
print('');
switch ($name) {
case 'namespace':
$this->printEditBox($name);
break;
case 'search':
case 'replace':
$multiline = isset($_REQUEST['multiline']);
$placeholder = $this->getLang($this->getPlaceholderId($name));
$this->printEditBox($name, FALSE, TRUE, !$multiline, $placeholder);
$this->printTextArea($name, $multiline, $placeholder);
break;
case 'summary':
$this->printEditBox($name);
$this->printCheckBox('minor', 'lbl_minor');
break;
}
print(' ');
print(' ');
}
/**
*
*/
private function getPlaceholderId($editName) {
switch ($editName) {
case 'search':
switch ($_REQUEST['searchmode']) {
case 'text':
return 'hnt_textsearch';
case 'regexp':
return isset($_REQUEST['advregexp']) ? 'hnt_advregexpsearch' : 'hnt_regexpsearch';
}
case 'replace':
return 'hnt_' . $_REQUEST['searchmode'] . 'replace';
}
return '';
}
/**
*
*/
private function printOptions() {
$style = 'min-width: ' . $this->getLang('dim_options') . ';';
print('');
print('
');
print('
' . $this->getLang('lbl_searchmode') . '
');
$this->printRadioButton('searchmode', 'text', 'lbl_searchtext');
$this->printRadioButton('searchmode', 'regexp', 'lbl_searchregexp');
print('
');
$this->printCheckBox('matchcase', 'lbl_matchcase');
$this->printCheckBox('multiline', 'lbl_multiline');
print('
');
print('');
$this->printAction('javascript:openAdvancedOptions();', 'ttl_extoptions', 'settings');
print('
');
$style = 'width: ' . $this->getLang('dim_extoptions') . ';';
print('');
print('
');
$this->printAction('javascript:closeAdvancedOptions();', '', 'close');
print('
');
$this->printCheckBox('advregexp', 'lbl_advregexp');
$this->printCheckBox('matchctx', 'printMatchContextLabel');
$this->printCheckBox('searchlimit', 'printSearchLimitLabel');
$this->printCheckBox('keepmarks', 'printKeepMarksLabel');
$this->printCheckBox('tplpatterns', 'lbl_tplpatterns');
$this->printCheckBox('checksummary', 'lbl_checksummary');
print('
');
}
/**
*
*/
private function printMatchContextLabel() {
$label = preg_split('/(\{\d\})/', $this->getLang('lbl_matchctx'), -1, PREG_SPLIT_DELIM_CAPTURE);
$edits = array('{1}' => 'ctxchars', '{2}' => 'ctxlines');
$this->printLabel('matchctx', $label[0]);
$this->printEditBox($edits[$label[1]], TRUE, isset($_REQUEST['matchctx']));
$this->printLabel('matchctx', $label[2]);
$this->printEditBox($edits[$label[3]], TRUE, isset($_REQUEST['matchctx']));
$this->printLabel('matchctx', $label[4]);
}
/**
*
*/
private function printSearchLimitLabel() {
$label = explode('{1}', $this->getLang('lbl_searchlimit'));
$this->printLabel('searchlimit', $label[0]);
$this->printEditBox('searchmax', TRUE, isset($_REQUEST['searchlimit']));
$this->printLabel('searchlimit', $label[1]);
}
/**
*
*/
private function printKeepMarksLabel() {
$label = explode('{1}', $this->getLang('lbl_keepmarks'));
$disabled = isset($_REQUEST['keepmarks']) ? '' : ' disabled="disabled"';
$this->printLabel('keepmarks', $label[0]);
print('');
for ($i = 1; $i <= 4; $i++) {
$selected = $_REQUEST['markpolicy'] == $i ? ' selected="selected"' : '';
print('' . $this->getLang('lbl_keepmarks' . $i) . ' ');
}
print(' ');
$this->printLabel('keepmarks', $label[1]);
}
/**
*
*/
private function printEditBox($name, $submitted = TRUE, $enabled = TRUE, $visible = TRUE, $placeholder = '') {
$html = ' ');
}
/**
*
*/
private function printTextArea($name, $visible = TRUE, $placeholder = '') {
$html = '