r54216 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54215‎ | r54216 | r54217 >
Date:16:19, 2 August 2009
Author:ashley
Status:deferred
Tags:
Comment:
CreateBox:
*changed spaces to tabs
*tweaked spacing
*changed addWikiText(wfMsg()) to addWikiMsg() in order to avoid double-parsing
*changed else if to elseif and NULL to null, per http://www.mediawiki.org/wiki/Manual:Coding_conventions#Homesick_C_developers
Modified paths:
  • /trunk/extensions/CreateBox/CreateBox.i18n.php (modified) (history)
  • /trunk/extensions/CreateBox/CreateBox.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CreateBox/CreateBox.i18n.php
@@ -2,6 +2,7 @@
33 /**
44 * Internationalisation file for the CreateBox extension.
55 *
 6+ * @file
67 * @ingroup Extensions
78 * @author Ross McClure
89 */
@@ -12,7 +13,7 @@
1314 * @author Ross McClure
1415 */
1516 $messages['en'] = array(
16 - 'createbox-desc' => 'Specialised inputbox for page creation',
 17+ 'createbox-desc' => 'Specialised inputbox for page creation',
1718 'createbox-create' => 'Create',
1819 'createbox-exists' => "Sorry, \"'''{{FULLPAGENAME}}'''\" already exists.
1920
Index: trunk/extensions/CreateBox/CreateBox.php
@@ -24,10 +24,14 @@
2525 http://www.gnu.org/copyleft/gpl.html
2626
2727 To install, add following to LocalSettings.php
28 - require_once("extensions/create.php");
 28+ require_once("extensions/CreateBox/CreateBox.php");
2929 */
3030
31 -//Avoid unstubbing $wgParser too early on modern (1.12+) MW versions, as per r35980
 31+if ( !defined( 'MEDIAWIKI' ) ) {
 32+ die( "This is not a valid entry point.\n" );
 33+}
 34+
 35+// Avoid unstubbing $wgParser too early on modern (1.12+) MW versions, as per r35980
3236 if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) {
3337 $wgHooks['ParserFirstCallInit'][] = 'wfCreateBox';
3438 } else {
@@ -36,83 +40,86 @@
3741
3842 $wgHooks['UnknownAction'][] = 'actionCreate';
3943 $wgExtensionCredits['parserhook'][] = array(
40 - 'path' => __FILE__,
41 - 'name' => 'CreateBox',
42 - 'url' => 'http://www.mediawiki.org/wiki/Extension:CreateBox',
43 - 'description' => 'Specialized inputbox for page creation',
44 - 'author' => 'Ross McClure',
45 - 'version' => '1.6',
 44+ 'path' => __FILE__,
 45+ 'name' => 'CreateBox',
 46+ 'author' => 'Ross McClure',
 47+ 'version' => '1.6',
 48+ 'url' => 'http://www.mediawiki.org/wiki/Extension:CreateBox',
 49+ 'description' => 'Specialized inputbox for page creation',
4650 'descriptionmsg' => 'createbox-desc',
4751 );
4852
49 -$dir = dirname(__FILE__) . '/';
 53+$dir = dirname( __FILE__ ) . '/';
5054 $wgExtensionMessagesFiles['CreateBox'] = $dir . 'CreateBox.i18n.php';
5155
5256 function wfCreateBox() {
53 - global $wgParser;
54 - $wgParser->setHook( 'createbox', 'acMakeBox' );
 57+ global $wgParser;
 58+ $wgParser->setHook( 'createbox', 'acMakeBox' );
5559 return true;
5660 }
5761
58 -function actionCreate($action, $article) {
59 - wfLoadExtensionMessages('CreateBox');
60 - if($action != 'create') return true;
 62+function actionCreate( $action, $article ) {
 63+ wfLoadExtensionMessages( 'CreateBox' );
 64+ if( $action != 'create' )
 65+ return true;
6166
62 - global $wgRequest;
63 - $prefix = $wgRequest->getVal('prefix');
64 - $text = $wgRequest->getVal('title');
65 - if($prefix && strpos($text, $prefix)!==0) {
66 - $title = Title::newFromText( $prefix . $text );
67 - if(is_null($title)) {
68 - global $wgTitle;
69 - $wgTitle = Title::makeTitle( NS_SPECIAL, 'Badtitle' );
70 - throw new ErrorPageError( 'badtitle', 'badtitletext' );
71 - }
72 - else if($title->getArticleID() == 0) acRedirect($title, 'edit');
73 - else acRedirect($title, 'create');
74 - }
75 - else if($wgRequest->getVal('section')=='new' || $article->getID() == 0) {
76 - acRedirect($article->getTitle(), 'edit');
77 - } else {
78 - global $wgOut;
79 - $text = $article->getTitle()->getPrefixedText();
80 - $wgOut->setPageTitle($text);
81 - $wgOut->setHTMLTitle(wfMsg('pagetitle', $text.' - '.wfMsg('createbox-create')));
82 - $wgOut->addWikiText(wfMsg('createbox-exists'));
83 - }
84 - return false;
 67+ global $wgRequest;
 68+ $prefix = $wgRequest->getVal( 'prefix' );
 69+ $text = $wgRequest->getVal( 'title' );
 70+ if( $prefix && strpos( $text, $prefix ) !== 0 ) {
 71+ $title = Title::newFromText( $prefix . $text );
 72+ if( is_null( $title ) ) {
 73+ global $wgTitle;
 74+ $wgTitle = Title::makeTitle( NS_SPECIAL, 'Badtitle' );
 75+ throw new ErrorPageError( 'badtitle', 'badtitletext' );
 76+ } elseif( $title->getArticleID() == 0 )
 77+ acRedirect( $title, 'edit' );
 78+ else
 79+ acRedirect( $title, 'create' );
 80+ } elseif( $wgRequest->getVal( 'section' ) == 'new' || $article->getID() == 0 ) {
 81+ acRedirect( $article->getTitle(), 'edit' );
 82+ } else {
 83+ global $wgOut;
 84+ $text = $article->getTitle()->getPrefixedText();
 85+ $wgOut->setPageTitle( $text );
 86+ $wgOut->setHTMLTitle( wfMsg( 'pagetitle', $text . ' - ' . wfMsg( 'createbox-create' ) ) );
 87+ $wgOut->addWikiMsg( 'createbox-exists' );
 88+ }
 89+ return false;
8590 }
8691
87 -function acGetOption(&$input,$name,$value=NULL) {
88 - if(preg_match("/^\s*$name\s*=\s*(.*)/mi",$input,$matches)) {
89 - if(is_int($value)) return intval($matches[1]);
90 - else return htmlspecialchars($matches[1]);
91 - }
92 - return $value;
 92+function acGetOption( &$input, $name, $value = null ) {
 93+ if( preg_match( "/^\s*$name\s*=\s*(.*)/mi", $input, $matches ) ) {
 94+ if( is_int( $value ) )
 95+ return intval( $matches[1] );
 96+ else
 97+ return htmlspecialchars( $matches[1] );
 98+ }
 99+ return $value;
93100 }
94101
95 -function acMakeBox($input, $argv, &$parser) {
96 - wfLoadExtensionMessages('CreateBox');
97 - global $wgRequest, $wgScript;
98 - if($wgRequest->getVal('action')=='create') {
99 - $prefix = $wgRequest->getVal('prefix');
100 - $preload = $wgRequest->getVal('preload');
101 - $editintro = $wgRequest->getVal('editintro');
102 - $text = $parser->getTitle()->getPrefixedText();
103 - if($prefix && strpos($text, $prefix)===0)
104 - $text = substr($text, strlen($prefix));
105 - } else {
106 - $prefix = acGetOption($input,'prefix');
107 - $preload = acGetOption($input,'preload');
108 - $editintro = acGetOption($input,'editintro');
109 - $text = acGetOption($input,'default');
110 - }
111 - $submit = htmlspecialchars($wgScript);
112 - $width = acGetOption($input, 'width', 0);
113 - $align = acGetOption($input, 'align', 'center');
114 - $br = ((acGetOption($input, 'break', 'no')=='no') ? '' : '<br />');
115 - $label = acGetOption($input, 'buttonlabel', wfMsgHtml('createbox-create'));
116 - $output=<<<ENDFORM
 102+function acMakeBox( $input, $argv, &$parser ) {
 103+ wfLoadExtensionMessages( 'CreateBox' );
 104+ global $wgRequest, $wgScript;
 105+ if( $wgRequest->getVal( 'action' ) == 'create' ) {
 106+ $prefix = $wgRequest->getVal( 'prefix' );
 107+ $preload = $wgRequest->getVal( 'preload' );
 108+ $editintro = $wgRequest->getVal( 'editintro' );
 109+ $text = $parser->getTitle()->getPrefixedText();
 110+ if( $prefix && strpos( $text, $prefix ) === 0 )
 111+ $text = substr( $text, strlen( $prefix ) );
 112+ } else {
 113+ $prefix = acGetOption( $input, 'prefix' );
 114+ $preload = acGetOption( $input, 'preload' );
 115+ $editintro = acGetOption( $input, 'editintro' );
 116+ $text = acGetOption( $input, 'default' );
 117+ }
 118+ $submit = htmlspecialchars( $wgScript );
 119+ $width = acGetOption( $input, 'width', 0 );
 120+ $align = acGetOption( $input, 'align', 'center' );
 121+ $br = ( ( acGetOption( $input, 'break', 'no' ) == 'no' ) ? '' : '<br />' );
 122+ $label = acGetOption( $input, 'buttonlabel', wfMsgHtml( 'createbox-create' ) );
 123+ $output = <<<ENDFORM
117124 <div class="createbox" align="{$align}">
118125 <form name="createbox" action="{$submit}" method="get" class="createboxForm">
119126 <input type='hidden' name="action" value="create">
@@ -123,15 +130,15 @@
124131 <input type='submit' name="create" class="createboxButton" value="{$label}"/>
125132 </form></div>
126133 ENDFORM;
127 - return $parser->replaceVariables($output);
 134+ return $parser->replaceVariables( $output );
128135 }
129136
130 -function acRedirect($title, $action) {
131 - global $wgRequest, $wgOut;
132 - $query = "action={$action}&prefix=" . $wgRequest->getVal('prefix') .
133 - "&preload=" . $wgRequest->getVal('preload') .
134 - "&editintro=" . $wgRequest->getVal('editintro') .
135 - "&section=" . $wgRequest->getVal('section');
136 - $wgOut->setSquidMaxage( 1200 );
137 - $wgOut->redirect($title->getFullURL( $query ), '301');
138 -}
 137+function acRedirect( $title, $action ) {
 138+ global $wgRequest, $wgOut;
 139+ $query = "action={$action}&prefix=" . $wgRequest->getVal( 'prefix' ) .
 140+ '&preload=' . $wgRequest->getVal( 'preload' ) .
 141+ '&editintro=' . $wgRequest->getVal( 'editintro' ) .
 142+ '&section=' . $wgRequest->getVal( 'section' );
 143+ $wgOut->setSquidMaxage( 1200 );
 144+ $wgOut->redirect( $title->getFullURL( $query ), '301' );
 145+}
\ No newline at end of file

Status & tagging log