Index: trunk/extensions/EditSubpages/EditSubpages.php |
— | — | @@ -5,18 +5,18 @@ |
6 | 6 | * via MediaWiki:Unlockedpages |
7 | 7 | */ |
8 | 8 | |
9 | | -if(!defined('MEDIAWIKI')) { |
10 | | - echo('This file is an extension to the MediaWiki software and cannot be used standalone'); |
11 | | - die(1); |
| 9 | +if( !defined( 'MEDIAWIKI' ) ) { |
| 10 | + echo 'This file is an extension to the MediaWiki software and cannot be used standalone'; |
| 11 | + die( 1 ); |
12 | 12 | } |
13 | 13 | |
14 | 14 | $wgExtensionCredits['other'][] = array( |
15 | 15 | 'path' => __FILE__, |
16 | | - 'name' => "EditSubpages", |
| 16 | + 'name' => 'EditSubpages', |
17 | 17 | 'descriptionmsg' => 'editsubpages-desc', |
18 | | - 'author' => "<span class=\"plainlinks\">[http://strategywiki.org/wiki/User:Ryan_Schmidt Ryan Schmidt] and [http://strategywiki.org/wiki/User:Prod Prod]</span>", |
19 | | - 'url' => "http://www.mediawiki.org/wiki/Extension:EditSubpages", |
20 | | - 'version' => "3.0", |
| 18 | + 'author' => array( '<span class="plainlinks\>[http://strategywiki.org/wiki/User:Ryan_Schmidt Ryan Schmidt]</span>', '<span class="plainlinks">[http://strategywiki.org/wiki/User:Prod Prod]</span>' ), |
| 19 | + 'url' => 'https://www.mediawiki.org/wiki/Extension:EditSubpages', |
| 20 | + 'version' => '3.0', |
21 | 21 | ); |
22 | 22 | |
23 | 23 | $wgHooks['userCan'][] = 'EditSubpages'; |
— | — | @@ -27,10 +27,10 @@ |
28 | 28 | $wgExtensionMessagesFiles['EditSubpages'] = $dir .'EditSubpages.i18n.php'; |
29 | 29 | $evEditSubpagesCache = array(); |
30 | 30 | |
31 | | -function EditSubpages($title, $user, $action, $result) { |
| 31 | +function EditSubpages( $title, $user, $action, $result ) { |
32 | 32 | global $evEditSubpagesCache; |
33 | 33 | $pagename = $title->getText(); //name of page w/ spaces, not underscores |
34 | | - if(!array_key_exists('pagename', $evEditSubpagesCache) || $pagename != $evEditSubpagesCache['pagename']) { |
| 34 | + if( !array_key_exists( 'pagename', $evEditSubpagesCache ) || $pagename != $evEditSubpagesCache['pagename'] ) { |
35 | 35 | $ns = $title->getNsText(); //namespace |
36 | 36 | if( $title->isTalkPage() ) { |
37 | 37 | $ns = $title->getTalkNsText(); |
— | — | @@ -63,10 +63,11 @@ |
64 | 64 | 'loggedin' => $user->isLoggedIn(), |
65 | 65 | ); |
66 | 66 | } |
67 | | - if(($action == 'edit' || $action == 'submit')){ |
68 | | - foreach($evEditSubpagesCache['pages'] as $value) { |
69 | | - if( strpos( $value, '*' ) === false || strpos( $value, '*' ) !== 0 ) |
| 67 | + if( ( $action == 'edit' || $action == 'submit' ) ){ |
| 68 | + foreach( $evEditSubpagesCache['pages'] as $value ) { |
| 69 | + if( strpos( $value, '*' ) === false || strpos( $value, '*' ) !== 0 ) { |
70 | 70 | continue; // "*" doesn't start the line, so treat it as a comment (aka skip over it) |
| 71 | + } |
71 | 72 | $flags = array( 's' => 1, 'c' => 1, 't' => 1, 'e' => 1, 'b' => 0, 'u' => 0, 'i' => 0, 'n' => 0, 'r' => 0, 'w' => 0 ); //default flags |
72 | 73 | $value = trim( trim( trim( trim( $value ), "*[]" ) ), "*[]" ); |
73 | 74 | /* flags |
— | — | @@ -81,60 +82,64 @@ |
82 | 83 | * r = regex fragment |
83 | 84 | * w = wildcard matching |
84 | 85 | */ |
85 | | - $pieces = explode('|', $value, 3); |
86 | | - if( isset($pieces[1]) && strpos($pieces[1], '+') === 0 ) { |
| 86 | + $pieces = explode( '|', $value, 3 ); |
| 87 | + if( isset( $pieces[1] ) && strpos( $pieces[1], '+' ) === 0 ) { |
87 | 88 | //flag parsing |
88 | | - $flaglist1 = explode('+', $pieces[1], 2); |
89 | | - if(isset($flaglist1[1])) { |
90 | | - $flaglist2 = explode('-', $flaglist1[1], 2); |
| 89 | + $flaglist1 = explode( '+', $pieces[1], 2 ); |
| 90 | + if( isset( $flaglist1[1] ) ) { |
| 91 | + $flaglist2 = explode( '-', $flaglist1[1], 2 ); |
91 | 92 | } else { |
92 | | - $flaglist2 = explode('-', $pieces[1], 2); |
| 93 | + $flaglist2 = explode( '-', $pieces[1], 2 ); |
93 | 94 | } |
94 | | - $flagpos = str_split($flaglist2[0]); |
95 | | - if(isset($flaglist2[1])) { |
96 | | - $flagneg = str_split($flaglist2[1]); |
| 95 | + $flagpos = str_split( $flaglist2[0] ); |
| 96 | + if( isset( $flaglist2[1] ) ) { |
| 97 | + $flagneg = str_split( $flaglist2[1] ); |
97 | 98 | } else { |
98 | | - $flagneg = array(''); |
| 99 | + $flagneg = array( '' ); |
99 | 100 | } |
100 | | - foreach($flagpos as $flag) { |
| 101 | + foreach( $flagpos as $flag ) { |
101 | 102 | $flags[$flag] = 1; |
102 | 103 | } |
103 | | - foreach($flagneg as $flag) { |
| 104 | + foreach( $flagneg as $flag ) { |
104 | 105 | $flags[$flag] = 0; |
105 | 106 | } |
106 | 107 | } |
107 | | - $found = checkPage($pieces[0], $evEditSubpagesCache['text'], $flags); |
108 | | - if(!$found && $flags['n']) |
109 | | - $found = checkPage($pieces[0], $evEditSubpagesCache['pagename'], $flags); |
| 108 | + $found = checkPage( $pieces[0], $evEditSubpagesCache['text'], $flags ); |
| 109 | + if(!$found && $flags['n']) { |
| 110 | + $found = checkPage( $pieces[0], $evEditSubpagesCache['pagename'], $flags ); |
| 111 | + } |
110 | 112 | if(!$found && $flags['t']) { |
111 | | - $newtitle = Title::newFromText($pieces[0]); |
| 113 | + $newtitle = Title::newFromText( $pieces[0] ); |
112 | 114 | //make sure that it's a valid title |
113 | 115 | if( $newtitle instanceOf Title && !$newtitle->isTalkPage() ) { |
114 | 116 | $talk = $newtitle->getTalkPage(); |
115 | 117 | $talkpage = $talk->getPrefixedText(); |
116 | | - $found = checkPage($talkpage, $evEditSubpagesCache['talktext'], $flags); |
117 | | - if(!$found) |
118 | | - $found = checkPage($talkpage, $evEditSubpagesCache['text'], $flags); |
| 118 | + $found = checkPage( $talkpage, $evEditSubpagesCache['talktext'], $flags ); |
| 119 | + if( !$found ) { |
| 120 | + $found = checkPage( $talkpage, $evEditSubpagesCache['text'], $flags ); |
| 121 | + } |
119 | 122 | } |
120 | 123 | } |
121 | | - if(!$found) |
| 124 | + if( !$found ) { |
122 | 125 | continue; |
| 126 | + } |
123 | 127 | |
124 | | - if(!$flags['u'] && $evEditSubpagesCache['loggedin']) |
| 128 | + if( !$flags['u'] && $evEditSubpagesCache['loggedin'] ) { |
125 | 129 | return true; |
| 130 | + } |
126 | 131 | //the page matches, now process it and let the software know whether or not to allow the user to do this action |
127 | | - if(!$flags['c'] && !$newtitle->exists()) { |
| 132 | + if( !$flags['c'] && !$newtitle->exists() ) { |
128 | 133 | $result = false; |
129 | 134 | return false; |
130 | 135 | } |
131 | | - if(!$flags['e'] && $newtitle->exists()) { |
| 136 | + if( !$flags['e'] && $newtitle->exists() ) { |
132 | 137 | $result = false; |
133 | 138 | return false; |
134 | 139 | } |
135 | 140 | $result = true; |
136 | 141 | return false; |
137 | 142 | } |
138 | | - if(!$evEditSubpagesCache['loggedin']) { |
| 143 | + if( !$evEditSubpagesCache['loggedin'] ) { |
139 | 144 | $result = false; |
140 | 145 | return false; |
141 | 146 | } |
— | — | @@ -142,7 +147,7 @@ |
143 | 148 | return true; |
144 | 149 | } |
145 | 150 | |
146 | | -function checkPage($page, $check, $flags) { |
| 151 | +function checkPage( $page, $check, $flags ) { |
147 | 152 | if( $flags['w'] && !$flags['r'] ) { |
148 | 153 | $flags['r'] = 1; |
149 | 154 | $page = preg_quote( $page, '/' ); |
— | — | @@ -164,14 +169,17 @@ |
165 | 170 | return preg_match( '/^' . $page . '$/' . $i, $check ); |
166 | 171 | } |
167 | 172 | if( $flags['i'] ) { |
168 | | - $page = strtolower($page); |
169 | | - $check = strtolower($check); |
| 173 | + $page = strtolower( $page ); |
| 174 | + $check = strtolower( $check ); |
170 | 175 | } |
171 | | - if( $page == $check ) |
| 176 | + if( $page == $check ) { |
172 | 177 | return true; |
173 | | - if( $flags['s'] && strpos( $check, $page . '/' ) === 0 ) |
| 178 | + } |
| 179 | + if( $flags['s'] && strpos( $check, $page . '/' ) === 0 ) { |
174 | 180 | return true; |
175 | | - if( $flags['b'] && strpos( $page, $check . '/' ) === 0 ) |
| 181 | + } |
| 182 | + if( $flags['b'] && strpos( $page, $check . '/' ) === 0 ) { |
176 | 183 | return true; |
| 184 | + } |
177 | 185 | return false; |
178 | 186 | } |