X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/extensions/InputBox/InputBox.classes.php diff --git a/extensions/InputBox/InputBox.classes.php b/extensions/InputBox/InputBox.classes.php new file mode 100644 index 00000000..c2c0d40d --- /dev/null +++ b/extensions/InputBox/InputBox.classes.php @@ -0,0 +1,719 @@ +mParser = $parser; + // Default value for dir taken from the page language (bug 37018) + $this->mDir = $this->mParser->getTargetLanguage()->getDir(); + // 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(); + $this->mParser->getOutput()->addModuleStyles( [ + 'ext.inputBox.styles', + 'mediawiki.ui.input', + 'mediawiki.ui.checkbox', + ] ); + } + + public function render() { + // Handle various types + switch ( $this->mType ) { + case 'create': + case 'comment': + $this->mParser->getOutput()->addModules( 'ext.inputBox' ); + return $this->getCreateForm(); + case 'move': + return $this->getMoveForm(); + case 'commenttitle': + return $this->getCommentForm(); + case 'search': + return $this->getSearchForm( 'search' ); + case 'fulltext': + return $this->getSearchForm( 'fulltext' ); + case 'search2': + return $this->getSearchForm2(); + default: + return Xml::tags( 'div', null, + Xml::element( 'strong', + [ 'class' => 'error' ], + strlen( $this->mType ) > 0 + ? wfMessage( 'inputbox-error-bad-type', $this->mType )->text() + : wfMessage( 'inputbox-error-no-type' )->text() + ) + ); + } + } + + /* + * Returns the action name and value to use in inputboxes which redirects to edit pages. + * Decides, if the link should redirect to VE edit page (veaction=edit) or to wikitext editor + * (action=edit). + * + * @return Array Array with name and value data + */ + private function getEditActionArgs() { + // default is wikitext editor + $args = [ + 'name' => 'action', + 'value' => 'edit', + ]; + // check, if VE is installed and VE editor is requested + if ( $this->shouldUseVE() ) { + $args = [ + 'name' => 'veaction', + 'value' => 'edit', + ]; + } + return $args; + } + + /** + * Get common classes, that could be added and depend on, if + * a line break between a button and an input field is added or not. + * + * @return String + */ + private function getLinebreakClasses() { + return strtolower( $this->mBR ) === '
' ? 'mw-inputbox-input ' : ''; + } + + /** + * Generate search form + * @param $type + * @return string HTML + */ + public function getSearchForm( $type ) { + global $wgContLang, $wgNamespaceAliases; + + // Use button label fallbacks + if ( !$this->mButtonLabel ) { + $this->mButtonLabel = wfMessage( 'inputbox-tryexact' )->text(); + } + if ( !$this->mSearchButtonLabel ) { + $this->mSearchButtonLabel = wfMessage( 'inputbox-searchfulltext' )->text(); + } + if ( $this->mID !== '' ) { + $idArray = [ 'id' => Sanitizer::escapeId( $this->mID ) ]; + } else { + $idArray = []; + } + // We need a unqiue id to link