Index: trunk/extensions/CreateBox/CreateBox.i18n.php |
— | — | @@ -2,6 +2,7 @@ |
3 | 3 | /** |
4 | 4 | * Internationalisation file for the CreateBox extension. |
5 | 5 | * |
| 6 | + * @file |
6 | 7 | * @ingroup Extensions |
7 | 8 | * @author Ross McClure |
8 | 9 | */ |
— | — | @@ -12,7 +13,7 @@ |
13 | 14 | * @author Ross McClure |
14 | 15 | */ |
15 | 16 | $messages['en'] = array( |
16 | | - 'createbox-desc' => 'Specialised inputbox for page creation', |
| 17 | + 'createbox-desc' => 'Specialised inputbox for page creation', |
17 | 18 | 'createbox-create' => 'Create', |
18 | 19 | 'createbox-exists' => "Sorry, \"'''{{FULLPAGENAME}}'''\" already exists. |
19 | 20 | |
Index: trunk/extensions/CreateBox/CreateBox.php |
— | — | @@ -24,10 +24,14 @@ |
25 | 25 | http://www.gnu.org/copyleft/gpl.html |
26 | 26 | |
27 | 27 | To install, add following to LocalSettings.php |
28 | | - require_once("extensions/create.php"); |
| 28 | + require_once("extensions/CreateBox/CreateBox.php"); |
29 | 29 | */ |
30 | 30 | |
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 |
32 | 36 | if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) { |
33 | 37 | $wgHooks['ParserFirstCallInit'][] = 'wfCreateBox'; |
34 | 38 | } else { |
— | — | @@ -36,83 +40,86 @@ |
37 | 41 | |
38 | 42 | $wgHooks['UnknownAction'][] = 'actionCreate'; |
39 | 43 | $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', |
46 | 50 | 'descriptionmsg' => 'createbox-desc', |
47 | 51 | ); |
48 | 52 | |
49 | | -$dir = dirname(__FILE__) . '/'; |
| 53 | +$dir = dirname( __FILE__ ) . '/'; |
50 | 54 | $wgExtensionMessagesFiles['CreateBox'] = $dir . 'CreateBox.i18n.php'; |
51 | 55 | |
52 | 56 | function wfCreateBox() { |
53 | | - global $wgParser; |
54 | | - $wgParser->setHook( 'createbox', 'acMakeBox' ); |
| 57 | + global $wgParser; |
| 58 | + $wgParser->setHook( 'createbox', 'acMakeBox' ); |
55 | 59 | return true; |
56 | 60 | } |
57 | 61 | |
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; |
61 | 66 | |
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; |
85 | 90 | } |
86 | 91 | |
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; |
93 | 100 | } |
94 | 101 | |
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 |
117 | 124 | <div class="createbox" align="{$align}"> |
118 | 125 | <form name="createbox" action="{$submit}" method="get" class="createboxForm"> |
119 | 126 | <input type='hidden' name="action" value="create"> |
— | — | @@ -123,15 +130,15 @@ |
124 | 131 | <input type='submit' name="create" class="createboxButton" value="{$label}"/> |
125 | 132 | </form></div> |
126 | 133 | ENDFORM; |
127 | | - return $parser->replaceVariables($output); |
| 134 | + return $parser->replaceVariables( $output ); |
128 | 135 | } |
129 | 136 | |
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 | | - "§ion=" . $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 | + '§ion=' . $wgRequest->getVal( 'section' ); |
| 143 | + $wgOut->setSquidMaxage( 1200 ); |
| 144 | + $wgOut->redirect( $title->getFullURL( $query ), '301' ); |
| 145 | +} |
\ No newline at end of file |