Index: trunk/extensions/Call/Call.php |
— | — | @@ -22,7 +22,7 @@ |
23 | 23 | $wgExtensionCredits['specialpage'][] = array( |
24 | 24 | 'path' => __FILE__, |
25 | 25 | 'name' => 'Call', |
26 | | - 'version' => '1.1', |
| 26 | + 'version' => '1.2', |
27 | 27 | 'author' => 'Algorithmix', |
28 | 28 | 'description' => 'Create a hyperlink to a template (or to a normal wiki article) with parameter passing. Can be used at the browser’s command line or within wiki text.', |
29 | 29 | 'descriptionmsg' => 'call-desc', |
Index: trunk/extensions/Call/Call_body.php |
— | — | @@ -21,30 +21,40 @@ |
22 | 22 | * will tale the raw text of "Template:Abc", replace all occurencies of 'foo' by 'bar' and save the result as a normal |
23 | 23 | * article named 'Xyz' in the main namespace. |
24 | 24 | * added a functionality to split wiki tables into calls of a template per row (cmd=convertTableToTemplateCalls) |
| 25 | + * @version 0.7 |
| 26 | + * empty parameters are now no longer ignored; so you can replace a symbol by "nothing" when using saveAsPage |
| 27 | + * introduced 'link1' and 'link2', label1 and label2 |
| 28 | + * link replaces ",name," by ",name=value," |
| 29 | + * link2 replaces "name" by "value" and "," by "&" |
25 | 30 | */ |
26 | 31 | |
27 | 32 | class Call extends SpecialPage |
28 | 33 | { |
29 | 34 | function Call() { |
30 | 35 | SpecialPage::SpecialPage("Call"); |
31 | | - wfLoadExtensionMessages('Call'); |
| 36 | + self::loadMessages(); |
32 | 37 | } |
33 | 38 | |
34 | | - |
| 39 | + |
35 | 40 | function execute($par) { |
36 | 41 | global $wgParser; |
37 | 42 | global $wgOut, $wgRequest, $wgRawHtml, $wgUser; |
38 | 43 | $oldRawHtml = $wgRawHtml; |
39 | 44 | $wgRawHtml = false; // disable raw html if it's enabled as this could be XSS security risk |
40 | 45 | $this->setHeaders(); |
41 | | - |
| 46 | + |
42 | 47 | global $_REQUEST; |
43 | 48 | $argkeys = array_keys($_REQUEST); |
44 | | - |
| 49 | + |
45 | 50 | // find the position of "title" and count succeeding arguments until we find one that matches |
46 | 51 | // one of the patterns which belong to typical session cookie variables |
47 | | - $argTitle=-1; $argCount=0; $n=0; |
| 52 | + // store link info |
| 53 | + $argTitle=-1; $argCount=0; $n=0; $link1=''; $link2=''; $label1 = 'link 1'; $label2 = 'link 2'; |
48 | 54 | foreach ($argkeys as $argKey) { |
| 55 | + if ($argKey=='link1') $link1=$wgRequest->getText($argKey); |
| 56 | + if ($argKey=='label1') $label1=$wgRequest->getText($argKey); |
| 57 | + if ($argKey=='link2') $link2=$wgRequest->getText($argKey); |
| 58 | + if ($argKey=='label2') $label2=$wgRequest->getText($argKey); |
49 | 59 | if ($argKey=='title') $argTitle = $n; |
50 | 60 | else if ($argTitle>=0) { |
51 | 61 | if (preg_match('/(UserName|UserID|_session|Token)$/',$argKey)) break; |
— | — | @@ -76,9 +86,13 @@ |
77 | 87 | if (++$n > $argCount) break; |
78 | 88 | $arg = $wgRequest->getText($argKey); |
79 | 89 | if ($arg=='') { |
| 90 | + $link1 = str_replace(",$argKey,",",$argKey=,",$link1); |
| 91 | + $link2 = str_replace($argKey,"",$link2); |
80 | 92 | $arg = str_replace( "_", " ", $argKey ); |
81 | 93 | $wikitext .= ( '|' . $arg ); |
82 | 94 | } else { |
| 95 | + $link1 = str_replace(",$argKey,",",$argKey=$arg,",$link1); |
| 96 | + $link2 = str_replace($argKey,str_replace(' ','_',$arg),$link2); |
83 | 97 | $arg = str_replace( "_", " ", $arg ); |
84 | 98 | $wikitext .= ( '|' . $argKey . '=' . $arg ); |
85 | 99 | } |
— | — | @@ -124,18 +138,29 @@ |
125 | 139 | |
126 | 140 | if ($wikitext=='' || $wikitext=='Special:Call' ) { |
127 | 141 | // Called without parameters: dump explanation |
128 | | - $wgOut->addHTML(wfMsg('call-text')); |
| 142 | + $wgOut->addHTML("The Call extension expects a wiki page and optional parameters for that page as an argument.<br>\n<br>\n" |
| 143 | + ."Example 1: <tt>[[Special:Call/My Template,parm1=value1]]</tt><br/>\n" |
| 144 | + ."Example 2: <tt>[[Special:Call/Talk:My Discussion,parm1=value1]]</tt><br/>\n" |
| 145 | + ."Example 3: <tt>[[Special:Call/:My Page,parm1=value1,parm2=value2]]</tt><br/>\n<br/>\n" |
| 146 | + ."Example 4 (Browser URL): <tt>http://mydomain/mywiki/index.php?Special:Call/:My Page,parm1=value1</tt><br/>\n<br/>" |
| 147 | + ."The <i>Call extension</i> will call the given page and pass the parameters.<br>\n" |
| 148 | + ."You will see the contents of the called page and its title but its 'type' will be that of a special page,<br>" |
| 149 | + ."i.e. such a page cannot be edited.<br>The contents you see may vary depending on the value of the parameters you passed.<br>\n<br>" |
| 150 | + ."The <i>Call extension</i> is useful to build interactive applications with MediaWiki.<br>\n" |
| 151 | + ."For an example see <a href='http://semeb.com/dpldemo/Template:Catlist'>the DPL GUI</a> ..<br/>\n" |
| 152 | + ."In case of problems you can try <b>Special:Call/DebuG</b>\n"); |
129 | 153 | } |
130 | 154 | else if ($debug) { |
131 | 155 | // Called with DebuG target: dump parameter list |
132 | 156 | $wgOut->addHTML("<pre>\n{{".$wikitext."}}\n</pre>"); |
133 | | - if ($saveAsPage!='') $wgOut->addHTML(wfMsg('call-save',$saveAsPageLink) ); |
| 157 | + if ($saveAsPage!='') $wgOut->addHTML("The output of this call would be saved to a page called ''$saveAsPageLink''."); |
134 | 158 | } |
135 | 159 | else { |
136 | 160 | $parm=array(); |
137 | 161 | foreach (split('\|',$wikitext) as $parmArg) { |
138 | 162 | $pp = split('=',$parmArg,2); |
139 | 163 | if (count($pp) == 2) $parm[$pp[0]] = $pp[1]; |
| 164 | + else $parm[$pp[0]] = ''; |
140 | 165 | } |
141 | 166 | if ($cmd=='convertTableToTemplateCalls') { |
142 | 167 | // execute command |
— | — | @@ -150,12 +175,16 @@ |
151 | 176 | if (!($saveAsTitle->exists())) { |
152 | 177 | $article = new Article($saveAsTitle); |
153 | 178 | $article->doEdit( $rawText, $saveAsPage, EDIT_NEW | EDIT_FORCE_BOT ); |
154 | | - $wgOut->addHTML($wgOut->parse(wfMsg('call-save-success' ,$saveAsPageLink) ) ); |
| 179 | + $wgOut->addHTML($wgOut->parse("The following text has been saved to page <big>[[$saveAsPageLink]]</big>.")); |
155 | 180 | } |
156 | 181 | else { |
157 | | - $wgOut->addHTML($wgOut->parse(wfMsg('call-save-failed',$saveAsPageLink) ) ); |
| 182 | + $wgOut->addHTML($wgOut->parse("The following text has NOT been saved to page <big>[[$saveAsPageLink]]</big> ". |
| 183 | + "because that page already exists.")); |
158 | 184 | } |
159 | 185 | // output the text we produced as a note to the user |
| 186 | + if ($link1!='') $wgOut->addHTML($wgOut->parse("[[Special:Call/$link1|$label1]]")); |
| 187 | + $link2=str_replace(',','&',$link2); |
| 188 | + if ($link2!='') $wgOut->addHTML($wgOut->parse("[$link2 $label2]")); |
160 | 189 | $wgOut->addHTML("<pre>\n$rawText\n</pre>"); |
161 | 190 | } |
162 | 191 | else { |
— | — | @@ -221,4 +250,17 @@ |
222 | 251 | } |
223 | 252 | return join("\n",$text); |
224 | 253 | } |
| 254 | + |
| 255 | + function loadMessages() { |
| 256 | + static $messagesLoaded = false; |
| 257 | + global $wgMessageCache; |
| 258 | + if ( $messagesLoaded ) return true; |
| 259 | + $messagesLoaded = true; |
| 260 | + |
| 261 | + require( dirname( __FILE__ ) . '/Call.i18n.php' ); |
| 262 | + foreach ( $allMessages as $lang => $langMessages ) { |
| 263 | + $wgMessageCache->addMessages( $langMessages, $lang ); |
| 264 | + } |
| 265 | + return true; |
| 266 | + } |
225 | 267 | } |