r114407 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114406‎ | r114407 | r114408 >
Date:20:49, 21 March 2012
Author:skizzerz
Status:new
Tags:
Comment:
* Spaces, braces, and clean up $wgExtensionCredits a bit (no actual code changes)
Modified paths:
  • /trunk/extensions/EditSubpages/EditSubpages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EditSubpages/EditSubpages.php
@@ -5,18 +5,18 @@
66 * via MediaWiki:Unlockedpages
77 */
88
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 );
1212 }
1313
1414 $wgExtensionCredits['other'][] = array(
1515 'path' => __FILE__,
16 - 'name' => "EditSubpages",
 16+ 'name' => 'EditSubpages',
1717 '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',
2121 );
2222
2323 $wgHooks['userCan'][] = 'EditSubpages';
@@ -27,10 +27,10 @@
2828 $wgExtensionMessagesFiles['EditSubpages'] = $dir .'EditSubpages.i18n.php';
2929 $evEditSubpagesCache = array();
3030
31 -function EditSubpages($title, $user, $action, $result) {
 31+function EditSubpages( $title, $user, $action, $result ) {
3232 global $evEditSubpagesCache;
3333 $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'] ) {
3535 $ns = $title->getNsText(); //namespace
3636 if( $title->isTalkPage() ) {
3737 $ns = $title->getTalkNsText();
@@ -63,10 +63,11 @@
6464 'loggedin' => $user->isLoggedIn(),
6565 );
6666 }
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 ) {
7070 continue; // "*" doesn't start the line, so treat it as a comment (aka skip over it)
 71+ }
7172 $flags = array( 's' => 1, 'c' => 1, 't' => 1, 'e' => 1, 'b' => 0, 'u' => 0, 'i' => 0, 'n' => 0, 'r' => 0, 'w' => 0 ); //default flags
7273 $value = trim( trim( trim( trim( $value ), "*[]" ) ), "*[]" );
7374 /* flags
@@ -81,60 +82,64 @@
8283 * r = regex fragment
8384 * w = wildcard matching
8485 */
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 ) {
8788 //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 );
9192 } else {
92 - $flaglist2 = explode('-', $pieces[1], 2);
 93+ $flaglist2 = explode( '-', $pieces[1], 2 );
9394 }
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] );
9798 } else {
98 - $flagneg = array('');
 99+ $flagneg = array( '' );
99100 }
100 - foreach($flagpos as $flag) {
 101+ foreach( $flagpos as $flag ) {
101102 $flags[$flag] = 1;
102103 }
103 - foreach($flagneg as $flag) {
 104+ foreach( $flagneg as $flag ) {
104105 $flags[$flag] = 0;
105106 }
106107 }
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+ }
110112 if(!$found && $flags['t']) {
111 - $newtitle = Title::newFromText($pieces[0]);
 113+ $newtitle = Title::newFromText( $pieces[0] );
112114 //make sure that it's a valid title
113115 if( $newtitle instanceOf Title && !$newtitle->isTalkPage() ) {
114116 $talk = $newtitle->getTalkPage();
115117 $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+ }
119122 }
120123 }
121 - if(!$found)
 124+ if( !$found ) {
122125 continue;
 126+ }
123127
124 - if(!$flags['u'] && $evEditSubpagesCache['loggedin'])
 128+ if( !$flags['u'] && $evEditSubpagesCache['loggedin'] ) {
125129 return true;
 130+ }
126131 //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() ) {
128133 $result = false;
129134 return false;
130135 }
131 - if(!$flags['e'] && $newtitle->exists()) {
 136+ if( !$flags['e'] && $newtitle->exists() ) {
132137 $result = false;
133138 return false;
134139 }
135140 $result = true;
136141 return false;
137142 }
138 - if(!$evEditSubpagesCache['loggedin']) {
 143+ if( !$evEditSubpagesCache['loggedin'] ) {
139144 $result = false;
140145 return false;
141146 }
@@ -142,7 +147,7 @@
143148 return true;
144149 }
145150
146 -function checkPage($page, $check, $flags) {
 151+function checkPage( $page, $check, $flags ) {
147152 if( $flags['w'] && !$flags['r'] ) {
148153 $flags['r'] = 1;
149154 $page = preg_quote( $page, '/' );
@@ -164,14 +169,17 @@
165170 return preg_match( '/^' . $page . '$/' . $i, $check );
166171 }
167172 if( $flags['i'] ) {
168 - $page = strtolower($page);
169 - $check = strtolower($check);
 173+ $page = strtolower( $page );
 174+ $check = strtolower( $check );
170175 }
171 - if( $page == $check )
 176+ if( $page == $check ) {
172177 return true;
173 - if( $flags['s'] && strpos( $check, $page . '/' ) === 0 )
 178+ }
 179+ if( $flags['s'] && strpos( $check, $page . '/' ) === 0 ) {
174180 return true;
175 - if( $flags['b'] && strpos( $page, $check . '/' ) === 0 )
 181+ }
 182+ if( $flags['b'] && strpos( $page, $check . '/' ) === 0 ) {
176183 return true;
 184+ }
177185 return false;
178186 }