r94616 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94615‎ | r94616 | r94617 >
Date:10:46, 16 August 2011
Author:devayon
Status:deferred
Tags:
Comment:
control for mainlabel
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/languages/SMW_Messages.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php
@@ -60,7 +60,7 @@
6161 * @global WebRequest $wgRequest
6262 * @return array
6363 */
64 - protected function processParams(){
 64+ protected function processParams() {
6565 global $wgRequest;
6666 $params = array_merge(
6767 array(
@@ -68,11 +68,103 @@
6969 'offset' => $wgRequest->getVal( 'offset', '0' ),
7070 'limit' => $wgRequest->getVal( 'limit', '20' ) ),
7171 $this->processPoSortFormBox( $wgRequest ),
72 - $this->processFormatSelectBox( $wgRequest ) );
 72+ $this->processFormatSelectBox( $wgRequest ),
 73+ $this->processMainLabelFormBox( $wgRequest )
 74+ );
7375 return $params;
7476 }
7577
7678 /**
 79+ * A method which decodes form data sent through form-elements generated
 80+ * by its complement, getMainLabelFormBoxSep().
 81+ *
 82+ * @param WebRequest $wgRequest
 83+ * @return array
 84+ */
 85+ protected function processMainLabelFormBox( WebRequest $wgRequest ) {
 86+ $mainLabel = $wgRequest->getVal( 'pmainlabel', '' );
 87+ $result = array( 'mainlabel' => $mainLabel );
 88+ return $result;
 89+ }
 90+
 91+ /**
 92+ * Generates the form elements for the main-label parameter. Use its
 93+ * complement processMainLabelFormBox() to decode data sent through these
 94+ * elements.
 95+ *
 96+ * @global string $smwgScriptPath
 97+ * @global OutputPage $wgOut
 98+ * @return array the first element has the link to enable mainlabel, and the second gives the mainlabel control
 99+ */
 100+ protected function getMainLabelFormBoxSep() {
 101+ global $smwgScriptPath, $wgOut;
 102+ $result = array();
 103+ $param = $this->uiCore->getParameters();
 104+ if ( is_array( $param ) && array_key_exists( 'mainlabel', $param ) ) {
 105+ $mainLabel = $param['mainlabel'];
 106+ } else {
 107+ $mainLabel = '';
 108+ }
 109+ if ( $mainLabel == '-' ) {
 110+ $mainLabelText = '';
 111+ $linkDisplay = 'inline';
 112+ $formDisplay = 'none';
 113+ } else {
 114+ $mainLabelText = $mainLabel;
 115+ $linkDisplay = 'none';
 116+ $formDisplay = 'block';
 117+ }
 118+ if ( $this->uiCore->getQueryString() == '' ) {
 119+ $linkDisplay = 'inline';
 120+ $formDisplay = 'none';
 121+ }
 122+
 123+ $this->enableJQuery();
 124+ $javascriptText = <<<EOT
 125+<script type="text/javascript">
 126+
 127+ function smwRemoveMainLabel(){
 128+ jQuery('#mainlabelhid').attr('value','-');
 129+ jQuery('#mainlabelvis').attr('value','');
 130+ jQuery('#add_mainlabel').show();
 131+ jQuery('#smwmainlabel').hide();
 132+ }
 133+ function smwAddMainLabel(){
 134+ jQuery('#mainlabelhid').attr('value','');
 135+ jQuery('#mainlabelvis').attr('value','');
 136+ jQuery('#smwmainlabel').show();
 137+ jQuery('#add_mainlabel').hide();
 138+ }
 139+ jQuery(document).ready(function(){
 140+ jQuery('#mainlabelvis').bind('change', function(){
 141+ jQuery('#mainlabelhid').attr('value',jQuery('#mainlabelvis').attr('value'));
 142+ });
 143+ });
 144+</script>
 145+EOT;
 146+ $wgOut->addScript( $javascriptText );
 147+ $result[0] = Html::openElement( 'span', array( 'id' => 'add_mainlabel', 'style' => "display:$linkDisplay;" ) ) .
 148+ '[' . Html::element( 'a', array( 'href' => 'javascript:smwAddMainLabel()',
 149+ 'rel' => 'nofollow', 'id' => 'add_mainlabel' ),
 150+ wfMsg( 'smw_qc_addmainlabel' ) ) .
 151+ ']</span>';
 152+
 153+ $result[1] = Html::openElement( 'div', array( 'id' => 'smwmainlabel', 'class' => 'smwsort', 'style' => "display:$formDisplay;" ) ) .
 154+ Html::openElement( 'span', array( 'class' => 'smwquisortlabel' ) ) .
 155+ Html::openElement( 'span', array( 'class' => 'smw-remove' ) ) .
 156+ Html::openElement( 'a', array( 'href' => 'javascript:smwRemoveMainLabel()' ) ) .
 157+ '<img src="' . $smwgScriptPath . '/skins/images/close-button.png" alt="' . wfMsg( 'smw_qui_delete' ) . '">' .
 158+ '</a>' .
 159+ '</span>' .
 160+ '<strong>' . wfMsg( 'smw_qc_mainlabel' ) . '</strong>' .
 161+ '</span>' .
 162+ '<input size="25" value="' . $mainLabelText . '" id="mainlabelvis" />' .
 163+ Html::hidden( 'pmainlabel', $mainLabel, array( 'id' => 'mainlabelhid' ) ) .
 164+ '</div>';
 165+ return $result;
 166+ }
 167+
 168+ /**
77169 * Displays a form section showing the options for a given format,
78170 * based on the getParameters() value for that format's query printer.
79171 *
@@ -85,7 +177,7 @@
86178 * Overridden from parent to ignore GUI parameters 'format' 'limit' and 'offset'
87179 */
88180 protected function showFormatOptions( $format, array $paramValues, array $ignoredAttribs = array() ) {
89 - return parent::showFormatOptions( $format, $paramValues, array( 'format', 'limit', 'offset' ) );
 181+ return parent::showFormatOptions( $format, $paramValues, array( 'format', 'limit', 'offset', 'mainlabel' ) );
90182 }
91183 /**
92184 * Creates the input form
@@ -107,11 +199,12 @@
108200 // Main query and format options
109201 $result .= $this->getQueryFormBox();
110202 // sorting and prinouts
111 - $result .= '<div class="smwqcsortbox">' . $this->getPoSortFormBox() . '</div>';
 203+ $mainLabelHtml = $this->getMainLabelFormBoxSep();
 204+ $result .= '<div class="smwqcsortbox">' . $mainLabelHtml[1] . $this->getPoSortFormBox() . $mainLabelHtml[0] . '</div>';
112205 // additional options
113 - //START: show|hide additional options
114 - $result .= '<div class="smwqcformatas"><strong>'.wfMsg('smw_ask_format_as').'</strong>';
115 - $result .= $formatBox[0].'<span id="show_additional_options" style="display:inline;"><a href="#addtional" rel="nofollow" onclick="' .
 206+ // START: show|hide additional options
 207+ $result .= '<div class="smwqcformatas"><strong>' . wfMsg( 'smw_ask_format_as' ) . '</strong>';
 208+ $result .= $formatBox[0] . '<span id="show_additional_options" style="display:inline;"><a href="#addtional" rel="nofollow" onclick="' .
116209 "jQuery('#additional_options').show('blind');" .
117210 "document.getElementById('show_additional_options').style.display='none';" .
118211 "document.getElementById('hide_additional_options').style.display='inline';" . '">' .
@@ -122,7 +215,7 @@
123216 "document.getElementById('show_additional_options').style.display='inline';" . '">' .
124217 wfMsg( 'smw_qc_hide_addnal_opts' ) . '</a></span>';
125218 $result .= '</div>';
126 - //END: show|hide additional options
 219+ // END: show|hide additional options
127220 $result .= '<div id="additional_options" style="display:none">';
128221
129222 $result .= $formatBox[1]; // display the format options
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_Messages.php
@@ -236,6 +236,8 @@
237237
238238 // Messages for Query Creator Special
239239 'querycreator' => 'Query Creator',
 240+ 'smw_qc_mainlabel' => 'Main label',
 241+ 'smw_qc_addmainlabel' => 'Add main label',
240242 'smw_qc_show_addnal_opts' => 'Show more options',
241243 'smw_qc_hide_addnal_opts' => 'Show less options',
242244 'smw_qc_query_help' => 'Enter a query using the form below. Select wiki pages based on

Follow-up revisions

RevisionCommit summaryAuthorDate
r94656mainlabel as a printout control. Follow-up r94616devayon16:27, 16 August 2011