r63810 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63809‎ | r63810 | r63811 >
Date:10:12, 16 March 2010
Author:jojo
Status:ok
Tags:
Comment:
fix: instantiate article; make regexs more restrictive
Modified paths:
  • /trunk/extensions/Collection/Collection.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Collection/Collection.body.php
@@ -736,7 +736,7 @@
737737 );
738738 } elseif ( substr( $line, 0, 1 ) == ':' ) { // article
739739 $articleTitle = trim( substr( $line, 1 ) );
740 - if ( preg_match( '/\[\[:?(.*?)(\|(.*?))?\]\]/', $articleTitle, $match ) ) {
 740+ if ( preg_match( '/^\[\[:?(.*?)(\|(.*?))?\]\]$/', $articleTitle, $match ) ) {
741741 $articleTitle = $match[1];
742742 if ( isset( $match[3] ) ) {
743743 $displayTitle = $match[3];
@@ -745,7 +745,7 @@
746746 }
747747 $oldid = -1;
748748 $currentVersion = 1;
749 - } elseif ( preg_match( '/\[\{\{fullurl:(.*?)\|oldid=(.*?)\}\}\s+(.*?)\]/', $articleTitle, $match ) ) {
 749+ } elseif ( preg_match( '/^\[\{\{fullurl:(.*?)\|oldid=(.*?)\}\}\s+(.*?)\]$/', $articleTitle, $match ) ) {
750750 $articleTitle = $match[1];
751751 if ( isset( $match[3] ) ) {
752752 $displayTitle = $match[3];
@@ -754,6 +754,8 @@
755755 }
756756 $oldid = $match[2];
757757 $currentVersion = 0;
 758+ } else {
 759+ return null;
758760 }
759761
760762 $articleTitle = Title::newFromText( $articleTitle );
@@ -794,6 +796,7 @@
795797
796798 function loadCollection( $title, $append=false ) {
797799 global $wgOut;
 800+
798801 if ( is_null( $title ) ) {
799802 $wgOut->showErrorPage( 'coll-notitle_title', 'coll-notitle_msg' );
800803 return;
@@ -815,6 +818,8 @@
816819 $items = $collection['items'];
817820 }
818821
 822+ $article = new Article( $title );
 823+
819824 foreach( preg_split( '/[\r\n]+/', $article->getContent() ) as $line ) {
820825 $item = $this->parseCollectionLine( $collection, $line, $append );
821826 if ( !is_null( $item ) ) {

Status & tagging log