r4912 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r4911‎ | r4912 | r4913 >
Date:23:55, 22 August 2004
Author:vibber
Status:old
Tags:
Comment:
Add back the slower version of Title::makeTitle as Title::makeTitleSafe()
and use it in a few places where user names, images, or messages are being
used to create titles.
Modified paths:
  • /trunk/phase3/includes/DifferenceEngine.php (modified) (history)
  • /trunk/phase3/includes/Image.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/SpecialBooksources.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/index.php (modified) (history)

Diff [purge]

Index: trunk/phase3/index.php
@@ -96,7 +96,7 @@
9797 SpecialPage::executePath( $wgTitle );
9898 } else {
9999 if ( Namespace::getMedia() == $wgTitle->getNamespace() ) {
100 - $wgTitle = Title::makeTitle( Namespace::getImage(), $wgTitle->getDBkey() );
 100+ $wgTitle = Title::makeTitle( NS_IMAGE, $wgTitle->getDBkey() );
101101 }
102102
103103 switch( $wgTitle->getNamespace() ) {
Index: trunk/phase3/includes/DifferenceEngine.php
@@ -60,10 +60,10 @@
6161 $this->mOldComment = $sk->formatComment($this->mOldComment);
6262 $this->mNewComment = $sk->formatComment($this->mNewComment);
6363
64 - $oldUserLink = $sk->makeLinkObj( Title::makeTitle( NS_USER, $this->mOldUser ), $this->mOldUser );
65 - $newUserLink = $sk->makeLinkObj( Title::makeTitle( NS_USER, $this->mNewUser ), $this->mNewUser );
66 - $oldUTLink = $sk->makeLinkObj( Title::makeTitle( NS_USER_TALK, $this->mOldUser ), $talk );
67 - $newUTLink = $sk->makeLinkObj( Title::makeTitle( NS_USER_TALK, $this->mNewUser ), $talk );
 64+ $oldUserLink = $sk->makeLinkObj( Title::makeTitleSafe( NS_USER, $this->mOldUser ), $this->mOldUser );
 65+ $newUserLink = $sk->makeLinkObj( Title::makeTitleSafe( NS_USER, $this->mNewUser ), $this->mNewUser );
 66+ $oldUTLink = $sk->makeLinkObj( Title::makeTitleSafe( NS_USER_TALK, $this->mOldUser ), $talk );
 67+ $newUTLink = $sk->makeLinkObj( Title::makeTitleSafe( NS_USER_TALK, $this->mNewUser ), $talk );
6868 $oldContribs = $sk->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ), $contribs,
6969 'target=' . urlencode($this->mOldUser) );
7070 $newContribs = $sk->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ), $contribs,
Index: trunk/phase3/includes/Title.php
@@ -138,8 +138,8 @@
139139 }
140140
141141 # From a namespace index and a DB key.
142 - # It's assumed that $ns and $title are *valid*, for instance
143 - # when they came directly from the database.
 142+ # It's assumed that $ns and $title are *valid*, for instance when
 143+ # they came directly from the database or a special page name.
144144 /* static */ function &makeTitle( $ns, $title ) {
145145 $t =& new Title();
146146 $t->mInterwiki = '';
@@ -151,6 +151,19 @@
152152 $t->mTextform = str_replace( '_', ' ', $title );
153153 return $t;
154154 }
 155+
 156+ # From a namespace index and a DB key.
 157+ # These will be checked for validity, which is a bit slower
 158+ # than makeTitle() but safer for user-provided data.
 159+ /* static */ function makeTitleSafe( $ns, $title ) {
 160+ $t = new Title();
 161+ $t->mDbkeyform = Title::makeName( $ns, $title );
 162+ if( $t->secureAndSplit() ) {
 163+ return $t;
 164+ } else {
 165+ return NULL;
 166+ }
 167+ }
