r104799 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104798‎ | r104799 | r104800 >
Date:00:05, 1 December 2011
Author:juliano
Status:deferred
Tags:
Comment:
Fix Article class compatibility with MediaWiki 1.18 (r91123).
Modified paths:
  • /trunk/extensions/Wikilog/TODO (modified) (history)
  • /trunk/extensions/Wikilog/Wikilog.php (modified) (history)
  • /trunk/extensions/Wikilog/WikilogItemPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikilog/WikilogItemPage.php
@@ -48,15 +48,32 @@
4949 * @param $title Article title object.
5050 * @param $wi Wikilog info object.
5151 */
52 - function __construct( &$title, &$wi ) {
 52+ public function __construct( Title $title, WikilogItem $item = null ) {
5353 parent::__construct( $title );
54 - $this->mItem = WikilogItem::newFromInfo( $wi );
 54+ $this->mItem = $item;
5555 }
5656
5757 /**
 58+ * Return the appropriate WikiPage object for WikilogItemPage.
 59+ */
 60+ protected function newPage( Title $title ) {
 61+ return new WikilogWikiItemPage( $title );
 62+ }
 63+
 64+ /**
 65+ * Constructor from a page ID.
 66+ * @param $id Int article ID to load.
 67+ */
 68+ public static function newFromID( $id ) {
 69+ $t = Title::newFromID( $id );
 70+ $i = WikilogItem::newFromID( $id );
 71+ return $t == null ? null : new self( $t, $i );
 72+ }
 73+
 74+ /**
5875 * View page action handler.
5976 */
60 - function view() {
 77+ public function view() {
6178 global $wgOut, $wgUser, $wgContLang, $wgFeed, $wgWikilogFeedClasses;
6279
6380 # Get skin
@@ -132,35 +149,62 @@
133150 }
134151
135152 /**
 153+ * Compatibility with MediaWiki 1.17.
 154+ * @todo Remove this in Wl1.3.
 155+ */
 156+ public function preSaveTransform( $text ) {
 157+ return $this->newPage( $this->getTitle() )->preSaveTransform( $text );
 158+ }
 159+}
 160+
 161+/**
 162+ * Wikilog WikiPage class for WikilogItemPage.
 163+ */
 164+class WikilogWikiItemPage
 165+ extends WikiPage
 166+{
 167+ /**
 168+ * Constructor from a page ID.
 169+ * @param $id Int article ID to load.
 170+ */
 171+ public static function newFromID( $id ) {
 172+ $t = Title::newFromID( $id );
 173+ return $t == null ? null : new self( $t );
 174+ }
 175+
 176+ /**
136177 * Override for preSaveTransform. Enables quick post publish by signing
137178 * the article using the standard --~~~~ marker. This causes the signature
138179 * marker to be replaced by a {{wl-publish:...}} parser function call,
139180 * that is then saved to the database and causes the post to be published.
140181 */
141 - function preSaveTransform( $text ) {
 182+ public function preSaveTransform( $text, User $user = null, ParserOptions $popts = null ) {
142183 global $wgParser, $wgUser;
 184+ $user = is_null( $user ) ? $wgUser : $user;
143185
144 - $popt = ParserOptions::newFromUser( $wgUser );
 186+ if ( $popts === null ) {
 187+ $popts = ParserOptions::newFromUser( $user );
 188+ }
145189
146190 $t = WikilogUtils::getPublishParameters();
147 - $date = $t['date'];
148 - $user = $t['user'];
 191+ $date_txt = $t['date'];
 192+ $user_txt = $t['user'];
149193
150194 $sigs = array(
151 - '/\n?(--)?~~~~~\n?/m' => "\n{{wl-publish: {$date} }}\n",
152 - '/\n?(--)?~~~~\n?/m' => "\n{{wl-publish: {$date} | {$user} }}\n",
153 - '/\n?(--)?~~~\n?/m' => "\n{{wl-author: {$user} }}\n"
 195+ '/\n?(--)?~~~~~\n?/m' => "\n{{wl-publish: {$date_txt} }}\n",
 196+ '/\n?(--)?~~~~\n?/m' => "\n{{wl-publish: {$date_txt} | {$user_txt} }}\n",
 197+ '/\n?(--)?~~~\n?/m' => "\n{{wl-author: {$user_txt} }}\n"
154198 );
155199
156200 if ( !StubObject::isRealObject( $wgParser ) ) {
157201 $wgParser->_unstub();
158202 }
159 - $wgParser->startExternalParse( $this->mTitle, $popt, Parser::OT_WIKI );
 203+ $wgParser->startExternalParse( $this->mTitle, $popts, Parser::OT_WIKI );
160204
161205 $text = $wgParser->replaceVariables( $text );
162206 $text = preg_replace( array_keys( $sigs ), array_values( $sigs ), $text );
163207 $text = $wgParser->mStripState->unstripBoth( $text );
164208
165 - return parent::preSaveTransform( $text );
 209+ return parent::preSaveTransform( $text, $user, $popts );
166210 }
167211 }
Index: trunk/extensions/Wikilog/Wikilog.php
@@ -107,6 +107,7 @@
108108 // Namespace pages
109109 'WikilogMainPage' => $dir . 'WikilogMainPage.php',
110110 'WikilogItemPage' => $dir . 'WikilogItemPage.php',
 111+ 'WikilogWikiItemPage' => $dir . 'WikilogItemPage.php',
111112 'WikilogCommentsPage' => $dir . 'WikilogCommentsPage.php',
112113
113114 // Captcha adapter
@@ -274,7 +275,8 @@
275276 return true;
276277 }
277278 } elseif ( $wi->isItem() ) {
278 - $article = new WikilogItemPage( $title, $wi );
 279+ $item = WikilogItem::newFromInfo( $wi );
 280+ $article = new WikilogItemPage( $title, $item );
279281 } else {
280282 $article = new WikilogMainPage( $title, $wi );
281283 }
Index: trunk/extensions/Wikilog/TODO
@@ -2,4 +2,4 @@
33
44 === Wikilog 1.3.0. ===
55
6 -(empty)
 6+* Remove WikilogItemPage::preSaveTransform() (Mw 1.17 compatibility).

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r91123* Split off WikiPage class from Article, WikiFilePage class from ImagePage, a...aaron22:09, 29 June 2011

Status & tagging log