Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php |
— | — | @@ -60,7 +60,7 @@ |
61 | 61 | * @global WebRequest $wgRequest |
62 | 62 | * @return array |
63 | 63 | */ |
64 | | - protected function processParams(){ |
| 64 | + protected function processParams() { |
65 | 65 | global $wgRequest; |
66 | 66 | $params = array_merge( |
67 | 67 | array( |
— | — | @@ -68,11 +68,103 @@ |
69 | 69 | 'offset' => $wgRequest->getVal( 'offset', '0' ), |
70 | 70 | 'limit' => $wgRequest->getVal( 'limit', '20' ) ), |
71 | 71 | $this->processPoSortFormBox( $wgRequest ), |
72 | | - $this->processFormatSelectBox( $wgRequest ) ); |
| 72 | + $this->processFormatSelectBox( $wgRequest ), |
| 73 | + $this->processMainLabelFormBox( $wgRequest ) |
| 74 | + ); |
73 | 75 | return $params; |
74 | 76 | } |
75 | 77 | |
76 | 78 | /** |
| 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 | + /** |
77 | 169 | * Displays a form section showing the options for a given format, |
78 | 170 | * based on the getParameters() value for that format's query printer. |
79 | 171 | * |
— | — | @@ -85,7 +177,7 @@ |
86 | 178 | * Overridden from parent to ignore GUI parameters 'format' 'limit' and 'offset' |
87 | 179 | */ |
88 | 180 | 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' ) ); |
90 | 182 | } |
91 | 183 | /** |
92 | 184 | * Creates the input form |
— | — | @@ -107,11 +199,12 @@ |
108 | 200 | // Main query and format options |
109 | 201 | $result .= $this->getQueryFormBox(); |
110 | 202 | // 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>'; |
112 | 205 | // 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="' . |
116 | 209 | "jQuery('#additional_options').show('blind');" . |
117 | 210 | "document.getElementById('show_additional_options').style.display='none';" . |
118 | 211 | "document.getElementById('hide_additional_options').style.display='inline';" . '">' . |
— | — | @@ -122,7 +215,7 @@ |
123 | 216 | "document.getElementById('show_additional_options').style.display='inline';" . '">' . |
124 | 217 | wfMsg( 'smw_qc_hide_addnal_opts' ) . '</a></span>'; |
125 | 218 | $result .= '</div>'; |
126 | | - //END: show|hide additional options |
| 219 | + // END: show|hide additional options |
127 | 220 | $result .= '<div id="additional_options" style="display:none">'; |
128 | 221 | |
129 | 222 | $result .= $formatBox[1]; // display the format options |
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_Messages.php |
— | — | @@ -236,6 +236,8 @@ |
237 | 237 | |
238 | 238 | // Messages for Query Creator Special |
239 | 239 | 'querycreator' => 'Query Creator', |
| 240 | + 'smw_qc_mainlabel' => 'Main label', |
| 241 | + 'smw_qc_addmainlabel' => 'Add main label', |
240 | 242 | 'smw_qc_show_addnal_opts' => 'Show more options', |
241 | 243 | 'smw_qc_hide_addnal_opts' => 'Show less options', |
242 | 244 | 'smw_qc_query_help' => 'Enter a query using the form below. Select wiki pages based on |