2008-10-27 20:33:18 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Classes for InputBox extension
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
|
|
|
*/
|
|
|
|
|
|
|
|
// InputBox class
|
|
|
|
class InputBox {
|
|
|
|
|
|
|
|
/* Fields */
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2008-10-27 21:35:00 +00:00
|
|
|
private $mParser;
|
2008-11-13 08:50:13 +00:00
|
|
|
private $mType = '';
|
|
|
|
private $mWidth = 50;
|
|
|
|
private $mPreload = '';
|
2014-09-07 01:23:19 +00:00
|
|
|
private $mPreloadparams = array();
|
2008-11-13 08:50:13 +00:00
|
|
|
private $mEditIntro = '';
|
2009-01-13 02:18:30 +00:00
|
|
|
private $mSummary = '';
|
2010-03-31 12:33:11 +00:00
|
|
|
private $mNosummary = '';
|
2009-01-13 02:18:30 +00:00
|
|
|
private $mMinor = '';
|
2008-11-13 08:50:13 +00:00
|
|
|
private $mPage = '';
|
|
|
|
private $mBR = 'yes';
|
|
|
|
private $mDefaultText = '';
|
2011-10-26 20:31:20 +00:00
|
|
|
private $mPlaceholderText = '';
|
2008-11-13 08:50:13 +00:00
|
|
|
private $mBGColor = 'transparent';
|
|
|
|
private $mButtonLabel = '';
|
|
|
|
private $mSearchButtonLabel = '';
|
|
|
|
private $mFullTextButton = '';
|
|
|
|
private $mLabelText = '';
|
|
|
|
private $mHidden = '';
|
|
|
|
private $mNamespaces = '';
|
|
|
|
private $mID = '';
|
|
|
|
private $mInline = false;
|
2008-12-31 03:31:41 +00:00
|
|
|
private $mPrefix = '';
|
2012-09-02 13:50:42 +00:00
|
|
|
private $mDir = '';
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
/* Functions */
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
public function __construct( $parser ) {
|
2008-10-28 01:56:15 +00:00
|
|
|
$this->mParser = $parser;
|
2012-09-02 13:50:42 +00:00
|
|
|
// Default value for dir taken from the page language (bug 37018)
|
|
|
|
$this->mDir = $this->mParser->getTargetLanguage()->getDir();
|
2012-11-15 22:59:31 +00:00
|
|
|
// Split caches by language, to make sure visitors do not see a cached
|
|
|
|
// version in a random language (since labels are in the user language)
|
|
|
|
$this->mParser->getOptions()->getUserLangObj();
|
2015-02-23 08:45:05 +00:00
|
|
|
$this->mParser->getOutput()->addModuleStyles( array(
|
|
|
|
'ext.inputBox.styles',
|
|
|
|
'mediawiki.ui.input',
|
|
|
|
'mediawiki.ui.checkbox',
|
|
|
|
) );
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
public function render() {
|
|
|
|
// Handle various types
|
2014-05-18 09:07:27 +00:00
|
|
|
switch ( $this->mType ) {
|
2008-10-27 20:33:18 +00:00
|
|
|
case 'create':
|
|
|
|
case 'comment':
|
2014-03-24 06:08:56 +00:00
|
|
|
$this->mParser->getOutput()->addModules( 'ext.inputBox' );
|
2008-10-27 20:33:18 +00:00
|
|
|
return $this->getCreateForm();
|
2014-04-05 20:43:15 +00:00
|
|
|
case 'move':
|
|
|
|
return $this->getMoveForm();
|
2008-10-28 00:08:08 +00:00
|
|
|
case 'commenttitle':
|
|
|
|
return $this->getCommentForm();
|
2008-10-27 20:33:18 +00:00
|
|
|
case 'search':
|
2009-01-01 00:55:18 +00:00
|
|
|
return $this->getSearchForm('search');
|
|
|
|
case 'fulltext':
|
|
|
|
return $this->getSearchForm('fulltext');
|
2008-10-27 20:33:18 +00:00
|
|
|
case 'search2':
|
|
|
|
return $this->getSearchForm2();
|
|
|
|
default:
|
|
|
|
return Xml::tags( 'div', null,
|
|
|
|
Xml::element( 'strong',
|
|
|
|
array(
|
|
|
|
'class' => 'error'
|
|
|
|
),
|
2008-10-28 01:56:15 +00:00
|
|
|
strlen( $this->mType ) > 0
|
2012-11-15 22:59:31 +00:00
|
|
|
? wfMessage( 'inputbox-error-bad-type', $this->mType )->text()
|
|
|
|
: wfMessage( 'inputbox-error-no-type' )->text()
|
2008-10-27 20:33:18 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate search form
|
2011-06-17 16:26:31 +00:00
|
|
|
* @param $type
|
2012-08-30 16:20:32 +00:00
|
|
|
* @return string HTML
|
2008-10-27 20:33:18 +00:00
|
|
|
*/
|
2009-01-01 00:55:18 +00:00
|
|
|
public function getSearchForm( $type ) {
|
2011-07-14 03:51:10 +00:00
|
|
|
global $wgContLang, $wgNamespaceAliases;
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
// Use button label fallbacks
|
2008-10-27 21:35:00 +00:00
|
|
|
if ( !$this->mButtonLabel ) {
|
2014-04-05 19:40:46 +00:00
|
|
|
$this->mButtonLabel = wfMessage( 'inputbox-tryexact' )->text();
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
2008-10-27 21:35:00 +00:00
|
|
|
if ( !$this->mSearchButtonLabel ) {
|
2014-04-05 19:40:46 +00:00
|
|
|
$this->mSearchButtonLabel = wfMessage( 'inputbox-searchfulltext' )->text();
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
2014-04-06 19:35:30 +00:00
|
|
|
if ( $this->mID !== '' ) {
|
|
|
|
$idArray = array( 'id' => Sanitizer::escapeId( $this->mID ) );
|
|
|
|
} else {
|
|
|
|
$idArray = array();
|
|
|
|
}
|
|
|
|
// We need a unqiue id to link <label> to checkboxes, but also
|
|
|
|
// want multiple <inputbox>'s to not be invalid html
|
|
|
|
$idRandStr = Sanitizer::escapeId( '-' . $this->mID . wfRandom(), 'noninitial' );
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
// Build HTML
|
|
|
|
$htmlOut = Xml::openElement( 'div',
|
|
|
|
array(
|
2014-05-18 09:51:07 +00:00
|
|
|
'class' => 'mw-inputbox-centered',
|
|
|
|
'style' => $this->bgColorStyle(),
|
2008-10-27 20:33:18 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$htmlOut .= Xml::openElement( 'form',
|
|
|
|
array(
|
|
|
|
'name' => 'searchbox',
|
|
|
|
'class' => 'searchbox',
|
2014-01-04 09:31:54 +00:00
|
|
|
'action' => SpecialPage::getTitleFor( 'Search' )->getLocalUrl(),
|
2014-04-06 19:35:30 +00:00
|
|
|
) + $idArray
|
2008-10-27 20:33:18 +00:00
|
|
|
);
|
|
|
|
$htmlOut .= Xml::element( 'input',
|
|
|
|
array(
|
2015-02-23 08:45:05 +00:00
|
|
|
'class' => 'searchboxInput mw-ui-input mw-ui-input-inline',
|
2008-10-27 20:33:18 +00:00
|
|
|
'name' => 'search',
|
2008-10-27 21:35:00 +00:00
|
|
|
'type' => $this->mHidden ? 'hidden' : 'text',
|
|
|
|
'value' => $this->mDefaultText,
|
2011-10-26 20:31:20 +00:00
|
|
|
'placeholder' => $this->mPlaceholderText,
|
2008-10-27 21:35:00 +00:00
|
|
|
'size' => $this->mWidth,
|
2012-09-02 13:50:42 +00:00
|
|
|
'dir' => $this->mDir,
|
2008-10-27 20:33:18 +00:00
|
|
|
)
|
|
|
|
);
|
2011-06-17 16:26:31 +00:00
|
|
|
|
2014-05-18 09:07:27 +00:00
|
|
|
if ( $this->mPrefix != '' ) {
|
2008-12-31 03:31:41 +00:00
|
|
|
$htmlOut .= Xml::element( 'input',
|
|
|
|
array(
|
|
|
|
'name' => 'prefix',
|
|
|
|
'type' => 'hidden',
|
|
|
|
'value' => $this->mPrefix,
|
|
|
|
)
|
2011-06-17 16:26:31 +00:00
|
|
|
);
|
2008-12-31 03:31:41 +00:00
|
|
|
}
|
2011-06-17 16:26:31 +00:00
|
|
|
|
2008-10-27 21:35:00 +00:00
|
|
|
$htmlOut .= $this->mBR;
|
2008-10-27 20:33:18 +00:00
|
|
|
|
|
|
|
// Determine namespace checkboxes
|
2008-10-27 21:35:00 +00:00
|
|
|
$namespacesArray = explode( ',', $this->mNamespaces );
|
|
|
|
if ( $this->mNamespaces ) {
|
2011-07-14 03:51:10 +00:00
|
|
|
$namespaces = $wgContLang->getNamespaces();
|
|
|
|
$nsAliases = array_merge( $wgContLang->getNamespaceAliases(), $wgNamespaceAliases );
|
|
|
|
$showNamespaces = array();
|
2012-01-12 17:23:46 +00:00
|
|
|
$checkedNS = array();
|
2011-07-14 03:51:10 +00:00
|
|
|
# Check for valid namespaces
|
|
|
|
foreach ( $namespacesArray as $userNS ) {
|
|
|
|
$userNS = trim( $userNS ); # no whitespace
|
|
|
|
|
|
|
|
# Namespace needs to be checked if flagged with "**"
|
2011-08-22 23:47:01 +00:00
|
|
|
if ( strpos( $userNS, '**' ) ) {
|
2011-07-14 03:51:10 +00:00
|
|
|
$userNS = str_replace( '**', '', $userNS );
|
|
|
|
$checkedNS[$userNS] = true;
|
|
|
|
}
|
|
|
|
|
2012-08-30 16:20:32 +00:00
|
|
|
$mainMsg = wfMessage( 'inputbox-ns-main' )->inContentLanguage()->text();
|
2014-05-18 09:07:27 +00:00
|
|
|
if ( $userNS == 'Main' || $userNS == $mainMsg ) {
|
2011-07-14 03:51:10 +00:00
|
|
|
$i = 0;
|
2014-05-18 09:07:27 +00:00
|
|
|
} elseif ( array_search( $userNS, $namespaces ) ) {
|
2011-07-14 03:51:10 +00:00
|
|
|
$i = array_search( $userNS, $namespaces );
|
|
|
|
} elseif ( isset( $nsAliases[$userNS] ) ) {
|
|
|
|
$i = $nsAliases[$userNS];
|
|
|
|
} else {
|
2013-03-05 12:16:06 +00:00
|
|
|
continue; # Namespace not recognized, skip
|
2011-07-14 03:51:10 +00:00
|
|
|
}
|
|
|
|
$showNamespaces[$i] = $userNS;
|
2014-05-18 09:07:27 +00:00
|
|
|
if ( isset( $checkedNS[$userNS] ) && $checkedNS[$userNS] ) {
|
2011-07-14 03:51:10 +00:00
|
|
|
$checkedNS[$i] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Show valid namespaces
|
2014-05-18 09:07:27 +00:00
|
|
|
foreach ( $showNamespaces as $i => $name ) {
|
2008-10-27 20:33:18 +00:00
|
|
|
$checked = array();
|
2011-07-14 03:51:10 +00:00
|
|
|
// Namespace flagged with "**" or if it's the only one
|
|
|
|
if ( ( isset( $checkedNS[$i] ) && $checkedNS[$i] ) || count( $showNamespaces ) == 1 ) {
|
2008-10-27 20:33:18 +00:00
|
|
|
$checked = array( 'checked' => 'checked' );
|
|
|
|
}
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2011-07-14 03:51:10 +00:00
|
|
|
if ( count( $showNamespaces ) == 1 ) {
|
|
|
|
// Checkbox
|
|
|
|
$htmlOut .= Xml::element( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'ns' . $i,
|
|
|
|
'value' => 1,
|
2014-04-06 19:35:30 +00:00
|
|
|
'id' => 'mw-inputbox-ns' . $i . $idRandStr
|
2011-07-14 03:51:10 +00:00
|
|
|
) + $checked
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// Checkbox
|
2015-02-23 08:45:05 +00:00
|
|
|
$htmlOut .= ' <div class="inputbox-element mw-ui-checkbox">';
|
2011-07-14 03:51:10 +00:00
|
|
|
$htmlOut .= Xml::element( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'name' => 'ns' . $i,
|
|
|
|
'value' => 1,
|
2014-04-06 19:35:30 +00:00
|
|
|
'id' => 'mw-inputbox-ns' . $i . $idRandStr
|
2011-07-14 03:51:10 +00:00
|
|
|
) + $checked
|
|
|
|
);
|
|
|
|
// Label
|
2015-02-23 08:45:05 +00:00
|
|
|
$htmlOut .= Xml::label( $name, 'mw-inputbox-ns' . $i . $idRandStr );
|
2011-07-14 03:51:10 +00:00
|
|
|
$htmlOut .= '</div> ';
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-27 20:56:23 +00:00
|
|
|
|
|
|
|
// Line break
|
2008-10-27 21:35:00 +00:00
|
|
|
$htmlOut .= $this->mBR;
|
2014-05-18 09:07:27 +00:00
|
|
|
} elseif ( $type == 'search' ) {
|
2008-10-27 20:33:18 +00:00
|
|
|
// Go button
|
|
|
|
$htmlOut .= Xml::element( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'submit',
|
|
|
|
'name' => 'go',
|
2015-01-07 23:35:10 +00:00
|
|
|
'class' => 'mw-ui-button',
|
2008-10-27 21:35:00 +00:00
|
|
|
'value' => $this->mButtonLabel
|
2008-10-27 20:33:18 +00:00
|
|
|
)
|
|
|
|
);
|
2010-05-30 17:33:59 +00:00
|
|
|
$htmlOut .= ' ';
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
// Search button
|
|
|
|
$htmlOut .= Xml::element( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'submit',
|
|
|
|
'name' => 'fulltext',
|
2015-01-07 23:35:10 +00:00
|
|
|
'class' => 'mw-ui-button',
|
2008-10-27 21:35:00 +00:00
|
|
|
'value' => $this->mSearchButtonLabel
|
2008-10-27 20:33:18 +00:00
|
|
|
)
|
|
|
|
);
|
2011-06-17 16:26:31 +00:00
|
|
|
|
2009-02-26 20:15:49 +00:00
|
|
|
// Hidden fulltext param for IE (bug 17161)
|
2014-05-18 09:07:27 +00:00
|
|
|
if ( $type == 'fulltext' ) {
|
2010-10-29 15:32:44 +00:00
|
|
|
$htmlOut .= Html::hidden( 'fulltext', 'Search' );
|
2009-02-26 20:15:49 +00:00
|
|
|
}
|
2011-06-17 16:26:31 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
$htmlOut .= Xml::closeElement( 'form' );
|
|
|
|
$htmlOut .= Xml::closeElement( 'div' );
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
// Return HTML
|
|
|
|
return $htmlOut;
|
|
|
|
}
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2011-10-26 03:49:06 +00:00
|
|
|
/**
|
2008-10-27 20:33:18 +00:00
|
|
|
* Generate search form version 2
|
|
|
|
*/
|
|
|
|
public function getSearchForm2() {
|
|
|
|
// Use button label fallbacks
|
2008-10-27 21:35:00 +00:00
|
|
|
if ( !$this->mButtonLabel ) {
|
2014-04-05 19:40:46 +00:00
|
|
|
$this->mButtonLabel = wfMessage( 'inputbox-tryexact' )->text();
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2014-04-06 19:35:30 +00:00
|
|
|
if ( $this->mID !== '' ) {
|
|
|
|
$unescapedID = $this->mID;
|
|
|
|
} else {
|
|
|
|
// The label element needs a unique id, use
|
|
|
|
// random number to avoid multiple input boxes
|
|
|
|
// having conflicts.
|
|
|
|
$unescapedID = wfRandom();
|
|
|
|
}
|
|
|
|
$id = Sanitizer::escapeId( $unescapedID, 'noninitial' );
|
2008-10-27 20:33:18 +00:00
|
|
|
$htmlLabel = '';
|
2008-10-27 21:35:00 +00:00
|
|
|
if ( isset( $this->mLabelText ) && strlen( trim( $this->mLabelText ) ) ) {
|
2008-11-29 04:07:46 +00:00
|
|
|
$this->mLabelText = $this->mParser->recursiveTagParse( $this->mLabelText );
|
|
|
|
$htmlLabel = Xml::openElement( 'label', array( 'for' => 'bodySearchInput' . $id ) );
|
|
|
|
$htmlLabel .= $this->mLabelText;
|
|
|
|
$htmlLabel .= Xml::closeElement( 'label' );
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
|
|
|
$htmlOut = Xml::openElement( 'form',
|
|
|
|
array(
|
|
|
|
'name' => 'bodySearch' . $id,
|
|
|
|
'id' => 'bodySearch' . $id,
|
2014-05-18 09:51:07 +00:00
|
|
|
'class' => 'bodySearch' . ( $this->mInline ? ' mw-inputbox-inline' : '' ),
|
2014-01-04 09:31:54 +00:00
|
|
|
'action' => SpecialPage::getTitleFor( 'Search' )->getLocalUrl(),
|
2008-10-27 20:33:18 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$htmlOut .= Xml::openElement( 'div',
|
|
|
|
array(
|
2014-05-18 09:51:07 +00:00
|
|
|
'class' => 'bodySearchWrap' . ( $this->mInline ? ' mw-inputbox-inline' : '' ),
|
|
|
|
'style' => $this->bgColorStyle(),
|
2008-10-27 20:33:18 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$htmlOut .= $htmlLabel;
|
|
|
|
$htmlOut .= Xml::element( 'input',
|
|
|
|
array(
|
2008-10-27 21:35:00 +00:00
|
|
|
'type' => $this->mHidden ? 'hidden' : 'text',
|
2008-10-27 20:33:18 +00:00
|
|
|
'name' => 'search',
|
2015-02-23 08:45:05 +00:00
|
|
|
'class' => 'mw-ui-input mw-ui-input-inline',
|
2008-10-27 21:35:00 +00:00
|
|
|
'size' => $this->mWidth,
|
2012-09-02 13:50:42 +00:00
|
|
|
'id' => 'bodySearchInput' . $id,
|
|
|
|
'dir' => $this->mDir,
|
2008-10-27 20:33:18 +00:00
|
|
|
)
|
|
|
|
);
|
2015-02-23 08:45:05 +00:00
|
|
|
$htmlOut .= ' ' . Xml::element( 'input',
|
2008-10-27 20:33:18 +00:00
|
|
|
array(
|
|
|
|
'type' => 'submit',
|
|
|
|
'name' => 'go',
|
2008-10-27 21:35:00 +00:00
|
|
|
'value' => $this->mButtonLabel,
|
2015-01-07 23:35:10 +00:00
|
|
|
'class' => 'mw-ui-button',
|
2008-10-27 20:33:18 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Better testing needed here!
|
2008-10-27 21:35:00 +00:00
|
|
|
if ( !empty( $this->mFullTextButton ) ) {
|
2008-10-27 20:33:18 +00:00
|
|
|
$htmlOut .= Xml::element( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'submit',
|
|
|
|
'name' => 'fulltext',
|
2015-01-07 23:35:10 +00:00
|
|
|
'class' => 'mw-ui-button',
|
2008-10-27 21:35:00 +00:00
|
|
|
'value' => $this->mSearchButtonLabel
|
2008-10-27 20:33:18 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
$htmlOut .= Xml::closeElement( 'div' );
|
|
|
|
$htmlOut .= Xml::closeElement( 'form' );
|
|
|
|
|
|
|
|
// Return HTML
|
|
|
|
return $htmlOut;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate create page form
|
|
|
|
*/
|
|
|
|
public function getCreateForm() {
|
2008-10-27 20:56:23 +00:00
|
|
|
global $wgScript;
|
2008-10-27 20:33:18 +00:00
|
|
|
|
2008-10-27 21:35:00 +00:00
|
|
|
if ( $this->mType == "comment" ) {
|
|
|
|
if ( !$this->mButtonLabel ) {
|
2014-04-22 15:46:10 +00:00
|
|
|
$this->mButtonLabel = wfMessage( 'inputbox-postcomment' )->text();
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
|
|
|
} else {
|
2008-10-27 21:35:00 +00:00
|
|
|
if ( !$this->mButtonLabel ) {
|
2014-04-05 19:40:46 +00:00
|
|
|
$this->mButtonLabel = wfMessage( 'inputbox-createarticle' )->text();
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
$htmlOut = Xml::openElement( 'div',
|
|
|
|
array(
|
2014-05-18 09:51:07 +00:00
|
|
|
'class' => 'mw-inputbox-centered',
|
|
|
|
'style' => $this->bgColorStyle(),
|
2008-10-27 20:33:18 +00:00
|
|
|
)
|
|
|
|
);
|
2009-12-15 11:23:43 +00:00
|
|
|
$createBoxParams = array(
|
|
|
|
'name' => 'createbox',
|
|
|
|
'class' => 'createbox',
|
|
|
|
'action' => $wgScript,
|
|
|
|
'method' => 'get'
|
2008-10-27 20:33:18 +00:00
|
|
|
);
|
2014-05-18 09:07:27 +00:00
|
|
|
if ( $this->mID !== '' ) {
|
2014-04-05 23:55:09 +00:00
|
|
|
$createBoxParams['id'] = Sanitizer::escapeId( $this->mID );
|
2009-12-15 11:23:43 +00:00
|
|
|
}
|
|
|
|
$htmlOut .= Xml::openElement( 'form', $createBoxParams );
|
2008-10-27 20:33:18 +00:00
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'action',
|
|
|
|
'value' => 'edit',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'preload',
|
2008-10-27 21:35:00 +00:00
|
|
|
'value' => $this->mPreload,
|
2008-10-27 20:33:18 +00:00
|
|
|
)
|
|
|
|
);
|
2014-09-07 01:23:19 +00:00
|
|
|
foreach ( $this->mPreloadparams as $preloadparams ) {
|
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'preloadparams[]',
|
|
|
|
'value' => $preloadparams,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2008-10-27 20:33:18 +00:00
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'editintro',
|
2008-10-27 21:35:00 +00:00
|
|
|
'value' => $this->mEditIntro,
|
2008-10-27 20:33:18 +00:00
|
|
|
)
|
|
|
|
);
|
2009-01-13 02:18:30 +00:00
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'summary',
|
|
|
|
'value' => $this->mSummary,
|
|
|
|
)
|
|
|
|
);
|
2010-03-31 12:33:11 +00:00
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'nosummary',
|
|
|
|
'value' => $this->mNosummary,
|
|
|
|
)
|
|
|
|
);
|
2010-03-18 19:11:12 +00:00
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'prefix',
|
|
|
|
'value' => $this->mPrefix,
|
|
|
|
)
|
|
|
|
);
|
2009-01-13 02:18:30 +00:00
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'minor',
|
|
|
|
'value' => $this->mMinor,
|
|
|
|
)
|
|
|
|
);
|
2008-10-27 21:35:00 +00:00
|
|
|
if ( $this->mType == 'comment' ) {
|
2008-10-27 20:33:18 +00:00
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'section',
|
|
|
|
'value' => 'new',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
2008-10-27 21:35:00 +00:00
|
|
|
'type' => $this->mHidden ? 'hidden' : 'text',
|
2008-10-27 20:33:18 +00:00
|
|
|
'name' => 'title',
|
2015-02-23 08:45:05 +00:00
|
|
|
'class' => 'createboxInput mw-ui-input mw-ui-input-inline',
|
2008-10-27 21:35:00 +00:00
|
|
|
'value' => $this->mDefaultText,
|
2011-10-26 20:31:20 +00:00
|
|
|
'placeholder' => $this->mPlaceholderText,
|
2012-09-02 13:50:42 +00:00
|
|
|
'size' => $this->mWidth,
|
|
|
|
'dir' => $this->mDir,
|
2008-10-27 20:33:18 +00:00
|
|
|
)
|
|
|
|
);
|
2008-10-27 21:35:00 +00:00
|
|
|
$htmlOut .= $this->mBR;
|
2008-10-27 20:33:18 +00:00
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'submit',
|
|
|
|
'name' => 'create',
|
2015-01-07 23:35:10 +00:00
|
|
|
'class' => 'mw-ui-button mw-ui-progressive',
|
2008-10-27 21:35:00 +00:00
|
|
|
'value' => $this->mButtonLabel
|
2008-10-27 20:33:18 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$htmlOut .= Xml::closeElement( 'form' );
|
|
|
|
$htmlOut .= Xml::closeElement( 'div' );
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
// Return HTML
|
|
|
|
return $htmlOut;
|
|
|
|
}
|
2011-06-17 16:26:31 +00:00
|
|
|
|
2014-04-05 20:43:15 +00:00
|
|
|
/**
|
|
|
|
* Generate move page form
|
|
|
|
*/
|
|
|
|
public function getMoveForm() {
|
|
|
|
global $wgScript;
|
|
|
|
|
|
|
|
if ( !$this->mButtonLabel ) {
|
|
|
|
$this->mButtonLabel = wfMessage( 'inputbox-movearticle' )->text();
|
|
|
|
}
|
|
|
|
|
|
|
|
$htmlOut = Xml::openElement( 'div',
|
|
|
|
array(
|
2014-05-18 09:51:07 +00:00
|
|
|
'class' => 'mw-inputbox-centered',
|
|
|
|
'style' => $this->bgColorStyle(),
|
2014-04-05 20:43:15 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$moveBoxParams = array(
|
|
|
|
'name' => 'movebox',
|
|
|
|
'class' => 'mw-movebox',
|
|
|
|
'action' => $wgScript,
|
|
|
|
'method' => 'get'
|
|
|
|
);
|
2014-05-18 09:07:27 +00:00
|
|
|
if ( $this->mID !== '' ) {
|
2014-04-05 20:43:15 +00:00
|
|
|
$moveBoxParams['id'] = Sanitizer::escapeId( $this->mID );
|
|
|
|
}
|
|
|
|
$htmlOut .= Xml::openElement( 'form', $moveBoxParams );
|
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'title',
|
|
|
|
'value' => SpecialPage::getTitleFor( 'Movepage', $this->mPage )->getPrefixedText(),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'wpReason',
|
|
|
|
'value' => $this->mSummary,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'prefix',
|
|
|
|
'value' => $this->mPrefix,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
|
|
|
'type' => $this->mHidden ? 'hidden' : 'text',
|
|
|
|
'name' => 'wpNewTitle',
|
2015-02-23 08:45:05 +00:00
|
|
|
'class' => 'mw-moveboxInput mw-ui-input mw-ui-input-inline',
|
2014-04-05 20:43:15 +00:00
|
|
|
'value' => $this->mDefaultText,
|
|
|
|
'placeholder' => $this->mPlaceholderText,
|
|
|
|
'size' => $this->mWidth,
|
|
|
|
'dir' => $this->mDir,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$htmlOut .= $this->mBR;
|
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'submit',
|
2015-01-07 23:35:10 +00:00
|
|
|
'class' => 'mw-ui-button mw-ui-progressive',
|
2014-04-05 20:43:15 +00:00
|
|
|
'value' => $this->mButtonLabel
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$htmlOut .= Xml::closeElement( 'form' );
|
|
|
|
$htmlOut .= Xml::closeElement( 'div' );
|
|
|
|
|
|
|
|
// Return HTML
|
|
|
|
return $htmlOut;
|
|
|
|
}
|
|
|
|
|
2008-10-28 00:08:08 +00:00
|
|
|
/**
|
|
|
|
* Generate new section form
|
|
|
|
*/
|
|
|
|
public function getCommentForm() {
|
|
|
|
global $wgScript;
|
|
|
|
|
|
|
|
if ( !$this->mButtonLabel ) {
|
2014-04-22 15:46:10 +00:00
|
|
|
$this->mButtonLabel = wfMessage( 'inputbox-postcommenttitle' )->text();
|
2008-10-28 00:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$htmlOut = Xml::openElement( 'div',
|
|
|
|
array(
|
2014-05-18 09:51:07 +00:00
|
|
|
'class' => 'mw-inputbox-centered',
|
|
|
|
'style' => $this->bgColorStyle(),
|
2008-10-28 00:08:08 +00:00
|
|
|
)
|
|
|
|
);
|
2009-12-15 11:23:43 +00:00
|
|
|
$commentFormParams = array(
|
|
|
|
'name' => 'commentbox',
|
|
|
|
'class' => 'commentbox',
|
|
|
|
'action' => $wgScript,
|
|
|
|
'method' => 'get'
|
2008-10-28 00:08:08 +00:00
|
|
|
);
|
2014-05-18 09:07:27 +00:00
|
|
|
if ( $this->mID !== '' ) {
|
2014-04-05 23:55:09 +00:00
|
|
|
$commentFormParams['id'] = Sanitizer::escapeId( $this->mID );
|
2009-12-15 11:23:43 +00:00
|
|
|
}
|
|
|
|
$htmlOut .= Xml::openElement( 'form', $commentFormParams );
|
2008-10-28 00:08:08 +00:00
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'action',
|
|
|
|
'value' => 'edit',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'preload',
|
|
|
|
'value' => $this->mPreload,
|
|
|
|
)
|
|
|
|
);
|
2014-09-07 01:23:19 +00:00
|
|
|
foreach ( $this->mPreloadparams as $preloadparams ) {
|
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'preloadparams[]',
|
|
|
|
'value' => $preloadparams,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2008-10-28 00:08:08 +00:00
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'editintro',
|
|
|
|
'value' => $this->mEditIntro,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
2008-11-17 21:54:38 +00:00
|
|
|
'type' => $this->mHidden ? 'hidden' : 'text',
|
2008-10-28 00:08:08 +00:00
|
|
|
'name' => 'preloadtitle',
|
2015-02-23 08:45:05 +00:00
|
|
|
'class' => 'commentboxInput mw-ui-input mw-ui-input-inline',
|
2008-10-28 00:08:08 +00:00
|
|
|
'value' => $this->mDefaultText,
|
2011-10-26 20:31:20 +00:00
|
|
|
'placeholder' => $this->mPlaceholderText,
|
2012-09-02 13:50:42 +00:00
|
|
|
'size' => $this->mWidth,
|
|
|
|
'dir' => $this->mDir,
|
2008-10-28 00:08:08 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'section',
|
|
|
|
'value' => 'new',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'title',
|
|
|
|
'value' => $this->mPage
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$htmlOut .= $this->mBR;
|
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'submit',
|
|
|
|
'name' => 'create',
|
2015-01-07 23:35:10 +00:00
|
|
|
'class' => 'mw-ui-button mw-ui-progressive',
|
2008-10-28 00:08:08 +00:00
|
|
|
'value' => $this->mButtonLabel
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$htmlOut .= Xml::closeElement( 'form' );
|
|
|
|
$htmlOut .= Xml::closeElement( 'div' );
|
|
|
|
|
|
|
|
// Return HTML
|
|
|
|
return $htmlOut;
|
|
|
|
}
|
2008-10-27 20:33:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract options from a blob of text
|
|
|
|
*
|
|
|
|
* @param string $text Tag contents
|
|
|
|
*/
|
|
|
|
public function extractOptions( $text ) {
|
|
|
|
// Parse all possible options
|
|
|
|
$values = array();
|
2008-10-27 20:56:23 +00:00
|
|
|
foreach ( explode( "\n", $text ) as $line ) {
|
|
|
|
if ( strpos( $line, '=' ) === false )
|
2008-10-27 20:33:18 +00:00
|
|
|
continue;
|
|
|
|
list( $name, $value ) = explode( '=', $line, 2 );
|
2014-09-07 01:23:19 +00:00
|
|
|
$name = strtolower( trim( $name ) );
|
|
|
|
$value = Sanitizer::decodeCharReferences( trim( $value ) );
|
|
|
|
if ( $name == 'preloadparams[]' ) {
|
|
|
|
// We have to special-case this one because it's valid for it to appear more than once.
|
|
|
|
$this->mPreloadparams[] = $value;
|
|
|
|
} else {
|
|
|
|
$values[ $name ] = $value;
|
|
|
|
}
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2012-09-02 13:50:42 +00:00
|
|
|
// Validate the dir value.
|
|
|
|
if ( isset( $values['dir'] ) && !in_array( $values['dir'], array( 'ltr', 'rtl' ) ) ) {
|
|
|
|
unset( $values['dir'] );
|
|
|
|
}
|
|
|
|
|
2008-11-13 08:50:13 +00:00
|
|
|
// Build list of options, with local member names
|
2008-10-27 20:33:18 +00:00
|
|
|
$options = array(
|
2008-11-13 08:50:13 +00:00
|
|
|
'type' => 'mType',
|
|
|
|
'width' => 'mWidth',
|
|
|
|
'preload' => 'mPreload',
|
|
|
|
'page' => 'mPage',
|
|
|
|
'editintro' => 'mEditIntro',
|
2009-01-13 02:18:30 +00:00
|
|
|
'summary' => 'mSummary',
|
2010-03-31 12:33:11 +00:00
|
|
|
'nosummary' => 'mNosummary',
|
2009-01-13 02:18:30 +00:00
|
|
|
'minor' => 'mMinor',
|
2008-11-13 08:50:13 +00:00
|
|
|
'break' => 'mBR',
|
|
|
|
'default' => 'mDefaultText',
|
2011-10-26 20:31:20 +00:00
|
|
|
'placeholder' => 'mPlaceholderText',
|
2008-11-13 08:50:13 +00:00
|
|
|
'bgcolor' => 'mBGColor',
|
|
|
|
'buttonlabel' => 'mButtonLabel',
|
|
|
|
'searchbuttonlabel' => 'mSearchButtonLabel',
|
|
|
|
'fulltextbutton' => 'mFullTextButton',
|
|
|
|
'namespaces' => 'mNamespaces',
|
|
|
|
'labeltext' => 'mLabelText',
|
|
|
|
'hidden' => 'mHidden',
|
|
|
|
'id' => 'mID',
|
|
|
|
'inline' => 'mInline',
|
2008-12-31 03:31:41 +00:00
|
|
|
'prefix' => 'mPrefix',
|
2012-09-02 13:50:42 +00:00
|
|
|
'dir' => 'mDir',
|
2008-10-27 20:33:18 +00:00
|
|
|
);
|
2008-10-27 20:56:23 +00:00
|
|
|
foreach ( $options as $name => $var ) {
|
|
|
|
if ( isset( $values[$name] ) ) {
|
2008-11-13 08:50:13 +00:00
|
|
|
$this->$var = $values[$name];
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-01 13:29:46 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
// Insert a line break if configured to do so
|
2009-01-01 13:29:46 +00:00
|
|
|
$this->mBR = ( strtolower( $this->mBR ) == "no" ) ? ' ' : '<br />';
|
2008-10-27 20:33:18 +00:00
|
|
|
|
|
|
|
// Validate the width; make sure it's a valid, positive integer
|
2008-10-27 21:35:00 +00:00
|
|
|
$this->mWidth = intval( $this->mWidth <= 0 ? 50 : $this->mWidth );
|
2009-01-01 13:29:46 +00:00
|
|
|
|
2010-03-30 03:59:15 +00:00
|
|
|
// Validate background color
|
|
|
|
if ( !$this->isValidColor( $this->mBGColor ) ) {
|
|
|
|
$this->mBGColor = 'transparent';
|
|
|
|
}
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
|
|
|
|
2010-03-30 03:59:15 +00:00
|
|
|
/**
|
|
|
|
* Do a security check on the bgcolor parameter
|
|
|
|
*/
|
|
|
|
public function isValidColor( $color ) {
|
|
|
|
$regex = <<<REGEX
|
|
|
|
/^ (
|
|
|
|
[a-zA-Z]* | # color names
|
|
|
|
\# [0-9a-f]{3} | # short hexadecimal
|
|
|
|
\# [0-9a-f]{6} | # long hexadecimal
|
|
|
|
rgb \s* \( \s* (
|
|
|
|
\d+ \s* , \s* \d+ \s* , \s* \d+ | # rgb integer
|
|
|
|
[0-9.]+% \s* , \s* [0-9.]+% \s* , \s* [0-9.]+% # rgb percent
|
|
|
|
) \s* \)
|
|
|
|
) $ /xi
|
|
|
|
REGEX;
|
|
|
|
return (bool) preg_match( $regex, $color );
|
|
|
|
}
|
2014-05-18 09:51:07 +00:00
|
|
|
|
|
|
|
private function bgColorStyle() {
|
|
|
|
if ( $this->mBGColor != 'transparent' ) {
|
|
|
|
return 'background-color: ' . $this->mBGColor . ';';
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|