https://www.mediawiki.org/wiki/Special:Code/MediaWiki/104799
Revision: 104799 Author: juliano Date: 2011-12-01 00:05:30 +0000 (Thu, 01 Dec 2011) Log Message: ----------- Fix Article class compatibility with MediaWiki 1.18 (r91123). Modified Paths: -------------- trunk/extensions/Wikilog/TODO trunk/extensions/Wikilog/Wikilog.php trunk/extensions/Wikilog/WikilogItemPage.php Modified: trunk/extensions/Wikilog/TODO =================================================================== --- trunk/extensions/Wikilog/TODO 2011-12-01 00:04:59 UTC (rev 104798) +++ trunk/extensions/Wikilog/TODO 2011-12-01 00:05:30 UTC (rev 104799) @@ -2,4 +2,4 @@ === Wikilog 1.3.0. === -(empty) +* Remove WikilogItemPage::preSaveTransform() (Mw 1.17 compatibility). Modified: trunk/extensions/Wikilog/Wikilog.php =================================================================== --- trunk/extensions/Wikilog/Wikilog.php 2011-12-01 00:04:59 UTC (rev 104798) +++ trunk/extensions/Wikilog/Wikilog.php 2011-12-01 00:05:30 UTC (rev 104799) @@ -107,6 +107,7 @@ // Namespace pages 'WikilogMainPage' => $dir . 'WikilogMainPage.php', 'WikilogItemPage' => $dir . 'WikilogItemPage.php', + 'WikilogWikiItemPage' => $dir . 'WikilogItemPage.php', 'WikilogCommentsPage' => $dir . 'WikilogCommentsPage.php', // Captcha adapter @@ -274,7 +275,8 @@ return true; } } elseif ( $wi->isItem() ) { - $article = new WikilogItemPage( $title, $wi ); + $item = WikilogItem::newFromInfo( $wi ); + $article = new WikilogItemPage( $title, $item ); } else { $article = new WikilogMainPage( $title, $wi ); } Modified: trunk/extensions/Wikilog/WikilogItemPage.php =================================================================== --- trunk/extensions/Wikilog/WikilogItemPage.php 2011-12-01 00:04:59 UTC (rev 104798) +++ trunk/extensions/Wikilog/WikilogItemPage.php 2011-12-01 00:05:30 UTC (rev 104799) @@ -48,15 +48,32 @@ * @param $title Article title object. * @param $wi Wikilog info object. */ - function __construct( &$title, &$wi ) { + public function __construct( Title $title, WikilogItem $item = null ) { parent::__construct( $title ); - $this->mItem = WikilogItem::newFromInfo( $wi ); + $this->mItem = $item; } /** + * Return the appropriate WikiPage object for WikilogItemPage. + */ + protected function newPage( Title $title ) { + return new WikilogWikiItemPage( $title ); + } + + /** + * Constructor from a page ID. + * @param $id Int article ID to load. + */ + public static function newFromID( $id ) { + $t = Title::newFromID( $id ); + $i = WikilogItem::newFromID( $id ); + return $t == null ? null : new self( $t, $i ); + } + + /** * View page action handler. */ - function view() { + public function view() { global $wgOut, $wgUser, $wgContLang, $wgFeed, $wgWikilogFeedClasses; # Get skin @@ -132,35 +149,62 @@ } /** + * Compatibility with MediaWiki 1.17. + * @todo Remove this in Wl1.3. + */ + public function preSaveTransform( $text ) { + return $this->newPage( $this->getTitle() )->preSaveTransform( $text ); + } +} + +/** + * Wikilog WikiPage class for WikilogItemPage. + */ +class WikilogWikiItemPage + extends WikiPage +{ + /** + * Constructor from a page ID. + * @param $id Int article ID to load. + */ + public static function newFromID( $id ) { + $t = Title::newFromID( $id ); + return $t == null ? null : new self( $t ); + } + + /** * Override for preSaveTransform. Enables quick post publish by signing * the article using the standard --~~~~ marker. This causes the signature * marker to be replaced by a {{wl-publish:...}} parser function call, * that is then saved to the database and causes the post to be published. */ - function preSaveTransform( $text ) { + public function preSaveTransform( $text, User $user = null, ParserOptions $popts = null ) { global $wgParser, $wgUser; + $user = is_null( $user ) ? $wgUser : $user; - $popt = ParserOptions::newFromUser( $wgUser ); + if ( $popts === null ) { + $popts = ParserOptions::newFromUser( $user ); + } $t = WikilogUtils::getPublishParameters(); - $date = $t['date']; - $user = $t['user']; + $date_txt = $t['date']; + $user_txt = $t['user']; $sigs = array( - '/\n?(--)?~~~~~\n?/m' => "\n{{wl-publish: {$date} }}\n", - '/\n?(--)?~~~~\n?/m' => "\n{{wl-publish: {$date} | {$user} }}\n", - '/\n?(--)?~~~\n?/m' => "\n{{wl-author: {$user} }}\n" + '/\n?(--)?~~~~~\n?/m' => "\n{{wl-publish: {$date_txt} }}\n", + '/\n?(--)?~~~~\n?/m' => "\n{{wl-publish: {$date_txt} | {$user_txt} }}\n", + '/\n?(--)?~~~\n?/m' => "\n{{wl-author: {$user_txt} }}\n" ); if ( !StubObject::isRealObject( $wgParser ) ) { $wgParser->_unstub(); } - $wgParser->startExternalParse( $this->mTitle, $popt, Parser::OT_WIKI ); + $wgParser->startExternalParse( $this->mTitle, $popts, Parser::OT_WIKI ); $text = $wgParser->replaceVariables( $text ); $text = preg_replace( array_keys( $sigs ), array_values( $sigs ), $text ); $text = $wgParser->mStripState->unstripBoth( $text ); - return parent::preSaveTransform( $text ); + return parent::preSaveTransform( $text, $user, $popts ); } } _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs