r70149 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70148‎ | r70149 | r70150 >
Date:18:01, 29 July 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Tidy WikiPageMessageGroup

Delay constructing the title object. This also prevents an
error when serializing and using sqlite as db. There are
still plenty of cases when serialization can fail.
Modified paths:
  • /trunk/extensions/Translate/MessageGroups.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/MessageGroups.php
@@ -731,31 +731,34 @@
732732 }
733733
734734 class WikiPageMessageGroup extends WikiMessageGroup {
735 - protected $type = 'mediawiki';
 735+ protected $title;
736736
737 - public $title;
738 -
739737 public function __construct( $id, $source ) {
740738 $this->id = $id;
741 - $title = Title::newFromText( $source );
 739+ $this->title = $source;
 740+ $this->namespaces = array( NS_TRANSLATIONS, NS_TRANSLATIONS_TALK );
 741+ }
742742
743 - if ( !$title ) {
744 - throw new MWException( 'Invalid title' );
 743+ public function getTitle() {
 744+ if ( is_string( $this->title ) ) {
 745+ $this->title = Title::newFromText( $this->title );
745746 }
 747+ return $this->title;
 748+ }
746749
747 - $this->title = $title;
748 - $this->namespaces = array( NS_TRANSLATIONS, NS_TRANSLATIONS_TALK );
 750+ public function getType() {
 751+ return 'mediawiki';
749752 }
750753
751754 public function getDefinitions() {
752755 $dbr = wfGetDB( DB_SLAVE );
753756 $tables = 'translate_sections';
754757 $vars = array( 'trs_key', 'trs_text' );
755 - $conds = array( 'trs_page' => $this->title->getArticleId() );
 758+ $conds = array( 'trs_page' => $this->getTitle()->getArticleId() );
756759 $res = $dbr->select( $tables, $vars, $conds, __METHOD__ );
757760
758761 $defs = array();
759 - $prefix = $this->title->getPrefixedDBKey() . '/';
 762+ $prefix = $this->getTitle()->getPrefixedDBKey() . '/';
760763 $re = '~<tvar\|([^>]+)>(.*?)</>~u';
761764
762765 foreach ( $res as $r ) {
@@ -830,6 +833,7 @@
831834 $target = SpecialPage::getTitleFor( 'MyLanguage', $title )->getPrefixedText();
832835 return wfMsgNoTrans( 'translate-tag-page-desc', $title, $target );
833836 }
 837+
834838 }
835839
836840 class MessageGroups {
@@ -989,8 +993,6 @@
990994 public $classes;
991995 private function __construct() {
992996 self::init();
993 -
994 -
995997 }
996998
997999 public static function singleton() {

Status & tagging log