r51055 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51054‎ | r51055 | r51056 >
Date:10:51, 27 May 2009
Author:shinjiman
Status:deferred (Comments)
Tags:
Comment:
Update the Call codebase to 0.7
written by Algorithmix
Modified paths:
  • /trunk/extensions/Call/Call.php (modified) (history)
  • /trunk/extensions/Call/Call_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Call/Call.php
@@ -22,7 +22,7 @@
2323 $wgExtensionCredits['specialpage'][] = array(
2424 'path' => __FILE__,
2525 'name' => 'Call',
26 - 'version' => '1.1',
 26+ 'version' => '1.2',
2727 'author' => 'Algorithmix',
2828 '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.',
2929 'descriptionmsg' => 'call-desc',
Index: trunk/extensions/Call/Call_body.php
@@ -21,30 +21,40 @@
2222 * will tale the raw text of "Template:Abc", replace all occurencies of 'foo' by 'bar' and save the result as a normal
2323 * article named 'Xyz' in the main namespace.
2424 * 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 "&"
2530 */
2631
2732 class Call extends SpecialPage
2833 {
2934 function Call() {
3035 SpecialPage::SpecialPage("Call");
31 - wfLoadExtensionMessages('Call');
 36+ self::loadMessages();
3237 }
3338
34 -
 39+
3540 function execute($par) {
3641 global $wgParser;
3742 global $wgOut, $wgRequest, $wgRawHtml, $wgUser;
3843 $oldRawHtml = $wgRawHtml;
3944 $wgRawHtml = false; // disable raw html if it's enabled as this could be XSS security risk
4045 $this->setHeaders();
41 -
 46+
4247 global $_REQUEST;
4348 $argkeys = array_keys($_REQUEST);
44 -
 49+
4550 // find the position of "title" and count succeeding arguments until we find one that matches
4651 // 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';
4854 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);
4959 if ($argKey=='title') $argTitle = $n;
5060 else if ($argTitle>=0) {
5161 if (preg_match('/(UserName|UserID|_session|Token)$/',$argKey)) break;
@@ -76,9 +86,13 @@
7787 if (++$n > $argCount) break;
7888 $arg = $wgRequest->getText($argKey);
7989 if ($arg=='') {
 90+ $link1 = str_replace(",$argKey,",",$argKey=,",$link1);
 91+ $link2 = str_replace($argKey,"",$link2);
8092 $arg = str_replace( "_", " ", $argKey );
8193 $wikitext .= ( '|' . $arg );
8294 } else {
 95+ $link1 = str_replace(",$argKey,",",$argKey=$arg,",$link1);
 96+ $link2 = str_replace($argKey,str_replace(' ','_',$arg),$link2);
8397 $arg = str_replace( "_", " ", $arg );
8498 $wikitext .= ( '|' . $argKey . '=' . $arg );
8599 }
@@ -124,18 +138,29 @@
125139
126140 if ($wikitext=='' || $wikitext=='Special:Call' ) {
127141 // 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: &nbsp; <tt>[[Special:Call/My Template,parm1=value1]]</tt><br/>\n"
 144+ ."Example 2: &nbsp; <tt>[[Special:Call/Talk:My Discussion,parm1=value1]]</tt><br/>\n"
 145+ ."Example 3: &nbsp; <tt>[[Special:Call/:My Page,parm1=value1,parm2=value2]]</tt><br/>\n<br/>\n"
 146+ ."Example 4 (Browser URL): &nbsp; <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");
129153 }
130154 else if ($debug) {
131155 // Called with DebuG target: dump parameter list
132156 $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''.");
134158 }
135159 else {
136160 $parm=array();
137161 foreach (split('\|',$wikitext) as $parmArg) {
138162 $pp = split('=',$parmArg,2);
139163 if (count($pp) == 2) $parm[$pp[0]] = $pp[1];
 164+ else $parm[$pp[0]] = '';
140165 }
141166 if ($cmd=='convertTableToTemplateCalls') {
142167 // execute command
@@ -150,12 +175,16 @@
151176 if (!($saveAsTitle->exists())) {
152177 $article = new Article($saveAsTitle);
153178 $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>."));
155180 }
156181 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."));
158184 }
159185 // 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]"));
160189 $wgOut->addHTML("<pre>\n$rawText\n</pre>");
161190 }
162191 else {
@@ -221,4 +250,17 @@
222251 }
223252 return join("\n",$text);
224253 }
 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+ }
225267 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r51056follow up r51055, fix up i18n for Call extensionshinjiman11:37, 27 May 2009
r51057follow up r51055 and r51056, remove unused function loadMessages().shinjiman11:44, 27 May 2009

Comments

#Comment by Siebrand (talk | contribs)   11:00, 27 May 2009

And remove all i18n in the process? Please fix.

#Comment by Shinjiman (talk | contribs)   13:41, 27 May 2009

Fixed in r51056 and r51057.

Status & tagging log