r82428 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82427‎ | r82428 | r82429 >
Date:00:18, 19 February 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added some stuff to improve workflow
Modified paths:
  • /trunk/extensions/ApprovedRevs/ApprovedRevs.hooks.php (modified) (history)
  • /trunk/extensions/ApprovedRevs/ApprovedRevs.i18n.php (modified) (history)
  • /trunk/extensions/ApprovedRevs/ApprovedRevs.php (modified) (history)
  • /trunk/extensions/ApprovedRevs/ApprovedRevs_body.php (modified) (history)
  • /trunk/extensions/ApprovedRevs/SpecialApprovedRevs.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ApprovedRevs/ApprovedRevs_body.php
@@ -9,6 +9,7 @@
1010 * @author Yaron Koren
1111 */
1212 class ApprovedRevs {
 13+
1314 /**
1415 * Gets the approved revision ID for this page, or null if there isn't
1516 * one.
Index: trunk/extensions/ApprovedRevs/ApprovedRevs.i18n.php
@@ -38,6 +38,10 @@
3939 'approvedrevs-revisionnumber' => 'revision $1',
4040 'approvedrevs-approvedby' => 'approved by $1 on $2',
4141 'approvedrevs-difffromlatest' => 'diff from latest',
 42+ 'approvedrevs-viewlatest' => 'view latest',
 43+ 'approvedrevs-approvelatest' => 'approve latest',
 44+ 'approvedrevs-approvethisrev' => 'Approve this revision',
 45+ 'approvedrevs-viewlatestrev' => 'View the latest revision',
4246 'right-approverevisions' => 'Set a certain revision of a wiki page as approved',
4347 'right-viewlinktolatest' => 'View explanatory text at the top of pages that have an approved revision',
4448 );
Index: trunk/extensions/ApprovedRevs/ApprovedRevs.php
@@ -27,6 +27,7 @@
2828 $egApprovedRevsNamespaces = array( NS_MAIN, NS_TEMPLATE, NS_HELP, NS_PROJECT );
2929 $egApprovedRevsBlankIfUnapproved = false;
3030 $egApprovedRevsAutomaticApprovals = true;
 31+$egApprovedRevsShowApproveLatest = false;
3132
3233 // internationalization
3334 $wgExtensionMessagesFiles['ApprovedRevs'] = $egApprovedRevsIP . 'ApprovedRevs.i18n.php';
@@ -62,6 +63,7 @@
6364 $wgHooks['LoadExtensionSchemaUpdates'][] = 'ApprovedRevsHooks::describeDBSchema';
6465 $wgHooks['EditPage::showEditForm:initial'][] = 'ApprovedRevsHooks::addWarningToEditPage';
6566 $wgHooks['sfHTMLBeforeForm'][] = 'ApprovedRevsHooks::addWarningToSFForm';
 67+$wgHooks['ArticleViewHeader'][] = 'ApprovedRevsHooks::onArticleViewHeader';
6668
6769 // logging
6870 $wgLogTypes['approval'] = 'approval';
Index: trunk/extensions/ApprovedRevs/SpecialApprovedRevs.php
@@ -22,18 +22,22 @@
2323 ApprovedRevs::addCSS();
2424 $this->setHeaders();
2525 list( $limit, $offset ) = wfCheckLimits();
 26+
2627 $mode = $wgRequest->getVal( 'show' );
2728 $rep = new SpecialApprovedRevsPage( $mode );
 29+
2830 if ( method_exists( $rep, 'execute' ) ) {
2931 return $rep->execute( $query );
3032 } else {
3133 return $rep->doQuery( $offset, $limit );
3234 }
3335 }
 36+
3437 }
3538
3639 class SpecialApprovedRevsPage extends QueryPage {
37 - private $mMode;
 40+
 41+ protected $mMode;
3842
3943 public function __construct( $mode ) {
4044 if ( $this instanceof SpecialPage ) {
@@ -56,6 +60,7 @@
5761 $approvedPagesPage = SpecialPage::getPage( 'ApprovedRevs' );
5862 $approvedPagesTitle = SpecialPage::getPage( 'ApprovedRevs' )->getTitle();
5963 $navLine = wfMsg( 'approvedrevs-view' ) . ' ';
 64+
6065 if ( $this->mMode == '' ) {
6166 $navLine .= Xml::element( 'strong',
6267 null,
@@ -67,7 +72,9 @@
6873 wfMsg( 'approvedrevs-approvedpages' )
6974 );
7075 }
71 - $navLine .= " | ";
 76+
 77+ $navLine .= ' | ';
 78+
7279 if ( $this->mMode == 'notlatest' ) {
7380 $navLine .= Xml::element( 'strong',
7481 null,
@@ -79,7 +86,9 @@
8087 wfMsg( 'approvedrevs-notlatestpages' )
8188 );
8289 }
83 - $navLine .= " | ";
 90+
 91+ $navLine .= ' | ';
 92+
8493 if ( $this->mMode == 'unapproved' ) {
8594 $navLine .= Xml::element( 'strong',
8695 null,
@@ -91,8 +100,8 @@
92101 wfMsg( 'approvedrevs-unapprovedpages' )
93102 );
94103 }
95 - $header = Xml::tags( 'p', null, $navLine ) . "\n";
96 - return $header;
 104+
 105+ return Xml::tags( 'p', null, $navLine ) . "\n";
97106 }
98107
99108 /**
@@ -100,12 +109,14 @@
101110 */
102111 function linkParameters() {
103112 $params = array();
 113+
104114 if ( $this->mMode == 'notlatest' ) {
105115 $params['show'] = 'notlatest';
106116 } elseif ( $this->mMode == 'unapproved' ) {
107117 $params['show'] = 'unapproved';
108118 } else { // all approved pages
109119 }
 120+
110121 return $params;
111122 }
112123
@@ -141,7 +152,8 @@
142153 WHERE p.page_latest != ar.rev_id AND $nsCond";
143154 } elseif ( $this->mMode == 'unapproved' ) {
144155 return "SELECT 'Page' AS type,
145 - p.page_id AS id
 156+ p.page_id AS id,
 157+ p.page_latest AS latest_id
146158 FROM $approved_revs ar RIGHT OUTER JOIN $page p
147159 ON ar.page_id = p.page_id
148160 WHERE ar.page_id IS NULL AND $nsCond";
@@ -185,7 +197,7 @@
186198 } elseif ( $this->mMode == 'unapproved' ) {
187199 return array(
188200 'tables' => array( 'ar' => 'approved_revs', 'p' => 'page' ),
189 - 'fields' => array( 'p.page_id AS id' ),
 201+ 'fields' => array( 'p.page_id AS id', 'p.page_latest AS latest_id' ),
190202 'join_conds' => array(
191203 'p' => array(
192204 'RIGHT OUTER JOIN', 'ar.page_id=p.page_id'
@@ -224,10 +236,36 @@
225237
226238 function formatResult( $skin, $result ) {
227239 $title = Title::newFromId( $result->id );
228 - $pageLink = $skin->makeLinkObj( $title );
229240
 241+ // link introduced in 1.16, where makeLinkObj got deprecated
 242+ $pageLink = is_callable( $skin, 'link' ) ? $skin->link( $title ) : $skin->makeLinkObj( $title );
 243+
230244 if ( $this->mMode == 'unapproved' ) {
231 - return $pageLink;
 245+ global $egApprovedRevsShowApproveLatest;
 246+
 247+ $viewLatest = Xml::element( 'a',
 248+ array( 'href' => $title->getLocalUrl(
 249+ array(
 250+ 'oldid' => $result->latest_id
 251+ )
 252+ ) ),
 253+ wfMsg( 'approvedrevs-viewlatest' )
 254+ );
 255+
 256+ $approveLatest = '';
 257+ if ( $egApprovedRevsShowApproveLatest ) {
 258+ $approveLatest = ', ' . Xml::element( 'a',
 259+ array( 'href' => $title->getLocalUrl(
 260+ array(
 261+ 'action' => 'approve',
 262+ 'oldid' => $result->latest_id
 263+ )
 264+ ) ),
 265+ wfMsg( 'approvedrevs-approvelatest' )
 266+ );
 267+ }
 268+
 269+ return "$pageLink ({$viewLatest}{$approveLatest})";
232270 } elseif ( $this->mMode == 'notlatest' ) {
233271 $diffLink = Xml::element( 'a',
234272 array( 'href' => $title->getLocalUrl(
@@ -243,14 +281,10 @@
244282 } else {
245283 global $wgUser, $wgOut, $wgLang;
246284
247 - if ( $result->rev_id == $result->latest_id ) {
248 - $class = "approvedRevIsLatest";
249 - } else {
250 - $class = "approvedRevNotLatest";
251 - }
252 -
253285 $additionalInfo = Xml::element( 'span',
254 - array ( 'class' => $class ),
 286+ array (
 287+ 'class' => $result->rev_id == $result->latest_id ? 'approvedRevIsLatest' : 'approvedRevNotLatest'
 288+ ),
255289 wfMsg( 'approvedrevs-revisionnumber', $result->rev_id )
256290 );
257291
Index: trunk/extensions/ApprovedRevs/ApprovedRevs.hooks.php
@@ -406,6 +406,7 @@
407407 // show the revision, instead of the history page
408408 $article->doPurge();
409409 $article->view();
 410+
410411 return false;
411412 }
412413
@@ -450,6 +451,7 @@
451452 // show the revision, instead of the history page
452453 $article->doPurge();
453454 $article->view();
 455+
454456 return false;
455457 }
456458
@@ -537,4 +539,52 @@
538540 }
539541 return true;
540542 }
 543+
 544+ /**
 545+ * Hook to insert things into article headers.
 546+ *
 547+ * @since 0.5.6
 548+ *
 549+ * @param Article &$article
 550+ * @param boolean $outputDone
 551+ * @param boolean $useParserCache
 552+ *
 553+ * @return true
 554+ */
 555+ public static function onArticleViewHeader( Article &$article, &$outputDone, &$useParserCache ) {
 556+ global $wgOut, $wgRequest, $egApprovedRevsBlankIfUnapproved;
 557+
 558+ if ( ApprovedRevs::pageIsApprovable( $article->getTitle() )
 559+ && $article->getTitle()->userCan( 'approverevisions' ) ) {
 560+
 561+ $approvedId = ApprovedRevs::getApprovedRevID( $article->getTitle() );
 562+
 563+ if ( empty( $approvedId ) || $approvedId != $article->getRevIdFetched() ) {
 564+ if ( $egApprovedRevsBlankIfUnapproved && !$wgRequest->getCheck( 'oldid' ) ) {
 565+ $wgOut->addHTML( Xml::element( 'a',
 566+ array( 'href' => $article->getTitle()->getLocalUrl(
 567+ array(
 568+ 'oldid' => $article->getRevIdFetched()
 569+ )
 570+ ) ),
 571+ wfMsg( 'approvedrevs-viewlatestrev' )
 572+ ) );
 573+ }
 574+ else {
 575+ $wgOut->addHTML( '<b>' . Xml::element( 'a',
 576+ array( 'href' => $article->getTitle()->getLocalUrl(
 577+ array(
 578+ 'action' => 'approve',
 579+ 'oldid' => $article->getRevIdFetched()
 580+ )
 581+ ) ),
 582+ wfMsg( 'approvedrevs-approvethisrev' )
 583+ ) . '</b>' );
 584+ }
 585+ }
 586+ }
 587+
 588+ return true;
 589+ }
 590+
541591 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r82430follow up to r82428jeroendedauw00:31, 19 February 2011

Status & tagging log