r90324 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90323‎ | r90324 | r90325 >
Date:23:19, 17 June 2011
Author:yaron
Status:deferred
Tags:
Comment:
Set #formlink to show a red link if target page doesn't exist; cleaned up class-setting code a little
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_ParserFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_ParserFunctions.php
@@ -153,7 +153,7 @@
154154 array_shift( $params ); // don't need the parser
155155 // set defaults
156156 $inFormName = $inLinkStr = $inLinkType = $inQueryStr = $inTargetName = '';
157 - $popupClassString = "";
 157+ $classStr = "";
158158 // assign params - support unlabelled params, for backwards compatibility
159159 foreach ( $params as $i => $param ) {
160160 $elements = explode( '=', $param, 2 );
@@ -176,7 +176,7 @@
177177 } elseif ( $param_name == null && $value == 'popup'
178178 && version_compare( $wgVersion, '1.16', '>=' )) {
179179 self::loadScriptsForPopupForm( $parser );
180 - $popupClassString = 'class="popupformlink"';
 180+ $classStr = 'popupformlink';
181181 }
182182 elseif ( $i == 0 ) {
183183 $inFormName = $param;
@@ -226,18 +226,23 @@
227227 if ( $inLinkType == 'button' ) {
228228 $link_url = html_entity_decode( $link_url, ENT_QUOTES );
229229 $link_url = str_replace( "'", "\'", $link_url );
230 - $str = "<form $popupClassString>";
 230+ $str = "<form class=\"$classStr\">";
231231 $str .= Xml::element( 'input', array(
232232 'type' => 'button',
233233 'value' => $inLinkStr,
234234 'onclick' => "window.location.href='$link_url'",
235235 ) ) . "</form>";
236236 } elseif ( $inLinkType == 'post button' ) {
237 - $str = "<form action=\"$link_url\" method=\"post\" $popupClassString>";
 237+ $str = "<form action=\"$link_url\" method=\"post\" class=\"$classStr\">";
238238 $str .= Xml::element( 'input', array( 'type' => 'submit', 'value' => $inLinkStr ) );
239239 $str .= "$hidden_inputs</form>";
240240 } else {
241 - $str = "<a href=\"$link_url\" $popupClassString>$inLinkStr</a>";
 241+ // If target page doesn't exist, make it a red link
 242+ $targetTitle = Title::newFromText( $inTargetName );
 243+ if ( !$targetTitle->exists() ) {
 244+ $classStr .= " new";
 245+ }
 246+ $str = "<a href=\"$link_url\" class=\"$classStr\">$inLinkStr</a>";
242247 }
243248 // hack to remove newline from beginning of output, thanks to
244249 // http://jimbojw.com/wiki/index.php?title=Raw_HTML_Output_from_a_MediaWiki_Parser_Function
@@ -253,7 +258,7 @@
254259 $inFormName = $inValue = $inButtonStr = $inQueryStr = '';
255260 $inAutocompletionSource = '';
256261 $inSize = 25;
257 - $popupClassString = "";
 262+ $classStr = "";
258263 // assign params - support unlabelled params, for backwards compatibility
259264 foreach ( $params as $i => $param ) {
260265 $elements = explode( '=', $param, 2 );
@@ -282,7 +287,7 @@
283288 } elseif ( $param_name == null && $value == 'popup'
284289 && version_compare( $wgVersion, '1.16', '>=' )) {
285290 self::loadScriptsForPopupForm( $parser );
286 - $popupClassString = 'class="popupforminput"';
 291+ $classStr = 'popupforminput';
287292 }
288293 elseif ( $i == 0 )
289294 $inFormName = $param;
@@ -317,7 +322,7 @@
318323 $fs_url = $fs->getTitle()->getLocalURL();
319324 if ( empty( $inAutocompletionSource ) ) {
320325 $str = <<<END
321 - <form action="$fs_url" method="get" $popupClassString>
 326+ <form action="$fs_url" method="get" class="$classStr">
322327 <p>
323328
324329 END;
@@ -325,7 +330,7 @@
326331 array( 'type' => 'text', 'name' => 'page_name', 'size' => $inSize, 'value' => $inValue, 'class' => 'formInput' ) );
327332 } else {
328333 $str = <<<END
329 - <form name="createbox" action="$fs_url" method="get" $popupClassString>
 334+ <form name="createbox" action="$fs_url" method="get" class="$classStr">
330335 <p>
331336
332337 END;

Follow-up revisions

RevisionCommit summaryAuthorDate
r90407Follow-up to r90324 - in some cases (some MW versions?), Title::newFromText()...yaron17:39, 19 June 2011
r90959Follow-up to r90324 - red link is displayed only if a target is specified *an...yaron14:17, 28 June 2011