r107997 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107996‎ | r107997 | r107998 >
Date:08:43, 4 January 2012
Author:ialex
Status:ok
Tags:
Comment:
* Use getTimestamp() to get the timestamp of the last edit
* Removed usage of $wgTitle where possible
* Removed call to Parser::disableCache() from ArticleFromTitle hook; was throwing an exception
Modified paths:
  • /trunk/extensions/BlogPage/BlogHooks.php (modified) (history)
  • /trunk/extensions/BlogPage/BlogPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/BlogPage/BlogPage.php
@@ -37,7 +37,7 @@
3838 }
3939
4040 function view() {
41 - global $wgOut, $wgUser, $wgTitle, $wgBlogPageDisplay;
 41+ global $wgOut, $wgUser, $wgBlogPageDisplay;
4242
4343 wfProfileIn( __METHOD__ );
4444
@@ -45,8 +45,8 @@
4646
4747 wfDebugLog( 'BlogPage', __METHOD__ );
4848
49 - $wgOut->setHTMLTitle( $wgTitle->getText() );
50 - $wgOut->setPageTitle( $wgTitle->getText() );
 49+ $wgOut->setHTMLTitle( $this->getTitle()->getText() );
 50+ $wgOut->setPageTitle( $this->getTitle()->getText() );
5151
5252 // Don't throw a bunch of E_NOTICEs when we're viewing the page of a
5353 // nonexistent blog post
@@ -94,7 +94,7 @@
9595 if( $wgUseEditButtonFloat == true && method_exists( $sk, 'editMenu' ) ) {
9696 $wgOut->addHTML( $sk->editMenu() );
9797 }
98 - $wgOut->addHTML( "<h1 class=\"page-title\">{$wgTitle->getText()}</h1>\n" );
 98+ $wgOut->addHTML( "<h1 class=\"page-title\">{$this->getTitle()->getText()}</h1>\n" );
9999 $wgOut->addHTML( $this->getByLine() );
100100
101101 $wgOut->addHTML( "\n<!--start Article::view-->\n" );
@@ -196,70 +196,22 @@
197197 }
198198
199199 /**
200 - * Get the last edit date of the page with the given ID from the revision
201 - * table and cache it in memcached.
202 - * The return value of this function can be passed to the various $wgLang
203 - * methods for i18n-compatible code.
204 - *
205 - * @param $pageId Integer: page ID number
206 - * @return Integer: page creation date
207 - */
208 - public static function getLastEditTimestamp( $pageId ) {
209 - global $wgMemc;
210 -
211 - // Try memcached first
212 - $key = wfMemcKey( 'page', 'last_edit_date', $pageId );
213 - $data = $wgMemc->get( $key );
214 -
215 - if( !$data ) {
216 - wfDebugLog( 'BlogPage', "Loading last_edit_date for page {$pageId} from database" );
217 - $dbr = wfGetDB( DB_SLAVE );
218 - $lastEditDate = $dbr->selectField(
219 - 'revision',
220 - 'MAX(rev_timestamp)',
221 - array( 'rev_page' => $pageId ),
222 - __METHOD__,
223 - array( 'ORDER BY' => 'rev_timestamp ASC' )
224 - );
225 - $wgMemc->set( $key, $lastEditDate );
226 - } else {
227 - wfDebugLog( 'BlogPage', "Loading last_edit_date for page {$pageId} from cache" );
228 - $lastEditDate = $data;
229 - }
230 -
231 - return $lastEditDate;
232 - }
233 -
234 - /**
235200 * Get the "by X, Y and Z" line, which also contains other nifty
236201 * information, such as the date of the last edit and the creation date.
237202 *
238203 * @return String
239204 */
240205 function getByLine() {
241 - global $wgTitle, $wgLang;
 206+ global $wgLang;
242207
243208 $count = 0;
244209
245210 // Get date of last edit
246 - /*
247 - $year = substr( $wgTitle->getTouched(), 0, 4 );
248 - $month = substr( $wgTitle->getTouched(), 4, 2 );
249 - $day = substr( $wgTitle->getTouched(), 6, 2 );
250 - $edit_date = date( 'F d, Y', mktime( 0, 0, 0, $month, $day, $year ) );
251 - */
252 - //$edit_date = $wgLang->timeanddate( $wgTitle->getTouched(), true );
253 - // Title::getTouched() sucks, because apparently voting for a page
254 - // invalidates page cache, too... --ashley, 7 August 2011
255 - $edit_date = $wgLang->timeanddate(
256 - self::getLastEditTimestamp( $wgTitle->getArticleID() ),
257 - true
258 - );
 211+ $edit_date = $wgLang->timeanddate( $this->getTimestamp(), true );
259212
260213 // Get date of when article was created
261 - #$create_date = date( 'F d, Y', $this->getCreateDate( $wgTitle->getArticleID() ) );
262214 $create_date = $wgLang->timeanddate(
263 - self::getCreateDate( $wgTitle->getArticleID() ),
 215+ self::getCreateDate( $this->getId() ),
264216 true
265217 );
266218
@@ -381,7 +333,7 @@
382334 }
383335
384336 function getAuthorArticles( $author_index ) {
385 - global $wgTitle, $wgOut, $wgBlogPageDisplay, $wgMemc;
 337+ global $wgOut, $wgBlogPageDisplay, $wgMemc;
386338
387339 if ( $wgBlogPageDisplay['author_articles'] == false ) {
388340 return '';
@@ -431,7 +383,7 @@
432384 $array_count = 0;
433385
434386 foreach( $res as $row ) {
435 - if ( $row->page_id != $wgTitle->getArticleID() && $array_count < 3 ) {
 387+ if ( $row->page_id != $this->getId() && $array_count < 3 ) {
436388 $articles[] = array(
437389 'page_title' => $row->page_title,
438390 'page_id' => $row->page_id
@@ -502,9 +454,9 @@
503455 * @return Array: array containing each editors' user ID and user name
504456 */
505457 function getEditorsList() {
506 - global $wgMemc, $wgTitle;
 458+ global $wgMemc;
507459
508 - $pageTitleId = $wgTitle->getArticleID();
 460+ $pageTitleId = $this->getId();
509461
510462 $key = wfMemcKey( 'recenteditors', 'list', $pageTitleId );
511463 $data = $wgMemc->get( $key );
@@ -594,10 +546,10 @@
595547 * @return Array: array containing each voters' user ID and user name
596548 */
597549 function getVotersList() {
598 - global $wgMemc, $wgTitle;
 550+ global $wgMemc;
599551
600552 // Gets the page ID for the query
601 - $pageTitleId = $wgTitle->getArticleID();
 553+ $pageTitleId = $this->getId();
602554
603555 $key = wfMemcKey( 'recentvoters', 'list', $pageTitleId );
604556 $data = $wgMemc->get( $key );
@@ -684,7 +636,7 @@
685637 * @return String: HTML or nothing
686638 */
687639 function embedWidget() {
688 - global $wgTitle, $wgBlogPageDisplay, $wgServer, $wgScriptPath;
 640+ global $wgBlogPageDisplay, $wgServer, $wgScriptPath;
689641
690642 // Not enabled? ContentWidget not available?
691643 if (
@@ -695,7 +647,7 @@
696648 return '';
697649 }
698650
699 - $title = Title::makeTitle( $wgTitle->getNamespace(), $wgTitle->getText() );
 651+ $title = $this->getTitle();
700652
701653 $output = '';
702654 $output .= '<div class="recent-container bottom-fix"><h2>' .
@@ -1102,7 +1054,7 @@
11031055 * @return String: first $maxChars characters from the page
11041056 */
11051057 public static function getBlurb( $pageTitle, $namespace, $maxChars, $fontSize = 'small' ) {
1106 - global $wgTitle, $wgOut, $wgContLang;
 1058+ global $wgOut, $wgContLang;
11071059
11081060 // Get raw text
11091061 $title = Title::makeTitle( $namespace, $pageTitle );
@@ -1139,9 +1091,8 @@
11401092 $text = '__NOTOC__ ' . $text;
11411093
11421094 // Run text through parser
1143 - $blurbParser = new Parser();
1144 - $blurbText = $blurbParser->parse( $text, $wgTitle, $wgOut->parserOptions(), true );
1145 - $blurbText = strip_tags( $blurbText->getText() );
 1095+ $blurbText = $wgOut->parse( $text );
 1096+ $blurbText = strip_tags( $blurbText );
11461097
11471098 $blurbText = preg_replace( '/&lt;comments&gt;&lt;\/comments&gt;/i', '', $blurbText );
11481099 $blurbText = preg_replace( '/&lt;vote&gt;&lt;\/vote&gt;/i', '', $blurbText );
@@ -1259,4 +1210,4 @@
12601211 }
12611212 return $timeStr;
12621213 }
1263 -}
\ No newline at end of file
 1214+}
Index: trunk/extensions/BlogPage/BlogHooks.php
@@ -16,7 +16,7 @@
1717 * @return Boolean: true
1818 */
1919 public static function blogFromTitle( &$title, &$article ) {
20 - global $wgRequest, $wgOut, $wgParser, $wgHooks, $wgScriptPath;
 20+ global $wgRequest, $wgOut, $wgHooks, $wgScriptPath;
2121 global $wgSupressPageTitle, $wgSupressSubTitle, $wgSupressPageCategories;
2222
2323 if ( $title->getNamespace() == NS_BLOG ) {
@@ -34,7 +34,6 @@
3535 };
3636
3737 $wgOut->enableClientCache( false );
38 - $wgParser->disableCache();
3938
4039 // Add CSS
4140 if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) {
@@ -397,4 +396,4 @@
398397 return true;
399398 }
400399 */
401 -}
\ No newline at end of file
 400+}

Status & tagging log