r19784 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r19783‎ | r19784 | r19785 >
Date:09:47, 5 February 2007
Author:erik
Status:old
Tags:
Comment:
generic namespace handler support for view, edit, history
fixes
Modified paths:
  • /branches/wikidata/includes/Article.php (modified) (history)
  • /branches/wikidata/includes/DefaultSettings.php (modified) (history)
  • /branches/wikidata/includes/EditPage.php (modified) (history)
  • /branches/wikidata/includes/Namespace.php (modified) (history)
  • /branches/wikidata/includes/NamespaceStore.php (modified) (history)
  • /branches/wikidata/includes/OutputPage.php (modified) (history)
  • /branches/wikidata/includes/PageHistory.php (modified) (history)
  • /branches/wikidata/includes/SpecialNamespaces.php (modified) (history)
  • /branches/wikidata/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: branches/wikidata/includes/Article.php
@@ -604,13 +604,28 @@
605605 function view() {
606606 global $wgUser, $wgOut, $wgRequest, $wgContLang;
607607 global $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol, $wgParser;
608 - global $wgUseTrackbacks, $wgNamespaceRobotPolicies;
 608+ global $wgUseTrackbacks, $wgNamespaceRobotPolicies, $wgTitle;
609609 $sk = $wgUser->getSkin();
610610
611611 wfProfileIn( __METHOD__ );
612612
 613+ # We may want to view this page using a handler class
 614+ $ns=$this->mTitle->getNamespace();
 615+ $handlerClass=Namespace::getHandlerForNamespaceId($ns);
 616+ if(!empty($handlerClass)) {
 617+ $handlerPath=Namespace::getHandlerPathForNamespaceId($ns);
 618+ $hfilename=$handlerPath.$handlerClass.".php";
 619+ if(file_exists($hfilename)) {
 620+ require_once($hfilename);
 621+ $handlerInstance=new $handlerClass();
 622+ $handlerInstance->view();
 623+ return;
 624+ } else {
 625+ $wgOut->showErrorPage('namespace_handler_not_found','namespace_handler_not_found_error',$hfilename,$wgContLang->getFormattedNsText($ns));
 626+ }
 627+ }
 628+
613629 $parserCache =& ParserCache::singleton();
614 - $ns = $this->mTitle->getNamespace(); # shortcut
615630
616631 # Get variables from query string
617632 $oldid = $this->getOldID();
Index: branches/wikidata/includes/NamespaceStore.php
@@ -394,7 +394,7 @@
395395
396396 /**
397397 * Maintain index used by getIndexByName
398 - */
 398+ */
399399 function refreshReverseIndex() {
400400 $this->reverseindex = array();
401401 foreach ($this->nsarray as $ns) {
@@ -665,6 +665,15 @@
666666 function getAllNamespaceObjects( ) {
667667 return $this->nsarray;
668668 }
 669+
 670+ function isContent($id) {
 671+ return $this->nsarray[$id]->isCountable();
 672+ }
 673+ function getHandlerForId($id) {
 674+ return $this->nsarray[$id]->getHandlerClass();
 675+
 676+ }
 677+
669678 }
670679
671680
Index: branches/wikidata/includes/EditPage.php
@@ -290,6 +290,23 @@
291291 wfProfileIn( $fname );
292292 wfDebug( "$fname: enter\n" );
293293
 294+ # We may want to edit this page using a handler class
 295+ $ns=$wgTitle->getNamespace();
 296+ $handlerClass=Namespace::getHandlerForNamespaceId($ns);
 297+ if(!empty($handlerClass)) {
 298+ $handlerPath=Namespace::getHandlerPathForNamespaceId($ns);
 299+ $hfilename=$handlerPath.$handlerClass.".php";
 300+ if(file_exists($hfilename)) {
 301+ require_once($hfilename);
 302+ $handlerInstance=new $handlerClass();
 303+ $handlerInstance->edit();
 304+ return;
 305+ } else {
 306+ $wgOut->showErrorPage('namespace_handler_not_found','namespace_handler_not_found_error',$hfilename,$wgContLang->getFormattedNsText($ns));
 307+ }
 308+ }
 309+
 310+
294311 // this is not an article
295312 $wgOut->setArticleFlag(false);
296313
Index: branches/wikidata/includes/OutputPage.php
@@ -745,12 +745,16 @@
746746 * Outputs a pretty page to explain why the request exploded.
747747 *
748748 * @param string $title Message key for page title.
749 - * @param string $msg Message key for page text.
 749+ * @param string $msg Message key for page text.
 750+ * @param string, string .. (optional) substitutions for $1, $2 .. in the error message.
750751 * @return nothing
751752 */
752753 public function showErrorPage( $title, $msg ) {
753754 global $wgTitle;
754 -
 755+
 756+ # Optional error message substitutions $1, $2 ...
 757+ $args = func_get_args();
 758+ array_shift( $args );
755759 $this->mDebugtext .= 'Original title: ' .
756760 $wgTitle->getPrefixedText() . "\n";
757761 $this->setPageTitle( wfMsg( $title ) );
@@ -761,7 +765,7 @@
762766 $this->mRedirect = '';
763767
764768 $this->mBodytext = '';
765 - $this->addWikiText( wfMsg( $msg ) );
 769+ $this->addWikiText( wfMsg( $msg, $args ) );
766770 $this->returnToMain( false );
767771 }
768772
Index: branches/wikidata/includes/Namespace.php
@@ -640,6 +640,27 @@
641641 return $nsstore->deleteNamespace($this,$deleteSystem);
642642 }
643643
 644+
 645+ static function isContent($id) {
 646+ $nsstore= wfGetNamespaceStore();
 647+ return $nsstore->isContent($id);
 648+ }
 649+
 650+ static function getHandlerForNamespaceId($id) {
 651+ $nsstore=wfGetNamespaceStore();
 652+ return $nsstore->getHandlerForId($id);
 653+ }
 654+
 655+ static function getHandlerPathForNamespaceId($id) {
 656+ global $wgCustomHandlerPath;
 657+ $handler=Namespace::getHandlerForNamespaceId($id);
 658+ if(array_key_exists($handler,$wgCustomHandlerPath)) {
 659+ return $wgCustomHandlerPath[$handler];
 660+ } else {
 661+ return $wgCustomHandlerPath['*'];
 662+ }
 663+ }
 664+
644665 }
645666
646667 ?>
Index: branches/wikidata/includes/DefaultSettings.php
@@ -1012,6 +1012,7 @@
10131013 //$wgGroupPermissions['sysop']['deleterevision'] = true;
10141014 //$wgGroupPermissions['bureaucrat']['hiderevision'] = true;
10151015
 1016+
10161017 /**
10171018 * The developer group is deprecated, but can be activated if need be
10181019 * to use the 'lockdb' and 'unlockdb' special pages. Those require
@@ -1041,7 +1042,6 @@
10421043 $wgNamespaceProtection = array();
10431044 $wgNamespaceProtection[ NS_MEDIAWIKI ] = array( 'editinterface' );
10441045
1045 -
10461046 /**
10471047 * Number of seconds an account is required to age before
10481048 * it's given the implicit 'autoconfirm' group membership.
@@ -2460,4 +2460,21 @@
24612461 */
24622462 $wgEnableCascadingProtection = true;
24632463
 2464+
 2465+/* This will be prepended to all search paths for namespace
 2466+ * handler files, followed by the name of the handler as a filename.
 2467+ * Something like:
 2468+ *
 2469+ * /var/www/mywiki/extensions/CustomEditor.php
 2470+ *
 2471+ * You can change this on a per-handler basis, relative to the
 2472+ * path above (begin without slash, terminate with slash).
 2473+ * Use '*' as a HandlerName to define he default path which
 2474+ * will be used for all handlers which are not specifically set.
 2475+ *
 2476+ * Must be slash-terminated.
 2477+ *
 2478+ */
 2479+$wgCustomHandlerPath = array('*'=>"{$IP}/extensions/");
 2480+
24642481 ?>
Index: branches/wikidata/includes/PageHistory.php
@@ -59,6 +59,22 @@
6060 $fname = 'PageHistory::history';
6161 wfProfileIn( $fname );
6262
 63+ # We may want to view this page using a handler class
 64+ $ns=$this->mTitle->getNamespace();
 65+ $handlerClass=Namespace::getHandlerForNamespaceId($ns);
 66+ if(!empty($handlerClass)) {
 67+ $handlerPath=Namespace::getHandlerPathForNamespaceId($ns);
 68+ $hfilename=$handlerPath.$handlerClass.".php";
 69+ if(file_exists($hfilename)) {
 70+ require_once($hfilename);
 71+ $handlerInstance=new $handlerClass();
 72+ $handlerInstance->history();
 73+ return;
 74+ } else {
 75+ $wgOut->showErrorPage('namespace_handler_not_found','namespace_handler_not_found_error',$hfilename,$wgContLang->getFormattedNsText($ns));
 76+ }
 77+ }
 78+
6379 /*
6480 * Setup page variables.
6581 */
Index: branches/wikidata/includes/SpecialNamespaces.php
@@ -784,7 +784,7 @@
785785 $nsobj = $nsstore->getNamespaceObjectByIndex($targetid);
786786
787787 $talktargetid=$nsobj->getTalk();
788 - $talk4nsobj=$nsstore->getNamespaceObjectByIndex($targettalkid);
 788+ $talk4nsobj=$nsstore->getNamespaceObjectByIndex($talktargetid);
789789
790790 if($converttalk && is_null($talktargetid)) {
791791 $this->showForm (wfMsg('pseudonamespace_target_talk_not_found'));
@@ -823,8 +823,9 @@
824824 $this->showForm();
825825 }
826826 function showPseudoError($rv,$targetid,$prefix) {
827 - global $wgNamespaces;
828 - $istalk=$wgNamespaces[$targetid]->isTalk();
 827+ $nsstore = wfGetNamespaceStore();
 828+ $targetobj=$nsstore->getNamespaceObjectByIndex($targetid);
 829+ $istalk=$targetobj->isTalk();
829830 # For messages
830831 $talk=$istalk ? 'talk_' : '';
831832 if($rv[NS_RESULT]==NS_PSEUDO_NOT_FOUND) {
@@ -836,7 +837,7 @@
837838 } elseif($rv[NS_RESULT]==NS_DUPLICATE_TITLES) {
838839 $this->showForm(
839840 wfMsg("pseudonamespace_{$talk}conversion_error",$prefix),
840 - $this->pseudoDupes($wgNamespaces[$targetid]->getDefaultName(),$rv[NS_DUPLICATE_TITLE_LIST]));
 841+ $this->pseudoDupes($targetobj->getDefaultName(),$rv[NS_DUPLICATE_TITLE_LIST]));
841842 }
842843 }
843844
Index: branches/wikidata/languages/messages/MessagesEn.php
@@ -2865,6 +2865,8 @@
28662866 'namespace_not_deletable'=>'The namespace cannot be deleted.',
28672867 'namespace_has_gone_missing'=>'A namespace with the number $1 was not found.',
28682868 'namespace_not_deletable_system'=>'The namespace with the number $1 is a system namespace which is required for the operation of MediaWiki.',
 2869+'namespace_handler_not_found'=>'Namespace handler not found!',
 2870+'namespace_handler_not_found_error'=>'This page requires a special handler to view, expected in the directory \'$1\'! Please make sure that this file is present before viewing pages of the type \'$2\'.',
28692871
28702872 );
28712873