r40925 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40924‎ | r40925 | r40926 >
Date:19:09, 16 September 2008
Author:ialex
Status:old
Tags:
Comment:
* Added $wgUseMetadataEdit and $wgMetadataWhitelist to DefaultSettings.php, they exist since r6887.
* Fixed two E_NOTICE while editing a page with $wgUseMetadataEdit = true;
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/EditPage.php
@@ -231,93 +231,87 @@
232232 * and set $wgMetadataWhitelist to the *full* title of the template whitelist
233233 */
234234 function extractMetaDataFromArticle () {
235 - global $wgUseMetadataEdit , $wgMetadataWhitelist , $wgLang ;
236 - $this->mMetaData = '' ;
237 - if ( !$wgUseMetadataEdit ) return ;
238 - if ( $wgMetadataWhitelist == '' ) return ;
239 - $s = '' ;
 235+ global $wgUseMetadataEdit, $wgMetadataWhitelist, $wgContLang;
 236+ $this->mMetaData = '';
 237+ if ( !$wgUseMetadataEdit ) return;
 238+ if ( $wgMetadataWhitelist == '' ) return;
 239+ $s = '';
240240 $t = $this->getContent();
241241
242242 # MISSING : <nowiki> filtering
243243
244244 # Categories and language links
245 - $t = explode ( "\n" , $t ) ;
246 - $catlow = strtolower ( $wgLang->getNsText ( NS_CATEGORY ) ) ;
247 - $cat = $ll = array() ;
248 - foreach ( $t AS $key => $x )
249 - {
250 - $y = trim ( strtolower ( $x ) ) ;
251 - while ( substr ( $y , 0 , 2 ) == '[[' )
252 - {
253 - $y = explode ( ']]' , trim ( $x ) ) ;
254 - $first = array_shift ( $y ) ;
255 - $first = explode ( ':' , $first ) ;
256 - $ns = array_shift ( $first ) ;
257 - $ns = trim ( str_replace ( '[' , '' , $ns ) ) ;
258 - if ( strlen ( $ns ) == 2 OR strtolower ( $ns ) == $catlow )
259 - {
260 - $add = '[[' . $ns . ':' . implode ( ':' , $first ) . ']]' ;
261 - if ( strtolower ( $ns ) == $catlow ) $cat[] = $add ;
262 - else $ll[] = $add ;
263 - $x = implode ( ']]' , $y ) ;
264 - $t[$key] = $x ;
265 - $y = trim ( strtolower ( $x ) ) ;
 245+ $t = explode ( "\n" , $t );
 246+ $catlow = strtolower ( $wgContLang->getNsText( NS_CATEGORY ) );
 247+ $cat = $ll = array();
 248+ foreach ( $t AS $key => $x ) {
 249+ $y = trim ( strtolower ( $x ) );
 250+ while ( substr ( $y , 0 , 2 ) == '[[' ) {
 251+ $y = explode ( ']]' , trim ( $x ) );
 252+ $first = array_shift ( $y );
 253+ $first = explode ( ':' , $first );
 254+ $ns = array_shift ( $first );
 255+ $ns = trim ( str_replace ( '[' , '' , $ns ) );
 256+ if ( $wgContLang->getLanguageName( $ns ) || strtolower ( $ns ) == $catlow ) {
 257+ $add = '[[' . $ns . ':' . implode ( ':' , $first ) . ']]';
 258+ if ( strtolower ( $ns ) == $catlow ) $cat[] = $add;
 259+ else $ll[] = $add;
 260+ $x = implode ( ']]' , $y );
 261+ $t[$key] = $x;
 262+ $y = trim ( strtolower ( $x ) );
 263+ } else {
 264+ $x = implode ( ']]' , $y );
 265+ $y = trim ( strtolower ( $x ) );
266266 }
267267 }
268268 }
269 - if ( count ( $cat ) ) $s .= implode ( ' ' , $cat ) . "\n" ;
270 - if ( count ( $ll ) ) $s .= implode ( ' ' , $ll ) . "\n" ;
271 - $t = implode ( "\n" , $t ) ;
 269+ if ( count ( $cat ) ) $s .= implode ( ' ' , $cat ) . "\n";
 270+ if ( count ( $ll ) ) $s .= implode ( ' ' , $ll ) . "\n";
 271+ $t = implode ( "\n" , $t );
272272
273273 # Load whitelist
274274 $sat = array () ; # stand-alone-templates; must be lowercase
275 - $wl_title = Title::newFromText ( $wgMetadataWhitelist ) ;
276 - $wl_article = new Article ( $wl_title ) ;
277 - $wl = explode ( "\n" , $wl_article->getContent() ) ;
278 - foreach ( $wl AS $x )
279 - {
280 - $isentry = false ;
281 - $x = trim ( $x ) ;
282 - while ( substr ( $x , 0 , 1 ) == '*' )
283 - {
284 - $isentry = true ;
285 - $x = trim ( substr ( $x , 1 ) ) ;
 275+ $wl_title = Title::newFromText ( $wgMetadataWhitelist );
 276+ $wl_article = new Article ( $wl_title );
 277+ $wl = explode ( "\n" , $wl_article->getContent() );
 278+ foreach ( $wl AS $x ) {
 279+ $isentry = false;
 280+ $x = trim ( $x );
 281+ while ( substr ( $x , 0 , 1 ) == '*' ) {
 282+ $isentry = true;
 283+ $x = trim ( substr ( $x , 1 ) );
286284 }
287 - if ( $isentry )
288 - {
289 - $sat[] = strtolower ( $x ) ;
 285+ if ( $isentry ) {
 286+ $sat[] = strtolower ( $x );
290287 }
291288
292289 }
293290
294291 # Templates, but only some
295 - $t = explode ( '{{' , $t ) ;
 292+ $t = explode ( '{{' , $t );
296293 $tl = array () ;
297 - foreach ( $t AS $key => $x )
298 - {
299 - $y = explode ( '}}' , $x , 2 ) ;
300 - if ( count ( $y ) == 2 )
301 - {
302 - $z = $y[0] ;
303 - $z = explode ( '|' , $z ) ;
304 - $tn = array_shift ( $z ) ;
305 - if ( in_array ( strtolower ( $tn ) , $sat ) )
306 - {
307 - $tl[] = '{{' . $y[0] . '}}' ;
308 - $t[$key] = $y[1] ;
309 - $y = explode ( '}}' , $y[1] , 2 ) ;
 294+ foreach ( $t AS $key => $x ) {
 295+ $y = explode ( '}}' , $x , 2 );
 296+ if ( count ( $y ) == 2 ) {
 297+ $z = $y[0];
 298+ $z = explode ( '|' , $z );
 299+ $tn = array_shift ( $z );
 300+ if ( in_array ( strtolower ( $tn ) , $sat ) ) {
 301+ $tl[] = '{{' . $y[0] . '}}';
 302+ $t[$key] = $y[1];
 303+ $y = explode ( '}}' , $y[1] , 2 );
310304 }
311 - else $t[$key] = '{{' . $x ;
 305+ else $t[$key] = '{{' . $x;
312306 }
313 - else if ( $key != 0 ) $t[$key] = '{{' . $x ;
314 - else $t[$key] = $x ;
 307+ else if ( $key != 0 ) $t[$key] = '{{' . $x;
 308+ else $t[$key] = $x;
315309 }
316 - if ( count ( $tl ) ) $s .= implode ( ' ' , $tl ) ;
317 - $t = implode ( '' , $t ) ;
 310+ if ( count ( $tl ) ) $s .= implode ( ' ' , $tl );
 311+ $t = implode ( '' , $t );
318312
319 - $t = str_replace ( "\n\n\n" , "\n" , $t ) ;
320 - $this->mArticle->mContent = $t ;
321 - $this->mMetaData = $s ;
 313+ $t = str_replace ( "\n\n\n" , "\n" , $t );
 314+ $this->mArticle->mContent = $t;
 315+ $this->mMetaData = $s;
322316 }
323317
324318 /*
@@ -952,7 +946,7 @@
953947 }
954948
955949 # Handle the user preference to force summaries here, but not for null edits
956 - if ( $this->section != 'new' && !$this->allowBlankSummary && 0 != strcmp($oldtext, $text) &&
 950+ if ( $this->section != 'new' && !$this->allowBlankSummary && 0 != strcmp($oldtext, $text) &&
957951 !is_object( Title::newFromRedirect( $text ) ) # check if it's not a redirect
958952 ) {
959953 if ( md5( $this->summary ) == $this->autoSumm ) {
@@ -1346,6 +1340,7 @@
13471341 $ew = $wgUser->getOption( 'editwidth' );
13481342 if ( $ew ) $ew = " style=\"width:100%\"";
13491343 else $ew = '';
 1344+ $cols = $wgUser->getIntOption( 'cols' );
13501345 /* /ToDo */
13511346 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
13521347 }
Index: trunk/phase3/includes/DefaultSettings.php
@@ -2027,11 +2027,23 @@
20282028 $wgRC2UDPPrefix = '';
20292029 $wgRC2UDPOmitBots = false;
20302030
2031 -# Enable user search in Special:Newpages
2032 -# This is really a temporary hack around an index install bug on some Wikipedias.
2033 -# Kill it once fixed.
 2031+/**
 2032+ * Enable user search in Special:Newpages
 2033+ * This is really a temporary hack around an index install bug on some Wikipedias.
 2034+ * Kill it once fixed.
 2035+ */
20342036 $wgEnableNewpagesUserFilter = true;
20352037
 2038+/**
 2039+ * Whether to use metadata edition
 2040+ * This will put categories, language links and allowed templates in a separate text box
 2041+ * while editing pages
 2042+ * EXPERIMENTAL
 2043+ */
 2044+$wgUseMetadataEdit = false;
 2045+/** Full name (including namespace) of the page containing templates names that will be allowed as metadata */
 2046+$wgMetadataWhitelist = '';
 2047+
20362048 #
20372049 # Copyright and credits settings
20382050 #

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r6887separate metadata editor, pre-alphamagnus_manske13:46, 29 December 2004