http://www.mediawiki.org/wiki/Special:Code/MediaWiki/65340
Revision: 65340
Author: siebrand
Date: 2010-04-20 21:03:48 +0000 (Tue, 20 Apr 2010)
Log Message:
-----------
stylize.php, trailing whitespace removed, indentation updated
Modified Paths:
--------------
trunk/extensions/Call/Call.i18n.php
trunk/extensions/Call/Call.php
trunk/extensions/Call/Call_body.php
Modified: trunk/extensions/Call/Call.i18n.php
===================================================================
--- trunk/extensions/Call/Call.i18n.php 2010-04-20 20:30:11 UTC (rev 65339)
+++ trunk/extensions/Call/Call.i18n.php 2010-04-20 21:03:48 UTC (rev 65340)
@@ -555,7 +555,7 @@
*/
$messages['id'] = array(
'call' => 'Panggilan',
- 'call-desc' => 'Buat sebuah pranala ke templat (atau halaman wiki
biasa) dengan parameter.
+ 'call-desc' => 'Buat sebuah pranala ke templat (atau halaman wiki
biasa) dengan parameter.
Dapat digunakan pada baris perintah penjelajah web atau di antara teks wiki',
'call-text' => "Pengaya \"Panggilan\" membutuhkan sebuah halaman wiki
dan parameter opsional untuk halaman tersebut untuk digunakan sebagai argumen.
Modified: trunk/extensions/Call/Call.php
===================================================================
--- trunk/extensions/Call/Call.php 2010-04-20 20:30:11 UTC (rev 65339)
+++ trunk/extensions/Call/Call.php 2010-04-20 21:03:48 UTC (rev 65340)
@@ -5,7 +5,7 @@
* added "return true;" at the end of wfCallLoadMessages()
*/
# Not a valid entry point, skip unless MEDIAWIKI is defined
-if (!defined('MEDIAWIKI')) {
+if ( !defined( 'MEDIAWIKI' ) ) {
echo <<<EOT
To install Call as a special page, put the following line in LocalSettings.php:
require_once( "\$IP/extensions/Call/Call.php" );
@@ -13,7 +13,7 @@
exit( 1 );
}
-$dir = dirname(__FILE__) .'/';
+$dir = dirname( __FILE__ ) . '/';
$wgAutoloadClasses['Call'] = $dir . 'Call_body.php';
$wgExtensionMessagesFiles['Call'] = $dir . 'Call.i18n.php';
$wgExtensionAliasesFiles['Call'] = $dir . 'Call.alias.php';
Modified: trunk/extensions/Call/Call_body.php
===================================================================
--- trunk/extensions/Call/Call_body.php 2010-04-20 20:30:11 UTC (rev 65339)
+++ trunk/extensions/Call/Call_body.php 2010-04-20 21:03:48 UTC (rev 65340)
@@ -28,215 +28,239 @@
* link2 replaces "name" by "value" and "," by "&"
*/
-class Call extends SpecialPage
-{
- function Call() {
- SpecialPage::SpecialPage("Call");
- wfLoadExtensionMessages('Call');
- }
+class Call extends SpecialPage {
+ function Call() {
+ SpecialPage::SpecialPage( "Call" );
+ wfLoadExtensionMessages( 'Call' );
+ }
-
- function execute($par) {
- global $wgParser;
- global $wgOut, $wgRequest, $wgRawHtml, $wgUser;
- $oldRawHtml = $wgRawHtml;
- $wgRawHtml = false; // disable raw html if it's
enabled as this could be XSS security risk
- $this->setHeaders();
-
- global $_REQUEST;
- $argkeys = array_keys($_REQUEST);
-
- // find the position of "title" and count succeeding
arguments until we find one that matches
- // one of the patterns which belong to typical session
cookie variables
- // store link info
- $argTitle=-1; $argCount=0; $n=0; $link1=''; $link2='';
$label1 = 'link 1'; $label2 = 'link 2';
- foreach ($argkeys as $argKey) {
- if ($argKey=='link1')
$link1=$wgRequest->getText($argKey);
- if ($argKey=='label1')
$label1=$wgRequest->getText($argKey);
- if ($argKey=='link2')
$link2=$wgRequest->getText($argKey);
- if ($argKey=='label2')
$label2=$wgRequest->getText($argKey);
- if ($argKey=='title') $argTitle = $n;
- else if ($argTitle>=0) {
- if
(preg_match('/(UserName|UserID|_session|Token)$/',$argKey)) break;
- ++$argCount;
- }
- $n++;
- }
- $debug=
!(strpos($wgRequest->getText('title'),'DebuG')===false);
- if ($debug) {
- $wgOut->addHTML("<pre>\n");
- foreach ($argkeys as $argKeyNr => $argKey) {
- $wgOut->addHTML("$argKeyNr:$argKey:");
-
$wgOut->addHTML($wgRequest->getText($argKey)."\n",1);
- }
-
$wgOut->addHTML("\npar=$par\nargTitle=$argTitle\nargCount=$argCount</pre>");
- }
+ function execute( $par ) {
+ global $wgParser;
+ global $wgOut, $wgRequest, $wgRawHtml, $wgUser;
+ $oldRawHtml = $wgRawHtml;
+ $wgRawHtml = false; // disable raw html if it's enabled
as this could be XSS security risk
+ $this->setHeaders();
- $wikitext=''; $n=0; $i=-1;
- foreach ($argkeys as $argKeyNr => $argKey) {
- $i++;
- if ($i<$argTitle) continue;
- if ($i==$argTitle) {
- $wikitext .=
preg_replace(',^[^/]+/,','',$wgRequest->getText($argKey),1);
- $wikitext = str_replace( ",", "|",
$wikitext );
- $wikitext = str_replace( "_", " ",
$wikitext );
- continue;
- }
- if (++$n > $argCount) break;
- $arg = $wgRequest->getText($argKey);
- if ($arg=='') {
- $link1 =
str_replace(",$argKey,",",$argKey=,",$link1);
- $link2 = str_replace($argKey,"",$link2);
- $arg = str_replace( "_", " ", $argKey );
- $wikitext .= ( '|' . $arg );
- } else {
- $link1 =
str_replace(",$argKey,",",$argKey=$arg,",$link1);
- $link2 =
str_replace($argKey,str_replace(' ','_',$arg),$link2);
- $arg = str_replace( "_", " ", $arg );
- $wikitext .= ( '|' . $argKey . '=' .
$arg );
+ global $_REQUEST;
+ $argkeys = array_keys( $_REQUEST );
+
+ // find the position of "title" and count succeeding arguments
until we find one that matches
+ // one of the patterns which belong to typical session cookie
variables
+ // store link info
+ $argTitle = -1; $argCount = 0; $n = 0; $link1 = ''; $link2 =
''; $label1 = 'link 1'; $label2 = 'link 2';
+ foreach ( $argkeys as $argKey ) {
+ if ( $argKey == 'link1' ) {
+ $link1 = $wgRequest->getText( $argKey );
+ }
+ if ( $argKey == 'label1' ) {
+ $label1 = $wgRequest->getText( $argKey );
+ }
+ if ( $argKey == 'link2' ) {
+ $link2 = $wgRequest->getText( $argKey );
+ }
+ if ( $argKey == 'label2' ) {
+ $label2 = $wgRequest->getText( $argKey );
+ }
+ if ( $argKey == 'title' ) {
+ $argTitle = $n;
+ } else if ( $argTitle >= 0 ) {
+ if ( preg_match(
'/(UserName|UserID|_session|Token)$/', $argKey ) ) {
+ break;
}
- }
+ ++$argCount;
+ }
+ $n++;
+ }
- if ($wikitext=='' && $par!='') {
- // the first argument may contain parameters which are
separated by comma
- // this is the case if [[Call,a=b]] syntax is used
- $wikitext = str_replace( ",", "|", $par );
+ $debug = !( strpos( $wgRequest->getText( 'title' ), 'DebuG' )
=== false );
+ if ( $debug ) {
+ $wgOut->addHTML( "<pre>\n" );
+ foreach ( $argkeys as $argKeyNr => $argKey ) {
+ $wgOut->addHTML( "$argKeyNr:$argKey:" );
+ $wgOut->addHTML( $wgRequest->getText( $argKey )
. "\n", 1 );
+ }
+ $wgOut->addHTML(
"\npar=$par\nargTitle=$argTitle\nargCount=$argCount</pre>" );
+ }
+
+ $wikitext = ''; $n = 0; $i = -1;
+ foreach ( $argkeys as $argKeyNr => $argKey ) {
+ $i++;
+ if ( $i < $argTitle ) {
+ continue;
+ }
+ if ( $i == $argTitle ) {
+ $wikitext .= preg_replace( ',^[^/]+/,', '',
$wgRequest->getText( $argKey ), 1 );
+ $wikitext = str_replace( ",", "|", $wikitext );
$wikitext = str_replace( "_", " ", $wikitext );
- }
+ continue;
+ }
+ if ( ++$n > $argCount ) {
+ break;
+ }
+ $arg = $wgRequest->getText( $argKey );
+ if ( $arg == '' ) {
+ $link1 = str_replace( ",$argKey,",
",$argKey=,", $link1 );
+ $link2 = str_replace( $argKey, "", $link2 );
+ $arg = str_replace( "_", " ", $argKey );
+ $wikitext .= ( '|' . $arg );
+ } else {
+ $link1 = str_replace( ",$argKey,",
",$argKey=$arg,", $link1 );
+ $link2 = str_replace( $argKey, str_replace( '
', '_', $arg ), $link2 );
+ $arg = str_replace( "_", " ", $arg );
+ $wikitext .= ( '|' . $argKey . '=' . $arg );
+ }
+ }
- // check if the result shall be saved as a wiki article
- $saveAsPageLink=''; $saveAsPage=''; $saveAsTitle=null;
- $wikitextS =
preg_replace('/^.*\|\s*saveAsPage\s*=\s*/s','',$wikitext);
- if ($wikitextS != $wikitext) {
- $saveAsPageLink=
preg_replace('/\s*\|.*/s','',$wikitextS);
- $saveAsTitle =
Title::newFromText($saveAsPageLink);
- $saveAsPage = $saveAsTitle->getText();
- if ($saveAsTitle->getNamespace()==14)
$saveAsPageLink = ':'.$saveAsPageLink;
- }
+ if ( $wikitext == '' && $par != '' ) {
+ // the first argument may contain parameters which are
separated by comma
+ // this is the case if [[Call,a=b]] syntax is used
+ $wikitext = str_replace( ",", "|", $par );
+ $wikitext = str_replace( "_", " ", $wikitext );
+ }
- // check if we want to execute a built-in command
- $cmd =
preg_replace('/^.*\|\s*cmd\s*=\s*/s','',$wikitext);
- if ($cmd == $wikitext) $cmd='';
- else {
- $cmd = preg_replace('/\s*\|.*/s','',$cmd);
- }
+ // check if the result shall be saved as a wiki article
+ $saveAsPageLink = ''; $saveAsPage = ''; $saveAsTitle = null;
+ $wikitextS = preg_replace( '/^.*\|\s*saveAsPage\s*=\s*/s', '',
$wikitext );
+ if ( $wikitextS != $wikitext ) {
+ $saveAsPageLink = preg_replace( '/\s*\|.*/s', '',
$wikitextS );
+ $saveAsTitle = Title::newFromText( $saveAsPageLink );
+ $saveAsPage = $saveAsTitle->getText();
+ if ( $saveAsTitle->getNamespace() == 14 ) {
+ $saveAsPageLink = ':' . $saveAsPageLink;
+ }
+ }
- // in both cases we need the raw text of the called page
- $rawText='';
- if ($cmd!='' || $saveAsPage!='') {
- $template = preg_replace('/\|.*/','',$wikitext);
- if (strpos(':',$template) === false) $template =
'Template:'.$template;
- else if ($template[0]==':') $template =
substr($template,1);
- $title = Title::newFromText($template);
- if ($title!=null && !$title->exists()) $rawText=
"'$template' not found.";
- else {
- $article = new Article($title);
- $rawText = $article->getContent();
- }
+ // check if we want to execute a built-in command
+ $cmd = preg_replace( '/^.*\|\s*cmd\s*=\s*/s', '', $wikitext );
+ if ( $cmd == $wikitext ) {
+ $cmd = '';
+ } else {
+ $cmd = preg_replace( '/\s*\|.*/s', '', $cmd );
+ }
+
+ // in both cases we need the raw text of the called page
+ $rawText = '';
+ if ( $cmd != '' || $saveAsPage != '' ) {
+ $template = preg_replace( '/\|.*/', '', $wikitext );
+ if ( strpos( ':', $template ) === false ) {
+ $template = 'Template:' . $template;
+ } else if ( $template[0] == ':' ) {
+ $template = substr( $template, 1 );
}
+ $title = Title::newFromText( $template );
+ if ( $title != null && !$title->exists() ) {
+ $rawText = "'$template' not found.";
+ } else {
+ $article = new Article( $title );
+ $rawText = $article->getContent();
+ }
+ }
- if ($wikitext=='' || $wikitext=='Special:Call' ) {
- // Called without parameters: dump explanation
- $wgOut->addHTML(wfMsg('call-text'));
- }
- else if ($debug) {
- // Called with DebuG target: dump parameter list
- $wgOut->addHTML("<pre>\n{{".$wikitext."}}\n</pre>");
- if ($saveAsPage!='') $wgOut->addHTML(
wfMsg('call-save',$saveAsPageLink) );
- }
- else {
- $parm=array();
- foreach (split('\|',$wikitext) as $parmArg) {
- $pp = split('=',$parmArg,2);
- if (count($pp) == 2) $parm[$pp[0]] =
$pp[1];
- else $parm[$pp[0]] = '';
+ if ( $wikitext == '' || $wikitext == 'Special:Call' ) {
+ // Called without parameters: dump explanation
+ $wgOut->addHTML( wfMsg( 'call-text' ) );
+ } else if ( $debug ) {
+ // Called with DebuG target: dump parameter list
+ $wgOut->addHTML( "<pre>\n{{" . $wikitext . "}}\n</pre>"
);
+ if ( $saveAsPage != '' ) {
+ $wgOut->addHTML( wfMsg( 'call-save',
$saveAsPageLink ) );
+ }
+ } else {
+ $parm = array();
+ foreach ( split( '\|', $wikitext ) as $parmArg ) {
+ $pp = split( '=', $parmArg, 2 );
+ if ( count( $pp ) == 2 ) {
+ $parm[$pp[0]] = $pp[1];
+ } else {
+ $parm[$pp[0]] = '';
}
- if ($cmd=='convertTableToTemplateCalls') {
- // execute command
- $rawText =
Call::convertTableToTemplateCalls($rawText,$parm);
- }
- if ($saveAsPage != '') {
- // replace literals in text
- foreach ($parm as $arg => $value) {
- $rawText =
str_replace($arg,$value,$rawText);
- }
- // do not save if article is already
present
- if (!($saveAsTitle->exists())) {
- $article = new
Article($saveAsTitle);
- $article->doEdit( $rawText,
$saveAsPage, EDIT_NEW | EDIT_FORCE_BOT );
-
$wgOut->addHTML($wgOut->parse(wfMsg('call-save-success' ,$saveAsPageLink) ) );
- }
- else {
-
$wgOut->addHTML($wgOut->parse(wfMsg('call-save-failed',$saveAsPageLink) ) );
- }
- // output the text we produced as a note to the
user
- if ($link1!='')
$wgOut->addHTML($wgOut->parse("[[Special:Call/$link1|$label1]]"));
- $link2=str_replace(',','&',$link2);
- if ($link2!='')
$wgOut->addHTML($wgOut->parse("[$link2 $label2]"));
-
$wgOut->addHTML("<pre>\n$rawText\n</pre>");
- }
- else {
- // call the template and produce output
-
$wgOut->addHTML($wgOut->parse("{{".$wikitext."}}"));
- }
- }
+ }
+ if ( $cmd == 'convertTableToTemplateCalls' ) {
+ // execute command
+ $rawText = Call::convertTableToTemplateCalls(
$rawText, $parm );
+ }
+ if ( $saveAsPage != '' ) {
+ // replace literals in text
+ foreach ( $parm as $arg => $value ) {
+ $rawText = str_replace( $arg, $value,
$rawText );
+ }
+ // do not save if article is already present
+ if ( !( $saveAsTitle->exists() ) ) {
+ $article = new Article( $saveAsTitle );
+ $article->doEdit( $rawText,
$saveAsPage, EDIT_NEW | EDIT_FORCE_BOT );
+ $wgOut->addHTML( $wgOut->parse( wfMsg(
'call-save-success' , $saveAsPageLink ) ) );
+ } else {
+ $wgOut->addHTML( $wgOut->parse( wfMsg(
'call-save-failed', $saveAsPageLink ) ) );
+ }
+ // output the text we produced as a note to the
user
+ if ( $link1 != '' ) {
+ $wgOut->addHTML( $wgOut->parse(
"[[Special:Call/$link1|$label1]]" ) );
+ }
+ $link2 = str_replace( ',', '&', $link2 );
+ if ( $link2 != '' ) {
+ $wgOut->addHTML( $wgOut->parse(
"[$link2 $label2]" ) );
+ }
+ $wgOut->addHTML( "<pre>\n$rawText\n</pre>" );
+ } else {
+ // call the template and produce output
+ $wgOut->addHTML( $wgOut->parse( "{{" .
$wikitext . "}}" ) );
+ }
+ }
- $skin = $wgUser->getSkin();
- $wgRawHtml = $oldRawHtml;
+ $skin = $wgUser->getSkin();
+ $wgRawHtml = $oldRawHtml;
- $newTitle = split("\,",$par,2);
- if ($newTitle!=null && strlen($newTitle[0])>0) {
- $newTitle[0]=str_replace("_"," ",$newTitle[0]);
- $newTitle[0]=preg_replace("/^:/","",$newTitle[0]);
- $wgOut->setPageTitle($newTitle[0]);
- }
- // $wgOut->addMeta("http:expires", "0");
-
+ $newTitle = split( "\,", $par, 2 );
+ if ( $newTitle != null && strlen( $newTitle[0] ) > 0 ) {
+ $newTitle[0] = str_replace( "_", " ", $newTitle[0] );
+ $newTitle[0] = preg_replace( "/^:/", "", $newTitle[0] );
+ $wgOut->setPageTitle( $newTitle[0] );
}
+ }
- static function convertTableToTemplateCalls($rawText, $parms) {
- $text=array();
- $state=0;
- $n=-1;
- $field=array();
- $head=true;
- $tpl='???';
- foreach (split("\n",$rawText) as $line) {
- // $text[] = "$state $n $line";
- if ($state==0) {
- if (strpos($line,'|-')!==false) {
- $state=1;
- $n=-1;
- $tpl=$field[0];
- $field[0] = 'ID';
- } else if (strpos($line,'|')==0) {
- $n++;
- $field[$n]=substr($line,1);
- }
- } else if (strpos($line,'|-')!==false) {
- $n=-1;
- } else if (strpos($line,'|}')!==false) {
- $text[] = '}}';
- break;
- } else if ($line=='') {
- $text[]='';
- } else if ($line[0]=='|') {
- $n++;
- if ($n==0) {
- if ($head) {
- $text[] = "{{DT Article|index=";
- $head=false;
- }
- $text[] =
"}}\n==".substr($line,1)."==\n{{".$tpl."\n|".$field[$n].'='.substr($line,1);
- } else {
- $text[] = '|'.$field[$n].'=';
- $text[] = substr($line,1);
- }
- } else {
- $text[] = $line;
+ static function convertTableToTemplateCalls( $rawText, $parms ) {
+ $text = array();
+ $state = 0;
+ $n = -1;
+ $field = array();
+ $head = true;
+ $tpl = '???';
+ foreach ( split( "\n", $rawText ) as $line ) {
+ // $text[] = "$state $n $line";
+ if ( $state == 0 ) {
+ if ( strpos( $line, '|-' ) !== false ) {
+ $state = 1;
+ $n = -1;
+ $tpl = $field[0];
+ $field[0] = 'ID';
+ } else if ( strpos( $line, '|' ) == 0 ) {
+ $n++;
+ $field[$n] = substr( $line, 1 );
}
- }
- return join("\n",$text);
- }
+ } else if ( strpos( $line, '|-' ) !== false ) {
+ $n = -1;
+ } else if ( strpos( $line, '|}' ) !== false ) {
+ $text[] = '}}';
+ break;
+ } else if ( $line == '' ) {
+ $text[] = '';
+ } else if ( $line[0] == '|' ) {
+ $n++;
+ if ( $n == 0 ) {
+ if ( $head ) {
+ $text[] = "{{DT Article|index=";
+ $head = false;
+ }
+ $text[] = "}}\n==" . substr( $line, 1 )
. "==\n{{" . $tpl . "\n|" . $field[$n] . '=' . substr( $line, 1 );
+ } else {
+ $text[] = '|' . $field[$n] . '=';
+ $text[] = substr( $line, 1 );
+ }
+ } else {
+ $text[] = $line;
+ }
+ }
+ return join( "\n", $text );
+ }
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs