r78045 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78044‎ | r78045 | r78046 >
Date:05:37, 8 December 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Adding special page to push multiple pages
Modified paths:
  • /trunk/extensions/Push/Push.i18n.php (modified) (history)
  • /trunk/extensions/Push/Push.php (modified) (history)
  • /trunk/extensions/Push/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/Push/includes/Push_Functions.php (added) (history)
  • /trunk/extensions/Push/includes/Push_Tab.php (modified) (history)
  • /trunk/extensions/Push/specials/Push_Body.php (modified) (history)
  • /trunk/extensions/Push/specials/ext.push.special.js (added) (history)

Diff [purge]

Index: trunk/extensions/Push/Push.i18n.php
@@ -39,4 +39,11 @@
4040
4141 // Special page
4242 'special-push' => 'Push pages',
 43+ 'push-special-description' => 'This page enables you to push content of one or more pages to one or more MediaWiki wikis.
 44+
 45+To push pages, enter the titles in the text box below, one title per line and hit push all. This can take a while to complete.',
 46+ 'push-special-pushing-desc' => 'Pushing pages to $1.',
 47+ 'push-special-button-text' => 'Push pages',
 48+ 'push-special-target-is' => 'Target wiki: $1',
 49+ 'push-special-select-targets' => 'Target wikis:',
4350 );
\ No newline at end of file
Index: trunk/extensions/Push/specials/Push_Body.php
@@ -29,6 +29,16 @@
3030 }
3131
3232 /**
 33+ * Sets headers - this should be called from the execute() method of all derived classes!
 34+ */
 35+ public function setHeaders() {
 36+ global $wgOut;
 37+ $wgOut->setArticleRelated( false );
 38+ $wgOut->setRobotPolicy( "noindex,nofollow" );
 39+ $wgOut->setPageTitle( $this->getDescription() );
 40+ }
 41+
 42+ /**
3343 * Main method.
3444 *
3545 * @since 0.1
@@ -36,17 +46,219 @@
3747 * @param string $arg
3848 */
3949 public function execute( $arg ) {
40 - global $wgOut, $wgUser;
 50+ global $wgOut, $wgUser, $wgRequest, $egPushTargets;
4151
42 - $wgOut->setPageTitle( wfMsg( 'special-push' ) );
 52+ $this->setHeaders();
 53+ $this->outputHeader();
4354
4455 // If the user is authorized, display the page, if not, show an error.
4556 if ( !$this->userCanExecute( $wgUser ) ) {
4657 $this->displayRestrictionError();
4758 return;
4859 }
 60+
 61+ if ( count( $egPushTargets ) == 0 ) {
 62+ $wgOut->addHTML( '<p>' . htmlspecialchars( wfMsg( 'push-tab-no-targets' ) ) . '</p>' );
 63+ return;
 64+ }
4965
 66+ $doPush = false;
 67+
 68+ if ( $wgRequest->getCheck( 'addcat' ) ) {
 69+ $pages = $wgRequest->getText( 'pages' );
 70+ $catname = $wgRequest->getText( 'catname' );
 71+
 72+ if ( $catname !== '' && $catname !== null && $catname !== false ) {
 73+ $t = Title::makeTitleSafe( NS_MAIN, $catname );
 74+ if ( $t ) {
 75+ /**
 76+ * @todo Fixme: this can lead to hitting memory limit for very large
 77+ * categories. Ideally we would do the lookup synchronously
 78+ * during the export in a single query.
 79+ */
 80+ $catpages = $this->getPagesFromCategory( $t );
 81+ if ( $catpages ) $pages .= "\n" . implode( "\n", $catpages );
 82+ }
 83+ }
 84+ }
 85+ else if( $wgRequest->getCheck( 'addns' ) ) {
 86+ $pages = $wgRequest->getText( 'pages' );
 87+ $nsindex = $wgRequest->getText( 'nsindex', '' );
 88+
 89+ if ( strval( $nsindex ) !== '' ) {
 90+ /**
 91+ * Same implementation as above, so same @todo
 92+ */
 93+ $nspages = $this->getPagesFromNamespace( $nsindex );
 94+ if ( $nspages ) $pages .= "\n" . implode( "\n", $nspages );
 95+ }
 96+ }
 97+ else if( $wgRequest->wasPosted() ) {
 98+ $pages = $wgRequest->getText( 'pages' );
 99+ if( $pages != '' ) $doPush= true;
 100+ }
 101+ else {
 102+ $pages = '';
 103+ }
 104+
 105+ if ( $doPush ) {
 106+ $this->doPush();
 107+ }
 108+ else {
 109+ $this->displayPushInterface( $arg, $pages );
 110+ }
 111+ }
 112+
 113+ protected function doPush() {
 114+ global $wgOut, $wgLang;
 115+
 116+ $targets = array();
 117+
50118 // TODO
 119+ $wgOut->addWikiMsg( 'push-special-pushing-desc', $wgLang->listToText( $targets ) );
 120+
 121+ $this->loadJs();
 122+
 123+ // TODO
 124+ }
 125+
 126+ /**
 127+ * @since 0.2
 128+ */
 129+ protected function displayPushInterface( $arg, $pages ) {
 130+ global $wgOut, $wgUser, $wgRequest, $egPushTargets;
 131+
 132+ $wgOut->addWikiMsg( 'push-special-description' );
 133+
 134+ $form = Xml::openElement( 'form', array( 'method' => 'post',
 135+ 'action' => $this->getTitle()->getLocalUrl( 'action=submit' ) ) );
 136+ $form .= Xml::inputLabel( wfMsg( 'export-addcattext' ) , 'catname', 'catname', 40 ) . '&#160;';
 137+ $form .= Xml::submitButton( wfMsg( 'export-addcat' ), array( 'name' => 'addcat' ) ) . '<br />';
 138+
 139+ $form .= Xml::namespaceSelector( $wgRequest->getText( 'nsindex', '' ), null, 'nsindex', wfMsg( 'export-addnstext' ) ) . '&#160;';
 140+ $form .= Xml::submitButton( wfMsg( 'export-addns' ), array( 'name' => 'addns' ) ) . '<br />';
 141+
 142+ $form .= Xml::element( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ), $pages, false );
 143+ $form .= '<br />';
 144+
 145+ $form .= Xml::checkLabel( wfMsg( 'export-templates' ), 'templates', 'wpExportTemplates', false ) . '<br />';
 146+
 147+ if ( count( $egPushTargets ) == 1 ) {
 148+ $names = array_keys( $egPushTargets );
 149+ $form .= '<b>' . htmlspecialchars( wfMsgExt( 'push-special-target-is', 'parsemag', $names[0] ) ) . '</b><br />';
 150+ }
 151+ else {
 152+ $form .= '<b>' . htmlspecialchars( wfMsg( 'push-special-select-targets' ) ) . '</b><br />';
 153+
 154+ foreach ( $egPushTargets as $targetName => $targetUrl ) {
 155+ $form .= Xml::checkLabel( $targetName, $targetName, $targetName, true ) . '<br />';
 156+ }
 157+ }
 158+
 159+ $form .= Xml::submitButton( wfMsg( 'push-special-button-text' ), array( 'style' => 'width: 125px; height: 30px' ) );
 160+ $form .= Xml::closeElement( 'form' );
 161+
 162+ $wgOut->addHTML( $form );
 163+ }
 164+
 165+ /**
 166+ * Returns all pages for a category (up to 5000).
 167+ *
 168+ * @since 0.2
 169+ *
 170+ * @param Title $title
 171+ *
 172+ * @return array
 173+ */
 174+ protected function getPagesFromCategory( Title $title ) {
 175+ global $wgContLang;
 176+
 177+ $name = $title->getDBkey();
 178+
 179+ $dbr = wfGetDB( DB_SLAVE );
 180+ $res = $dbr->select(
 181+ array( 'page', 'categorylinks' ),
 182+ array( 'page_namespace', 'page_title' ),
 183+ array( 'cl_from=page_id', 'cl_to' => $name ),
 184+ __METHOD__,
 185+ array( 'LIMIT' => '5000' )
 186+ );
 187+
 188+ $pages = array();
 189+
 190+ foreach ( $res as $row ) {
 191+ $n = $row->page_title;
 192+ if ($row->page_namespace) {
 193+ $ns = $wgContLang->getNsText( $row->page_namespace );
 194+ $n = $ns . ':' . $n;
 195+ }
 196+
 197+ $pages[] = $n;
 198+ }
 199+ return $pages;
 200+ }
 201+
 202+ /**
 203+ * Returns all pages for a namespace (up to 5000).
 204+ *
 205+ * @since 0.2
 206+ *
 207+ * @param integer $nsindex
 208+ *
 209+ * @return array
 210+ */
 211+ protected function getPagesFromNamespace( $nsindex ) {
 212+ global $wgContLang;
 213+
 214+ $dbr = wfGetDB( DB_SLAVE );
 215+ $res = $dbr->select(
 216+ 'page',
 217+ array( 'page_namespace', 'page_title' ),
 218+ array( 'page_namespace' => $nsindex ),
 219+ __METHOD__,
 220+ array( 'LIMIT' => '5000' )
 221+ );
 222+
 223+ $pages = array();
 224+
 225+ foreach ( $res as $row ) {
 226+ $n = $row->page_title;
 227+
 228+ if ( $row->page_namespace ) {
 229+ $ns = $wgContLang->getNsText( $row->page_namespace );
 230+ $n = $ns . ':' . $n;
 231+ }
 232+
 233+ $pages[] = $n;
 234+ }
 235+ return $pages;
51236 }
 237+
 238+ /**
 239+ * Loads the needed JavaScript.
 240+ * Takes care of non-RL compatibility.
 241+ *
 242+ * @since 0.2
 243+ */
 244+ protected static function loadJs() {
 245+ global $wgOut;
 246+
 247+ // For backward compatibility with MW < 1.17.
 248+ if ( is_callable( array( $wgOut, 'addModules' ) ) ) {
 249+ $wgOut->addModules( 'ext.push.special' );
 250+ }
 251+ else {
 252+ global $egPushScriptPath;
 253+
 254+ PushFunctions::addJSLocalisation();
 255+
 256+ $wgOut->includeJQuery();
 257+
 258+ $wgOut->addHeadItem(
 259+ 'ext.push.special',
 260+ Html::linkedScript( $egPushScriptPath . '/specials/ext.push.special.js' )
 261+ );
 262+ }
 263+ }
52264
53265 }
\ No newline at end of file
Index: trunk/extensions/Push/specials/ext.push.special.js
Property changes on: trunk/extensions/Push/specials/ext.push.special.js
___________________________________________________________________
Added: svn:eol-style
54266 + native
Index: trunk/extensions/Push/Push.php
@@ -22,7 +22,7 @@
2323 die( 'Not an entry point.' );
2424 }
2525
26 -define( 'Push_VERSION', '0.1' );
 26+define( 'Push_VERSION', '0.2 alpha' );
2727
2828 $wgExtensionCredits['other'][] = array(
2929 'path' => __FILE__,
@@ -44,16 +44,17 @@
4545
4646 $wgAutoloadClasses['PushHooks'] = dirname( __FILE__ ) . '/Push.hooks.php';
4747 $wgAutoloadClasses['PushTab'] = dirname( __FILE__ ) . '/includes/Push_Tab.php';
 48+$wgAutoloadClasses['PushFunctions'] = dirname( __FILE__ ) . '/includes/Push_Functions.php';
4849 $wgAutoloadClasses['SpecialPush'] = dirname( __FILE__ ) . '/specials/Push_Body.php';
4950
50 -//$wgSpecialPages['Push'] = 'SpecialPush';
51 -//$wgSpecialPageGroups['Push'] = 'pagetools';
 51+$wgSpecialPages['Push'] = 'SpecialPush';
 52+$wgSpecialPageGroups['Push'] = 'pagetools';
5253
5354 $wgHooks['UnknownAction'][] = 'PushTab::onUnknownAction';
5455 $wgHooks['SkinTemplateTabs'][] = 'PushTab::displayTab';
5556 $wgHooks['SkinTemplateNavigation'][] = 'PushTab::displayTab2';
5657
57 -//$wgHooks['AdminLinks'][] = 'PushHooks::addToAdminLinks';
 58+$wgHooks['AdminLinks'][] = 'PushHooks::addToAdminLinks';
5859
5960 $wgAvailableRights[] = 'push';
6061 $wgAvailableRights[] = 'pushadmin';
@@ -80,19 +81,13 @@
8182 'scripts' => 'includes/ext.push.tab.js',
8283 'dependencies' => array(),
8384 'messages' => $egPushJSMessages
 85+ );
 86+
 87+ $wgResourceModules['ext.push.special'] = $moduleTemplate + array(
 88+ 'scripts' => 'includes/ext.push.special.js',
 89+ 'dependencies' => array(),
 90+ 'messages' => $egPushJSMessages
8491 );
8592 }
8693
87 -function efPushAddJSLocalisation() {
88 - global $egPushJSMessages, $wgOut;
89 -
90 - $data = array();
91 -
92 - foreach ( $egPushJSMessages as $msg ) {
93 - $data[$msg] = wfMsgNoTrans( $msg );
94 - }
95 -
96 - $wgOut->addInlineScript( 'var wgPushMessages = ' . json_encode( $data ) . ';' );
97 -}
98 -
9994 require_once 'Push_Settings.php';
Index: trunk/extensions/Push/RELEASE-NOTES
@@ -4,11 +4,16 @@
55 Latest version of the release notes: http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Push/RELEASE-NOTES?view=co
66
77
8 -== Version 0.1 ==
 8+=== Version 0.2 ===
 9+
 10+* Added Special:Push for bulk pushing
 11+* Added AdminLinks hook
 12+
 13+=== Version 0.1 ===
914 2010-12-08
1015
1116 Initial release.
1217
13 -* Push tab that allows pushing the page to one or more other wikis
14 -* ApprovedRevs support
15 -* 'push' right
\ No newline at end of file
 18+* Added push tab that allows pushing the page to one or more other wikis
 19+* Added ApprovedRevs support
 20+* Added 'push' right
\ No newline at end of file
Index: trunk/extensions/Push/includes/Push_Tab.php
@@ -10,7 +10,6 @@
1111 *
1212 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1313 */
14 -
1514 final class PushTab {
1615
1716 /**
@@ -87,7 +86,7 @@
8887 else {
8988 global $egPushScriptPath;
9089
91 - efPushAddJSLocalisation();
 90+ PushFunctions::addJSLocalisation();
9291
9392 $wgOut->includeJQuery();
9493
Index: trunk/extensions/Push/includes/Push_Functions.php
@@ -0,0 +1,29 @@
 2+<?php
 3+
 4+/**
 5+ * Statis class with utility methods for the Push extension.
 6+ *
 7+ * @since 0.2
 8+ *
 9+ * @file Push_Functions.php
 10+ * @ingroup Push
 11+ *
 12+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 13+ */
 14+final class PushFunctions {
 15+
 16+ public static function addJSLocalisation() {
 17+ global $egPushJSMessages, $wgOut;
 18+
 19+ $data = array();
 20+
 21+ foreach ( $egPushJSMessages as $msg ) {
 22+ $data[$msg] = wfMsgNoTrans( $msg );
 23+ }
 24+
 25+ $wgOut->addInlineScript( 'var wgPushMessages = ' . json_encode( $data ) . ';' );
 26+ }
 27+
 28+
 29+
 30+}
\ No newline at end of file
Property changes on: trunk/extensions/Push/includes/Push_Functions.php
___________________________________________________________________
Added: svn:eol-style
131 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r78048Follow up to r78045jeroendedauw06:09, 8 December 2010

Status & tagging log