Yaron Koren has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/177251

Change subject: Added #formredlink parser function, restored #formlink to 
previous behavior
......................................................................

Added #formredlink parser function, restored #formlink to previous behavior

Change-Id: I7c2a83d39344116be6a3f38e045bd701366d9756
---
M includes/SF_ParserFunctions.php
M includes/SF_Utils.php
M languages/SF_Magic.php
3 files changed, 36 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticForms 
refs/changes/51/177251/1

diff --git a/includes/SF_ParserFunctions.php b/includes/SF_ParserFunctions.php
index 5573f2b..f39db8b 100644
--- a/includes/SF_ParserFunctions.php
+++ b/includes/SF_ParserFunctions.php
@@ -153,6 +153,7 @@
                $parser->setFunctionHook( 'default_form', array( 
'SFParserFunctions', 'renderDefaultForm' ) );
                $parser->setFunctionHook( 'forminput', array( 
'SFParserFunctions', 'renderFormInput' ) );
                $parser->setFunctionHook( 'formlink', array( 
'SFParserFunctions', 'renderFormLink' ) );
+               $parser->setFunctionHook( 'formredlink', array( 
'SFParserFunctions', 'renderFormRedLink' ) );
                $parser->setFunctionHook( 'queryformlink', array( 
'SFParserFunctions', 'renderQueryFormLink' ) );
                if ( defined( get_class( $parser ) . '::SFH_OBJECT_ARGS' ) ) {
                        $parser->setFunctionHook( 'arraymap', array( 
'SFParserFunctions', 'renderArrayMapObj' ), SFH_OBJECT_ARGS );
@@ -204,7 +205,16 @@
 
                // hack to remove newline from beginning of output, thanks to
                // 
http://jimbojw.com/wiki/index.php?title=Raw_HTML_Output_from_a_MediaWiki_Parser_Function
-               return $parser->insertStripItem( SFUtils::createFormLink( 
$parser, 'FormEdit', $params ), $parser->mStripState );
+               return $parser->insertStripItem( SFUtils::createFormLink( 
$parser, $params, 'formlink' ), $parser->mStripState );
+       }
+
+       static function renderFormRedLink ( &$parser ) {
+               $params = func_get_args();
+               array_shift( $params ); // We don't need the parser.
+
+               // hack to remove newline from beginning of output, thanks to
+               // 
http://jimbojw.com/wiki/index.php?title=Raw_HTML_Output_from_a_MediaWiki_Parser_Function
+               return $parser->insertStripItem( SFUtils::createFormLink( 
$parser, $params, 'formredlink' ), $parser->mStripState );
        }
 
        static function renderQueryFormLink ( &$parser ) {
@@ -213,7 +223,7 @@
 
                // hack to remove newline from beginning of output, thanks to
                // 
http://jimbojw.com/wiki/index.php?title=Raw_HTML_Output_from_a_MediaWiki_Parser_Function
-               return $parser->insertStripItem( SFUtils::createFormLink( 
$parser, 'RunQuery', $params ), $parser->mStripState );
+               return $parser->insertStripItem( SFUtils::createFormLink( 
$parser, $params, 'queryformlink' ), $parser->mStripState );
        }
 
        static function renderFormInput ( &$parser ) {
diff --git a/includes/SF_Utils.php b/includes/SF_Utils.php
index 41f254b..55012d8 100644
--- a/includes/SF_Utils.php
+++ b/includes/SF_Utils.php
@@ -616,8 +616,8 @@
                $templateExists = $title->exists();
                foreach ( $values as $value ) {
                        if ( $templateExists ) {
-                               $label = $wgParser->recursiveTagParse( '{{' .  
$templateName .
-                                       '|' .  $value . '}}' );
+                               $label = $wgParser->recursiveTagParse( '{{' . 
$templateName .
+                                       '|' . $value . '}}' );
                                if ( $label == '' ) {
                                        $labels[$value] = $value;
                                } else {
@@ -914,12 +914,11 @@
                return true;
        }
 
-       static function createFormLink ( &$parser, $specialPageName, $params ) {
+       static function createFormLink ( &$parser, $params, $parserFunctionName 
) {
                // Set defaults.
                $inFormName = $inLinkStr = $inLinkType = $inTooltip =
                        $inQueryStr = $inTargetName = '';
-               $inEditExistingTarget = false;
-               if ( $specialPageName == 'RunQuery' ) {
+               if ( $parserFunctionName == 'queryformlink' ) {
                        $inLinkStr = wfMessage( 'runquery' )->text();
                }
                $classStr = '';
@@ -971,8 +970,6 @@
                                $classStr = 'popupformlink';
                        } elseif ( $param_name == null && $value == 'new 
window' ) {
                                $targetWindow = '_blank';
-                       } elseif ( $param_name == null && $value == 'edit 
existing target' ) {
-                               $inEditExistingTarget = true;
                        } elseif ( $param_name !== null && 
!$positionalParameters ) {
                                $value = urlencode( $value );
                                parse_str( "$param_name=$value", $arr );
@@ -995,17 +992,32 @@
                        }
                }
 
+               // Not the most graceful way to do this, but it is the
+               // easiest - if this is the #formredlink function, just
+               // ignore whatever values were passed in for these params.
+               if ( $parserFunctionName == 'formredlink' ) {
+                       $inLinkStr = $inLinkType = $inTooltip = null;
+               }
+
                // If "red link only" was specified, and a target page was
                // specified, and it exists, just link to the page.
                if ( $inTargetName != '' ) {
                        $targetTitle = Title::newFromText( $inTargetName );
                        $targetPageExists = ( $targetTitle != '' && 
$targetTitle->exists() );
+               } else {
+                       $targetPageExists = false;
                }
-               if ( !$inEditExistingTarget && $targetPageExists ) {
-                       return Linker::link( $targetTitle );
-               } 
 
-               $formSpecialPage = SpecialPageFactory::getPage( 
$specialPageName );
+               if ( $parserFunctionName == 'formredlink' && $targetPageExists 
) {
+                       return Linker::link( $targetTitle );
+               }
+
+               if ( $parserFunctionName == 'queryformlink' ) {
+                       $formSpecialPage = SpecialPageFactory::getPage( 
'RunQuery' );
+               } else {
+                       $formSpecialPage = SpecialPageFactory::getPage( 
'FormEdit' );
+               }
+
                if ( strpos( $inFormName, '/' ) == true ) {
                        $query = array( 'form' => $inFormName, 'target' => 
$inTargetName );
                        $link_url = $formSpecialPage->getTitle()->getLocalURL( 
$query );
diff --git a/languages/SF_Magic.php b/languages/SF_Magic.php
index 56b41d6..01f1bdf 100644
--- a/languages/SF_Magic.php
+++ b/languages/SF_Magic.php
@@ -11,6 +11,7 @@
        'default_form' => array( 0, 'default_form' ),
        'forminput' => array( 0, 'forminput' ),
        'formlink' => array( 0, 'formlink' ),
+       'formredlink' => array( 0, 'formredlink' ),
        'queryformlink' => array( 0, 'queryformlink' ),
        'arraymap' => array( 0, 'arraymap' ),
        'arraymaptemplate' => array( 0, 'arraymaptemplate' ),

-- 
To view, visit https://gerrit.wikimedia.org/r/177251
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7c2a83d39344116be6a3f38e045bd701366d9756
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticForms
Gerrit-Branch: master
Gerrit-Owner: Yaron Koren <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to