155168
156169 /* static */ function newMainPage() {
157170 return Title::newFromText( wfMsg( 'mainpage' ) );
Index: trunk/phase3/includes/Image.php
@@ -26,7 +26,7 @@
2727 global $wgUploadDirectory;
2828
2929 $this->name = $name;
30 - $this->title = Title::makeTitle( Namespace::getImage(), $this->name );
 30+ $this->title = Title::makeTitleSafe( NS_IMAGE, $this->name );
3131 //$this->imagePath = wfImagePath( $name );
3232 $hash = md5( $this->title->getDBkey() );
3333 $this->imagePath = $wgUploadDirectory . '/' . $hash{0} . '/' .substr( $hash, 0, 2 ) . "/{$name}";
@@ -377,7 +377,7 @@
378378 'img_user_text' => $wgUser->getName(),
379379 ), $fname, 'IGNORE'
380380 );
381 - $descTitle = Title::makeTitle( NS_IMAGE, $name );
 381+ $descTitle = Title::makeTitleSafe( NS_IMAGE, $name );
382382
383383 if ( $dbw->affectedRows() ) {
384384 # Successfully inserted, this is a new image
Index: trunk/phase3/includes/Skin.php
@@ -1696,7 +1696,7 @@
16971697 }
16981698 # this can be passed the NS number as defined in Language.php
16991699 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=0 ) {
1700 - $title = Title::makeTitle( $namespace, $name );
 1700+ $title = Title::makeTitleSafe( $namespace, $name );
17011701 $this->checkTitle($title, $name);
17021702 return $title->getLocalURL( $urlaction );
17031703 }
@@ -1770,7 +1770,7 @@
17711771 }
17721772
17731773 function makeImageLink( $name, $url, $alt = '' ) {
1774 - $nt = Title::makeTitle( Namespace::getImage(), $name );
 1774+ $nt = Title::makeTitleSafe( NS_IMAGE, $name );
17751775 return $this->makeImageLinkObj( $nt, $alt );
17761776 }
17771777
@@ -1903,7 +1903,7 @@
19041904 # $img is an Image object
19051905 function makeThumbLinkObj( $img, $label = '', $align = 'right', $boxwidth = 180, $boxheight=false, $framed=false , $manual_thumb = "" ) {
19061906 global $wgStylePath, $wgLang;
1907 - # $image = Title::makeTitle( Namespace::getImage(), $name );
 1907+ # $image = Title::makeTitleSafe( NS_IMAGE, $name );
19081908 $url = $img->getURL();
19091909
19101910 #$label = htmlspecialchars( $label );
@@ -1945,7 +1945,7 @@
19461946
19471947 if ( $manual_thumb != '' ) # Use manually specified thumbnail
19481948 {
1949 - $manual_title = Title::makeTitle( Namespace::getImage(), $manual_thumb ); #new Title ( $manual_thumb ) ;
 1949+ $manual_title = Title::makeTitleSafe( NS_IMAGE, $manual_thumb ); #new Title ( $manual_thumb ) ;
19501950 $manual_img = Image::newFromTitle( $manual_title );
19511951 $thumbUrl = $manual_img->getURL();
19521952 if ( $manual_img->exists() )
@@ -1986,7 +1986,7 @@
19871987 }
19881988
19891989 function makeMediaLink( $name, $url, $alt = "" ) {
1990 - $nt = Title::makeTitle( Namespace::getMedia(), $name );
 1990+ $nt = Title::makeTitleSafe( Namespace::getMedia(), $name );
19911991 return $this->makeMediaLinkObj( $nt, $alt );
19921992 }
19931993
Index: trunk/phase3/includes/OutputPage.php
@@ -829,7 +829,7 @@
830830 foreach ( $namespaces as $key => $val ) {
831831 # Make title object
832832 $dbk = $dbkeys[$key];
833 - $title = $titles[$key] = Title::makeTitle( $val, $dbk );
 833+ $title = $titles[$key] = Title::makeTitleSafe( $val, $dbk );
834834
835835 # Skip invalid entries.
836836 # Result will be ugly, but prevents crash.
Index: trunk/phase3/includes/SpecialBooksources.php
@@ -41,7 +41,7 @@
4242
4343 # First, see if we have a custom list setup in
4444 # [[Wikipedia:Book sources]] or equivalent.
45 - $bstitle = Title::makeTitle( NS_WIKIPEDIA, wfMsg( "booksources" ) );
 45+ $bstitle = Title::makeTitleSafe( NS_WIKIPEDIA, wfMsg( "booksources" ) );
4646 $dbr =& wfGetDB( DB_SLAVE );
4747 $bstext = $dbr->selectField( 'cur', 'cur_text', $bstitle->curCond(), $fname );
4848 if( $bstext ) {

Status & tagging log